diff --git a/src/moon/ui/screens/moon-test.cpp b/src/moon/ui/screens/moon-test.cpp index 1e985016..855ebf6f 100644 --- a/src/moon/ui/screens/moon-test.cpp +++ b/src/moon/ui/screens/moon-test.cpp @@ -25,19 +25,30 @@ void MoonTest::Init(){ //printf("%s\n", res.body.c_str()); MoonScreen::Init(); } -bool b = true; -bool c = true; -bool d = true; -float e = 0; +bool b = true; +float e = 0; int bIndex = 0; + +int rIndex = 0; + vector test = {"Val zero", "Val uwo", "Val owu"}; +vector randomize = {"owo", "awa", "uwu", "wololo", "idk"}; + +MWValue * testBtn; + +void testF(){ + rIndex = rand() % randomize.size(); + testBtn->title = randomize[rIndex]; + cout << rIndex << endl; +} void MoonTest::Mount(){ - this->widgets.clear(); - this->widgets.push_back(new MWValue({.index = &bIndex, .values = &test}, "Toggle 3 owo", 25, 95)); - this->widgets.push_back(new MWValue({.bvar = &b}, "Toggle owo", 25, 55)); - this->widgets.push_back(new MWValue({.fvar = &e, .max = 10, .min = 0, .step = 0.1f}, "Toggle 2 owo", 25, 75)); + this->widgets.clear(); + this->widgets.push_back(new MWValue(22, 57, "Bool:", {.bvar = &b})); + this->widgets.push_back(new MWValue(22, 74, "Number:", {.fvar = &e, .max = 10, .min = 0, .step = 0.1f})); + this->widgets.push_back(new MWValue(22, 91, "Array:", {.index = &bIndex, .values = &test})); + this->widgets.push_back(testBtn = new MWValue(22, 108, "Randomize", {.btn = testF})); MoonScreen::Mount(); } @@ -45,7 +56,7 @@ int x = 0; int y = 20; void MoonTest::Draw(){ - MoonDrawText(0, 0, "Test text", 1.0, {255, 255, 255, 255}, true, false); + MoonDrawText(0, 0, "Hi uwu", 0.5, {255, 255, 255, 255}, true, false); string menuTitle = "Placeholder"; float txtWidth = MoonGetTextWidth(menuTitle, 1.0, true); diff --git a/src/moon/ui/utils/moon-draw-utils.cpp b/src/moon/ui/utils/moon-draw-utils.cpp index e558046e..e76e2acc 100644 --- a/src/moon/ui/utils/moon-draw-utils.cpp +++ b/src/moon/ui/utils/moon-draw-utils.cpp @@ -11,7 +11,7 @@ void MoonDrawText(float x, float y, std::string text, float scale, struct Color gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); if(dropShadow){ gDPSetEnvColor(gDisplayListHead++, 10, 10, 10, 255); - moon_draw_text(x, SCREEN_HEIGHT - y - 1, getTranslatedText(text.c_str()), scale); + moon_draw_text(x, SCREEN_HEIGHT - y - 1 * scale, getTranslatedText(text.c_str()), scale); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255); } gDPSetEnvColor(gDisplayListHead++, color.r, color.g, color.b, color.a); diff --git a/src/moon/ui/widgets/mw-value.cpp b/src/moon/ui/widgets/mw-value.cpp index bb947ba6..1352ed3f 100644 --- a/src/moon/ui/widgets/mw-value.cpp +++ b/src/moon/ui/widgets/mw-value.cpp @@ -9,26 +9,40 @@ using namespace std; bool mwvStickExecuted; -MWValue::MWValue(MWValueBind bind, std::string title, float x, float y){ +MWValue::MWValue(float x, float y, std::string title, MWValueBind bind){ this->x = x; this->y = y; this->bind = bind; this->title = title; } +int focusAnimRange = 80; +float focusAnimation = focusAnimRange / 2; +int focusAnimationPingPong; + void MWValue::Init(){ mwvStickExecuted = false; } + void MWValue::Draw(){ + + float step = 0.6; + + if(focusAnimation >= focusAnimRange) + focusAnimationPingPong = 1; + else if (focusAnimation <= focusAnimRange / 2) + focusAnimationPingPong = 0; + + focusAnimation += step * (focusAnimationPingPong ? -1 : 1); + float scale = 1; float titleWidth = MoonGetTextWidth(this->title + " ", scale, false); - int barWidth = SCREEN_WIDTH - 50 - 20; + int barWidth = SCREEN_WIDTH - 50 - 14; float tmpWidth = titleWidth; - Color focusColors[] = { - {255, 255, 255, 80}, - {255, 247, 0, 80}, + {255, 255, 255, 40 + focusAnimation / 2}, + {255, 247, 0, 40 + focusAnimation / 2}, {0, 0, 0, 0}, }; @@ -39,9 +53,9 @@ void MWValue::Draw(){ if(this->bind.bvar != NULL){ bool status = *this->bind.bvar; - Color toggleColors[] = { - {32, 255, 3, 255}, - {255, 32, 3, 255} + Color toggleColors[] = { + {61, 255, 113, 255}, + {255, 61, 61, 255} }; string statusText = status ? Moon_GetKey("TEXT_OPT_ENABLED") : Moon_GetKey("TEXT_OPT_DISABLED"); @@ -53,17 +67,20 @@ void MWValue::Draw(){ string text = (*this->bind.values)[index]; tmpWidth += MoonGetTextWidth(text, scale, false); - MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2 + titleWidth, this->y, text, scale, {100, 100, 255, 255}, true, true); + MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2 + titleWidth, this->y, text, scale, {58, 249, 252, 255}, true, true); } else if(isFloat || isInt){ float value = isFloat ? *this->bind.fvar : *this->bind.ivar; float max = this->bind.max; - string text = to_string((int)(100 * (value / max))) + " %"; + string text = to_string((int)(100 * (value / max))) + "%"; tmpWidth += MoonGetTextWidth(text, scale, false); - MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2 + titleWidth, this->y, text, scale, {100, 100, 255, 255}, true, true); + MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2 + titleWidth, this->y, text, scale, {58, 249, 252, 255}, true, true); } + if(this->bind.btn != NULL) + tmpWidth = titleWidth; + MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2, this->y, this->title, scale, {255, 255, 255, 255}, true, true); } @@ -71,24 +88,27 @@ void MWValue::Update(){ if(!this->focused) return; float xStick = GetStickValue(MoonButtons::L_STICK, false); - bool isBool = this->bind.bvar != NULL; + bool isBool = this->bind.bvar != NULL; bool isArray = this->bind.values != NULL && this->bind.index != NULL; - - bool isFloat = this->bind.fvar != NULL; - bool isInt = this->bind.ivar != NULL; + bool isFloat = this->bind.fvar != NULL; + bool isInt = this->bind.ivar != NULL; + bool isBtn = this->bind.btn != NULL; float maxValue = isArray ? (*this->bind.values).size() - 1 : this->bind.max; float minValue = isArray ? 0 : this->bind.min; float step = isArray ? 1 : this->bind.step; + if(isBtn && IsBtnPressed(MoonButtons::A_BTN)){ + this->bind.btn(); + return; + } + if(xStick < 0) { if(mwvStickExecuted) return; if(isBool) { *this->bind.bvar = !*this->bind.bvar; - std::cout << "Executed" << std::endl; } else if(isArray || isFloat || isInt) { - float cIndex = isArray ? (int) *this->bind.index : isFloat ? *this->bind.fvar : *this->bind.ivar; - cout << "Test" << endl; + float cIndex = isArray ? (int) *this->bind.index : isFloat ? *this->bind.fvar : *this->bind.ivar; if(cIndex > minValue){ if(isArray) *this->bind.index -= (int)step; if(isFloat) *this->bind.fvar -= step; @@ -97,8 +117,7 @@ void MWValue::Update(){ if(isArray) *this->bind.index = (int)maxValue; if(isFloat) *this->bind.fvar = maxValue; if(isInt) *this->bind.ivar = (int)maxValue; - } - std::cout << "Executed x2" << std::endl; + } } mwvStickExecuted = true; } @@ -118,7 +137,6 @@ void MWValue::Update(){ if(isFloat) *this->bind.fvar = minValue; if(isInt) *this->bind.ivar = (int)minValue; } - std::cout << "Executed x3" << std::endl; } mwvStickExecuted = true; } diff --git a/src/moon/ui/widgets/mw-value.h b/src/moon/ui/widgets/mw-value.h index 98429eaf..e5938050 100644 --- a/src/moon/ui/widgets/mw-value.h +++ b/src/moon/ui/widgets/mw-value.h @@ -13,17 +13,17 @@ struct MWValueBind{ float max; float min; float step; + void (*btn)(); int *index; std::vector* values; }; class MWValue : public MoonWidget { - private: + public: MWValueBind bind; std::string title; - public: - MWValue(MWValueBind bind, std::string title, float x, float y); + MWValue(float x, float y, std::string title, MWValueBind bind); void Init(); void Draw(); void Update(); diff --git a/src/moon/utils/moon-gfx.c b/src/moon/utils/moon-gfx.c index 11518114..60ac2dd8 100644 --- a/src/moon/utils/moon-gfx.c +++ b/src/moon/utils/moon-gfx.c @@ -45,7 +45,7 @@ void moon_draw_text(f32 x, f32 y, const u8 *str, float scale) { UNUSED s8 mark = DIALOG_MARK_NONE; s32 strPos = 0; u8 lineNum = 1; - y -= 16; + y -= 16 * scale; Mtx *_Matrix = (Mtx *) alloc_display_list(sizeof(Mtx)); if (!_Matrix) return;