[WIP] Added base for custom gui api

This commit is contained in:
KiritoDev 2021-04-27 23:46:41 -05:00
parent d4e1bf6935
commit 8e52a6caa8
16 changed files with 443 additions and 92 deletions

View File

@ -264,7 +264,7 @@ LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))
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_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
# RapidJSON Library
SRC_DIRS += src/moon/libs/rapidjson src/moon/libs/rapidjson/error src/moon/libs/rapidjson/internal src/moon/libs/rapidjson/msinttypes

View File

@ -425,16 +425,20 @@ void render_hud_camera_status(void) {
}
#ifdef TARGET_SWITCH
void render_nx_hud(void){
s16 x = GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(40);
s16 x = 40;
s16 y = 212;
s16 w = x + 12;
s16 h = y + 4;
moon_draw_rectangle(x - 1, y - 1, w + 1, h + 1, 57, 57, 57);
moon_draw_rectangle(w, y, w + 2, y + 4, 57, 57, 57);
moon_draw_rectangle(x, y, w, h, 194, 194, 194);
moon_draw_rectangle(x, y, x + (s16)(12 * getBatteryPercentage()), h, 76, 235, 52);
struct Color color;
//color = { .r = 57, .g = 57, .b = 57, .a = 255 }
//moon_draw_rectangle(x - 1, y - 1, w + 1, h + 1, COLOR(57, 57, 57, 255));
//moon_draw_rectangle(w, y, w + 2, y + 4, color);
//color = { .r = 57, .g = 57, .b = 57, .a = 255 }
//moon_draw_rectangle(x, y, w, h, COLOR(194, 194, 194, 255));
//color = { .r = 57, .g = 57, .b = 57, .a = 255 }
//moon_draw_rectangle(x, y, x + (s16)(12 * getBatteryPercentage()), h, COLOR(78, 235, 52, 255));
x = GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(20);
y = 207;

View File

@ -1779,8 +1779,7 @@ void shade_screen(void) {
// This is a bit weird. It reuses the dialog text box (width 130, height -80),
// so scale to at least fit the screen.
create_dl_scale_matrix(MENU_MTX_NOPUSH,
GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_HEIGHT / 130.0f, 3.0f, 1.0f);
create_dl_scale_matrix(MENU_MTX_NOPUSH, GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_HEIGHT / 130.0f, 3.0f, 1.0f);
gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, 110);
gSPDisplayList(gDisplayListHead++, dl_draw_text_bg_box);
@ -2151,78 +2150,71 @@ s8 gHudFlash = 0;
s16 render_pause_courses_and_castle(void) {
s16 num;
#ifdef EXT_OPTIONS_MENU
if (optmenu_open == 0) {
#endif
switch (gDialogBoxState) {
case DIALOG_STATE_OPENING:
gDialogLineNum = 1;
gDialogTextAlpha = 0;
level_set_transition(-1, 0);
play_sound(SOUND_MENU_PAUSE_HIGHPRIO, gDefaultSoundArgs);
if (moon_ui_open() == 0) {
switch (gDialogBoxState) {
case DIALOG_STATE_OPENING:
gDialogLineNum = 1;
gDialogTextAlpha = 0;
level_set_transition(-1, 0);
play_sound(SOUND_MENU_PAUSE_HIGHPRIO, gDefaultSoundArgs);
if (gCurrCourseNum >= COURSE_MIN && gCurrCourseNum <= COURSE_MAX) {
change_dialog_camera_angle();
gDialogBoxState = DIALOG_STATE_VERTICAL;
} else {
highlight_last_course_complete_stars();
gDialogBoxState = DIALOG_STATE_HORIZONTAL;
}
break;
case DIALOG_STATE_VERTICAL:
shade_screen();
render_pause_my_score_coins();
render_pause_red_coins();
/* Added support for the "Exit course at any time" cheat */
if ((gMarioStates[0].action & ACT_FLAG_PAUSE_EXIT) || (Cheats.EnableCheats && Cheats.ExitAnywhere)) {
render_pause_course_options(99, 93, &gDialogLineNum, 15);
}
if (gPlayer3Controller->buttonPressed & (A_BUTTON | START_BUTTON)) {
level_set_transition(0, 0);
play_sound(SOUND_MENU_PAUSE_2, gDefaultSoundArgs);
gDialogBoxState = DIALOG_STATE_OPENING;
gMenuMode = -1;
if (gDialogLineNum == 2) {
num = gDialogLineNum;
if (gCurrCourseNum >= COURSE_MIN && gCurrCourseNum <= COURSE_MAX) {
change_dialog_camera_angle();
gDialogBoxState = DIALOG_STATE_VERTICAL;
} else {
num = 1;
highlight_last_course_complete_stars();
gDialogBoxState = DIALOG_STATE_HORIZONTAL;
}
break;
case DIALOG_STATE_VERTICAL:
shade_screen();
render_pause_my_score_coins();
render_pause_red_coins();
/* Added support for the "Exit course at any time" cheat */
if ((gMarioStates[0].action & ACT_FLAG_PAUSE_EXIT) || (Cheats.EnableCheats && Cheats.ExitAnywhere)) {
render_pause_course_options(99, 93, &gDialogLineNum, 15);
}
return num;
}
break;
case DIALOG_STATE_HORIZONTAL:
shade_screen();
print_hud_pause_colorful_str();
render_pause_castle_menu_box(160, 143);
render_pause_castle_main_strings(104, 60);
if (gPlayer3Controller->buttonPressed & (A_BUTTON | START_BUTTON)) {
level_set_transition(0, 0);
play_sound(SOUND_MENU_PAUSE_2, gDefaultSoundArgs);
gDialogBoxState = DIALOG_STATE_OPENING;
gMenuMode = -1;
if (gPlayer3Controller->buttonPressed & (A_BUTTON | START_BUTTON)) {
level_set_transition(0, 0);
play_sound(SOUND_MENU_PAUSE_2, gDefaultSoundArgs);
gMenuMode = -1;
gDialogBoxState = DIALOG_STATE_OPENING;
if (gDialogLineNum == 2) {
num = gDialogLineNum;
} else {
num = 1;
}
return 1;
}
break;
}
return num;
}
break;
case DIALOG_STATE_HORIZONTAL:
shade_screen();
print_hud_pause_colorful_str();
render_pause_castle_menu_box(160, 143);
render_pause_castle_main_strings(104, 60);
if (gDialogTextAlpha < 250) {
gDialogTextAlpha += 25;
}
#ifdef EXT_OPTIONS_MENU
if (gPlayer3Controller->buttonPressed & (A_BUTTON | START_BUTTON)) {
level_set_transition(0, 0);
play_sound(SOUND_MENU_PAUSE_2, gDefaultSoundArgs);
gMenuMode = -1;
gDialogBoxState = DIALOG_STATE_OPENING;
return 1;
}
break;
}
if (gDialogTextAlpha < 250) {
gDialogTextAlpha += 25;
}
} else {
shade_screen();
optmenu_draw();
moon_draw_ui();
}
optmenu_check_buttons();
optmenu_draw_prompt();
#endif
moon_ui_toggle();
return 0;
}

View File

@ -1,22 +1,19 @@
#include "moon/texts/moon-loader.h"
#include "moon/network/moon-consumer.h"
#include "moon/ui/moon-ui-manager.h"
#include <iostream>
extern "C" {
#include "game/game_init.h"
#include "types.h"
void moon_init_languages(char *executable, char *gamedir) {
MoonConsumer consumer;
consumer.Init();
/*
#######################
Moon Languagues
#######################
*/
MoonResponse res;
MoonRequest req;
req.url = "https://raw.githubusercontent.com/Render96/Render96ex_Languages/master/PT_br.json";
req.file = "/home/alex/testout/Kalimba2.txt";
consumer.Get(req, &res);
printf("%s\n", res.body.c_str());
void moon_init_languages(char *executable, char *gamedir) {
Moon_InitLanguages(executable, gamedir);
}
@ -32,4 +29,26 @@ const char* moon_get_language_name( int id ) {
return languages[id]->name.c_str();
}
/*
#######################
Moon UI
#######################
*/
void moon_draw_ui(){
MoonDrawUI();
}
void moon_ui_toggle(){
MoonHandleToggle();
}
void moon_change_ui(int index){
MoonChangeUI(index);
}
u8 moon_ui_open(){
return isOpen;
}
}

View File

@ -9,5 +9,9 @@ u8 * moon_language_get_key( char* key );
void moon_set_language( int id );
const char* moon_get_language_name( int id );
void moon_draw_ui();
void moon_change_ui(int index);
u8 moon_ui_open();
void moon_ui_toggle();
#endif
#endif

View File

@ -0,0 +1,53 @@
#include "moon-screen.h"
extern "C" {
#include "sm64.h"
#include "game/game_init.h"
#include "gfx_dimensions.h"
#include "game/mario_misc.h"
}
void MoonScreen::Init(){
for(int i = 0; i < widgets.size(); i++)
widgets[i]->Init();
}
void MoonScreen::Mount(){}
void MoonScreen::Draw(){
this->screenWidth = SCREEN_WIDTH + abs(GFX_DIMENSIONS_FROM_LEFT_EDGE(0)) * 2;
this->screenHeight = SCREEN_HEIGHT;
for(int i = 0; i < widgets.size(); i++)
widgets[i]->Draw();
}
void MoonScreen::Update(){
for(int i = 0; i < widgets.size(); i++)
widgets[i]->Update();
}
void MoonScreen::Dispose(){
for(int i = 0; i < widgets.size(); i++)
widgets[i]->Dispose();
}
bool MoonScreen::IsPressed(MoonButtons button){
return gPlayer1Controller->buttonPressed & button;
}
bool MoonScreen::IsDown(MoonButtons button){
return gPlayer1Controller->buttonDown & button;
}
float GetValue(MoonButtons button){
switch(button){
case MoonButtons::L_STICK:
case MoonButtons::R_STICK:
return gPlayer1Controller->stickX;
case MoonButtons::U_STICK:
case MoonButtons::D_STICK:
return gPlayer1Controller->stickY;
default:
return 0.f;
}
}

View File

@ -0,0 +1,33 @@
#ifndef MoonScreenInterface
#define MoonScreenInterface
#include "moon-widget.h"
#include <vector>
enum MoonButtons {
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,
L_CBTN = 0x0002, R_CBTN = 0x0001
};
class MoonScreen {
private:
std::vector<MoonWidget*> widgets;
public:
virtual void Init();
virtual void Mount();
virtual void Draw();
virtual void Update();
virtual void Dispose();
bool IsPressed(MoonButtons button);
bool IsDown(MoonButtons button);
float GetValue(MoonButtons button);
float screenWidth;
float screenHeight;
};
#endif

View File

@ -0,0 +1,12 @@
#ifndef MoonWidgetInterface
#define MoonWidgetInterface
class MoonWidget {
public:
virtual void Init(){}
virtual void Draw(){}
virtual void Update(){}
virtual void Dispose(){}
};
#endif

View File

@ -0,0 +1,68 @@
#include <vector>
#include <iostream>
#include "interfaces/moon-screen.h"
#include "screens/moon-test.h"
extern "C" {
#include "game/game_init.h"
}
using namespace std;
bool isRunning = false;
bool isOpen = false;
int currentScreen = 0;
vector<MoonScreen*> screens;
MoonButtons toggle = MoonButtons::R_BTN;
void MoonUpdateStatus();
void MoonInitUI() {
if(screens.empty())
screens.push_back(new MoonTest());
screens[currentScreen]->Init();
screens[currentScreen]->Mount();
}
void MoonDrawUI() {
MoonUpdateStatus();
screens[currentScreen]->Update();
screens[currentScreen]->Draw();
}
void MoonDisposeUI() {
isRunning = false;
screens[currentScreen]->Dispose();
}
void MoonChangeUI(int index){
if(index == -1){
isOpen = false;
return;
}
if(!(isOpen && isRunning)) return;
currentScreen = index;
screens[currentScreen]->Init();
screens[currentScreen]->Mount();
}
void MoonHandleToggle(){
if(gPlayer1Controller->buttonPressed & toggle){
isOpen = !isOpen;
if(isOpen) isRunning = false;
}
}
void MoonUpdateStatus() {
if(!isOpen) {
if(isRunning) MoonDisposeUI();
return;
}
if(!isRunning) {
MoonInitUI();
isRunning = true;
}
}

View File

@ -0,0 +1,10 @@
#ifndef MoonSettingsUI
#define MoonSettingsUI
extern bool isOpen;
void MoonDrawUI();
void MoonChangeUI(int index);
void MoonHandleToggle();
#endif

View File

@ -0,0 +1,50 @@
#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"
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());
}
int x = 0;
int y = 30;
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;
}
MoonDrawRectangle(0, 0, this->screenWidth, this->screenHeight, {0, 0, 0, 100}, false);
MoonDrawText(x, y, "This is a test uwu", 1.0, {255, 255, 255, 255}, false);
MoonDrawColoredText(0, 50, "This is a test owo", 1.0, {255, 255, 255, 255}, false);
}

