mirror of https://github.com/sm64pc/sm64pc.git
[WIP] Added MWValue widget and fixes on the screen manager
This commit is contained in:
parent
abd0821422
commit
8b08b97160
|
@ -447,7 +447,7 @@ static void optmenu_draw_opt(const struct Option *opt, s16 x, s16 y, u8 sel) {
|
|||
int width;
|
||||
u8* tmpText;
|
||||
u8 buf[32] = { 0 };
|
||||
float scale = 0.8f;
|
||||
float scale = 0.9f;
|
||||
|
||||
if(opt->type == OPT_TOGGLE || opt->type == OPT_CHOICE) {
|
||||
lbl = base;
|
||||
|
|
|
@ -18,7 +18,7 @@ void moon_init_languages(char *executable, char *gamedir) {
|
|||
}
|
||||
|
||||
u8 * moon_language_get_key( char* key ){
|
||||
return Moon_GetKey(std::string(key));
|
||||
return getTranslatedText(Moon_GetKey(std::string(key)).c_str());
|
||||
}
|
||||
|
||||
void moon_set_language( int id ) {
|
||||
|
|
|
@ -103,16 +103,16 @@ void Moon_LoadLanguage( string path ) {
|
|||
language->courses.insert(language->courses.end(), &tmpCourses[0], &tmpCourses[course_name_table_size]);
|
||||
|
||||
for (WValue::ConstMemberIterator option = options.MemberBegin(); option != options.MemberEnd(); ++option) {
|
||||
language->strings.insert(pair<string, u8*>(
|
||||
language->strings.insert(pair<string, string>(
|
||||
narrow(option->name.GetString()),
|
||||
getTranslatedText(narrow(option->value.GetString()).c_str())
|
||||
narrow(option->value.GetString())
|
||||
));
|
||||
}
|
||||
|
||||
for (WValue::ConstMemberIterator item = strings.MemberBegin(); item != strings.MemberEnd(); ++item) {
|
||||
language->strings.insert(pair<string, u8*>(
|
||||
language->strings.insert(pair<string, string>(
|
||||
narrow(item->name.GetString()),
|
||||
getTranslatedText(narrow(item->value.GetString()).c_str())
|
||||
narrow(item->value.GetString())
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ void Moon_LoadLanguage( string path ) {
|
|||
languagesAmount = languages.size();
|
||||
}
|
||||
|
||||
u8 *Moon_GetKey(string key) {
|
||||
string Moon_GetKey(string key) {
|
||||
return current->strings[key];
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ inline std::string narrow (const std::wstring& str) {
|
|||
struct LanguageEntry {
|
||||
std::string name;
|
||||
std::string logo;
|
||||
std::map<std::string, u8*> strings;
|
||||
std::map<std::string, std::string> strings;
|
||||
std::vector<u8*> acts;
|
||||
std::vector<struct DialogEntry*> dialogs;
|
||||
std::vector<u8*> courses;
|
||||
|
@ -38,7 +38,7 @@ extern std::vector<LanguageEntry*> languages;
|
|||
|
||||
void Moon_LoadLanguage( std::string path );
|
||||
void Moon_InitLanguages( char *exePath, char *gamedir ) ;
|
||||
u8 * Moon_GetKey(std::string key);
|
||||
std::string Moon_GetKey(std::string key);
|
||||
void Moon_SetLanguage(LanguageEntry *new_language);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,12 +36,9 @@ void MoonScreen::Draw(){
|
|||
bool stickExecuted;
|
||||
|
||||
void MoonScreen::Update(){
|
||||
this->screenWidth = GFX_DIMENSIONS_ASPECT_RATIO > 1 ? SCREEN_WIDTH + abs(GFX_DIMENSIONS_FROM_LEFT_EDGE(0)) * 2 : SCREEN_WIDTH;
|
||||
this->screenHeight = SCREEN_HEIGHT;
|
||||
if(this->enabledWidgets) {
|
||||
|
||||
float xStick = this->GetValue(MoonButtons::L_STICK, false);
|
||||
float yStick = this->GetValue(MoonButtons::U_STICK, false);
|
||||
|
||||
float yStick = GetStickValue(MoonButtons::U_STICK, false);
|
||||
|
||||
if(!this->widgets.empty()){
|
||||
if(yStick > 0) {
|
||||
|
@ -68,12 +65,12 @@ void MoonScreen::Update(){
|
|||
}
|
||||
if(!yStick)
|
||||
stickExecuted = false;
|
||||
if(this->IsPressed(MoonButtons::A_BTN)) {
|
||||
if(IsBtnPressed(MoonButtons::A_BTN)) {
|
||||
this->selected = this->widgets[this->scrollIndex];
|
||||
this->selected->selected = false;
|
||||
this->selected->focused = true;
|
||||
}
|
||||
if(this->IsPressed(MoonButtons::B_BTN)) {
|
||||
if(IsBtnPressed(MoonButtons::B_BTN)) {
|
||||
if(this->selected != NULL){
|
||||
this->selected->selected = true;
|
||||
this->selected->focused = false;
|
||||
|
@ -92,15 +89,15 @@ void MoonScreen::Dispose(){
|
|||
widgets[i]->Dispose();
|
||||
}
|
||||
|
||||
bool MoonScreen::IsPressed(MoonButtons button){
|
||||
bool IsBtnPressed(MoonButtons button){
|
||||
return gPlayer1Controller->buttonPressed & button;
|
||||
}
|
||||
|
||||
bool MoonScreen::IsDown(MoonButtons button){
|
||||
bool IsBtnDown(MoonButtons button){
|
||||
return gPlayer1Controller->buttonDown & button;
|
||||
}
|
||||
|
||||
float MoonScreen::GetValue(MoonButtons button, bool absolute){
|
||||
float GetStickValue(MoonButtons button, bool absolute){
|
||||
switch(button){
|
||||
case MoonButtons::L_STICK:
|
||||
case MoonButtons::R_STICK:
|
||||
|
@ -111,4 +108,12 @@ float MoonScreen::GetValue(MoonButtons button, bool absolute){
|
|||
default:
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
float GetScreenWidth(bool u4_3){
|
||||
return GFX_DIMENSIONS_ASPECT_RATIO > 1 || u4_3 ? SCREEN_WIDTH + abs(GFX_DIMENSIONS_FROM_LEFT_EDGE(0)) * 2 : SCREEN_WIDTH;
|
||||
}
|
||||
|
||||
float GetScreenHeight() {
|
||||
return SCREEN_HEIGHT;
|
||||
}
|
|
@ -26,11 +26,13 @@ public:
|
|||
virtual void Draw();
|
||||
virtual void Update();
|
||||
virtual void Dispose();
|
||||
bool IsPressed(MoonButtons button);
|
||||
bool IsDown(MoonButtons button);
|
||||
float GetValue(MoonButtons button, bool absolute);
|
||||
float screenWidth;
|
||||
float screenHeight;
|
||||
};
|
||||
|
||||
bool IsBtnPressed(MoonButtons button);
|
||||
bool IsBtnDown(MoonButtons button);
|
||||
float GetStickValue(MoonButtons button, bool absolute);
|
||||
|
||||
float GetScreenWidth(bool u4_3);
|
||||
float GetScreenHeight();
|
||||
|
||||
#endif
|
|
@ -3,7 +3,7 @@
|
|||
#include "moon/ui/utils/moon-draw-utils.h"
|
||||
#include "moon/ui/moon-ui-manager.h"
|
||||
#include "moon/network/moon-consumer.h"
|
||||
|
||||
#include "moon/texts/moon-loader.h"
|
||||
#include "moon/ui/widgets/mw-value.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -25,47 +25,28 @@ void MoonTest::Init(){
|
|||
//printf("%s\n", res.body.c_str());
|
||||
MoonScreen::Init();
|
||||
}
|
||||
bool b = true;
|
||||
bool c = true;
|
||||
bool d = true;
|
||||
|
||||
void MoonTest::Mount(){
|
||||
this->widgets.clear();
|
||||
int a = 25;
|
||||
this->widgets.push_back(new MWValue(&a, 0, 20, MWValueType::INT));
|
||||
this->widgets.push_back(new MWValue(&a, 0, 40, MWValueType::INT));
|
||||
this->widgets.push_back(new MWValue(&a, 0, 60, MWValueType::INT));
|
||||
this->widgets.push_back(new MWValue(&a, 0, 80, MWValueType::INT));
|
||||
|
||||
this->widgets.clear();
|
||||
this->widgets.push_back(new MWValue({.bvar = &b}, "Toggle owo", 25, 50));
|
||||
this->widgets.push_back(new MWValue({.bvar = &c}, "Toggle 2 owo", 25, 70));
|
||||
MoonScreen::Mount();
|
||||
}
|
||||
|
||||
int x = 0;
|
||||
int y = 30;
|
||||
int y = 20;
|
||||
|
||||
void MoonTest::Draw(){
|
||||
|
||||
//if(this->IsDown(MoonButtons::L_CBTN)){
|
||||
// x -= 1;
|
||||
//}
|
||||
|
||||
//if(this->IsDown(MoonButtons::R_CBTN)){
|
||||
// x += 1;
|
||||
//}
|
||||
//
|
||||
//if(this->IsDown(MoonButtons::U_CBTN)){
|
||||
// y -= 1;
|
||||
//}
|
||||
|
||||
//if(this->IsDown(MoonButtons::D_CBTN)){
|
||||
// y += 1;
|
||||
//}
|
||||
|
||||
string test = "Placeholder";
|
||||
float txtWidth = MoonGetTextWidth(test, 1.0, false);
|
||||
MoonDrawRectangle(0, 0, this->screenWidth, this->screenHeight, {0, 0, 0, 255}, false);
|
||||
MoonDrawText(this->screenWidth / 2 - txtWidth / 2, y, test, 1.0, {255, 255, 255, 255}, false);
|
||||
// MoonDrawText(0, 40, test, 1.0, {255, 255, 255, 255}, false);
|
||||
//MoonDrawColoredText(0, 50, "This is a test owo", 1.0, {255, 255, 255, 255}, false);
|
||||
|
||||
// std::cout << this->screenWidth << " : " << GFX_DIMENSIONS_ASPECT_RATIO << std::endl;
|
||||
MoonDrawText(0, 0, "Test text", 1.0, {255, 255, 255, 255}, true, false);
|
||||
|
||||
string menuTitle = "Placeholder";
|
||||
float txtWidth = MoonGetTextWidth(menuTitle, 1.0, true);
|
||||
MoonDrawRectangle(0, 0, GetScreenWidth(false), GetScreenHeight(), {0, 0, 0, 100}, false);
|
||||
MoonDrawColoredText(SCREEN_WIDTH / 2 - txtWidth / 2, 20, menuTitle, 1.0, {255, 255, 255, 255}, true, true);
|
||||
MoonDrawRectangle(25, 50, SCREEN_WIDTH - 50, GetScreenHeight() * 0.6, {0, 0, 0, 100}, true);
|
||||
MoonScreen::Draw();
|
||||
}
|
|
@ -6,22 +6,31 @@ float MoonGetTextWidth(std::string text, float scale, bool colored) {
|
|||
return (float)moon_get_text_width(getTranslatedText(text.c_str()), scale, colored);
|
||||
}
|
||||
|
||||
void MoonDrawText(float x, float y, std::string text, float scale, struct Color color, bool u4_3){
|
||||
void MoonDrawText(float x, float y, std::string text, float scale, struct Color color, bool dropShadow, bool u4_3){
|
||||
if(!u4_3) x = GFX_DIMENSIONS_FROM_LEFT_EDGE(x);
|
||||
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);
|
||||
gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255);
|
||||
}
|
||||
gDPSetEnvColor(gDisplayListHead++, color.r, color.g, color.b, color.a);
|
||||
moon_draw_text(x, SCREEN_HEIGHT - y, getTranslatedText(text.c_str()), scale);
|
||||
gSPDisplayList(gDisplayListHead++, dl_ia_text_end);
|
||||
gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
void MoonDrawColoredText(float x, float y, std::string text, float scale, struct Color color, bool u4_3){
|
||||
void MoonDrawColoredText(float x, float y, std::string text, float scale, struct Color color, bool dropShadow, bool u4_3){
|
||||
if(!u4_3) x = GFX_DIMENSIONS_FROM_LEFT_EDGE(x);
|
||||
|
||||
gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin);
|
||||
gDPSetEnvColor(gDisplayListHead++, color.r, color.g, color.b, color.a);
|
||||
std::transform(text.begin(), text.end(), text.begin(), ::toupper);
|
||||
moon_draw_colored_text(x, y, getTranslatedText(text.c_str()), scale);
|
||||
if(dropShadow){
|
||||
moon_draw_colored_text(x, y + 1, getTranslatedText(text.c_str()), scale, {10, 10, 10, 255});
|
||||
}
|
||||
gDPSetEnvColor(gDisplayListHead++, color.r, color.g, color.b, color.a);
|
||||
struct Color white = { 255, 255, 255, 255 };
|
||||
moon_draw_colored_text(x, y, getTranslatedText(text.c_str()), scale, white);
|
||||
gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end);
|
||||
gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255);
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ extern "C" {
|
|||
#include "text/txtconv.h"
|
||||
}
|
||||
float MoonGetTextWidth (std::string text, float scale, bool colored);
|
||||
void MoonDrawText (float x, float y, std::string text, float scale, struct Color color, bool u4_3);
|
||||
void MoonDrawColoredText(float x, float y, std::string text, float scale, struct Color color, bool u4_3);
|
||||
void MoonDrawText (float x, float y, std::string text, float scale, struct Color color, bool dropShadow, bool u4_3);
|
||||
void MoonDrawColoredText(float x, float y, std::string text, float scale, struct Color color, bool dropShadow, bool u4_3);
|
||||
void MoonDrawRectangle (float x, float y, float w, float h, struct Color c, bool u4_3);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,21 +1,74 @@
|
|||
#include "mw-value.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <string>
|
||||
#include "moon/ui/utils/moon-draw-utils.h"
|
||||
#include "moon/texts/moon-loader.h"
|
||||
#include "moon/ui/interfaces/moon-screen.h"
|
||||
|
||||
// std::cout << ptr << std::endl;
|
||||
// int* a = static_cast<int*>(ptr);
|
||||
// int b = *a;
|
||||
using namespace std;
|
||||
|
||||
MWValue::MWValue(void* ptr, float x, float y, MWValueType type){
|
||||
this->value = ptr;
|
||||
bool mwvStickExecuted;
|
||||
|
||||
MWValue::MWValue(MWValueBind bind, std::string title, float x, float y){
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->bind = bind;
|
||||
this->title = title;
|
||||
}
|
||||
|
||||
void MWValue::Init(){}
|
||||
void MWValue::Draw(){
|
||||
MoonDrawText(this->x, this->y, this->focused ? "Focused" : this->selected ? "Selected" : "No selected", 1.0, {255, 255, 255, 255}, false);
|
||||
void MWValue::Init(){
|
||||
mwvStickExecuted = false;
|
||||
}
|
||||
void MWValue::Draw(){
|
||||
float scale = 1;
|
||||
float titleWidth = MoonGetTextWidth(this->title + " ", scale, false);
|
||||
int barWidth = SCREEN_WIDTH - 50 - 20;
|
||||
float tmpWidth = titleWidth;
|
||||
|
||||
|
||||
Color focusColors[] = {
|
||||
{255, 255, 255, 80},
|
||||
{255, 247, 0, 80},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
|
||||
MoonDrawRectangle(this->x + 10, this->y, barWidth, 16, focusColors[this->selected ? 0 : this->focused ? 1 : 2], true);
|
||||
|
||||
if(this->bind.bvar != NULL){
|
||||
bool status = *this->bind.bvar;
|
||||
Color toggleColors[] = {
|
||||
{255, 32, 3, 255},
|
||||
{32, 255, 32, 255}
|
||||
};
|
||||
string statusText = status ? Moon_GetKey("TEXT_OPT_ENABLED") : Moon_GetKey("TEXT_OPT_DISABLED");
|
||||
|
||||
tmpWidth += MoonGetTextWidth(statusText, scale, false);
|
||||
MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2 + titleWidth, this->y, statusText, scale, toggleColors[status ? 0 : 1] , true, false);
|
||||
}
|
||||
|
||||
MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2, this->y, this->title, scale, {255, 255, 255, 255}, true, false);
|
||||
}
|
||||
|
||||
void MWValue::Update(){
|
||||
float xStick = GetStickValue(MoonButtons::L_STICK, false);
|
||||
|
||||
if(xStick > 0) {
|
||||
if(mwvStickExecuted) return;
|
||||
if(this->bind.bvar != NULL && this->focused ) {
|
||||
*this->bind.bvar = !*this->bind.bvar;
|
||||
std::cout << "Executed" << std::endl;
|
||||
}
|
||||
mwvStickExecuted = true;
|
||||
}
|
||||
if(xStick < 0) {
|
||||
if(mwvStickExecuted) return;
|
||||
if(this->bind.bvar != NULL && this->focused ) {
|
||||
*this->bind.bvar = !*this->bind.bvar;
|
||||
std::cout << "Executed" << std::endl;
|
||||
}
|
||||
mwvStickExecuted = true;
|
||||
}
|
||||
if(!xStick)
|
||||
mwvStickExecuted = false;
|
||||
}
|
||||
void MWValue::Update(){}
|
||||
void MWValue::Dispose(){}
|
|
@ -2,16 +2,20 @@
|
|||
#define MoonWidgetValue
|
||||
|
||||
#include "moon/ui/interfaces/moon-widget.h"
|
||||
#include <string>
|
||||
|
||||
enum MWValueType{
|
||||
INT, FLOAT, BOOL
|
||||
struct MWValueBind{
|
||||
float *fvar;
|
||||
bool *bvar;
|
||||
int *ivar;
|
||||
};
|
||||
|
||||
class MWValue : public MoonWidget {
|
||||
private:
|
||||
void* value;
|
||||
MWValueBind bind;
|
||||
std::string title;
|
||||
public:
|
||||
MWValue(void* ptr, float x, float y, MWValueType type);
|
||||
MWValue(MWValueBind bind, std::string title, float x, float y);
|
||||
void Init();
|
||||
void Draw();
|
||||
void Update();
|
||||
|
|
|
@ -21,17 +21,20 @@ f32 moon_get_text_width(u8* text, float scale, u8 colored) {
|
|||
return size;
|
||||
}
|
||||
|
||||
void moon_draw_colored_text(f32 x, f32 y, const u8 *str, float scale) {
|
||||
void moon_draw_colored_text(f32 x, f32 y, const u8 *str, float scale, struct Color c) {
|
||||
void **hudLUT2 = segmented_to_virtual(main_hud_lut);
|
||||
u32 xStride = round(12 * scale);
|
||||
s32 strPos = 0;
|
||||
s32 w = round(16 * scale);
|
||||
gDPSetEnvColor(gDisplayListHead++, c.r, c.g, c.b, c.a);
|
||||
|
||||
while (str[strPos] != GLOBAR_CHAR_TERMINATOR) {
|
||||
if (str[strPos] == GLOBAL_CHAR_SPACE) {
|
||||
x += round(8 * scale);
|
||||
} else {
|
||||
moon_draw_texture(x, y, w, w, hudLUT2[str[strPos]]);
|
||||
gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, hudLUT2[str[strPos]]);
|
||||
gSPDisplayList(gDisplayListHead++, dl_rgba16_load_tex_block);
|
||||
gSPTextureRectangle(gDisplayListHead++, (u32)x << 2, (u32)y << 2, ((u32)x + 16) << 2, ((u32)y + 16) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10);
|
||||
x += xStride;
|
||||
}
|
||||
strPos++;
|
||||
|
@ -46,7 +49,7 @@ void moon_draw_text(f32 x, f32 y, const u8 *str, float scale) {
|
|||
Mtx *_Matrix = (Mtx *) alloc_display_list(sizeof(Mtx));
|
||||
if (!_Matrix) return;
|
||||
guScale(_Matrix, scale, scale - 0.1f, 1.f);
|
||||
create_dl_translation_matrix(MENU_MTX_PUSH, x, y, 0.0f);
|
||||
create_dl_translation_matrix(MENU_MTX_PUSH, x, y - 15, 0.0f);
|
||||
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(_Matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
|
||||
|
||||
while (str[strPos] != DIALOG_CHAR_TERMINATOR) {
|
||||
|
@ -128,11 +131,12 @@ void moon_draw_texture(s32 x, s32 y, u32 w, u32 h, u8 *texture) {
|
|||
void moon_draw_rectangle(f32 x, f32 y, f32 w, f32 h, struct Color c, u8 u4_3) {
|
||||
Mtx *_Matrix = (Mtx *) alloc_display_list(sizeof(Mtx));
|
||||
if (!_Matrix) return;
|
||||
|
||||
y = SCREEN_HEIGHT - y;
|
||||
|
||||
if(!u4_3){
|
||||
x = GFX_DIMENSIONS_FROM_LEFT_EDGE(x);
|
||||
y = SCREEN_HEIGHT - y;
|
||||
} else
|
||||
y += h;
|
||||
}
|
||||
|
||||
create_dl_translation_matrix(MENU_MTX_PUSH, x, y, 0);
|
||||
guScale(_Matrix, 1, 1, 1);
|
||||
|
|
|
@ -10,11 +10,8 @@ struct Color {
|
|||
u8 a;
|
||||
};
|
||||
|
||||
#define COLOR(red, green, blue, alpha) \
|
||||
{ .r = red, .g = green, .b = blue, .a = alpha }
|
||||
|
||||
f32 moon_get_text_width(u8* text, float scale, u8 colored);
|
||||
void moon_draw_colored_text(f32 x, f32 y, const u8 *str, float scale);
|
||||
void moon_draw_colored_text(f32 x, f32 y, const u8 *str, float scale, struct Color c);
|
||||
void moon_draw_text(f32 x, f32 y, const u8 *str, float scale);
|
||||
void moon_draw_rectangle(f32 x, f32 y, f32 w, f32 h, struct Color c, u8 u4_3);
|
||||
void moon_draw_texture(s32 x, s32 y, u32 w, u32 h, u8 *texture);
|
||||
|
|
Loading…
Reference in New Issue