Send Button In Chat

This commit is contained in:
TheBrokenRail 2024-02-01 14:56:16 -05:00
parent 69211eb31d
commit 4f32cfab45
15 changed files with 108 additions and 53 deletions

@ -1 +1 @@
Subproject commit 059e572256667f696f2f1ac9f5253859d54f50c4 Subproject commit 95e24d13fa223ff524f8920314c4984686c73928

View File

@ -31,5 +31,5 @@ struct TextInputBox {
void onClick(int x, int y); void onClick(int x, int y);
bool clicked(int x, int y); bool clicked(int x, int y);
static TextInputBox create(int id, const std::string &placeholder = "", const std::string &text = ""); static TextInputBox *create(int id, const std::string &placeholder = "", const std::string &text = "");
}; };

View File

@ -6,7 +6,7 @@
struct TextInputScreen { struct TextInputScreen {
Screen super; Screen super;
std::vector<TextInputBox *> m_textInputs; std::vector<TextInputBox *> *m_textInputs;
static void setup(Screen_vtable *vtable); static void setup(Screen_vtable *vtable);
}; };

View File

@ -12,23 +12,48 @@
// Structure // Structure
struct ChatScreen { struct ChatScreen {
TextInputScreen super; TextInputScreen super;
TextInputBox chat; TextInputBox *chat;
Button *send;
}; };
CUSTOM_VTABLE(chat_screen, Screen) { CUSTOM_VTABLE(chat_screen, Screen) {
TextInputScreen::setup(vtable); TextInputScreen::setup(vtable);
// Init // Init
static Screen_init_t original_init = vtable->init;
vtable->init = [](Screen *super) { vtable->init = [](Screen *super) {
Screen_init_non_virtual(super); original_init(super);
ChatScreen *self = (ChatScreen *) super; ChatScreen *self = (ChatScreen *) super;
self->super.m_textInputs.push_back(&self->chat); // Text Input
self->chat.init(super->font); self->chat = TextInputBox::create(1);
self->chat.setFocused(true); self->super.m_textInputs->push_back(self->chat);
self->chat->init(super->font);
self->chat->setFocused(true);
// Send Button
if (Minecraft_isTouchscreen(super->minecraft)) {
self->send = (Button *) new Touch_TButton;
} else {
self->send = new Button;
}
ALLOC_CHECK(self->send);
int send_id = 2;
std::string send_text = "Send";
if (Minecraft_isTouchscreen(super->minecraft)) {
Touch_TButton_constructor((Touch_TButton *) self->send, send_id, &send_text);
} else {
Button_constructor(self->send, send_id, &send_text);
}
super->rendered_buttons.push_back(self->send);
super->selectable_buttons.push_back(self->send);
// Hide Chat Messages
is_in_chat = true; is_in_chat = true;
}; };
// Removal // Removal
static Screen_removed_t original_removed = vtable->removed;
vtable->removed = [](Screen *super) { vtable->removed = [](Screen *super) {
Screen_removed_non_virtual(super); original_removed(super);
is_in_chat = false; is_in_chat = false;
ChatScreen *self = (ChatScreen *) super;
delete self->chat;
self->send->vtable->destructor_deleting(self->send);
}; };
// Rendering // Rendering
static Screen_render_t original_render = vtable->render; static Screen_render_t original_render = vtable->render;
@ -44,24 +69,41 @@ CUSTOM_VTABLE(chat_screen, Screen) {
vtable->setupPositions = [](Screen *super) { vtable->setupPositions = [](Screen *super) {
Screen_setupPositions_non_virtual(super); Screen_setupPositions_non_virtual(super);
ChatScreen *self = (ChatScreen *) super; ChatScreen *self = (ChatScreen *) super;
int height = 20; self->send->height = 20;
self->send->width = 40;
int x = 0; int x = 0;
int y = super->height - height; int y = super->height - self->send->height;
int width = super->width; int width = super->width - self->send->width;
self->chat.setSize(x, y, width, height); self->chat->setSize(x, y, width, self->send->height);
self->send->y = super->height - self->send->height;
self->send->x = x + width;
}; };
// Key Presses // Key Presses
static Screen_keyPressed_t original_keyPressed = vtable->keyPressed; static Screen_keyPressed_t original_keyPressed = vtable->keyPressed;
vtable->keyPressed = [](Screen *super, int key) { vtable->keyPressed = [](Screen *super, int key) {
// Handle Enter // Handle Enter
ChatScreen *self = (ChatScreen *) super; ChatScreen *self = (ChatScreen *) super;
if (key == 0x0d) { if (key == 0x0d && self->chat->m_bFocused) {
_chat_queue_message(self->chat.m_text.c_str()); if (self->chat->m_text.length() > 0) {
_chat_queue_message(self->chat->m_text.c_str());
}
Minecraft_setScreen(super->minecraft, NULL); Minecraft_setScreen(super->minecraft, NULL);
} }
// Call Original Method // Call Original Method
original_keyPressed(super, key); original_keyPressed(super, key);
}; };
// Button Click
vtable->buttonClicked = [](Screen *super, Button *button) {
ChatScreen *self = (ChatScreen *) super;
if (button == self->send) {
// Send
self->chat->setFocused(true);
super->vtable->keyPressed(super, 0x0d);
} else {
// Call Original Method
Screen_buttonClicked_non_virtual(super, button);
}
};
} }
static Screen *create_chat_screen() { static Screen *create_chat_screen() {
// Construct // Construct
@ -72,9 +114,6 @@ static Screen *create_chat_screen() {
// Set VTable // Set VTable
screen->super.super.vtable = get_chat_screen_vtable(); screen->super.super.vtable = get_chat_screen_vtable();
// Setup
screen->chat = TextInputBox::create(0);
// Return // Return
return (Screen *) screen; return (Screen *) screen;
} }

View File

@ -490,7 +490,7 @@ static ContainerMenu *ContainerMenu_injection(ContainerMenu *container_menu, Con
// Return // Return
return container_menu; return container_menu;
} }
static unsigned char *ContainerMenu_destructor_injection(ContainerMenu *container_menu) { static ContainerMenu *ContainerMenu_destructor_injection(ContainerMenu *container_menu) {
// Play Animation // Play Animation
Container *container = container_menu->container; Container *container = container_menu->container;
ChestTileEntity *tile_entity = (ChestTileEntity *) (((unsigned char *) container) - offsetof(ChestTileEntity, container)); ChestTileEntity *tile_entity = (ChestTileEntity *) (((unsigned char *) container) - offsetof(ChestTileEntity, container));
@ -500,7 +500,7 @@ static unsigned char *ContainerMenu_destructor_injection(ContainerMenu *containe
} }
// Call Original Method // Call Original Method
return ContainerMenu_destructor_non_virtual(container_menu); return ContainerMenu_destructor_complete_non_virtual(container_menu);
} }
#ifndef MCPI_HEADLESS_MODE #ifndef MCPI_HEADLESS_MODE
@ -720,8 +720,8 @@ void init_misc() {
// Animation // Animation
overwrite_calls((void *) ContainerMenu_constructor, (void *) ContainerMenu_injection); overwrite_calls((void *) ContainerMenu_constructor, (void *) ContainerMenu_injection);
overwrite_calls((void *) ContainerMenu_destructor_non_virtual, (void *) ContainerMenu_destructor_injection); overwrite_calls((void *) ContainerMenu_destructor_complete_non_virtual, (void *) ContainerMenu_destructor_injection);
patch_address(ContainerMenu_destructor_vtable_addr, (void *) ContainerMenu_destructor_injection); patch_address(ContainerMenu_destructor_complete_vtable_addr, (void *) ContainerMenu_destructor_injection);
} }
patch_address((void *) 0x115b48, (void *) ChestTileEntity_shouldSave_injection); patch_address((void *) 0x115b48, (void *) ChestTileEntity_shouldSave_injection);

