2020-12-02 18:18:49 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2022-07-30 23:52:50 -04:00
|
|
|
#include <SDL/SDL.h>
|
2021-01-27 16:26:19 -05:00
|
|
|
#include <libreborn/libreborn.h>
|
2021-09-11 23:18:12 -04:00
|
|
|
#include <symbols/minecraft.h>
|
2020-12-02 18:18:49 -05:00
|
|
|
|
2022-06-25 17:30:08 -04:00
|
|
|
#include <mods/init/init.h>
|
|
|
|
#include <mods/feature/feature.h>
|
|
|
|
#include <mods/input/input.h>
|
|
|
|
#include <mods/sign/sign.h>
|
2020-12-02 18:18:49 -05:00
|
|
|
|
2022-07-30 23:52:50 -04:00
|
|
|
// Handle Backspace
|
|
|
|
static int32_t sdl_key_to_minecraft_key_injection(int32_t sdl_key) {
|
|
|
|
if (sdl_key == SDLK_BACKSPACE) {
|
|
|
|
return 8;
|
|
|
|
} else {
|
|
|
|
// Call Original Method
|
2024-01-07 03:23:43 -05:00
|
|
|
return Common_sdl_key_to_minecraft_key(sdl_key);
|
2022-07-30 23:52:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 18:18:49 -05:00
|
|
|
// Open Sign Screen
|
2024-01-06 06:30:23 -05:00
|
|
|
static void LocalPlayer_openTextEdit_injection(LocalPlayer *local_player, TileEntity *sign) {
|
|
|
|
if (sign->id == 4) {
|
|
|
|
Minecraft *minecraft = local_player->minecraft;
|
|
|
|
TextEditScreen *screen = alloc_TextEditScreen();
|
2021-02-16 12:26:40 -05:00
|
|
|
ALLOC_CHECK(screen);
|
2024-01-07 03:23:43 -05:00
|
|
|
screen = TextEditScreen_constructor(screen, (SignTileEntity *) sign);
|
|
|
|
Minecraft_setScreen(minecraft, (Screen *) screen);
|
2020-12-02 18:18:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store Text Input
|
|
|
|
std::vector<char> input;
|
2021-06-28 22:59:24 -04:00
|
|
|
void sign_key_press(char key) {
|
2022-07-30 23:52:50 -04:00
|
|
|
input.push_back(key);
|
2020-12-02 18:18:49 -05:00
|
|
|
}
|
2024-01-06 06:30:23 -05:00
|
|
|
static void clear_input(__attribute__((unused)) Minecraft *minecraft) {
|
2020-12-02 18:18:49 -05:00
|
|
|
input.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle Text Input
|
2024-01-06 06:30:23 -05:00
|
|
|
static void TextEditScreen_updateEvents_injection(TextEditScreen *screen) {
|
2020-12-02 18:18:49 -05:00
|
|
|
// Call Original Method
|
2024-01-07 03:23:43 -05:00
|
|
|
TextEditScreen_updateEvents_non_virtual(screen);
|
2020-12-02 18:18:49 -05:00
|
|
|
|
2024-01-06 06:30:23 -05:00
|
|
|
if (!screen->passthrough_input) {
|
2020-12-02 18:18:49 -05:00
|
|
|
for (char key : input) {
|
2022-07-30 23:52:50 -04:00
|
|
|
// Handle Normal Key
|
2024-01-06 06:30:23 -05:00
|
|
|
screen->vtable->keyboardNewChar(screen, key);
|
2020-12-02 18:18:49 -05:00
|
|
|
}
|
|
|
|
}
|
2021-07-04 19:02:45 -04:00
|
|
|
clear_input(NULL);
|
2020-12-02 18:18:49 -05:00
|
|
|
}
|
|
|
|
|
2021-06-28 22:59:24 -04:00
|
|
|
// Init
|
|
|
|
void init_sign() {
|
2022-04-09 20:01:16 -04:00
|
|
|
if (feature_has("Fix Sign Placement", server_disabled)) {
|
2022-07-30 23:52:50 -04:00
|
|
|
// Handle Backspace
|
2024-01-06 06:30:23 -05:00
|
|
|
overwrite_calls((void *) Common_sdl_key_to_minecraft_key, (void *) sdl_key_to_minecraft_key_injection);
|
2020-12-02 18:18:49 -05:00
|
|
|
// Fix Signs
|
|
|
|
patch_address(LocalPlayer_openTextEdit_vtable_addr, (void *) LocalPlayer_openTextEdit_injection);
|
|
|
|
patch_address(TextEditScreen_updateEvents_vtable_addr, (void *) TextEditScreen_updateEvents_injection);
|
2022-07-30 23:52:50 -04:00
|
|
|
// Clear Input On Input Tick
|
2021-07-04 19:02:45 -04:00
|
|
|
input_run_on_tick(clear_input);
|
2020-12-02 18:18:49 -05:00
|
|
|
}
|
2021-06-28 22:59:24 -04:00
|
|
|
}
|