palladium/source/overlays/message_mgr.cpp
tobid7 b4a4b6a426 # Rewrite Stage 1.5
- Added Overlays (Performance / Keyboaed)
- Keyboard has Gamepad Movement WIP (kinda)
- Work on UI7 Started
- Added Input Manager
- Added Message Boxes (Animated)
- Added Signle Header Tween func for animated stuff (Keyboard Messages, etc)
- Add FastHash (Maybe useful later)
- Using const & for vec in lithium
- Add ability to copy a command by a Ref
- Make Lists in Commands OpenAccess for Modification (StaticObject)
- Add Static Object (System to PreRender Suff that never changes) but can still be recolored or moved
- Add Layer and Font change functions
- Make Renderer Tools (RotateCorner, CreateRect, CreateLine, InBox, OptiCommandList) static (OpenAccess)
- Add ReIndexing to PushCommand
- Add Ability to Init vec3 and vec4 with vec2 and add .xy and .zw to vec4
- Fully Animated Keyboard that currently has problem of Top Down GamePad movement
- Add Func to Get GamePad Icon Codepoints for TextRenderer
- Made deltatime a float
- Using filesystem::path().wstring for convertation (works)
- Add a New InBox to Renderer that only checks if a point is inside a boundingbox
- Disable Font loading on Renderer Init due to 3ds Freezes when using SystemFont
- Make SystemFont lineheight 10% larger than it is to be nearly the same size as the ttf fonts
- Fix Some SpaceOffsets between TTF and SystemFont Rendering
- Cleanup the Update Rendermode Func
- Use LayerRenderSystem by default now as it now runs faster even with ttf fonts
2025-01-19 20:16:43 +01:00

126 lines
3.9 KiB
C++

#include <pd/overlays/message_mgr.hpp>
namespace PD {
MessageMgr::Container::Container(const std::string& title,
const std::string& msg) {
this->title = title;
this->msg = msg;
size = vec2(150, 50);
// Precalculate colors
col_bg = PD::Color("#111111aa");
col_text = PD::Color("#ffffff");
// Setup Flyin Animation
FlyIn();
}
void MessageMgr::Container::Render(PD::LI::Renderer::Ref ren) {
// Create a Temp var to not recalculate
// the position everytime we use it
// even if the calculation would always
// result in the same we would waste a lot
// of cpu performance which is a big issue
// espeacilly on the Old3ds...
vec2 tpos = pos;
// Check if it goes out of screen
// Instant kills cause it will never be on
// Screen agains
if (tpos[1] + size[1] < 0) {
kill = true;
}
// If should be removed modify the color by fade
// Use a temp var as well to not call it twice
if (tbr) {
float f = 1.f - pos.Progress();
col_bg.a(col_bg.a() * f);
col_text.a(col_text.a() * f);
}
// Create a backup Layer to Render
// Text onto the next layer
int l = ren->Layer();
ren->DrawRectSolid(tpos, size, col_bg);
ren->Layer(l + 1);
ren->DrawText(tpos + vec2(4, 2), col_text, title);
ren->DrawText(tpos + vec2(4, 16), col_text, msg);
ren->Layer(l);
}
void MessageMgr::Container::Update(int slot, float delta) {
// Increase lifetime
lifetime += delta / 1000.f;
// Trigger move up Animation if
// the slot got changed
if (s != slot) {
ToBeMoved(slot);
s = slot;
}
// Update the animations
pos.Update(delta);
// Trigger the remove Event if lifetime
// goes beyond 4 secods
if (lifetime > 4 && !tbr) {
ToBeRemoved();
}
}
void MessageMgr::Container::FlyIn() {
// Come from out of the screen to 5, 185 into
// The screen as EaseInSine in 0.5 seconds
pos.From(vec2(-size[0], 240 - size[1] - 5))
.To(vec2(5, 240 - size[1] - 5))
.In(0.5)
.As(pos.EaseInSine);
}
void MessageMgr::Container::ToBeMoved(int slot) {
// Bit more special
// Get the current pos as temp one
vec2 tpos = pos;
// Calculate a temp Startpos which
// is the endpos of Flyin if
// it is fully playd (see next comment)
float spos = 240 - size[1] - 5;
// Now from the Current Position Move up by
// The Number of slot * the size.y + 5
// and make sure it flys diagonal if the
// Flyin hasn't ended yet. This animation uses EaseInSine
// And does it's move in 0.4 seconds to not have
// The new one and this one in collision for to much time
pos.From(tpos)
.To(vec2(5, spos - slot * (size[1] + 5)))
.As(pos.EaseInSine)
.In(0.4);
}
void MessageMgr::Container::ToBeRemoved() {
// This effect uses EaseOutSine and as well uses the fade anim
tbr = true;
// We Force set the Position to Finished to avoid collision
// to the ToBeMoved Animation And then set an EaseOutSine in 0.5
// seconds to move the Message 30 pixels up while fading out
pos.Finish();
vec2 tpos = pos;
pos.From(tpos).To(tpos - vec2(0, 30)).As(pos.EaseOutSine).In(0.5);
}
void MessageMgr::Push(const std::string& title, const std::string& text) {
// Simply Add a New Message Container
msgs.push_back(Container::New(title, text));
}
void MessageMgr::Update(float delta) {
// Go two layers up and Render on Top
ren->Layer(ren->Layer() + 2);
ren->OnScreen(Screen::Top);
for (size_t i = 0; i < msgs.size(); i++) {
// Update the Animation Handlers and Move older
// Messages up if a new one got pushed
msgs[i]->Update(msgs.size() - i - 1, delta);
msgs[i]->Render(ren);
}
/// OMG HE LOOPS TWICE OVER THE OBJECTS TO
/// CHECK IF THEY CAN BE REMOVED WOW.......
/// Just my Stupid fix for the flickering
/// Of the other messages if one get's removed
for (size_t i = 0; i < msgs.size(); i++) {
if (msgs[i]->ShouldBeRemoved()) {
msgs.erase(msgs.begin() + i);
}
}
}
} // namespace PD