[WIP] Changed colors and added scale fix

This commit is contained in:
KiritoDev 2021-05-03 06:14:44 -05:00
parent 671af8b836
commit 239c9c1be5
5 changed files with 64 additions and 35 deletions

View File

@ -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<string> test = {"Val zero", "Val uwo", "Val owu"};
vector<string> 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);

View File

@ -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);

View File

@ -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;
}

View File

@ -13,17 +13,17 @@ struct MWValueBind{
float max;
float min;
float step;
void (*btn)();
int *index;
std::vector<std::string>* 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();

View File

@ -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;