Send Button In Chat
This commit is contained in:
parent
69211eb31d
commit
4f32cfab45
2
dependencies/symbol-processor/src
vendored
2
dependencies/symbol-processor/src
vendored
@ -1 +1 @@
|
||||
Subproject commit 059e572256667f696f2f1ac9f5253859d54f50c4
|
||||
Subproject commit 95e24d13fa223ff524f8920314c4984686c73928
|
@ -31,5 +31,5 @@ struct TextInputBox {
|
||||
void onClick(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 = "");
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
struct TextInputScreen {
|
||||
Screen super;
|
||||
std::vector<TextInputBox *> m_textInputs;
|
||||
std::vector<TextInputBox *> *m_textInputs;
|
||||
|
||||
static void setup(Screen_vtable *vtable);
|
||||
};
|
||||
|
@ -12,23 +12,48 @@
|
||||
// Structure
|
||||
struct ChatScreen {
|
||||
TextInputScreen super;
|
||||
TextInputBox chat;
|
||||
TextInputBox *chat;
|
||||
Button *send;
|
||||
};
|
||||
CUSTOM_VTABLE(chat_screen, Screen) {
|
||||
TextInputScreen::setup(vtable);
|
||||
// Init
|
||||
static Screen_init_t original_init = vtable->init;
|
||||
vtable->init = [](Screen *super) {
|
||||
Screen_init_non_virtual(super);
|
||||
original_init(super);
|
||||
ChatScreen *self = (ChatScreen *) super;
|
||||
self->super.m_textInputs.push_back(&self->chat);
|
||||
self->chat.init(super->font);
|
||||
self->chat.setFocused(true);
|
||||
// Text Input
|
||||
self->chat = TextInputBox::create(1);
|
||||
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;
|
||||
};
|
||||
// Removal
|
||||
static Screen_removed_t original_removed = vtable->removed;
|
||||
vtable->removed = [](Screen *super) {
|
||||
Screen_removed_non_virtual(super);
|
||||
original_removed(super);
|
||||
is_in_chat = false;
|
||||
ChatScreen *self = (ChatScreen *) super;
|
||||
delete self->chat;
|
||||
self->send->vtable->destructor_deleting(self->send);
|
||||
};
|
||||
// Rendering
|
||||
static Screen_render_t original_render = vtable->render;
|
||||
@ -44,24 +69,41 @@ CUSTOM_VTABLE(chat_screen, Screen) {
|
||||
vtable->setupPositions = [](Screen *super) {
|
||||
Screen_setupPositions_non_virtual(super);
|
||||
ChatScreen *self = (ChatScreen *) super;
|
||||
int height = 20;
|
||||
self->send->height = 20;
|
||||
self->send->width = 40;
|
||||
int x = 0;
|
||||
int y = super->height - height;
|
||||
int width = super->width;
|
||||
self->chat.setSize(x, y, width, height);
|
||||
int y = super->height - self->send->height;
|
||||
int width = super->width - self->send->width;
|
||||
self->chat->setSize(x, y, width, self->send->height);
|
||||
self->send->y = super->height - self->send->height;
|
||||
self->send->x = x + width;
|
||||
};
|
||||
// Key Presses
|
||||
static Screen_keyPressed_t original_keyPressed = vtable->keyPressed;
|
||||
vtable->keyPressed = [](Screen *super, int key) {
|
||||
// Handle Enter
|
||||
ChatScreen *self = (ChatScreen *) super;
|
||||
if (key == 0x0d) {
|
||||
_chat_queue_message(self->chat.m_text.c_str());
|
||||
if (key == 0x0d && self->chat->m_bFocused) {
|
||||
if (self->chat->m_text.length() > 0) {
|
||||
_chat_queue_message(self->chat->m_text.c_str());
|
||||
}
|
||||
Minecraft_setScreen(super->minecraft, NULL);
|
||||
}
|
||||
// Call Original Method
|
||||
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() {
|
||||
// Construct
|
||||
@ -72,9 +114,6 @@ static Screen *create_chat_screen() {
|
||||
// Set VTable
|
||||
screen->super.super.vtable = get_chat_screen_vtable();
|
||||
|
||||
// Setup
|
||||
screen->chat = TextInputBox::create(0);
|
||||
|
||||
// Return
|
||||
return (Screen *) screen;
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ static ContainerMenu *ContainerMenu_injection(ContainerMenu *container_menu, Con
|
||||
// Return
|
||||
return container_menu;
|
||||
}
|
||||
static unsigned char *ContainerMenu_destructor_injection(ContainerMenu *container_menu) {
|
||||
static ContainerMenu *ContainerMenu_destructor_injection(ContainerMenu *container_menu) {
|
||||
// Play Animation
|
||||
Container *container = container_menu->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
|
||||
return ContainerMenu_destructor_non_virtual(container_menu);
|
||||
return ContainerMenu_destructor_complete_non_virtual(container_menu);
|
||||
}
|
||||
|
||||
#ifndef MCPI_HEADLESS_MODE
|
||||
@ -720,8 +720,8 @@ void init_misc() {
|
||||
|
||||
// Animation
|
||||
overwrite_calls((void *) ContainerMenu_constructor, (void *) ContainerMenu_injection);
|
||||
overwrite_calls((void *) ContainerMenu_destructor_non_virtual, (void *) ContainerMenu_destructor_injection);
|
||||
patch_address(ContainerMenu_destructor_vtable_addr, (void *) ContainerMenu_destructor_injection);
|
||||
overwrite_calls((void *) ContainerMenu_destructor_complete_non_virtual, (void *) ContainerMenu_destructor_injection);
|
||||
patch_address(ContainerMenu_destructor_complete_vtable_addr, (void *) ContainerMenu_destructor_injection);
|
||||
}
|
||||
patch_address((void *) 0x115b48, (void *) ChestTileEntity_shouldSave_injection);
|
||||
|
||||
|
@ -2,26 +2,26 @@
|
||||
|
||||
#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
|
||||
TextInputBox self;
|
||||
GuiComponent_constructor(&self.super);
|
||||
TextInputBox *self = new TextInputBox;
|
||||
GuiComponent_constructor(&self->super);
|
||||
|
||||
// Setup
|
||||
self.m_ID = id;
|
||||
self.m_xPos = 0;
|
||||
self.m_yPos = 0;
|
||||
self.m_width = 0;
|
||||
self.m_height = 0;
|
||||
self.m_placeholder = placeholder;
|
||||
self.m_text = text;
|
||||
self.m_bFocused = false;
|
||||
self.m_bEnabled = true;
|
||||
self.m_bCursorOn = true;
|
||||
self.m_insertHead = 0;
|
||||
self.m_lastFlashed = 0;
|
||||
self.m_pFont = nullptr;
|
||||
self.m_maxLength = -1;
|
||||
self->m_ID = id;
|
||||
self->m_xPos = 0;
|
||||
self->m_yPos = 0;
|
||||
self->m_width = 0;
|
||||
self->m_height = 0;
|
||||
self->m_placeholder = placeholder;
|
||||
self->m_text = text;
|
||||
self->m_bFocused = false;
|
||||
self->m_bEnabled = true;
|
||||
self->m_bCursorOn = true;
|
||||
self->m_insertHead = 0;
|
||||
self->m_lastFlashed = 0;
|
||||
self->m_pFont = nullptr;
|
||||
self->m_maxLength = -1;
|
||||
|
||||
// Return
|
||||
return self;
|
||||
|
@ -7,34 +7,44 @@ void TextInputScreen::setup(Screen_vtable *vtable) {
|
||||
vtable->keyPressed = [](Screen *super2, int key) {
|
||||
Screen_keyPressed_non_virtual(super2, key);
|
||||
TextInputScreen *self = (TextInputScreen *) super2;
|
||||
for (int i = 0; i < int(self->m_textInputs.size()); i++) {
|
||||
TextInputBox *textInput = self->m_textInputs[i];
|
||||
for (int i = 0; i < int(self->m_textInputs->size()); i++) {
|
||||
TextInputBox *textInput = (*self->m_textInputs)[i];
|
||||
textInput->keyPressed(key);
|
||||
}
|
||||
};
|
||||
vtable->keyboardNewChar = [](Screen *super2, char key) {
|
||||
Screen_keyboardNewChar_non_virtual(super2, key);
|
||||
TextInputScreen *self = (TextInputScreen *) super2;
|
||||
for (int i = 0; i < int(self->m_textInputs.size()); i++) {
|
||||
TextInputBox *textInput = self->m_textInputs[i];
|
||||
for (int i = 0; i < int(self->m_textInputs->size()); i++) {
|
||||
TextInputBox *textInput = (*self->m_textInputs)[i];
|
||||
textInput->charPressed(key);
|
||||
}
|
||||
};
|
||||
vtable->mouseClicked = [](Screen *super2, int x, int y, int param_1) {
|
||||
Screen_mouseClicked_non_virtual(super2, x, y, param_1);
|
||||
TextInputScreen *self = (TextInputScreen *) super2;
|
||||
for (int i = 0; i < int(self->m_textInputs.size()); i++) {
|
||||
TextInputBox *textInput = self->m_textInputs[i];
|
||||
for (int i = 0; i < int(self->m_textInputs->size()); i++) {
|
||||
TextInputBox *textInput = (*self->m_textInputs)[i];
|
||||
textInput->onClick(x, y);
|
||||
}
|
||||
};
|
||||
vtable->render = [](Screen *super2, int x, int y, float param_1) {
|
||||
Screen_render_non_virtual(super2, x, y, param_1);
|
||||
TextInputScreen *self = (TextInputScreen *) super2;
|
||||
for (int i = 0; i < int(self->m_textInputs.size()); i++) {
|
||||
TextInputBox *textInput = self->m_textInputs[i];
|
||||
for (int i = 0; i < int(self->m_textInputs->size()); i++) {
|
||||
TextInputBox *textInput = (*self->m_textInputs)[i];
|
||||
textInput->tick();
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ set(SRC
|
||||
src/gui/components/IntRectangle.def
|
||||
src/gui/components/RectangleArea.def
|
||||
src/gui/components/ScrollingPane.def
|
||||
src/gui/components/Touch_TButton.def
|
||||
src/app-platform/AppPlatform.def
|
||||
src/app-platform/AppPlatform_linux.def
|
||||
src/app-platform/AppPlatform_readAssetFile_return_value.def
|
||||
|
@ -1,7 +1,7 @@
|
||||
size 0xa74;
|
||||
|
||||
extends GuiComponent;
|
||||
|
||||
size 0xa74;
|
||||
|
||||
method void tick() = 0x27778;
|
||||
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;
|
||||
|
@ -1,5 +1,6 @@
|
||||
extends GuiComponent;
|
||||
|
||||
size 0x28;
|
||||
constructor (int param_1, std::string *text) = 0x1bc54;
|
||||
|
||||
method int hovered(Minecraft *minecraft, int click_x, int click_y) = 0x1be2c;
|
||||
|
@ -1,7 +1,8 @@
|
||||
size 0x8;
|
||||
|
||||
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 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;
|
||||
|
@ -3,3 +3,5 @@ extends ImageButton;
|
||||
constructor (Options_Option *option) = 0x1c968;
|
||||
|
||||
method void updateImage(Options *options) = 0x1ca58;
|
||||
|
||||
property Options_Option *option = 0x54;
|
||||
|
4
symbols/src/gui/components/Touch_TButton.def
Normal file
4
symbols/src/gui/components/Touch_TButton.def
Normal file
@ -0,0 +1,4 @@
|
||||
extends Button;
|
||||
|
||||
size 0x28;
|
||||
constructor (int param_1, std::string *text) = 0x1c168;
|
@ -1,6 +1,5 @@
|
||||
vtable 0x10e1b8;
|
||||
|
||||
constructor (Container *container, int param_1) = 0x919a8;
|
||||
virtual-method uchar *destructor() = 0x0;
|
||||
|
||||
property Container *container = 0x1c;
|
||||
|
@ -10,8 +10,6 @@ method int getFreeSlot() = 0x91ffc;
|
||||
method int getSlot(int id) = 0x91ce0;
|
||||
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;
|
||||
|
||||
property int *linked_slots = 0xc;
|
||||
|
Loading…
Reference in New Issue
Block a user