- Renderer now vould use more screen Objects - Register default Top and Bottom Screens (for Overlays and UI7) - Make ToHex an Inline header func - Add GetCompilerVersion - Add Library Compile And Version Info to common - Remove z of vertex object and shader in position - Add Container base and SubContainers to UI7 - Add abillity to Join Multiple Objects in Same Line and Center them - Fix LayerOrder Bug for updating texts in DrawList
124 lines
3.8 KiB
C++
124 lines
3.8 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) {
|
|
ren->OnScreen(ren->GetScreen(false));
|
|
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
|