mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-17 20:10:23 +03:00
Big leap for key rebinding and crossplatform-ness.
This commit is contained in:
@@ -382,50 +382,58 @@ void Gui::handleClick(int clickID, int mouseX, int mouseY)
|
||||
|
||||
void Gui::handleKeyPressed(int keyCode)
|
||||
{
|
||||
switch (keyCode)
|
||||
if (m_pMinecraft->m_options.isKey(KM_INVENTORY, keyCode))
|
||||
{
|
||||
case AKEYCODE_BUTTON_Y:
|
||||
{
|
||||
m_pMinecraft->setScreen(new IngameBlockSelectionScreen);
|
||||
break;
|
||||
}
|
||||
|
||||
case AKEYCODE_BACK:
|
||||
{
|
||||
int* slot = &m_pMinecraft->m_pLocalPlayer->m_pInventory->m_SelectedHotbarSlot;
|
||||
m_pMinecraft->setScreen(new IngameBlockSelectionScreen);
|
||||
return;
|
||||
}
|
||||
if (m_pMinecraft->m_options.isKey(KM_SLOT_R, keyCode))
|
||||
{
|
||||
int* slot = &m_pMinecraft->m_pLocalPlayer->m_pInventory->m_SelectedHotbarSlot;
|
||||
|
||||
#ifdef ENH_ENABLE_9TH_SLOT
|
||||
#define MAX_ITEMS (C_MAX_HOTBAR_ITEMS - 2)
|
||||
#else
|
||||
#define MAX_ITEMS (C_MAX_HOTBAR_ITEMS - 3)
|
||||
#endif
|
||||
//@HUH: for whatever reason, it ignores the 7th item
|
||||
if (*slot <= MAX_ITEMS)
|
||||
(*slot)++;
|
||||
//@HUH: for whatever reason, it ignores the 7th item
|
||||
if (*slot <= MAX_ITEMS)
|
||||
(*slot)++;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case AKEYCODE_BUTTON_X:
|
||||
{
|
||||
int* slot = &m_pMinecraft->m_pLocalPlayer->m_pInventory->m_SelectedHotbarSlot;
|
||||
|
||||
if (*slot > 0)
|
||||
(*slot)--;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case AKEYCODE_T:
|
||||
case AKEYCODE_SLASH:
|
||||
{
|
||||
if (m_pMinecraft->m_pScreen)
|
||||
break;
|
||||
|
||||
m_pMinecraft->setScreen(new ChatScreen(keyCode == AKEYCODE_SLASH));
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (m_pMinecraft->m_options.isKey(KM_SLOT_L, keyCode))
|
||||
{
|
||||
int* slot = &m_pMinecraft->m_pLocalPlayer->m_pInventory->m_SelectedHotbarSlot;
|
||||
|
||||
if (*slot > 0)
|
||||
(*slot)--;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef PLATFORM_ANDROID
|
||||
// Android already has this defined
|
||||
#elif defined(_WIN32)
|
||||
#define AKEYCODE_SLASH VK_OEM_2
|
||||
#elif defined(USE_SDL)
|
||||
#define AKEYCODE_SLASH SDLK_SLASH
|
||||
#else
|
||||
#error "Define the slash key here!"
|
||||
#endif
|
||||
|
||||
if (keyCode == AKEYCODE_SLASH || m_pMinecraft->m_options.isKey(KM_CHAT, keyCode))
|
||||
{
|
||||
if (m_pMinecraft->m_pScreen)
|
||||
return;
|
||||
|
||||
m_pMinecraft->setScreen(new ChatScreen(keyCode == AKEYCODE_SLASH));
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef AKEYCODE_SLASH
|
||||
#undef AKEYCODE_SLASH
|
||||
#endif
|
||||
}
|
||||
|
||||
void Gui::renderMessages(bool bShowAll)
|
||||
|
||||
@@ -70,7 +70,7 @@ bool Screen::isInGameScreen()
|
||||
|
||||
void Screen::keyPressed(int key)
|
||||
{
|
||||
if (key == AKEYCODE_MENU)//escape
|
||||
if (m_pMinecraft->m_options.isKey(KM_MENU_CANCEL, key))
|
||||
{
|
||||
m_pMinecraft->setScreen(nullptr);
|
||||
}
|
||||
@@ -78,19 +78,19 @@ void Screen::keyPressed(int key)
|
||||
if (m_buttonTabList.size())
|
||||
{
|
||||
#ifndef ENH_HIGHLIGHT_BY_HOVER
|
||||
if (m_pMinecraft->m_options.m_keyBinds[Options::MENU_NEXT].value == key)
|
||||
if (m_pMinecraft->m_options.isKey(MENU_NEXT, key))
|
||||
{
|
||||
m_tabButtonIndex++;
|
||||
if (m_tabButtonIndex == int(m_buttonTabList.size()))
|
||||
m_tabButtonIndex = 0;
|
||||
}
|
||||
if (m_pMinecraft->m_options.m_keyBinds[Options::MENU_PREVIOUS].value == key)
|
||||
if (m_pMinecraft->m_options.isKey(MENU_PREVIOUS, key))
|
||||
{
|
||||
m_tabButtonIndex--;
|
||||
if (m_tabButtonIndex == -1)
|
||||
m_tabButtonIndex = int(m_buttonTabList.size() - 1);
|
||||
}
|
||||
if (m_pMinecraft->m_options.m_keyBinds[Options::MENU_OK].value == key)
|
||||
if (m_pMinecraft->m_options.isKey(MENU_OK, key))
|
||||
{
|
||||
if (m_buttonTabList[m_tabButtonIndex]->m_bEnabled)
|
||||
{
|
||||
|
||||
@@ -107,7 +107,22 @@ void TextInputBox::keyPressed(Minecraft* minecraft, int key)
|
||||
break;
|
||||
}
|
||||
#else
|
||||
|
||||
char chr = '\0';
|
||||
|
||||
// here we'll just use the raw key codes...
|
||||
#ifdef _WIN32
|
||||
#define AKEYCODE_FORWARD_DEL VK_DELETE
|
||||
#define AKEYCODE_ARROW_LEFT VK_LEFT
|
||||
#define AKEYCODE_ARROW_RIGHT VK_RIGHT
|
||||
#define AKEYCODE_DEL VK_BACK
|
||||
#elif defined(USE_SDL)
|
||||
#define AKEYCODE_FORWARD_DEL SDLK_DELETE
|
||||
#define AKEYCODE_ARROW_LEFT SDLK_LEFT
|
||||
#define AKEYCODE_ARROW_RIGHT SDLK_RIGHT
|
||||
#define AKEYCODE_DEL SDLK_BACKSPACE
|
||||
#endif
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case AKEYCODE_FORWARD_DEL:
|
||||
@@ -127,6 +142,15 @@ void TextInputBox::keyPressed(Minecraft* minecraft, int key)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef AKEYCODE_FORWARD_DEL
|
||||
#undef AKEYCODE_FORWARD_DEL
|
||||
#undef AKEYCODE_ARROW_LEFT
|
||||
#undef AKEYCODE_ARROW_RIGHT
|
||||
#endif
|
||||
#ifdef AKEYCODE_DEL
|
||||
#undef AKEYCODE_DEL
|
||||
#endif
|
||||
|
||||
if (chr)
|
||||
charPressed(chr);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ void ChatScreen::render(int mouseX, int mouseY, float f)
|
||||
|
||||
void ChatScreen::keyPressed(int keyCode)
|
||||
{
|
||||
if (keyCode == AKEYCODE_ENTER)
|
||||
if (m_pMinecraft->m_options.isKey(KM_MENU_OK, keyCode))
|
||||
sendMessageAndExit();
|
||||
|
||||
Screen::keyPressed(keyCode);
|
||||
|
||||
@@ -32,12 +32,12 @@ void KeyboardInput::setKey(int keyCode, bool b)
|
||||
{
|
||||
int index = -1;
|
||||
|
||||
if (m_pOptions->getKey(KM_FORWARD) == keyCode) index = 0;
|
||||
if (m_pOptions->getKey(KM_BACK) == keyCode) index = 1;
|
||||
if (m_pOptions->getKey(KM_LEFT) == keyCode) index = 2;
|
||||
if (m_pOptions->getKey(KM_RIGHT) == keyCode) index = 3;
|
||||
if (m_pOptions->getKey(KM_JUMP) == keyCode) index = 4;
|
||||
if (m_pOptions->getKey(KM_SNEAK) == keyCode) index = 5;
|
||||
if (m_pOptions->getKey(KM_FORWARD) == keyCode) index = 0;
|
||||
if (m_pOptions->getKey(KM_BACKWARD) == keyCode) index = 1;
|
||||
if (m_pOptions->getKey(KM_LEFT) == keyCode) index = 2;
|
||||
if (m_pOptions->getKey(KM_RIGHT) == keyCode) index = 3;
|
||||
if (m_pOptions->getKey(KM_JUMP) == keyCode) index = 4;
|
||||
if (m_pOptions->getKey(KM_SNEAK) == keyCode) index = 5;
|
||||
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user