minecraft-pi-reborn/mods/src/sign/sign.cpp

58 lines
1.6 KiB
C++
Raw Permalink Normal View History

2020-12-02 23:18:49 +00:00
#include <vector>
2022-07-31 03:52:50 +00:00
#include <SDL/SDL.h>
2021-01-27 21:26:19 +00:00
#include <libreborn/libreborn.h>
2021-09-12 03:18:12 +00:00
#include <symbols/minecraft.h>
2020-12-02 23:18:49 +00:00
2022-06-25 21:30:08 +00:00
#include <mods/init/init.h>
#include <mods/feature/feature.h>
#include <mods/input/input.h>
#include <mods/sign/sign.h>
2020-12-02 23:18:49 +00:00
2022-07-31 03:52:50 +00:00
// Handle Backspace
2024-04-03 07:19:12 +00:00
static int32_t sdl_key_to_minecraft_key_injection(Common_sdl_key_to_minecraft_key_t original, int32_t sdl_key) {
2022-07-31 03:52:50 +00:00
if (sdl_key == SDLK_BACKSPACE) {
2024-02-01 08:12:24 +00:00
return 0x8;
} else if (sdl_key == SDLK_DELETE) {
return 0x2e;
} else if (sdl_key == SDLK_LEFT) {
return 0x25;
} else if (sdl_key == SDLK_RIGHT) {
return 0x27;
2024-02-03 03:25:22 +00:00
} else if (sdl_key == SDLK_F1) {
return 0x70;
} else if (sdl_key == SDLK_F5) {
return 0x74;
2022-07-31 03:52:50 +00:00
} else {
// Call Original Method
2024-04-03 07:19:12 +00:00
return original(sdl_key);
2022-07-31 03:52:50 +00:00
}
}
2020-12-02 23:18:49 +00:00
// Open Sign Screen
2024-01-06 11:30:23 +00:00
static void LocalPlayer_openTextEdit_injection(LocalPlayer *local_player, TileEntity *sign) {
2024-02-12 07:29:35 +00:00
if (sign->type == 4) {
2024-01-06 11:30:23 +00:00
Minecraft *minecraft = local_player->minecraft;
2024-05-17 04:36:28 +00:00
TextEditScreen *screen = new TextEditScreen;
2021-02-16 17:26:40 +00:00
ALLOC_CHECK(screen);
2024-05-15 09:02:19 +00:00
screen = screen->constructor((SignTileEntity *) sign);
minecraft->setScreen((Screen *) screen);
2020-12-02 23:18:49 +00:00
}
}
// Store Text Input
2021-06-29 02:59:24 +00:00
void sign_key_press(char key) {
2024-05-17 06:52:55 +00:00
Keyboard::_inputText.push_back(key);
2020-12-02 23:18:49 +00:00
}
2021-06-29 02:59:24 +00:00
// Init
void init_sign() {
2022-04-10 00:01:16 +00:00
if (feature_has("Fix Sign Placement", server_disabled)) {
2020-12-02 23:18:49 +00:00
// Fix Signs
2024-05-05 00:46:15 +00:00
patch_vtable(LocalPlayer_openTextEdit, LocalPlayer_openTextEdit_injection);
2020-12-02 23:18:49 +00:00
}
2024-02-01 08:12:24 +00:00
// Handle Backspace
2024-04-03 07:19:12 +00:00
overwrite_calls(Common_sdl_key_to_minecraft_key, sdl_key_to_minecraft_key_injection);
2021-06-29 02:59:24 +00:00
}