View File

@ -0,0 +1,12 @@
#ifndef MoonScreenTest
#define MoonScreenTest
#include "moon/ui/interfaces/moon-screen.h"
class MoonTest : public MoonScreen {
public:
void Init();
void Draw();
};
#endif

View File

@ -0,0 +1,30 @@
#include "moon-draw-utils.h"
#include <algorithm>
void MoonDrawText(float x, float y, std::string text, float scale, struct Color color, bool u4_3){
if(!u4_3){
x = GFX_DIMENSIONS_FROM_LEFT_EDGE(x);
y = SCREEN_HEIGHT - y;
}
gSPDisplayList(gDisplayListHead++, dl_ia_text_begin);
gDPSetEnvColor(gDisplayListHead++, color.r, color.g, color.b, color.a);
moon_draw_text(x, 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){
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);
gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end);
gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255);
}
void MoonDrawRectangle(float x, float y, float w, float h, struct Color c, bool u4_3){
moon_draw_rectangle(x, y, w, h, c, u4_3);
}

View File

@ -0,0 +1,20 @@
#ifndef MoonDrawUtils
#define MoonDrawUtils
#include <string>
extern "C" {
#include "moon/utils/moon-gfx.h"
#include "game/ingame_menu.h"
#include "game/game_init.h"
#include "game/segment2.h"
#include "gfx_dimensions.h"
#include "config.h"
#include "game/geo_misc.h"
#include "text/txtconv.h"
}
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 MoonDrawRectangle (float x, float y, float w, float h, struct Color c, bool u4_3);
#endif

