mirror of https://github.com/sm64pc/sm64pc.git
[WIP] Started migration of old screens to category system
This commit is contained in:
parent
239c9c1be5
commit
6af8138201
7
Makefile
7
Makefile
|
@ -263,8 +263,11 @@ LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))
|
|||
# Hi, I'm a PC
|
||||
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets src/text src/text/libs src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes src/nx
|
||||
|
||||
# Moon64 SRC Directories
|
||||
SRC_DIRS += src/moon src/moon/texts src/moon/utils src/moon/network src/moon/ui src/moon/ui/interfaces src/moon/ui/screens src/moon/ui/utils src/moon/ui/widgets
|
||||
# Moon64 SRC [Main] Directories
|
||||
SRC_DIRS += src/moon src/moon/texts src/moon/utils src/moon/network
|
||||
|
||||
# Moon64 SRC [View] Directories
|
||||
SRC_DIRS += src/moon/ui src/moon/ui/interfaces src/moon/ui/screens src/moon/ui/screens/options src/moon/ui/screens/options/categories src/moon/ui/utils src/moon/ui/widgets
|
||||
|
||||
# RapidJSON Library
|
||||
SRC_DIRS += src/moon/libs/rapidjson src/moon/libs/rapidjson/error src/moon/libs/rapidjson/internal src/moon/libs/rapidjson/msinttypes
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "interfaces/moon-screen.h"
|
||||
#include "screens/moon-test.h"
|
||||
#include "screens/options/main-view.h"
|
||||
|
||||
extern "C" {
|
||||
#include "game/game_init.h"
|
||||
|
@ -21,10 +21,10 @@ void MoonUpdateStatus();
|
|||
void MoonInitUI() {
|
||||
|
||||
if(screens.empty())
|
||||
screens.push_back(new MoonTest());
|
||||
screens.push_back(new MoonOptMain());
|
||||
|
||||
screens[currentScreen]->Mount();
|
||||
screens[currentScreen]->Init();
|
||||
screens[currentScreen]->Init();
|
||||
}
|
||||
|
||||
void MoonDrawUI() {
|
||||
|
@ -40,13 +40,13 @@ void MoonDisposeUI() {
|
|||
|
||||
void MoonChangeUI(int index){
|
||||
if(index == -1){
|
||||
isOpen = false;
|
||||
isOpen = false;
|
||||
return;
|
||||
}
|
||||
if(!(isOpen && isRunning)) return;
|
||||
currentScreen = index;
|
||||
screens[currentScreen]->Mount();
|
||||
screens[currentScreen]->Init();
|
||||
screens[currentScreen]->Init();
|
||||
}
|
||||
|
||||
void MoonHandleToggle(){
|
||||
|
@ -60,7 +60,7 @@ void MoonUpdateStatus() {
|
|||
if(!isOpen) {
|
||||
if(isRunning) MoonDisposeUI();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!isRunning) {
|
||||
MoonInitUI();
|
||||
isRunning = true;
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
#include "moon-test.h"
|
||||
#include <iostream>
|
||||
#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;
|
||||
|
||||
extern "C" {
|
||||
#include "sm64.h"
|
||||
#include "gfx_dimensions.h"
|
||||
}
|
||||
|
||||
void MoonTest::Init(){
|
||||
cout << "Screen called" << endl;
|
||||
//MoonConsumer consumer;
|
||||
//consumer.Init();
|
||||
//MoonResponse res;
|
||||
//MoonRequest req;
|
||||
//req.url = "https://raw.githubusercontent.com/Render96/Render96ex_Languages/master/PT_br.json";
|
||||
// req.file = "Kalimba2.txt";
|
||||
//consumer.Get(req, &res);
|
||||
//printf("%s\n", res.body.c_str());
|
||||
MoonScreen::Init();
|
||||
}
|
||||
|
||||
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(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();
|
||||
}
|
||||
|
||||
int x = 0;
|
||||
int y = 20;
|
||||
|
||||
void MoonTest::Draw(){
|
||||
MoonDrawText(0, 0, "Hi uwu", 0.5, {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();
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef IMoonCategory
|
||||
#define IMoonCategory
|
||||
|
||||
#include "moon/ui/interfaces/moon-widget.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class MoonCategory {
|
||||
public:
|
||||
MoonCategory(string categoryName){
|
||||
this->categoryName = categoryName;
|
||||
};
|
||||
string categoryName;
|
||||
std::vector<MoonWidget*> catOptions;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,29 @@
|
|||
#include "mgame.h"
|
||||
|
||||
#include "moon/network/moon-consumer.h"
|
||||
#include "moon/texts/moon-loader.h"
|
||||
#include "moon/ui/widgets/mw-value.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" {
|
||||
#include "pc/configfile.h"
|
||||
}
|
||||
|
||||
int languageIdx;
|
||||
vector<string> lngNames;
|
||||
MWValue * lngSwitch;
|
||||
|
||||
MGameCategory::MGameCategory() : MoonCategory("TEXT_OPT_GAME"){
|
||||
for (auto &lng : languages) {
|
||||
lngNames.push_back(lng->name);
|
||||
}
|
||||
this->catOptions.push_back(lngSwitch = new MWValue(22, 57, Moon_GetKey("TEXT_OPT_LANGUAGE"), {.index = &languageIdx, .values = &lngNames, .callback = [](){
|
||||
Moon_SetLanguage(languages[languageIdx]);
|
||||
lngSwitch->title = Moon_GetKey("TEXT_OPT_LANGUAGE");
|
||||
}}));
|
||||
this->catOptions.push_back(new MWValue(22, 74, Moon_GetKey("TEXT_OPT_PRECACHE"), {.bvar = &configPrecacheRes}));
|
||||
#ifdef TARGET_SWITCH
|
||||
this->catOptions.push_back(new MWValue(22, 91, Moon_GetKey("TEXT_OPT_SWITCH_HUD"), {.bvar = &configSwitchHud}));
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef MoonGameCategory
|
||||
#define MoonGameCategory
|
||||
|
||||
#include "mcategory.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class MGameCategory : public MoonCategory {
|
||||
public:
|
||||
MGameCategory();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,36 @@
|
|||
#include "mvideo.h"
|
||||
|
||||
#include "moon/network/moon-consumer.h"
|
||||
#include "moon/texts/moon-loader.h"
|
||||
#include "moon/ui/widgets/mw-value.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" {
|
||||
#include "pc/configfile.h"
|
||||
}
|
||||
|
||||
int texIdx;
|
||||
vector<string> texNames;
|
||||
|
||||
MVideoCategory::MVideoCategory() : MoonCategory("TEXT_OPT_VIDEO"){
|
||||
string filters[] = {
|
||||
"TEXT_OPT_NEAREST",
|
||||
"TEXT_OPT_LINEAR",
|
||||
"TEXT_OPT_THREEPT"
|
||||
};
|
||||
for (auto &tex : filters) {
|
||||
texNames.push_back(Moon_GetKey(tex));
|
||||
}
|
||||
this->catOptions.push_back(new MWValue(22, 57, Moon_GetKey("TEXT_OPT_FSCREEN"), {.bvar = &configWindow.fullscreen}));
|
||||
this->catOptions.push_back(new MWValue(22, 74, Moon_GetKey("TEXT_OPT_VSYNC"), {.bvar = &configWindow.vsync}));
|
||||
this->catOptions.push_back(new MWValue(22, 91, Moon_GetKey("TEXT_OPT_TEXFILTER"), {.index = (int*)&configFiltering, .values = &texNames}));
|
||||
this->catOptions.push_back(new MWValue(22, 108, Moon_GetKey("TEXT_OPT_HUD"), {.bvar = &configHUD}));
|
||||
this->catOptions.push_back(new MWValue(22, 125, Moon_GetKey("TEXT_OPT_RESETWND"), {.btn = [](){
|
||||
configWindow.reset = true;
|
||||
configWindow.settings_changed = true;
|
||||
}}));
|
||||
this->catOptions.push_back(new MWValue(22, 142, Moon_GetKey("TEXT_OPT_APPLY"), {.btn = [](){
|
||||
configWindow.settings_changed = true;
|
||||
}}));
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef MoonVideoCategory
|
||||
#define MoonVideoCategory
|
||||
|
||||
#include "mcategory.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class MVideoCategory : public MoonCategory {
|
||||
public:
|
||||
MVideoCategory();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,74 @@
|
|||
#include "main-view.h"
|
||||
#include <iostream>
|
||||
#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"
|
||||
#include "moon/ui/screens/options/categories/mcategory.h"
|
||||
|
||||
#include "moon/ui/screens/options/categories/mgame.h"
|
||||
#include "moon/ui/screens/options/categories/mvideo.h"
|
||||
using namespace std;
|
||||
|
||||
extern "C" {
|
||||
#include "sm64.h"
|
||||
#include "gfx_dimensions.h"
|
||||
#include "pc/configfile.h"
|
||||
}
|
||||
|
||||
vector<MoonCategory*> categories;
|
||||
bool cswStickExecuted;
|
||||
int categoryIndex = 0;
|
||||
string curTitle;
|
||||
|
||||
void MoonOptMain::setCategory(int index){
|
||||
this->widgets.clear();
|
||||
MoonCategory *cat = categories[index];
|
||||
vector<MoonWidget*> tmp = cat->catOptions;
|
||||
copy(tmp.begin(), tmp.end(), back_inserter(this->widgets));
|
||||
curTitle = Moon_GetKey(cat->categoryName);
|
||||
MoonScreen::Mount();
|
||||
}
|
||||
|
||||
void MoonOptMain::Mount(){
|
||||
this->widgets.clear();
|
||||
categories.push_back(new MGameCategory());
|
||||
categories.push_back(new MVideoCategory());
|
||||
this->setCategory(categoryIndex);
|
||||
}
|
||||
|
||||
void MoonOptMain::Update(){
|
||||
if(this->selected->focused){
|
||||
float xStick = GetStickValue(MoonButtons::L_STICK, false);
|
||||
if(xStick < 0) {
|
||||
if(cswStickExecuted) return;
|
||||
if(categoryIndex > 0)
|
||||
categoryIndex -= 1;
|
||||
else
|
||||
categoryIndex = categories.size() - 1;
|
||||
this->setCategory(categoryIndex);
|
||||
cswStickExecuted = true;
|
||||
}
|
||||
if(xStick > 0) {
|
||||
if(cswStickExecuted) return;
|
||||
if(categoryIndex < categories.size())
|
||||
categoryIndex += 1;
|
||||
else
|
||||
categoryIndex = 0;
|
||||
this->setCategory(categoryIndex);
|
||||
cswStickExecuted = true;
|
||||
}
|
||||
if(!xStick)
|
||||
cswStickExecuted = false;
|
||||
}
|
||||
MoonScreen::Update();
|
||||
}
|
||||
|
||||
void MoonOptMain::Draw(){
|
||||
float txtWidth = MoonGetTextWidth(curTitle, 1.0, true);
|
||||
MoonDrawRectangle(0, 0, GetScreenWidth(false), GetScreenHeight(), {0, 0, 0, 100}, false);
|
||||
MoonDrawColoredText(SCREEN_WIDTH / 2 - txtWidth / 2, 20, curTitle, 1.0, {255, 255, 255, 255}, true, true);
|
||||
MoonDrawRectangle(25, 50, SCREEN_WIDTH - 50, GetScreenHeight() * 0.6, {0, 0, 0, 100}, true);
|
||||
MoonScreen::Draw();
|
||||
}
|
|
@ -2,11 +2,13 @@
|
|||
#define MoonScreenTest
|
||||
#include "moon/ui/interfaces/moon-screen.h"
|
||||
|
||||
class MoonTest : public MoonScreen {
|
||||
class MoonOptMain : public MoonScreen {
|
||||
public:
|
||||
void Init();
|
||||
void Update();
|
||||
void Draw();
|
||||
void Mount();
|
||||
private:
|
||||
void setCategory(int index);
|
||||
};
|
||||
|
||||
|
|
@ -25,10 +25,10 @@ void MWValue::Init(){
|
|||
}
|
||||
|
||||
void MWValue::Draw(){
|
||||
|
||||
|
||||
float step = 0.6;
|
||||
|
||||
if(focusAnimation >= focusAnimRange)
|
||||
if(focusAnimation >= focusAnimRange)
|
||||
focusAnimationPingPong = 1;
|
||||
else if (focusAnimation <= focusAnimRange / 2)
|
||||
focusAnimationPingPong = 0;
|
||||
|
@ -40,12 +40,12 @@ void MWValue::Draw(){
|
|||
int barWidth = SCREEN_WIDTH - 50 - 14;
|
||||
float tmpWidth = titleWidth;
|
||||
|
||||
Color focusColors[] = {
|
||||
Color focusColors[] = {
|
||||
{255, 255, 255, 40 + focusAnimation / 2},
|
||||
{255, 247, 0, 40 + focusAnimation / 2},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
|
||||
|
||||
bool isFloat = this->bind.fvar != NULL;
|
||||
bool isInt = this->bind.ivar != NULL;
|
||||
|
||||
|
@ -53,7 +53,7 @@ void MWValue::Draw(){
|
|||
|
||||
if(this->bind.bvar != NULL){
|
||||
bool status = *this->bind.bvar;
|
||||
Color toggleColors[] = {
|
||||
Color toggleColors[] = {
|
||||
{61, 255, 113, 255},
|
||||
{255, 61, 61, 255}
|
||||
};
|
||||
|
@ -63,7 +63,7 @@ void MWValue::Draw(){
|
|||
MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2 + titleWidth, this->y, statusText, scale, toggleColors[status ? 0 : 1] , true, true);
|
||||
} else if(this->bind.values != NULL && this->bind.index != NULL){
|
||||
int index = *this->bind.index;
|
||||
|
||||
|
||||
string text = (*this->bind.values)[index];
|
||||
|
||||
tmpWidth += MoonGetTextWidth(text, scale, false);
|
||||
|
@ -71,13 +71,13 @@ void MWValue::Draw(){
|
|||
} 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))) + "%";
|
||||
|
||||
tmpWidth += MoonGetTextWidth(text, scale, false);
|
||||
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;
|
||||
|
||||
|
@ -108,19 +108,20 @@ void MWValue::Update(){
|
|||
if(isBool) {
|
||||
*this->bind.bvar = !*this->bind.bvar;
|
||||
} else if(isArray || isFloat || isInt) {
|
||||
float cIndex = isArray ? (int) *this->bind.index : isFloat ? *this->bind.fvar : *this->bind.ivar;
|
||||
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;
|
||||
if(isFloat) *this->bind.fvar -= step;
|
||||
if(isInt) *this->bind.ivar -= (int)step;
|
||||
} else {
|
||||
if(isArray) *this->bind.index = (int)maxValue;
|
||||
if(isFloat) *this->bind.fvar = maxValue;
|
||||
if(isFloat) *this->bind.fvar = maxValue;
|
||||
if(isInt) *this->bind.ivar = (int)maxValue;
|
||||
}
|
||||
}
|
||||
if(this->bind.callback != NULL) this->bind.callback();
|
||||
mwvStickExecuted = true;
|
||||
}
|
||||
}
|
||||
if(xStick > 0) {
|
||||
if(mwvStickExecuted) return;
|
||||
if(isBool) {
|
||||
|
@ -130,14 +131,15 @@ void MWValue::Update(){
|
|||
|
||||
if(cIndex < maxValue){
|
||||
if(isArray) *this->bind.index += (int)step;
|
||||
if(isFloat) *this->bind.fvar += step;
|
||||
if(isFloat) *this->bind.fvar += step;
|
||||
if(isInt) *this->bind.ivar += (int)step;
|
||||
} else {
|
||||
if(isArray) *this->bind.index = (int)minValue;
|
||||
if(isFloat) *this->bind.fvar = minValue;
|
||||
if(isFloat) *this->bind.fvar = minValue;
|
||||
if(isInt) *this->bind.ivar = (int)minValue;
|
||||
}
|
||||
}
|
||||
if(this->bind.callback != NULL) this->bind.callback();
|
||||
mwvStickExecuted = true;
|
||||
}
|
||||
if(!xStick)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
struct MWValueBind{
|
||||
bool *bvar;
|
||||
|
||||
float *fvar;
|
||||
float *fvar;
|
||||
int *ivar;
|
||||
float max;
|
||||
float min;
|
||||
|
@ -17,6 +17,8 @@ struct MWValueBind{
|
|||
|
||||
int *index;
|
||||
std::vector<std::string>* values;
|
||||
|
||||
void (*callback)();
|
||||
};
|
||||
|
||||
class MWValue : public MoonWidget {
|
||||
|
|
Loading…
Reference in New Issue