From f15625ff79001a137b6480af096163815e770638 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 10 May 2024 19:50:28 -0400 Subject: [PATCH] UI Tweaks --- mods/include/mods/misc/misc.h | 1 + mods/src/game-mode/ui.cpp | 29 ++++++++++++----------------- mods/src/misc/api.cpp | 21 +++++++++++++++++++++ mods/src/options/info.cpp | 26 +++----------------------- 4 files changed, 37 insertions(+), 40 deletions(-) diff --git a/mods/include/mods/misc/misc.h b/mods/include/mods/misc/misc.h index 44e410b9..6bdcea18 100644 --- a/mods/include/mods/misc/misc.h +++ b/mods/include/mods/misc/misc.h @@ -6,6 +6,7 @@ extern "C" { int32_t misc_get_real_selected_slot(Player *player); +void misc_render_background(int color, Minecraft *minecraft, int x, int y, int width, int height); typedef void (*misc_update_function_Minecraft_t)(Minecraft *obj); void misc_run_on_update(misc_update_function_Minecraft_t function); // obj == Minecraft * diff --git a/mods/src/game-mode/ui.cpp b/mods/src/game-mode/ui.cpp index 78c8c893..8b693eac 100644 --- a/mods/src/game-mode/ui.cpp +++ b/mods/src/game-mode/ui.cpp @@ -1,17 +1,13 @@ -// Config Needs To Load First -#include -#include "game-mode-internal.h" - -// Game Mode UI Code Is Useless In Headless Mode -#ifndef MCPI_HEADLESS_MODE - #include #include #include +#include #include #include +#include +#include "game-mode-internal.h" // Strings #define GAME_MODE_STR(mode) ("Game Mode: " mode) @@ -36,6 +32,9 @@ CUSTOM_VTABLE(create_world_screen, Screen) { static int inner_padding = 4; static int description_padding = 4; static int title_padding = 8; + static int button_height = 24; + static int content_y_offset_top = (title_padding * 2) + line_height; + static int content_y_offset_bottom = button_height + (bottom_padding * 2); // Init static Screen_init_t original_init = vtable->init; vtable->init = [](Screen *super) { @@ -79,7 +78,8 @@ CUSTOM_VTABLE(create_world_screen, Screen) { static Screen_render_t original_render = vtable->render; vtable->render = [](Screen *super, int x, int y, float param_1) { // Background - super->vtable->renderBackground(super); + misc_render_background(80, super->minecraft, 0, 0, super->width, super->height); + misc_render_background(32, super->minecraft, 0, content_y_offset_top, super->width, super->height - content_y_offset_top - content_y_offset_bottom); // Call Original Method original_render(super, x, y, param_1); // Title @@ -98,15 +98,15 @@ CUSTOM_VTABLE(create_world_screen, Screen) { CreateWorldScreen *self = (CreateWorldScreen *) super; // Height/Width int width = 120; - int height = 24; + int height = button_height; self->create->width = self->back->width = self->game_mode->width = width; int seed_width = self->game_mode->width; int name_width = width * 1.5f; self->create->height = self->back->height = self->game_mode->height = height; int text_box_height = self->game_mode->height; // Find Center Y - int top = (title_padding * 2) + line_height; - int bottom = super->height - self->create->height - (bottom_padding * 2); + int top = content_y_offset_top; + int bottom = super->height - content_y_offset_bottom; int center_y = ((bottom - top) / 2) + top; center_y -= (description_padding + line_height) / 2; // X/Y @@ -254,9 +254,4 @@ void _init_game_mode_ui() { // Hijack Create World Button overwrite_virtual_calls(SelectWorldScreen_tick, SelectWorldScreen_tick_injection); overwrite_virtual_calls(Touch_SelectWorldScreen_tick, Touch_SelectWorldScreen_tick_injection); -} - -#else -void _init_game_mode_ui() { -} -#endif +} \ No newline at end of file diff --git a/mods/src/misc/api.cpp b/mods/src/misc/api.cpp index 5ea182fc..67821852 100644 --- a/mods/src/misc/api.cpp +++ b/mods/src/misc/api.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include "misc-internal.h" @@ -139,6 +140,26 @@ static void Gui_handleKeyPressed_injection(Gui_handleKeyPressed_t original, Gui original(self, key); } +// Render Fancy Background +void misc_render_background(int color, Minecraft *minecraft, int x, int y, int width, int height) { + // https://github.com/ReMinecraftPE/mcpe/blob/f0d65eaecec1b3fe9c2f2b251e114a890c54ab77/source/client/gui/components/RolledSelectionList.cpp#L169-L179 + glColor4f(1, 1, 1, 1); + std::string texture = "gui/background.png"; + minecraft->textures->loadAndBindTexture(&texture); + Tesselator *t = &Tesselator_instance; + t->begin(7); + t->color(color, color, color, 255); + float x1 = x; + float x2 = x + width; + float y1 = y; + float y2 = y + height; + t->vertexUV(x1, y2, 0.0f, x1 / 32.0f, y2 / 32.0f); + t->vertexUV(x2, y2, 0.0f, x2 / 32.0f, y2 / 32.0f); + t->vertexUV(x2, y1, 0.0f, x2 / 32.0f, y1 / 32.0f); + t->vertexUV(x1, y1, 0.0f, x1 / 32.0f, y1 / 32.0f); + t->draw(); +} + // Init void _init_misc_api() { // Handle Custom Update Behavior diff --git a/mods/src/options/info.cpp b/mods/src/options/info.cpp index 0b5c0d6c..ec9c0900 100644 --- a/mods/src/options/info.cpp +++ b/mods/src/options/info.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include "options-internal.h" @@ -150,25 +150,6 @@ static void open_url(const std::string &url) { } } -// Render Fancy Background -static void render_background(Minecraft *minecraft, int x, int y, int width, int height) { - // https://github.com/ReMinecraftPE/mcpe/blob/f0d65eaecec1b3fe9c2f2b251e114a890c54ab77/source/client/gui/components/RolledSelectionList.cpp#L169-L179 - std::string texture = "gui/background.png"; - minecraft->textures->loadAndBindTexture(&texture); - Tesselator *t = &Tesselator_instance; - t->begin(7); - t->color(32, 32, 32, 255); - float x1 = x; - float x2 = x + width; - float y1 = y; - float y2 = y + height; - t->vertexUV(x1, y2, 0.0f, x1 / 32.0f, y2 / 32.0f); - t->vertexUV(x2, y2, 0.0f, x2 / 32.0f, y2 / 32.0f); - t->vertexUV(x2, y1, 0.0f, x2 / 32.0f, y1 / 32.0f); - t->vertexUV(x1, y1, 0.0f, x1 / 32.0f, y1 / 32.0f); - t->draw(); -} - // Create VTable CUSTOM_VTABLE(info_screen, Screen) { // Buttons @@ -207,9 +188,8 @@ CUSTOM_VTABLE(info_screen, Screen) { static Screen_render_t original_render = vtable->render; vtable->render = [](Screen *self, int x, int y, float param_1) { // Background - self->vtable->renderBackground(self); - // Gradient - render_background(self->minecraft, 0, content_y_offset_top, self->width, content_height); + misc_render_background(80, self->minecraft, 0, 0, self->width, self->height); + misc_render_background(32, self->minecraft, 0, content_y_offset_top, self->width, content_height); // Call Original Method original_render(self, x, y, param_1); // Title