mirror of https://github.com/sm64pc/sm64pc.git
[WIP] Fixed array names and added io modules system
This commit is contained in:
parent
c26ae83bc4
commit
86ad2e0921
3
Makefile
3
Makefile
|
@ -269,6 +269,9 @@ 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
|
||||
|
||||
# Moon64 SRC [IO] Directories
|
||||
SRC_DIRS += src/moon/io src/moon/io/modules
|
||||
|
||||
# RapidJSON Library
|
||||
SRC_DIRS += src/moon/libs/rapidjson src/moon/libs/rapidjson/error src/moon/libs/rapidjson/internal src/moon/libs/rapidjson/msinttypes
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef MoonIOModule
|
||||
#define MoonIOModule
|
||||
|
||||
class MIOModule {
|
||||
public:
|
||||
virtual void init(){}
|
||||
virtual void update(){}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,38 @@
|
|||
#include "mouse-io.h"
|
||||
|
||||
#ifdef WAPI_SDL2
|
||||
#include <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#ifdef WAPI_DXGI
|
||||
|
||||
#endif
|
||||
|
||||
unsigned int state;
|
||||
|
||||
void MouseIO::init(){
|
||||
this->xPos = 0;
|
||||
this->yPos = 0;
|
||||
this->xLocalPos = 0;
|
||||
this->yLocalPos = 0;
|
||||
this->xGlobalPos = 0;
|
||||
this->yGlobalPos = 0;
|
||||
this->vScroll = 0;
|
||||
this->hScroll = 0;
|
||||
}
|
||||
|
||||
void MouseIO::update(){
|
||||
#ifdef WAPI_SDL2
|
||||
SDL_ShowCursor(!this->hideCursor ? SDL_TRUE : SDL_FALSE);
|
||||
SDL_SetRelativeMouseMode(this->relativeMode ? SDL_TRUE : SDL_FALSE);
|
||||
SDL_GetRelativeMouseState(&this->xPos, &this->yPos);
|
||||
state = SDL_GetMouseState(&this->xLocalPos, &this->yLocalPos);
|
||||
SDL_GetGlobalMouseState(&this->xGlobalPos, &this->yGlobalPos);
|
||||
#elif defined(WAPI_DXGI)
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
bool MouseIO::isBtnPressed(MouseBtn btn){
|
||||
return (state & (btn == 0 ? SDL_BUTTON_LMASK : SDL_BUTTON_RMASK));
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef MouseIOModule
|
||||
#define MouseIOModule
|
||||
|
||||
#include "moon/io/io-module.h"
|
||||
|
||||
enum MouseBtn {
|
||||
LEFT_BTN,
|
||||
RIGHT_BTN
|
||||
};
|
||||
|
||||
class MouseIO : public MIOModule {
|
||||
public:
|
||||
int xPos;
|
||||
int yPos;
|
||||
int xLocalPos;
|
||||
int yLocalPos;
|
||||
int xGlobalPos;
|
||||
int yGlobalPos;
|
||||
float vScroll;
|
||||
float hScroll;
|
||||
bool relativeMode;
|
||||
bool hideCursor;
|
||||
void* window;
|
||||
void init();
|
||||
void update();
|
||||
bool isBtnPressed(MouseBtn btn);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
#include "moon-io.h"
|
||||
#include "moon/io/io-module.h"
|
||||
#include "moon/io/modules/mouse-io.h"
|
||||
|
||||
vector<MIOModule*> modules;
|
||||
|
||||
void InitIOModules(){
|
||||
modules.push_back(new MouseIO());
|
||||
for(auto &module : modules) module->init();
|
||||
}
|
||||
|
||||
void UpdateIOModules(){
|
||||
for(auto &module : modules) module->update();
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef MoonIOManager
|
||||
#define MoonIOManager
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "io-module.h"
|
||||
|
||||
using namespace std;
|
||||
extern vector<MIOModule*> modules;
|
||||
|
||||
void InitIOModules();
|
||||
void UpdateIOModules();
|
||||
template< typename T > T* GetIOModule() {
|
||||
for(int id = 0; id < modules.size(); id++){
|
||||
T* m = dynamic_cast<T*>(modules[id]);
|
||||
if (m) return m;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,7 +1,11 @@
|
|||
#include "moon/texts/moon-loader.h"
|
||||
#include "moon/ui/moon-ui-manager.h"
|
||||
#include "moon/io/moon-io.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "moon/io/moon-io.h"
|
||||
#include "moon/io/modules/mouse-io.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include "game/game_init.h"
|
||||
|
@ -51,4 +55,21 @@ u8 moon_ui_open(){
|
|||
return isOpen;
|
||||
}
|
||||
|
||||
/*
|
||||
#######################
|
||||
Moon IO
|
||||
#######################
|
||||
*/
|
||||
|
||||
void moon_modules_init(){
|
||||
InitIOModules();
|
||||
}
|
||||
void moon_modules_update(){
|
||||
UpdateIOModules();
|
||||
}
|
||||
void moon_update_window(void* window){
|
||||
MouseIO* tmp = GetIOModule<MouseIO>();
|
||||
if(tmp != NULL) tmp->window = window;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,5 +13,10 @@ void moon_draw_ui();
|
|||
void moon_change_ui(int index);
|
||||
u8 moon_ui_open();
|
||||
void moon_ui_toggle();
|
||||
|
||||
void moon_modules_init();
|
||||
void moon_modules_update();
|
||||
void moon_update_window(void* window);
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -43,6 +43,27 @@ bool stickExecuted;
|
|||
|
||||
void MoonScreen::Update(){
|
||||
if(this->enabledWidgets && !this->widgets.empty()) {
|
||||
if(this->useMouseInstead){
|
||||
// MouseIO* tmp = GetIOModule<MouseIO>();
|
||||
// if(tmp != NULL){
|
||||
// int mouseX = tmp->xLocalPos;
|
||||
// int mouseY = tmp->yLocalPos;
|
||||
// int baseY = 119;
|
||||
// int optionSize = 16;
|
||||
// if(mouseX >= 22 && mouseY > baseY){
|
||||
// int currentId = ((mouseY - baseY) / (optionSize * 2));
|
||||
// if(currentId < widgets.size()){
|
||||
// for(int i = 0; i < widgets.size(); i++) {
|
||||
// widgets[i]->selected = false;
|
||||
// widgets[i]->focused = false;
|
||||
// }
|
||||
// this->widgets[currentId]->selected = false;
|
||||
// this->widgets[currentId]->focused = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return;
|
||||
}
|
||||
float yStick = GetStickValue(MoonButtons::U_STICK, false);
|
||||
if(yStick > 0) {
|
||||
if(stickExecuted) return;
|
||||
|
|
|
@ -19,6 +19,7 @@ protected:
|
|||
std::vector<MoonWidget*> widgets;
|
||||
MoonWidget* selected;
|
||||
bool enabledWidgets = true;
|
||||
bool useMouseInstead = false; // unused
|
||||
int scrollIndex = 0;
|
||||
public:
|
||||
virtual void Init();
|
||||
|
|
|
@ -10,25 +10,20 @@ extern "C" {
|
|||
#include "pc/configfile.h"
|
||||
}
|
||||
|
||||
int texIdx;
|
||||
vector<string> texNames;
|
||||
vector<string> filters = {
|
||||
"TEXT_OPT_NEAREST",
|
||||
"TEXT_OPT_LINEAR",
|
||||
"TEXT_OPT_THREEPT"
|
||||
};
|
||||
|
||||
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));
|
||||
}
|
||||
#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, 91, "TEXT_OPT_TEXFILTER", {.index = (int*)&configFiltering, .values = &filters, .valueKeys = true}, true));
|
||||
this->catOptions.push_back(new MWValue(22, 108, "TEXT_OPT_HUD", {.bvar = &configHUD}, true));
|
||||
#ifndef TARGET_SWITCH
|
||||
#ifndef TARGET_SWITCH
|
||||
this->catOptions.push_back(new MWValue(22, 125, "TEXT_OPT_RESETWND", {.btn = [](){
|
||||
configWindow.reset = true;
|
||||
configWindow.settings_changed = true;
|
||||
|
@ -36,5 +31,5 @@ MVideoCategory::MVideoCategory() : MoonCategory("TEXT_OPT_VIDEO"){
|
|||
this->catOptions.push_back(new MWValue(22, 142, "TEXT_OPT_APPLY", {.btn = [](){
|
||||
configWindow.settings_changed = true;
|
||||
}}, true));
|
||||
#endif
|
||||
#endif
|
||||
}
|
|
@ -15,6 +15,9 @@
|
|||
#include "moon/ui/screens/options/categories/mcamera.h"
|
||||
#endif
|
||||
|
||||
#include "moon/io/moon-io.h"
|
||||
#include "moon/io/modules/mouse-io.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern "C" {
|
||||
|
@ -33,6 +36,10 @@ void MoonOptMain::setCategory(int index){
|
|||
MoonScreen::Mount();
|
||||
}
|
||||
|
||||
void MoonOptMain::Init(){
|
||||
this->useMouseInstead = true;
|
||||
}
|
||||
|
||||
void MoonOptMain::Mount(){
|
||||
this->widgets.clear();
|
||||
categories.push_back(new MGameCategory());
|
||||
|
@ -75,9 +82,11 @@ 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);
|
||||
MoonDrawRectangle(25, 50, SCREEN_WIDTH - 50, GetScreenHeight() * 0.6, {0, 0, 0, 100}, true);
|
||||
|
||||
MoonScreen::Draw();
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
class MoonOptMain : public MoonScreen {
|
||||
public:
|
||||
void Init();
|
||||
void Update();
|
||||
void Draw();
|
||||
void Mount();
|
||||
|
|
|
@ -75,7 +75,7 @@ void MWValue::Draw(){
|
|||
} else if(this->bind.values != NULL && this->bind.index != NULL){
|
||||
int index = *this->bind.index;
|
||||
|
||||
string text = (*this->bind.values)[index];
|
||||
string text = this->bind.valueKeys ? Moon_GetKey((*this->bind.values)[index]) : (*this->bind.values)[index];
|
||||
|
||||
tmpWidth += MoonGetTextWidth(text, scale, false);
|
||||
MoonDrawText(this->x + ( 10 + barWidth / 2 ) - tmpWidth / 2 + titleWidth, this->y, text, scale, {58, 249, 252, 255}, true, true);
|
||||
|
|
|
@ -17,6 +17,7 @@ struct MWValueBind{
|
|||
|
||||
int *index;
|
||||
std::vector<std::string>* values;
|
||||
bool valueKeys;
|
||||
|
||||
void (*callback)();
|
||||
};
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "../pc_main.h"
|
||||
#include "../configfile.h"
|
||||
#include "../cliopts.h"
|
||||
#include "moon/moon64.h"
|
||||
|
||||
#include "src/pc/controller/controller_keyboard.h"
|
||||
|
||||
|
@ -243,6 +244,7 @@ static void gfx_sdl_init(const char *window_title) {
|
|||
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
|
||||
);
|
||||
ctx = SDL_GL_CreateContext(wnd);
|
||||
moon_update_window(wnd);
|
||||
|
||||
gfx_sdl_set_vsync(configWindow.vsync);
|
||||
|
||||
|
|
|
@ -91,6 +91,7 @@ void send_display_list(struct SPTask *spTask) {
|
|||
#endif
|
||||
|
||||
void produce_one_frame(void) {
|
||||
moon_modules_update();
|
||||
gfx_start_frame();
|
||||
|
||||
const f32 master_mod = (f32)configMasterVolume / 127.0f;
|
||||
|
@ -181,14 +182,14 @@ static void on_anim_frame(double time) {
|
|||
}
|
||||
#endif
|
||||
|
||||
void main_func(char *argv[]) {
|
||||
void main_func(char *argv[]) {
|
||||
|
||||
static u64 pool[0x165000/8 / 4 * sizeof(void *)];
|
||||
main_pool_init(pool, pool + sizeof(pool) / sizeof(pool[0]));
|
||||
gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT);
|
||||
|
||||
const char *gamedir = gCLIOpts.GameDir[0] ? gCLIOpts.GameDir : FS_BASEDIR;
|
||||
const char *userpath = gCLIOpts.SavePath[0] ? gCLIOpts.SavePath : sys_user_path();
|
||||
const char *userpath = gCLIOpts.SavePath[0] ? gCLIOpts.SavePath : sys_user_path();
|
||||
fs_init(sys_ropaths, gamedir, userpath);
|
||||
configfile_load(configfile_name());
|
||||
|
||||
|
@ -233,10 +234,11 @@ void main_func(char *argv[]) {
|
|||
#endif
|
||||
;
|
||||
|
||||
moon_modules_init();
|
||||
gfx_init(wm_api, rendering_api, window_title);
|
||||
wm_api->set_keyboard_callbacks(keyboard_on_key_down, keyboard_on_key_up, keyboard_on_all_keys_up);
|
||||
|
||||
if (audio_api == NULL && audio_sdl.init())
|
||||
if (audio_api == NULL && audio_sdl.init())
|
||||
audio_api = &audio_sdl;
|
||||
|
||||
if (audio_api == NULL) {
|
||||
|
@ -246,7 +248,7 @@ void main_func(char *argv[]) {
|
|||
audio_init();
|
||||
sound_init();
|
||||
|
||||
thread5_game_loop(NULL);
|
||||
thread5_game_loop(NULL);
|
||||
inited = true;
|
||||
|
||||
// precache data if needed
|
||||
|
|
Loading…
Reference in New Issue