UI Tweaks

This commit is contained in:
TheBrokenRail 2024-05-10 19:50:28 -04:00
parent e2d32cad21
commit f15625ff79
4 changed files with 37 additions and 40 deletions

View File

@ -6,6 +6,7 @@
extern "C" { extern "C" {
int32_t misc_get_real_selected_slot(Player *player); 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); typedef void (*misc_update_function_Minecraft_t)(Minecraft *obj);
void misc_run_on_update(misc_update_function_Minecraft_t function); // obj == Minecraft * void misc_run_on_update(misc_update_function_Minecraft_t function); // obj == Minecraft *

View File

@ -1,17 +1,13 @@
// Config Needs To Load First
#include <libreborn/libreborn.h>
#include "game-mode-internal.h"
// Game Mode UI Code Is Useless In Headless Mode
#ifndef MCPI_HEADLESS_MODE
#include <string> #include <string>
#include <set> #include <set>
#include <symbols/minecraft.h> #include <symbols/minecraft.h>
#include <libreborn/libreborn.h>
#include <mods/text-input-box/TextInputScreen.h> #include <mods/text-input-box/TextInputScreen.h>
#include <mods/touch/touch.h> #include <mods/touch/touch.h>
#include <mods/misc/misc.h>
#include "game-mode-internal.h"
// Strings // Strings
#define GAME_MODE_STR(mode) ("Game Mode: " mode) #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 inner_padding = 4;
static int description_padding = 4; static int description_padding = 4;
static int title_padding = 8; 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 // Init
static Screen_init_t original_init = vtable->init; static Screen_init_t original_init = vtable->init;
vtable->init = [](Screen *super) { vtable->init = [](Screen *super) {
@ -79,7 +78,8 @@ CUSTOM_VTABLE(create_world_screen, Screen) {
static Screen_render_t original_render = vtable->render; static Screen_render_t original_render = vtable->render;
vtable->render = [](Screen *super, int x, int y, float param_1) { vtable->render = [](Screen *super, int x, int y, float param_1) {
// Background // 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 // Call Original Method
original_render(super, x, y, param_1); original_render(super, x, y, param_1);
// Title // Title
@ -98,15 +98,15 @@ CUSTOM_VTABLE(create_world_screen, Screen) {
CreateWorldScreen *self = (CreateWorldScreen *) super; CreateWorldScreen *self = (CreateWorldScreen *) super;
// Height/Width // Height/Width
int width = 120; int width = 120;
int height = 24; int height = button_height;
self->create->width = self->back->width = self->game_mode->width = width; self->create->width = self->back->width = self->game_mode->width = width;
int seed_width = self->game_mode->width; int seed_width = self->game_mode->width;
int name_width = width * 1.5f; int name_width = width * 1.5f;
self->create->height = self->back->height = self->game_mode->height = height; self->create->height = self->back->height = self->game_mode->height = height;
int text_box_height = self->game_mode->height; int text_box_height = self->game_mode->height;
// Find Center Y // Find Center Y
int top = (title_padding * 2) + line_height; int top = content_y_offset_top;
int bottom = super->height - self->create->height - (bottom_padding * 2); int bottom = super->height - content_y_offset_bottom;
int center_y = ((bottom - top) / 2) + top; int center_y = ((bottom - top) / 2) + top;
center_y -= (description_padding + line_height) / 2; center_y -= (description_padding + line_height) / 2;
// X/Y // X/Y
@ -254,9 +254,4 @@ void _init_game_mode_ui() {
// Hijack Create World Button // Hijack Create World Button
overwrite_virtual_calls(SelectWorldScreen_tick, SelectWorldScreen_tick_injection); overwrite_virtual_calls(SelectWorldScreen_tick, SelectWorldScreen_tick_injection);
overwrite_virtual_calls(Touch_SelectWorldScreen_tick, Touch_SelectWorldScreen_tick_injection); overwrite_virtual_calls(Touch_SelectWorldScreen_tick, Touch_SelectWorldScreen_tick_injection);
} }
#else
void _init_game_mode_ui() {
}
#endif

View File

@ -3,6 +3,7 @@
#include <libreborn/libreborn.h> #include <libreborn/libreborn.h>
#include <symbols/minecraft.h> #include <symbols/minecraft.h>
#include <GLES/gl.h>
#include <mods/misc/misc.h> #include <mods/misc/misc.h>
#include "misc-internal.h" #include "misc-internal.h"
@ -139,6 +140,26 @@ static void Gui_handleKeyPressed_injection(Gui_handleKeyPressed_t original, Gui
original(self, key); 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 // Init
void _init_misc_api() { void _init_misc_api() {
// Handle Custom Update Behavior // Handle Custom Update Behavior

View File

@ -3,7 +3,7 @@
#include <GLES/gl.h> #include <GLES/gl.h>
#include <mods/touch/touch.h> #include <mods/touch/touch.h>
#include <mods/home/home.h> #include <mods/misc/misc.h>
#include "options-internal.h" #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 // Create VTable
CUSTOM_VTABLE(info_screen, Screen) { CUSTOM_VTABLE(info_screen, Screen) {
// Buttons // Buttons
@ -207,9 +188,8 @@ CUSTOM_VTABLE(info_screen, Screen) {
static Screen_render_t original_render = vtable->render; static Screen_render_t original_render = vtable->render;
vtable->render = [](Screen *self, int x, int y, float param_1) { vtable->render = [](Screen *self, int x, int y, float param_1) {
// Background // Background
self->vtable->renderBackground(self); misc_render_background(80, self->minecraft, 0, 0, self->width, self->height);
// Gradient misc_render_background(32, self->minecraft, 0, content_y_offset_top, self->width, content_height);
render_background(self->minecraft, 0, content_y_offset_top, self->width, content_height);
// Call Original Method // Call Original Method
original_render(self, x, y, param_1); original_render(self, x, y, param_1);
// Title // Title