[WIP] Converted old options menu screens to MoonScreens (Bad Commit)

This commit is contained in:
KiritoDev 2021-05-03 23:29:59 -05:00
parent 0fcf880472
commit c26ae83bc4
13 changed files with 229 additions and 74 deletions

View File

@ -21,9 +21,15 @@ void MoonScreen::Init(){
void MoonScreen::Mount(){
if(!this->widgets.empty()){
this->selected = this->widgets[0];
this->selected->selected = true;
this->selected->focused = false;
this->scrollIndex = 0;
this->selected = NULL;
for(int i = 0; i < widgets.size(); i++) {
widgets[i]->selected = false;
widgets[i]->focused = false;
}
MoonWidget* sel = this->widgets[this->scrollIndex];
sel->selected = true;
sel->focused = false;
}
}
@ -36,46 +42,42 @@ void MoonScreen::Draw(){
bool stickExecuted;
void MoonScreen::Update(){
if(this->enabledWidgets) {
if(this->enabledWidgets && !this->widgets.empty()) {
float yStick = GetStickValue(MoonButtons::U_STICK, false);
if(!this->widgets.empty()){
if(yStick > 0) {
if(stickExecuted) return;
if(this->selected != NULL) return;
this->widgets[this->scrollIndex]->selected = false;
if(this->scrollIndex > 0)
this->scrollIndex--;
else
this->scrollIndex = this->widgets.size() - 1;
this->widgets[this->scrollIndex]->selected = true;
stickExecuted = true;
}
if(yStick < 0) {
if(stickExecuted) return;
if(this->selected != NULL) return;
this->widgets[this->scrollIndex]->selected = false;
if(this->scrollIndex < this->widgets.size() - 1)
this->scrollIndex++;
else
this->scrollIndex = 0;
this->widgets[this->scrollIndex]->selected = true;
stickExecuted = true;
}
if(!yStick)
stickExecuted = false;
if(IsBtnPressed(MoonButtons::A_BTN)) {
this->selected = this->widgets[this->scrollIndex];
this->selected->selected = false;
this->selected->focused = true;
}
if(IsBtnPressed(MoonButtons::B_BTN)) {
if(this->selected != NULL){
this->selected->selected = true;
this->selected->focused = false;
this->selected = NULL;
}
if(yStick > 0) {
if(stickExecuted) return;
if(this->selected != NULL) return;
this->widgets[this->scrollIndex]->selected = false;
if(this->scrollIndex > 0)
this->scrollIndex--;
else
this->scrollIndex = this->widgets.size() - 1;
this->widgets[this->scrollIndex]->selected = true;
stickExecuted = true;
}
if(yStick < 0) {
if(stickExecuted) return;
if(this->selected != NULL) return;
this->widgets[this->scrollIndex]->selected = false;
if(this->scrollIndex < this->widgets.size() - 1)
this->scrollIndex++;
else
this->scrollIndex = 0;
this->widgets[this->scrollIndex]->selected = true;
stickExecuted = true;
}
if(!yStick)
stickExecuted = false;
if(IsBtnPressed(MoonButtons::A_BTN)) {
this->selected = this->widgets[this->scrollIndex];
this->selected->selected = false;
this->selected->focused = true;
}
if(IsBtnPressed(MoonButtons::B_BTN)) {
if(this->selected != NULL){
this->selected->selected = true;
this->selected->focused = false;
this->selected = NULL;
}
}
for(int i = 0; i < widgets.size(); i++)
@ -111,7 +113,7 @@ float GetStickValue(MoonButtons button, bool absolute){
}
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;
return GFX_DIMENSIONS_ASPECT_RATIO > 1 || u4_3 ? SCREEN_WIDTH + abs(GFX_DIMENSIONS_FROM_LEFT_EDGE(0)) * 2 : SCREEN_WIDTH;
}
float GetScreenHeight() {

View File

@ -5,12 +5,12 @@
#include <vector>
enum MoonButtons {
A_BTN = 0x8000, B_BTN = 0x4000,
A_BTN = 0x8000, B_BTN = 0x4000,
L_BTN = 0x0020, R_BTN = 0x0010,
Z_BTN = 0x2000, START = 0x1000,
U_STICK = 0x0800, D_STICK = 0x0400,
L_STICK = 0x0200, R_STICK = 0x0100,
U_CBTN = 0x0008, D_CBTN = 0x0004,
U_STICK = 0x0800, D_STICK = 0x0400,
L_STICK = 0x0200, R_STICK = 0x0100,
U_CBTN = 0x0008, D_CBTN = 0x0004,
L_CBTN = 0x0002, R_CBTN = 0x0001
};
@ -19,7 +19,7 @@ protected:
std::vector<MoonWidget*> widgets;
MoonWidget* selected;
bool enabledWidgets = true;
int scrollIndex = 0;
int scrollIndex = 0;
public:
virtual void Init();
virtual void Mount();

View File

@ -0,0 +1,18 @@
#include "maudio.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"
}
MAudioCategory::MAudioCategory() : MoonCategory("TEXT_OPT_AUDIO"){
this->catOptions.push_back(new MWValue(22, 57, "TEXT_OPT_MVOLUME", {.ivar = (int*)&configMasterVolume, .max = 127.0f, .min = .0f, .step = 1.0f}, true));
this->catOptions.push_back(new MWValue(22, 74, "TEXT_OPT_MUSVOLUME", {.ivar = (int*)&configMusicVolume, .max = 127.0f, .min = .0f, .step = 1.0f}, true));
this->catOptions.push_back(new MWValue(22, 91, "TEXT_OPT_SFXVOLUME", {.ivar = (int*)&configSfxVolume, .max = 127.0f, .min = .0f, .step = 1.0f}, true));
this->catOptions.push_back(new MWValue(22, 108, "TEXT_OPT_ENVVOLUME", {.ivar = (int*)&configEnvVolume, .max = 127.0f, .min = .0f, .step = 1.0f}, true));
}

View File

@ -0,0 +1,13 @@
#ifndef MoonAudioCategory
#define MoonAudioCategory
#include "mcategory.h"
#include <vector>
#include <string>
class MAudioCategory : public MoonCategory {
public:
MAudioCategory();
};
#endif

View File

@ -0,0 +1,28 @@
#ifdef BETTERCAMERA
#include "mcamera.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"
}
MCameraCategory::MCameraCategory() : MoonCategory("TEXT_OPT_CAMERA"){
this->catOptions.push_back(new MWValue(22, 57, "TEXT_OPT_CAMON", {.bvar = &configEnableCamera }, true));
this->catOptions.push_back(new MWValue(22, 74, "TEXT_OPT_ANALOGUE", {.bvar = &configCameraAnalog }, true));
this->catOptions.push_back(new MWValue(22, 91, "TEXT_OPT_MOUSE", {.bvar = &configCameraMouse }, true));
this->catOptions.push_back(new MWValue(22, 108, "TEXT_OPT_INVERTX", {.bvar = &configCameraInvertX}, true));
this->catOptions.push_back(new MWValue(22, 125, "TEXT_OPT_INVERTY", {.bvar = &configCameraInvertY}, true));
this->catOptions.push_back(new MWValue(22, 142, "TEXT_OPT_CAMX", {.ivar = (int*)&configCameraXSens, .max = 100.0f, .min = .1f, .step = 1.0f}, true));
this->catOptions.push_back(new MWValue(22, 159, "TEXT_OPT_CAMY", {.ivar = (int*)&configCameraYSens, .max = 100.0f, .min = .1f, .step = 1.0f}, true));
this->catOptions.push_back(new MWValue(22, 176, "TEXT_OPT_CAMC", {.ivar = (int*)&configCameraAggr, .max = 100.0f, .min = .0f, .step = 1.0f}, true));
this->catOptions.push_back(new MWValue(22, 193, "TEXT_OPT_CAMP", {.ivar = (int*)&configCameraPan, .max = 100.0f, .min = .0f, .step = 1.0f}, true));
this->catOptions.push_back(new MWValue(22, 210, "TEXT_OPT_CAMD", {.ivar = (int*)&configCameraDegrade, .max = 100.0f, .min = .0f, .step = 1.0f}, true));
}
#endif

View File

@ -0,0 +1,13 @@
#ifndef MoonCameraCategory
#define MoonCameraCategory
#include "mcategory.h"
#include <vector>
#include <string>
class MCameraCategory : public MoonCategory {
public:
MCameraCategory();
};
#endif

View File

@ -0,0 +1,23 @@
#include "mcheats.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/cheats.h"
}
MCheatsCategory::MCheatsCategory() : MoonCategory("TEXT_OPT_CHEATS"){
this->catOptions.push_back(new MWValue(22, 57, "TEXT_OPT_CHEAT1", {.bvar = &Cheats.EnableCheats }, true));
this->catOptions.push_back(new MWValue(22, 74, "TEXT_OPT_CHEAT2", {.bvar = &Cheats.MoonJump }, true));
this->catOptions.push_back(new MWValue(22, 91, "TEXT_OPT_CHEAT3", {.bvar = &Cheats.GodMode }, true));
this->catOptions.push_back(new MWValue(22, 108, "TEXT_OPT_CHEAT4", {.bvar = &Cheats.InfiniteLives}, true));
this->catOptions.push_back(new MWValue(22, 125, "TEXT_OPT_CHEAT5", {.bvar = &Cheats.SuperSpeed }, true));
this->catOptions.push_back(new MWValue(22, 142, "TEXT_OPT_CHEAT6", {.bvar = &Cheats.Responsive }, true));
this->catOptions.push_back(new MWValue(22, 159, "TEXT_OPT_CHEAT7", {.bvar = &Cheats.ExitAnywhere }, true));
this->catOptions.push_back(new MWValue(22, 176, "TEXT_OPT_CHEAT8", {.bvar = &Cheats.HugeMario }, true));
this->catOptions.push_back(new MWValue(22, 193, "TEXT_OPT_CHEAT9", {.bvar = &Cheats.TinyMario }, true));
}

View File

@ -0,0 +1,13 @@
#ifndef MoonCheatsCategory
#define MoonCheatsCategory
#include "mcategory.h"
#include <vector>
#include <string>
class MCheatsCategory : public MoonCategory {
public:
MCheatsCategory();
};
#endif

View File

@ -8,22 +8,26 @@ using namespace std;
extern "C" {
#include "pc/configfile.h"
#include "pc/pc_main.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 = [](){
this->catOptions.push_back(new MWValue(22, 57, "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}));
}}, true));
this->catOptions.push_back(new MWValue(22, 74, "TEXT_OPT_PRECACHE", {.bvar = &configPrecacheRes}, true));
int exitY;
#ifdef TARGET_SWITCH
this->catOptions.push_back(new MWValue(22, 91, Moon_GetKey("TEXT_OPT_SWITCH_HUD"), {.bvar = &configSwitchHud}));
exitY = 108;
this->catOptions.push_back(new MWValue(22, 91, "TEXT_OPT_SWITCH_HUD", {.bvar = &configSwitchHud}, true));
#else
exitY = 91;
#endif
this->catOptions.push_back(new MWValue(22, exitY, "TEXT_EXIT_GAME", { .btn = game_exit}, true));
}

View File

@ -22,15 +22,19 @@ MVideoCategory::MVideoCategory() : MoonCategory("TEXT_OPT_VIDEO"){
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 = [](){
#ifndef TARGET_SWITCH
this->catOptions.push_back(new MWValue(22, 57, "TEXT_OPT_FSCREEN", {.bvar = &configWindow.fullscreen}, true));
this->catOptions.push_back(new MWValue(22, 74, "TEXT_OPT_VSYNC", {.bvar = &configWindow.vsync}, true));
#endif
this->catOptions.push_back(new MWValue(22, 91, "TEXT_OPT_TEXFILTER", {.index = (int*)&configFiltering, .values = &texNames}, true));
this->catOptions.push_back(new MWValue(22, 108, "TEXT_OPT_HUD", {.bvar = &configHUD}, true));
#ifndef TARGET_SWITCH
this->catOptions.push_back(new MWValue(22, 125, "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 = [](){
}}, true));
this->catOptions.push_back(new MWValue(22, 142, "TEXT_OPT_APPLY", {.btn = [](){
configWindow.settings_changed = true;
}}));
}}, true));
#endif
}