View File

@ -2,6 +2,9 @@
#include "game/ingame_menu.h"
#include "game/game_init.h"
#include "game/segment2.h"
#include "gfx_dimensions.h"
#include "config.h"
#include "game/geo_misc.h"
f32 moon_get_text_width(u8* text, float scale, u8 colored) {
f32 size = 0;
@ -95,6 +98,19 @@ void moon_draw_text(f32 x, f32 y, const u8 *str, float scale) {
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
}
Vtx *make_rect_verts(float w, float h) {
Vtx *verts = alloc_display_list(4 * sizeof(*verts));
if (verts != NULL) {
make_vertex(verts, 0, 0, -h, -1, 0, 0, 255, 255, 255, 255);
make_vertex(verts, 1, w, -h, -1, 0, 0, 255, 255, 255, 255);
make_vertex(verts, 2, w, 0, -1, 0, 0, 255, 255, 255, 255);
make_vertex(verts, 3, 0, 0, -1, 0, 0, 255, 255, 255, 255);
}
return verts;
}
void moon_draw_texture(s32 x, s32 y, u32 w, u32 h, u8 *texture) {
gSPDisplayList(gDisplayListHead++, dl_hud_img_begin);
gDPSetTile(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_32b, 0, 0, G_TX_LOADTILE, 0, G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOLOD);
@ -109,12 +125,29 @@ void moon_draw_texture(s32 x, s32 y, u32 w, u32 h, u8 *texture) {
gSPDisplayList(gDisplayListHead++, dl_hud_img_end);
}
void moon_draw_rectangle(s16 x1, s16 y1, s16 x2, s16 y2, u8 r, u8 g, u8 b) {
gDPPipeSync(gDisplayListHead++);
gDPSetRenderMode(gDisplayListHead++, G_RM_OPA_SURF, G_RM_OPA_SURF2);
gDPSetCycleType(gDisplayListHead++, G_CYC_FILL);
gDPSetFillColor(gDisplayListHead++, GPACK_RGBA5551(r, g, b, 255));
gDPFillRectangle(gDisplayListHead++, x1, y1, x2 + 1, y2 + 1);
gDPPipeSync(gDisplayListHead++);
gDPSetCycleType(gDisplayListHead++, G_CYC_1CYCLE);
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;
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);
Vtx *vertices = make_rect_verts(w, h);
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(_Matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
gDPSetEnvColor(gDisplayListHead++, c.r, c.g, c.b, c.a);
gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING)
gDPSetCombineMode(gDisplayListHead++, G_CC_FADE, G_CC_FADE);
gDPSetRenderMode(gDisplayListHead++, G_RM_XLU_SURF, G_RM_XLU_SURF2);
gSPVertex(gDisplayListHead++, vertices, 4, 0);
gSP2Triangles(gDisplayListHead++, 0, 1, 2, 0x0, 0, 2, 3, 0x0);
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255);
}

View File

@ -2,10 +2,21 @@
#define MoonGFX
#include "types.h"
struct Color {
u8 r;
u8 g;
u8 b;
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_text(f32 x, f32 y, const u8 *str, float scale);
void moon_draw_rectangle(s16 x1, s16 y1, s16 x2, s16 y2, u8 r, u8 g, u8 b);
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);
#endif