View File

@ -2,26 +2,26 @@
#include <mods/text-input-box/TextInputBox.h> #include <mods/text-input-box/TextInputBox.h>
TextInputBox TextInputBox::create(int id, const std::string &placeholder, const std::string &text) { TextInputBox *TextInputBox::create(int id, const std::string &placeholder, const std::string &text) {
// Construct // Construct
TextInputBox self; TextInputBox *self = new TextInputBox;
GuiComponent_constructor(&self.super); GuiComponent_constructor(&self->super);
// Setup // Setup
self.m_ID = id; self->m_ID = id;
self.m_xPos = 0; self->m_xPos = 0;
self.m_yPos = 0; self->m_yPos = 0;
self.m_width = 0; self->m_width = 0;
self.m_height = 0; self->m_height = 0;
self.m_placeholder = placeholder; self->m_placeholder = placeholder;
self.m_text = text; self->m_text = text;
self.m_bFocused = false; self->m_bFocused = false;
self.m_bEnabled = true; self->m_bEnabled = true;
self.m_bCursorOn = true; self->m_bCursorOn = true;
self.m_insertHead = 0; self->m_insertHead = 0;
self.m_lastFlashed = 0; self->m_lastFlashed = 0;
self.m_pFont = nullptr; self->m_pFont = nullptr;
self.m_maxLength = -1; self->m_maxLength = -1;
// Return // Return
return self; return self;

View File

@ -7,34 +7,44 @@ void TextInputScreen::setup(Screen_vtable *vtable) {
vtable->keyPressed = [](Screen *super2, int key) { vtable->keyPressed = [](Screen *super2, int key) {
Screen_keyPressed_non_virtual(super2, key); Screen_keyPressed_non_virtual(super2, key);
TextInputScreen *self = (TextInputScreen *) super2; TextInputScreen *self = (TextInputScreen *) super2;
for (int i = 0; i < int(self->m_textInputs.size()); i++) { for (int i = 0; i < int(self->m_textInputs->size()); i++) {
TextInputBox *textInput = self->m_textInputs[i]; TextInputBox *textInput = (*self->m_textInputs)[i];
textInput->keyPressed(key); textInput->keyPressed(key);
} }
}; };
vtable->keyboardNewChar = [](Screen *super2, char key) { vtable->keyboardNewChar = [](Screen *super2, char key) {
Screen_keyboardNewChar_non_virtual(super2, key); Screen_keyboardNewChar_non_virtual(super2, key);
TextInputScreen *self = (TextInputScreen *) super2; TextInputScreen *self = (TextInputScreen *) super2;
for (int i = 0; i < int(self->m_textInputs.size()); i++) { for (int i = 0; i < int(self->m_textInputs->size()); i++) {
TextInputBox *textInput = self->m_textInputs[i]; TextInputBox *textInput = (*self->m_textInputs)[i];
textInput->charPressed(key); textInput->charPressed(key);
} }
}; };
vtable->mouseClicked = [](Screen *super2, int x, int y, int param_1) { vtable->mouseClicked = [](Screen *super2, int x, int y, int param_1) {
Screen_mouseClicked_non_virtual(super2, x, y, param_1); Screen_mouseClicked_non_virtual(super2, x, y, param_1);
TextInputScreen *self = (TextInputScreen *) super2; TextInputScreen *self = (TextInputScreen *) super2;
for (int i = 0; i < int(self->m_textInputs.size()); i++) { for (int i = 0; i < int(self->m_textInputs->size()); i++) {
TextInputBox *textInput = self->m_textInputs[i]; TextInputBox *textInput = (*self->m_textInputs)[i];
textInput->onClick(x, y); textInput->onClick(x, y);
} }
}; };
vtable->render = [](Screen *super2, int x, int y, float param_1) { vtable->render = [](Screen *super2, int x, int y, float param_1) {
Screen_render_non_virtual(super2, x, y, param_1); Screen_render_non_virtual(super2, x, y, param_1);
TextInputScreen *self = (TextInputScreen *) super2; TextInputScreen *self = (TextInputScreen *) super2;
for (int i = 0; i < int(self->m_textInputs.size()); i++) { for (int i = 0; i < int(self->m_textInputs->size()); i++) {
TextInputBox *textInput = self->m_textInputs[i]; TextInputBox *textInput = (*self->m_textInputs)[i];
textInput->tick(); textInput->tick();
textInput->render(); textInput->render();
} }
}; };
vtable->init = [](Screen *super2) {
Screen_init_non_virtual(super2);
TextInputScreen *self = (TextInputScreen *) super2;
self->m_textInputs = new std::vector<TextInputBox *>;
};
vtable->removed = [](Screen *super2) {
Screen_removed_non_virtual(super2);
TextInputScreen *self = (TextInputScreen *) super2;
delete self->m_textInputs;
};
} }

View File

@ -110,6 +110,7 @@ set(SRC
src/gui/components/IntRectangle.def src/gui/components/IntRectangle.def
src/gui/components/RectangleArea.def src/gui/components/RectangleArea.def
src/gui/components/ScrollingPane.def src/gui/components/ScrollingPane.def
src/gui/components/Touch_TButton.def
src/app-platform/AppPlatform.def src/app-platform/AppPlatform.def
src/app-platform/AppPlatform_linux.def src/app-platform/AppPlatform_linux.def
src/app-platform/AppPlatform_readAssetFile_return_value.def src/app-platform/AppPlatform_readAssetFile_return_value.def

View File

@ -1,7 +1,7 @@
size 0xa74;
extends GuiComponent; extends GuiComponent;
size 0xa74;
method void tick() = 0x27778; method void tick() = 0x27778;
method void handleClick(int param_2, int param_3, int param_4) = 0x2599c; method void handleClick(int param_2, int param_3, int param_4) = 0x2599c;
method void renderOnSelectItemNameText(int param_1, Font *font, int param_2) = 0x26aec; method void renderOnSelectItemNameText(int param_1, Font *font, int param_2) = 0x26aec;

View File

@ -1,5 +1,6 @@
extends GuiComponent; extends GuiComponent;
size 0x28;
constructor (int param_1, std::string *text) = 0x1bc54; constructor (int param_1, std::string *text) = 0x1bc54;
method int hovered(Minecraft *minecraft, int click_x, int click_y) = 0x1be2c; method int hovered(Minecraft *minecraft, int click_x, int click_y) = 0x1be2c;

View File

@ -1,7 +1,8 @@
size 0x8; size 0x8;
constructor () = 0x28204; constructor () = 0x28204;
vtable 0x1039b0;
method void blit(int x_dest, int y_dest, int x_src, int y_src, int width_dest, int height_dest, int width_src, int height_src) = 0x282a4; method void blit(int x_dest, int y_dest, int x_src, int y_src, int width_dest, int height_dest, int width_src, int height_src) = 0x282a4;
method void drawCenteredString(Font *font, std::string *text, int x, int y, int color) = 0x2821c; method void drawCenteredString(Font *font, std::string *text, int x, int y, int color) = 0x2821c;
method void drawString(Font *font, std::string *text, int x, int y, int color) = 0x28284; method void drawString(Font *font, std::string *text, int x, int y, int color) = 0x28284;

View File

@ -3,3 +3,5 @@ extends ImageButton;
constructor (Options_Option *option) = 0x1c968; constructor (Options_Option *option) = 0x1c968;
method void updateImage(Options *options) = 0x1ca58; method void updateImage(Options *options) = 0x1ca58;
property Options_Option *option = 0x54;

View File

@ -0,0 +1,4 @@
extends Button;
size 0x28;
constructor (int param_1, std::string *text) = 0x1c168;

View File

@ -1,6 +1,5 @@
vtable 0x10e1b8; vtable 0x10e1b8;
constructor (Container *container, int param_1) = 0x919a8; constructor (Container *container, int param_1) = 0x919a8;
virtual-method uchar *destructor() = 0x0;
property Container *container = 0x1c; property Container *container = 0x1c;

View File

@ -10,8 +10,6 @@ method int getFreeSlot() = 0x91ffc;
method int getSlot(int id) = 0x91ce0; method int getSlot(int id) = 0x91ce0;
method int linkSlot(int linked_slot, int unlinked_slot, bool push_aside) = 0x92188; method int linkSlot(int linked_slot, int unlinked_slot, bool push_aside) = 0x92188;
virtual-method ItemInstance *getItem(int pos) = 0x8;
virtual-method void setItem(int pos, ItemInstance *item) = 0xc;
virtual-method bool add(ItemInstance *item_instance) = 0x30; virtual-method bool add(ItemInstance *item_instance) = 0x30;
property int *linked_slots = 0xc; property int *linked_slots = 0xc;