View File

@ -9,6 +9,12 @@
#include "moon/ui/screens/options/categories/mgame.h"
#include "moon/ui/screens/options/categories/mvideo.h"
#include "moon/ui/screens/options/categories/maudio.h"
#include "moon/ui/screens/options/categories/mcheats.h"
#ifdef BETTERCAMERA
#include "moon/ui/screens/options/categories/mcamera.h"
#endif
using namespace std;
extern "C" {
@ -20,26 +26,28 @@ extern "C" {
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);
this->widgets = cat->catOptions;
MoonScreen::Mount();
}
void MoonOptMain::Mount(){
this->widgets.clear();
categories.push_back(new MGameCategory());
#ifdef BETTERCAMERA
categories.push_back(new MCameraCategory());
#endif
categories.push_back(new MVideoCategory());
categories.push_back(new MAudioCategory());
categories.push_back(new MCheatsCategory());
this->setCategory(categoryIndex);
MoonScreen::Mount();
}
void MoonOptMain::Update(){
if(this->selected->focused){
if(this->selected == NULL) {
float xStick = GetStickValue(MoonButtons::L_STICK, false);
if(xStick < 0) {
if(cswStickExecuted) return;
@ -52,7 +60,7 @@ void MoonOptMain::Update(){
}
if(xStick > 0) {
if(cswStickExecuted) return;
if(categoryIndex < categories.size())
if(categoryIndex < categories.size() - 1)
categoryIndex += 1;
else
categoryIndex = 0;
@ -66,6 +74,7 @@ void MoonOptMain::Update(){
}
void MoonOptMain::Draw(){
string curTitle = Moon_GetKey(categories[categoryIndex]->categoryName);
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);

View File

@ -14,8 +14,18 @@ MWValue::MWValue(float x, float y, std::string title, MWValueBind bind){
this->y = y;
this->bind = bind;
this->title = title;
this->titleKey = false;
}
MWValue::MWValue(float x, float y, std::string title, MWValueBind bind, bool titleKey){
this->x = x;
this->y = y;
this->bind = bind;
this->title = title;
this->titleKey = titleKey;
}
int frameCounter = 0;
int focusAnimRange = 80;
float focusAnimation = focusAnimRange / 2;
int focusAnimationPingPong;
@ -35,8 +45,9 @@ void MWValue::Draw(){
focusAnimation += step * (focusAnimationPingPong ? -1 : 1);
string rawTitle = this->titleKey ? Moon_GetKey(this->title) : this->title;
float scale = 1;
float titleWidth = MoonGetTextWidth(this->title + " ", scale, false);
float titleWidth = MoonGetTextWidth(rawTitle + " ", scale, false);
int barWidth = SCREEN_WIDTH - 50 - 14;
float tmpWidth = titleWidth;
@ -81,7 +92,7 @@ void MWValue::Draw(){
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);
MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2, this->y, rawTitle, scale, {255, 255, 255, 255}, true, true);
}
void MWValue::Update(){
@ -104,7 +115,13 @@ void MWValue::Update(){
}
if(xStick < 0) {
if(mwvStickExecuted) return;
if(mwvStickExecuted) {
if(isBtn || isBool) return;
if(frameCounter <= 20){
frameCounter++;
return;
}
}
if(isBool) {
*this->bind.bvar = !*this->bind.bvar;
} else if(isArray || isFloat || isInt) {
@ -123,7 +140,13 @@ void MWValue::Update(){
mwvStickExecuted = true;
}
if(xStick > 0) {
if(mwvStickExecuted) return;
if(mwvStickExecuted) {
if(isBtn || isBool) return;
if(frameCounter <= 20){
frameCounter++;
return;
}
}
if(isBool) {
*this->bind.bvar = !*this->bind.bvar;
} else if(isArray || isFloat || isInt) {
@ -142,7 +165,9 @@ void MWValue::Update(){
if(this->bind.callback != NULL) this->bind.callback();
mwvStickExecuted = true;
}
if(!xStick)
if(!xStick){
mwvStickExecuted = false;
frameCounter = 0;
}
}
void MWValue::Dispose(){}

View File

@ -22,10 +22,13 @@ struct MWValueBind{
};
class MWValue : public MoonWidget {
protected:
bool titleKey;
public:
MWValueBind bind;
std::string title;
MWValue(float x, float y, std::string title, MWValueBind bind);
MWValue(float x, float y, std::string title, MWValueBind bind, bool titleKey);
void Init();
void Draw();
void Update();