diff --git a/platforms/sdl/main.cpp b/platforms/sdl/main.cpp index ed5d8dd..64c6f6d 100644 --- a/platforms/sdl/main.cpp +++ b/platforms/sdl/main.cpp @@ -42,6 +42,7 @@ static int TranslateSDLKeyCodeToVirtual(SDL_Scancode sdlCode) #define CODE(x) case SDL_SCANCODE_ ## x: return SDLVK_ ## x; #include "compat/SDLKeyCodes.h" #undef CODE + case SDL_NUM_SCANCODES: break; } return SDLVK_UNKNOWN; } @@ -275,7 +276,7 @@ static EM_BOOL main_loop(double time, void *user_data) } } -extern bool g_bIsMenuBackgroundAvailable; // client/gui/Screen.cpp +extern bool g_bIsMenuBackgroundAvailable; // client/app/IScreen.cpp extern bool g_bAreCloudsAvailable; // client/renderer/LevelRenderer.cpp extern bool g_bIsGrassColorAvailable; // world/level/GrassColor.cpp extern bool g_bIsFoliageColorAvailable; // world/level/FoliageColor.cpp @@ -402,7 +403,7 @@ int main(int argc, char *argv[]) g_pApp->init(); CheckOptionalTextureAvailability(); - + // Set Size resize(); diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index 5c8f99b..6d0e140 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -43,7 +43,6 @@ add_library(reminecraftpe-client STATIC player/input/RectangleArea.cpp player/input/RectangleArea.hpp player/input/TouchAreaModel.cpp player/input/TouchAreaModel.hpp player/input/TouchInputHolder.cpp player/input/TouchInputHolder.hpp - player/input/TouchscreenInput_TestFps.cpp player/input/TouchscreenInput_TestFps.hpp player/input/UnifiedTurnBuild.cpp player/input/UnifiedTurnBuild.hpp renderer/Chunk.cpp renderer/Chunk.hpp renderer/Culler.cpp renderer/Culler.hpp @@ -93,13 +92,15 @@ add_library(reminecraftpe-client STATIC sound/SoundRepository.cpp sound/SoundRepository.hpp sound/SoundSystem.cpp sound/SoundSystem.hpp ) -add_subdirectory(gui) -#add_subdirectory(player/input) +if (NEWUI) + # NOTE: NEWUI definition is actually used only in Minecraft.cpp + target_compile_definitions(reminecraftpe-client PRIVATE NEWUI) + add_subdirectory(newui) +else() + add_subdirectory(gui) +endif() -#add_library(reminecraftpe-client INTERFACE) target_link_libraries(reminecraftpe-client PUBLIC reminecraftpe-gui reminecraftpe-renderer - #reminecraftpe-network - #reminecraftpe-input ) diff --git a/source/client/app/IGui.cpp b/source/client/app/IGui.cpp index 205609f..bdec249 100644 --- a/source/client/app/IGui.cpp +++ b/source/client/app/IGui.cpp @@ -29,11 +29,11 @@ void IGui::onInventoryUpdated() { } -void IGui::tick() +void IGui::onTick() { } -void IGui::render(float f, bool bHaveScreen, int mouseX, int mouseY) +void IGui::onRender(float f, bool bHaveScreen, int mouseX, int mouseY) { } diff --git a/source/client/app/IGui.hpp b/source/client/app/IGui.hpp index 37805f0..31d1d17 100644 --- a/source/client/app/IGui.hpp +++ b/source/client/app/IGui.hpp @@ -20,8 +20,9 @@ public: virtual void addMessage(const std::string& str); virtual void onInventoryUpdated(); - virtual void tick(); - virtual void render(float f, bool bHaveScreen, int mouseX, int mouseY); + + virtual void onTick(); + virtual void onRender(float f, bool bHaveScreen, int mouseX, int mouseY); virtual bool isInside(int mx, int my); virtual void handleClick(int id, int mx, int my); diff --git a/source/client/app/IScreen.cpp b/source/client/app/IScreen.cpp index 387a8fe..e2b366f 100644 --- a/source/client/app/IScreen.cpp +++ b/source/client/app/IScreen.cpp @@ -8,6 +8,9 @@ #include "IScreen.hpp" +// TODO: This should be inside of an initialized "Minecraft" instance rather than the global namespace +bool g_bIsMenuBackgroundAvailable = false; + IScreen::IScreen() { m_width = 1; @@ -20,10 +23,10 @@ void IScreen::init(Minecraft* pMinecraft, int a3, int a4) m_width = a3; m_height = a4; m_pMinecraft = pMinecraft; - init(); + onInit(); } -void IScreen::init() +void IScreen::onInit() { } @@ -42,10 +45,6 @@ int IScreen::getYOffset() return 0; } -void IScreen::render(int xPos, int yPos, float unused) -{ -} - void IScreen::onEvents() { } @@ -58,7 +57,7 @@ void IScreen::keyboardEvent() { } -void IScreen::tick() +void IScreen::onTick() { } diff --git a/source/client/app/IScreen.hpp b/source/client/app/IScreen.hpp index 556f2e7..486ed22 100644 --- a/source/client/app/IScreen.hpp +++ b/source/client/app/IScreen.hpp @@ -17,18 +17,17 @@ public: virtual ~IScreen() = default; virtual void init(Minecraft*, int, int); - virtual void init(); - //virtual void updateTabButtonSelection(); virtual void setSize(int width, int height); - virtual void onRender(int mouseX, int mouseY, float f); virtual int getYOffset(); - virtual void render(int, int, float); + virtual void onInit(); + virtual void onRender(int mouseX, int mouseY, float f); virtual void onEvents(); + virtual void onTick(); + virtual void mouseEvent(); virtual void keyboardEvent(); virtual bool handleBackEvent(bool); - virtual void tick(); virtual void removed(); virtual void renderBackground(); virtual bool isPauseScreen(); @@ -37,9 +36,6 @@ public: virtual void confirmResult(bool, int); virtual void charInput(char); - // ported from 0.8 - //virtual void renderMenuBackground(float f); - int m_width; int m_height; bool m_bIgnore; diff --git a/source/client/app/Minecraft.cpp b/source/client/app/Minecraft.cpp index 33c874e..588aea6 100644 --- a/source/client/app/Minecraft.cpp +++ b/source/client/app/Minecraft.cpp @@ -12,7 +12,6 @@ #include "world/gamemode/SurvivalMode.hpp" #include "world/gamemode/CreativeMode.hpp" -#include "client/gui/Gui.hpp" #include "client/player/input/ControllerTurnInput.hpp" #include "client/player/input/MouseTurnInput.hpp" @@ -31,6 +30,12 @@ // custom: #include "client/renderer/PatchManager.hpp" +#ifdef NEWUI +#include "client/newui/Gui.hpp" +#else +#include "client/gui/Gui.hpp" +#endif + int Minecraft::width = C_DEFAULT_SCREEN_WIDTH; int Minecraft::height = C_DEFAULT_SCREEN_HEIGHT; float Minecraft::guiScaleMultiplier = 1.0f; @@ -147,7 +152,7 @@ void Minecraft::setScreen(IScreen* pScreen) m_pQueuedScreen = pScreen; return; } - + if (pScreen && pScreen->isErrorScreen()) { // not in original @@ -165,7 +170,7 @@ void Minecraft::setScreen(IScreen* pScreen) if (pScreen) { releaseMouse(); - pScreen->init(this, std::ceil(width * m_pGui->scale), std::ceil(height * m_pGui->scale)); + pScreen->init(this, std::ceil(float(width) * m_pGui->scale), std::ceil(float(height) * m_pGui->scale)); } else { @@ -529,7 +534,7 @@ void Minecraft::tickInput() if (b && !bai.isRemoveContinue()) handleBuildAction(&bai); - + bool flag = // If we are mouse operated, the LMB is held down and it's not in the GUI ((m_options->field_19 && Mouse::isButtonDown(BUTTON_LEFT) && !bIsInGUI) || @@ -685,7 +690,7 @@ void Minecraft::tick() tickInput(); - m_pGui->tick(); + m_pGui->onTick(); // if the level has been prepared, delete the prep thread if (!m_bPreparingLevel) @@ -734,7 +739,7 @@ void Minecraft::tick() } if (m_pScreen) - m_pScreen->tick(); + m_pScreen->onTick(); Multitouch::reset(); } @@ -969,7 +974,7 @@ void Minecraft::sizeUpdate(int newWidth, int newHeight) m_pGui->scale = getBestScaleForThisScreenSize(newWidth, newHeight) / guiScaleMultiplier; if (m_pScreen) - m_pScreen->setSize(std::ceil(Minecraft::width * m_pGui->scale), std::ceil(Minecraft::height * m_pGui->scale)); + m_pScreen->setSize(std::ceil(float(Minecraft::width) * m_pGui->scale), std::ceil(float(Minecraft::height) * m_pGui->scale)); if (m_pInputHolder) m_pInputHolder->setScreenSize(newWidth * guiScaleMultiplier, newHeight * guiScaleMultiplier); diff --git a/source/client/gui/CMakeLists.txt b/source/client/gui/CMakeLists.txt index 05166eb..ba3bf30 100644 --- a/source/client/gui/CMakeLists.txt +++ b/source/client/gui/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(reminecraftpe-gui STATIC components/SmallButton.cpp components/SmallButton.hpp components/TextInputBox.cpp components/TextInputBox.hpp components/WorldSelectionList.cpp components/WorldSelectionList.hpp + input/TouchscreenInput_TestFps.cpp input/TouchscreenInput_TestFps.hpp screens/ChatScreen.cpp screens/ChatScreen.hpp screens/ConfirmScreen.cpp screens/ConfirmScreen.hpp screens/CreateWorldScreen.cpp screens/CreateWorldScreen.hpp diff --git a/source/client/gui/Gui.cpp b/source/client/gui/Gui.cpp index 58a4b64..f60af6f 100644 --- a/source/client/gui/Gui.cpp +++ b/source/client/gui/Gui.cpp @@ -122,7 +122,7 @@ void Gui::onInventoryUpdated() //field_A3C = true; } -void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) +void Gui::onRender(float f, bool bHaveScreen, int mouseX, int mouseY) { Minecraft* m = m_pMinecraft; @@ -145,8 +145,8 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) field_4 = -90.0f; - int width = Minecraft::width * scale, - height = Minecraft::height * scale; + int width = std::ceil(Minecraft::width * scale), + height = std::ceil(Minecraft::height * scale); #ifdef ENH_TRANSPARENT_HOTBAR glEnable(GL_BLEND); @@ -354,7 +354,7 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) } } -void Gui::tick() +void Gui::onTick() { /* if (field_A18 > 0) diff --git a/source/client/gui/Gui.hpp b/source/client/gui/Gui.hpp index 64d3c60..e6b9bae 100644 --- a/source/client/gui/Gui.hpp +++ b/source/client/gui/Gui.hpp @@ -30,22 +30,22 @@ public: Gui(Minecraft* pMinecraft); // screens - IScreen* screenMain(); - IScreen* screenDeath(); - IScreen* screenPause(); - IScreen* screenSaveWorld(bool bCopyMap, Entity *pEnt); - IScreen* screenRenameMPWorld(std::string name); + IScreen* screenMain() override; + IScreen* screenDeath() override; + IScreen* screenPause() override; + IScreen* screenSaveWorld(bool bCopyMap, Entity *pEnt) override; + IScreen* screenRenameMPWorld(std::string name) override; - void addMessage(const std::string& str); - void onInventoryUpdated(); - void tick(); - void render(float f, bool bHaveScreen, int mouseX, int mouseY); + void addMessage(const std::string& str) override; + void onInventoryUpdated() override; + void onTick() override; + void onRender(float f, bool bHaveScreen, int mouseX, int mouseY) override; - bool isInside(int mx, int my); - void handleClick(int id, int mx, int my); - void handleKeyPressed(int keyCode); - void renderChatMessages(bool bShowAll); - int getNumSlots(); // Gets the number of slots in the inventory. Includes the '...' if in touch mode. + bool isInside(int mx, int my) override; + void handleClick(int id, int mx, int my) override; + void handleKeyPressed(int keyCode) override; + void renderChatMessages(bool bShowAll) override; + int getNumSlots() override; // Gets the number of slots in the inventory. Includes the '...' if in touch mode. void renderVignette(float a2, int a3, int a4); void renderSlot(int slot, int x, int y, float f); diff --git a/source/client/gui/Screen.cpp b/source/client/gui/Screen.cpp index d6ada24..b6d3ebe 100644 --- a/source/client/gui/Screen.cpp +++ b/source/client/gui/Screen.cpp @@ -25,11 +25,10 @@ void Screen::init(Minecraft* pMinecraft, int a3, int a4) { m_pFont = pMinecraft->m_pFont; IScreen::init(pMinecraft, a3, a4); - init(); updateTabButtonSelection(); } -void Screen::init() +void Screen::onInit() { } @@ -100,7 +99,7 @@ static const char* g_panoramaList[] = static float g_panoramaAngle = 0.0f; // TODO: This should be inside of an initialized "Minecraft" instance rather than the global namespace -bool g_bIsMenuBackgroundAvailable = false; +extern bool g_bIsMenuBackgroundAvailable; // client/app/IScreen.cpp void Screen::renderMenuBackground(float f) { @@ -255,53 +254,37 @@ void Screen::mouseReleased(int xPos, int yPos, int d) } } -void Screen::render(int xPos, int yPos, float unused) +void Screen::onRender(int xPos, int yPos, float unused) { for (int i = 0; i < int(m_buttons.size()); i++) { Button* button = m_buttons[i]; - button->render(m_pMinecraft, xPos, yPos); + button->onRender(m_pMinecraft, xPos, yPos); } #ifndef ORIGINAL_CODE for (int i = 0; i < int(m_textInputs.size()); i++) { TextInputBox* textInput = m_textInputs[i]; - textInput->tick(); - textInput->render(); + textInput->onTick(); + textInput->onRender(); } #endif } -void Screen::tick() +void Screen::onTick() { g_panoramaAngle++; } void Screen::setSize(int width, int height) { - m_width = width; - m_height = height; + IScreen::setSize(width, height); // not original code. Will need to re-init again m_buttons.clear(); m_textInputs.clear(); - init(); -} - -void Screen::onRender(int mouseX, int mouseY, float f) -{ - m_yOffset = getYOffset(); - if (m_yOffset != 0) { - // push the entire screen up - glPushMatrix(); - glTranslatef(0.0f, -float(m_yOffset), 0.0f); - } - - render(mouseX, mouseY, f); - - if (m_yOffset != 0) - glPopMatrix(); + onInit(); } int Screen::getYOffset() diff --git a/source/client/gui/Screen.hpp b/source/client/gui/Screen.hpp index a4cddd5..5b84431 100644 --- a/source/client/gui/Screen.hpp +++ b/source/client/gui/Screen.hpp @@ -23,30 +23,30 @@ public: Screen(); virtual ~Screen(); - void init(Minecraft*, int, int); - void updateTabButtonSelection(); - void setSize(int width, int height); - void onRender(int mouseX, int mouseY, float f); - int getYOffset(); + void init(Minecraft*, int, int) override; + void setSize(int width, int height) override; + int getYOffset() override; - virtual void render(int, int, float); - virtual void init(); - virtual void onEvents(); - virtual void mouseEvent(); - virtual void keyboardEvent(); - virtual void tick(); - virtual void renderBackground(int); - virtual void renderBackground(); - virtual void renderDirtBackground(int); + virtual void onInit() override; + virtual void onRender(int mouseX, int mouseY, float f) override; + + virtual void onEvents() override; + virtual void mouseEvent() override; + virtual void keyboardEvent() override; + virtual void onTick() override; + virtual void renderBackground() override; virtual void buttonClicked(Button*); virtual void mouseClicked(int, int, int); virtual void mouseReleased(int, int, int); - virtual void keyPressed(int); - virtual void charInput(char); + virtual void charInput(char) override; // ported from 0.8 virtual void renderMenuBackground(float f); + void updateTabButtonSelection(); + virtual void renderBackground(int); + virtual void renderDirtBackground(int); + virtual void keyPressed(int); public: std::vector m_buttons; std::vector m_buttonTabList; diff --git a/source/client/gui/components/Button.cpp b/source/client/gui/components/Button.cpp index d6b02a5..adca587 100644 --- a/source/client/gui/components/Button.cpp +++ b/source/client/gui/components/Button.cpp @@ -87,7 +87,7 @@ void Button::renderBg(Minecraft*, int, int) } -void Button::render(Minecraft* pMinecraft, int xPos, int yPos) +void Button::onRender(Minecraft* pMinecraft, int xPos, int yPos) { if (!m_bVisible) return; diff --git a/source/client/gui/components/Button.hpp b/source/client/gui/components/Button.hpp index b5b8a12..f28c32e 100644 --- a/source/client/gui/components/Button.hpp +++ b/source/client/gui/components/Button.hpp @@ -27,7 +27,7 @@ public: int getYImage(bool bHovered); void released(int xPos, int yPos); void renderBg(Minecraft*, int, int); - void render(Minecraft*, int xPos, int yPos); + void onRender(Minecraft*, int xPos, int yPos); public: int m_width; diff --git a/source/client/gui/components/OptionList.cpp b/source/client/gui/components/OptionList.cpp index 831c0ed..f65f130 100644 --- a/source/client/gui/components/OptionList.cpp +++ b/source/client/gui/components/OptionList.cpp @@ -41,7 +41,7 @@ void BooleanOptionItem::onClick(OptionList* pList, int mouseX, int mouseY) toggleState(pList); } -void BooleanOptionItem::render(OptionList* pList, int x, int y) +void BooleanOptionItem::onRender(OptionList* pList, int x, int y) { pList->drawString( pList->m_pMinecraft->m_pFont, @@ -91,7 +91,7 @@ HeaderOptionItem::HeaderOptionItem(const std::string& text) m_text = text; } -void HeaderOptionItem::render(OptionList* pList, int x, int y) +void HeaderOptionItem::onRender(OptionList* pList, int x, int y) { pList->drawString( pList->m_pMinecraft->m_pFont, @@ -122,7 +122,7 @@ void DistanceOptionItem::onClick(OptionList* pList, int mouseX, int mouseY) pList->m_pMinecraft->m_pLevelRenderer->allChanged(); } -void DistanceOptionItem::render(OptionList* pList, int x, int y) +void DistanceOptionItem::onRender(OptionList* pList, int x, int y) { pList->drawString( pList->m_pMinecraft->m_pFont, @@ -236,7 +236,7 @@ void OptionList::renderItem(int index, int x, int y, int height, Tesselator& t) { OptionItem* pItem = m_items[index]; - pItem->render(this, x, y); + pItem->onRender(this, x, y); } void OptionList::renderBackground(float f) diff --git a/source/client/gui/components/OptionList.hpp b/source/client/gui/components/OptionList.hpp index 0874c3f..d7c8bc3 100644 --- a/source/client/gui/components/OptionList.hpp +++ b/source/client/gui/components/OptionList.hpp @@ -20,7 +20,7 @@ public: OptionItem() {} virtual ~OptionItem() {} virtual void onClick(OptionList*, int mouseX, int mouseY) = 0; - virtual void render(OptionList*, int x, int y) = 0; + virtual void onRender(OptionList*, int x, int y) = 0; virtual bool maySelect() { return true; } virtual void setDisabled(bool b) { }; }; @@ -30,7 +30,7 @@ class BooleanOptionItem : public OptionItem public: BooleanOptionItem(bool* pValue, const std::string& text); void onClick(OptionList*, int mouseX, int mouseY) override; - void render(OptionList*, int x, int y) override; + void onRender(OptionList*, int x, int y) override; void setDisabled(bool b) override { m_bDisabled = b; } virtual void toggleState(OptionList*); @@ -58,7 +58,7 @@ class DistanceOptionItem : public OptionItem public: DistanceOptionItem(int* pValue, const std::string& text); void onClick(OptionList*, int mouseX, int mouseY) override; - void render(OptionList*, int x, int y) override; + void onRender(OptionList*, int x, int y) override; protected: std::string m_text; @@ -83,7 +83,7 @@ class HeaderOptionItem : public OptionItem { public: HeaderOptionItem(const std::string& text); - void render(OptionList*, int x, int y) override; + void onRender(OptionList*, int x, int y) override; bool maySelect() override { return false; } void onClick(OptionList*, int mouseX, int mouseY) override {} diff --git a/source/client/gui/components/RolledSelectionList.cpp b/source/client/gui/components/RolledSelectionList.cpp index f614d77..6dd7803 100644 --- a/source/client/gui/components/RolledSelectionList.cpp +++ b/source/client/gui/components/RolledSelectionList.cpp @@ -83,7 +83,7 @@ bool RolledSelectionList::capXPosition() return false; } -void RolledSelectionList::tick() +void RolledSelectionList::onTick() { float diff = g_RolledSelectionListUnk - field_34; g_RolledSelectionListUnk = field_34; @@ -91,7 +91,7 @@ void RolledSelectionList::tick() field_34 = field_30 - field_38; } -void RolledSelectionList::render(int mouseX, int mouseY, float f) +void RolledSelectionList::onRender(int mouseX, int mouseY, float f) { renderBackground(); diff --git a/source/client/gui/components/RolledSelectionList.hpp b/source/client/gui/components/RolledSelectionList.hpp index f2bbdc0..8fefdfe 100644 --- a/source/client/gui/components/RolledSelectionList.hpp +++ b/source/client/gui/components/RolledSelectionList.hpp @@ -18,8 +18,8 @@ public: RolledSelectionList(Minecraft*, int, int, int, int, int, int, int); virtual int getItemAtPosition(int, int); virtual bool capXPosition(); - virtual void tick(); - virtual void render(int mouseX, int mouseY, float); + virtual void onTick(); + virtual void onRender(int mouseX, int mouseY, float); virtual void renderHoleBackground(float y1, float y2, int a, int b); virtual void setRenderSelection(bool); virtual void setComponentSelected(bool); diff --git a/source/client/gui/components/ScrolledSelectionList.cpp b/source/client/gui/components/ScrolledSelectionList.cpp index bdbdf43..072ee8f 100644 --- a/source/client/gui/components/ScrolledSelectionList.cpp +++ b/source/client/gui/components/ScrolledSelectionList.cpp @@ -147,7 +147,7 @@ void ScrolledSelectionList::checkInput(int mouseX, int mouseY) } } -void ScrolledSelectionList::render(int mouseX, int mouseY, float f) +void ScrolledSelectionList::onRender(int mouseX, int mouseY, float f) { renderBackground(f); diff --git a/source/client/gui/components/ScrolledSelectionList.hpp b/source/client/gui/components/ScrolledSelectionList.hpp index 5179b8d..6105345 100644 --- a/source/client/gui/components/ScrolledSelectionList.hpp +++ b/source/client/gui/components/ScrolledSelectionList.hpp @@ -33,7 +33,7 @@ public: virtual void clickedHeader(int x, int y); virtual int getItemAtPosition(int x, int y); virtual void capYPosition(); - virtual void render(int mouseX, int mouseY, float f); + virtual void onRender(int mouseX, int mouseY, float f); virtual void renderHoleBackground(float, float, int, int); virtual void checkInput(int mouseX, int mouseY); virtual void onClickItem(int index, int mouseX, int mouseY); diff --git a/source/client/gui/components/TextInputBox.cpp b/source/client/gui/components/TextInputBox.cpp index a7eabda..71e2d8e 100644 --- a/source/client/gui/components/TextInputBox.cpp +++ b/source/client/gui/components/TextInputBox.cpp @@ -34,7 +34,7 @@ TextInputBox::TextInputBox(Screen* parent, int id, int x, int y, int width, int m_pParent = parent; } -void TextInputBox::init(Font* pFont) +void TextInputBox::onInit(Font* pFont) { m_pFont = pFont; } @@ -162,7 +162,7 @@ void TextInputBox::keyPressed(Minecraft* minecraft, int key) charPressed(chr); } -void TextInputBox::tick() +void TextInputBox::onTick() { if (!m_lastFlashed) m_lastFlashed = getTimeMs(); @@ -281,7 +281,7 @@ void TextInputBox::charPressed(int k) } } -void TextInputBox::render() +void TextInputBox::onRender() { fill(m_xPos, m_yPos, m_xPos + m_width, m_yPos + m_height, 0xFFAAAAAA); fill(m_xPos + 1, m_yPos + 1, m_xPos + m_width - 1, m_yPos + m_height - 1, 0xFF000000); diff --git a/source/client/gui/components/TextInputBox.hpp b/source/client/gui/components/TextInputBox.hpp index 1f28606..7cc3c70 100644 --- a/source/client/gui/components/TextInputBox.hpp +++ b/source/client/gui/components/TextInputBox.hpp @@ -24,12 +24,12 @@ class TextInputBox : public GuiComponent public: TextInputBox(Screen*, int id, int x, int y, int width = 200, int height = 12, const std::string& placeholder = "", const std::string& text = ""); - void init(Font* pFont); + void onInit(Font* pFont); void setEnabled(bool bEnabled); void keyPressed(Minecraft*, int key); void charPressed(int chr); - void render(); - void tick(); + void onRender(); + void onTick(); void setFocused(bool b); void onClick(int x, int y); bool clicked(int x, int y); diff --git a/source/client/gui/components/WorldSelectionList.cpp b/source/client/gui/components/WorldSelectionList.cpp index 31e4465..d0720c4 100644 --- a/source/client/gui/components/WorldSelectionList.cpp +++ b/source/client/gui/components/WorldSelectionList.cpp @@ -42,9 +42,9 @@ bool WorldSelectionList::capXPosition() return false; } -void WorldSelectionList::tick() +void WorldSelectionList::onTick() { - RolledSelectionList::tick(); + RolledSelectionList::onTick(); field_D0++; if (Mouse::isButtonDown(BUTTON_LEFT) || !field_28) return; diff --git a/source/client/gui/components/WorldSelectionList.hpp b/source/client/gui/components/WorldSelectionList.hpp index 78fd606..a708934 100644 --- a/source/client/gui/components/WorldSelectionList.hpp +++ b/source/client/gui/components/WorldSelectionList.hpp @@ -16,7 +16,7 @@ public: WorldSelectionList(Minecraft*, int, int); bool capXPosition() override; - void tick() override; + void onTick() override; int getNumberOfItems() override; void selectItem(int, bool) override; bool isSelectedItem(int) override; diff --git a/source/client/player/input/TouchscreenInput_TestFps.cpp b/source/client/gui/input/TouchscreenInput_TestFps.cpp similarity index 97% rename from source/client/player/input/TouchscreenInput_TestFps.cpp rename to source/client/gui/input/TouchscreenInput_TestFps.cpp index bc6aa8e..c1918b5 100644 --- a/source/client/player/input/TouchscreenInput_TestFps.cpp +++ b/source/client/gui/input/TouchscreenInput_TestFps.cpp @@ -7,7 +7,7 @@ ********************************************************************/ #include "TouchscreenInput_TestFps.hpp" -#include "Multitouch.hpp" +#include "client/player/input/Multitouch.hpp" #include "client/app/Minecraft.hpp" #include "client/options/Options.hpp" #include "world/entity/Player.hpp" @@ -131,7 +131,7 @@ void TouchscreenInput_TestFps::setScreenSize(int width, int height) // so are these areas we allocated. } -void TouchscreenInput_TestFps::tick(Player* pPlayer) +void TouchscreenInput_TestFps::onTick(Player* pPlayer) { m_horzInput = 0.0f; m_vertInput = 0.0f; @@ -246,7 +246,7 @@ static void RenderTouchButton(Tesselator* t, PolygonArea* pArea, int srcX, int s } } -void TouchscreenInput_TestFps::render(float f) +void TouchscreenInput_TestFps::onRender(float f) { glDisable(GL_CULL_FACE); glEnable(GL_BLEND); diff --git a/source/client/player/input/TouchscreenInput_TestFps.hpp b/source/client/gui/input/TouchscreenInput_TestFps.hpp similarity index 81% rename from source/client/player/input/TouchscreenInput_TestFps.hpp rename to source/client/gui/input/TouchscreenInput_TestFps.hpp index ce3588c..19e65e4 100644 --- a/source/client/player/input/TouchscreenInput_TestFps.hpp +++ b/source/client/gui/input/TouchscreenInput_TestFps.hpp @@ -8,11 +8,11 @@ #pragma once -#include "IMoveInput.hpp" #include "client/gui/GuiComponent.hpp" -#include "RectangleArea.hpp" -#include "PolygonArea.hpp" -#include "TouchAreaModel.hpp" +#include "client/player/input/IMoveInput.hpp" +#include "client/player/input/RectangleArea.hpp" +#include "client/player/input/PolygonArea.hpp" +#include "client/player/input/TouchAreaModel.hpp" class Minecraft; class Options; @@ -26,8 +26,8 @@ public: void releaseAllKeys() override; void setKey(int key, bool state) override; void setScreenSize(int width, int height) override; - void tick(Player*) override; - void render(float f) override; + void onTick(Player*) override; + void onRender(float f) override; RectangleArea getRectangleArea(); bool isButtonDown(int key); diff --git a/source/client/gui/screens/ChatScreen.cpp b/source/client/gui/screens/ChatScreen.cpp index a163dd4..f77656e 100644 --- a/source/client/gui/screens/ChatScreen.cpp +++ b/source/client/gui/screens/ChatScreen.cpp @@ -22,7 +22,7 @@ void ChatScreen::buttonClicked(Button* pButton) sendMessageAndExit(); } -void ChatScreen::init() +void ChatScreen::onInit() { m_btnSend.m_height = 20; m_btnSend.m_width = 40; @@ -34,7 +34,7 @@ void ChatScreen::init() m_btnSend.m_xPos = m_textChat.m_xPos + m_textChat.m_width; // set focus directly on the chat text box - m_textChat.init(m_pFont); + m_textChat.onInit(m_pFont); m_textChat.setFocused(true); m_buttons.push_back(&m_btnSend); @@ -47,14 +47,14 @@ void ChatScreen::removed() m_pMinecraft->m_pGui->m_bRenderChatMessages = true; } -void ChatScreen::render(int mouseX, int mouseY, float f) +void ChatScreen::onRender(int mouseX, int mouseY, float f) { renderBackground(); // override the default behavior of rendering chat messages m_pMinecraft->m_pGui->m_bRenderChatMessages = true; - Screen::render(mouseX, mouseY, f); + Screen::onRender(mouseX, mouseY, f); } void ChatScreen::keyPressed(int keyCode) diff --git a/source/client/gui/screens/ChatScreen.hpp b/source/client/gui/screens/ChatScreen.hpp index a3a5041..dabc22a 100644 --- a/source/client/gui/screens/ChatScreen.hpp +++ b/source/client/gui/screens/ChatScreen.hpp @@ -15,9 +15,9 @@ class ChatScreen : public Screen public: ChatScreen(bool slash = false); void buttonClicked(Button*) override; - void init() override; + void onInit() override; void removed() override; - void render(int mouseX, int mouseY, float f) override; + void onRender(int mouseX, int mouseY, float f) override; void keyPressed(int keyCode) override; void sendMessageAndExit(); diff --git a/source/client/gui/screens/ConfirmScreen.cpp b/source/client/gui/screens/ConfirmScreen.cpp index 4df8d0a..e3c5ef0 100644 --- a/source/client/gui/screens/ConfirmScreen.cpp +++ b/source/client/gui/screens/ConfirmScreen.cpp @@ -43,7 +43,7 @@ bool ConfirmScreen::handleBackEvent(bool b) return true; } -void ConfirmScreen::init() +void ConfirmScreen::onInit() { m_btnOK.m_xPos = m_width / 2 - 4 - 120; m_btnCancel.m_xPos = m_width / 2 + 4; @@ -59,12 +59,12 @@ void ConfirmScreen::init() m_buttonTabList.push_back(&m_btnCancel); } -void ConfirmScreen::render(int mouseX, int mouseY, float f) +void ConfirmScreen::onRender(int mouseX, int mouseY, float f) { renderBackground(); drawCenteredString(m_pFont, m_textLine1, m_width / 2, 50, 0xFFFFFF); drawCenteredString(m_pFont, m_textLine2, m_width / 2, 70, 0xFFFFFF); - Screen::render(mouseX, mouseY, f); + Screen::onRender(mouseX, mouseY, f); } void ConfirmScreen::postResult(bool b) diff --git a/source/client/gui/screens/ConfirmScreen.hpp b/source/client/gui/screens/ConfirmScreen.hpp index 28e7e01..f35ccce 100644 --- a/source/client/gui/screens/ConfirmScreen.hpp +++ b/source/client/gui/screens/ConfirmScreen.hpp @@ -19,8 +19,8 @@ public: void buttonClicked(Button* pButton) override; bool handleBackEvent(bool b) override; - void init() override; - void render(int mouseX, int mouseY, float f) override; + void onInit() override; + void onRender(int mouseX, int mouseY, float f) override; virtual void postResult(bool b); diff --git a/source/client/gui/screens/CreateWorldScreen.cpp b/source/client/gui/screens/CreateWorldScreen.cpp index 5e1d7c2..6013f9f 100644 --- a/source/client/gui/screens/CreateWorldScreen.cpp +++ b/source/client/gui/screens/CreateWorldScreen.cpp @@ -21,7 +21,7 @@ CreateWorldScreen::CreateWorldScreen() : #define CRAMPED() (100 + 32 + 58 > m_height) -void CreateWorldScreen::init() +void CreateWorldScreen::onInit() { m_textName.m_width = m_textSeed.m_width = 200; m_textName.m_height = m_textSeed.m_height = 20; @@ -43,8 +43,8 @@ void CreateWorldScreen::init() m_buttons.push_back(&m_btnCreate); m_buttonTabList.push_back(&m_btnBack); m_buttonTabList.push_back(&m_btnCreate); - m_textName.init(m_pFont); - m_textSeed.init(m_pFont); + m_textName.onInit(m_pFont); + m_textSeed.onInit(m_pFont); // 100 - yPos of textSeed // 32 - offset + height of "Leave blank for random" text @@ -124,10 +124,10 @@ void CreateWorldScreen::buttonClicked(Button* pButton) } } -void CreateWorldScreen::render(int mouseX, int mouseY, float f) +void CreateWorldScreen::onRender(int mouseX, int mouseY, float f) { renderBackground(); - Screen::render(mouseX, mouseY, f); + Screen::onRender(mouseX, mouseY, f); drawCenteredString(m_pFont, "Create New World", m_width / 2, CRAMPED() ? 10 : 30, 0xFFFFFF); drawString(m_pFont, "World name", m_textName.m_xPos, m_textName.m_yPos - 10, 0xDDDDDD); diff --git a/source/client/gui/screens/CreateWorldScreen.hpp b/source/client/gui/screens/CreateWorldScreen.hpp index b5b055c..01cf44e 100644 --- a/source/client/gui/screens/CreateWorldScreen.hpp +++ b/source/client/gui/screens/CreateWorldScreen.hpp @@ -17,9 +17,9 @@ class CreateWorldScreen : public Screen public: CreateWorldScreen(); - void init() override; + void onInit() override; void buttonClicked(Button* pButton) override; - void render(int mouseX, int mouseY, float f) override; + void onRender(int mouseX, int mouseY, float f) override; public: TextInputBox m_textName; diff --git a/source/client/gui/screens/DeathScreen.cpp b/source/client/gui/screens/DeathScreen.cpp index 921ac93..fc8a7f4 100644 --- a/source/client/gui/screens/DeathScreen.cpp +++ b/source/client/gui/screens/DeathScreen.cpp @@ -7,7 +7,7 @@ DeathScreen::DeathScreen() : m_tickCounter = 0; } -void DeathScreen::init() +void DeathScreen::onInit() { m_btnRespawn.m_width = m_btnTitle.m_width = m_width / 4; m_btnRespawn.m_xPos = m_width / 2 - 10 - m_btnRespawn.m_width; @@ -34,7 +34,7 @@ void DeathScreen::buttonClicked(Button* pButton) } } -void DeathScreen::tick() +void DeathScreen::onTick() { m_tickCounter++; } @@ -43,7 +43,7 @@ void DeathScreen::keyPressed(int key) { } -void DeathScreen::render(int x, int y, float f) +void DeathScreen::onRender(int x, int y, float f) { fillGradient(0, 0, m_width, m_height, 0xA0303080, 0x60000050); @@ -54,5 +54,5 @@ void DeathScreen::render(int x, int y, float f) // render the buttons after 1.5 seconds if (m_tickCounter >= 30) - Screen::render(x, y, f); + Screen::onRender(x, y, f); } diff --git a/source/client/gui/screens/DeathScreen.hpp b/source/client/gui/screens/DeathScreen.hpp index 7fc994e..02c1380 100644 --- a/source/client/gui/screens/DeathScreen.hpp +++ b/source/client/gui/screens/DeathScreen.hpp @@ -15,11 +15,11 @@ class DeathScreen : public Screen public: DeathScreen(); - virtual void init() override; + virtual void onInit() override; virtual void buttonClicked(Button* pButton) override; - virtual void tick() override; + virtual void onTick() override; virtual void keyPressed(int key) override; - virtual void render(int x, int y, float f) override; + virtual void onRender(int x, int y, float f) override; private: int m_tickCounter; diff --git a/source/client/gui/screens/DirectConnectScreen.cpp b/source/client/gui/screens/DirectConnectScreen.cpp index 7772f3c..b9824d4 100644 --- a/source/client/gui/screens/DirectConnectScreen.cpp +++ b/source/client/gui/screens/DirectConnectScreen.cpp @@ -17,7 +17,7 @@ DirectConnectScreen::DirectConnectScreen() : m_btnJoin(2, "Connect") {} -void DirectConnectScreen::init() +void DirectConnectScreen::onInit() { m_textAddress.m_width = 200; m_textAddress.m_height = 20; @@ -41,13 +41,13 @@ void DirectConnectScreen::init() m_buttons.push_back(&m_btnQuit); m_buttons.push_back(&m_btnJoin); - m_textAddress.init(m_pFont); + m_textAddress.onInit(m_pFont); } -void DirectConnectScreen::render(int x, int y, float f) +void DirectConnectScreen::onRender(int x, int y, float f) { renderBackground(); - Screen::render(x, y, f); + Screen::onRender(x, y, f); drawCenteredString(m_pFont, "Play Multiplayer", m_width / 2, 30, 0xFFFFFF); drawCenteredString(m_pFont, "Enter the IP address of a server to connect to it:", m_width / 2, m_textAddress.m_yPos - 20, 0x999999); diff --git a/source/client/gui/screens/DirectConnectScreen.hpp b/source/client/gui/screens/DirectConnectScreen.hpp index b237b71..0157eba 100644 --- a/source/client/gui/screens/DirectConnectScreen.hpp +++ b/source/client/gui/screens/DirectConnectScreen.hpp @@ -15,12 +15,12 @@ class DirectConnectScreen : public Screen public: DirectConnectScreen(); - virtual void init() override; + virtual void onInit() override; virtual void buttonClicked(Button* pButton) override; - virtual void render(int x, int y, float f) override; + virtual void onRender(int x, int y, float f) override; private: TextInputBox m_textAddress; Button m_btnQuit; Button m_btnJoin; -}; \ No newline at end of file +}; diff --git a/source/client/gui/screens/IngameBlockSelectionScreen.cpp b/source/client/gui/screens/IngameBlockSelectionScreen.cpp index 478f956..9405cb5 100644 --- a/source/client/gui/screens/IngameBlockSelectionScreen.cpp +++ b/source/client/gui/screens/IngameBlockSelectionScreen.cpp @@ -67,7 +67,7 @@ bool IngameBlockSelectionScreen::isAllowed(int slot) return slot >= 0 && slot < getInventory()->getNumSlots(); } -void IngameBlockSelectionScreen::init() +void IngameBlockSelectionScreen::onInit() { Inventory* pInv = getInventory(); @@ -131,9 +131,9 @@ void IngameBlockSelectionScreen::renderDemoOverlay() drawCenteredString(m_pMinecraft->m_pFont, g_sNotAvailableInDemoVersion, x, y, 0xFFFFFFFF); } -void IngameBlockSelectionScreen::render(int x, int y, float f) +void IngameBlockSelectionScreen::onRender(int x, int y, float f) { - Screen::render(x, y, f); + Screen::onRender(x, y, f); glDisable(GL_DEPTH_TEST); fill(0, 0, m_width, m_height, 0x80000000); diff --git a/source/client/gui/screens/IngameBlockSelectionScreen.hpp b/source/client/gui/screens/IngameBlockSelectionScreen.hpp index 4b29675..3802362 100644 --- a/source/client/gui/screens/IngameBlockSelectionScreen.hpp +++ b/source/client/gui/screens/IngameBlockSelectionScreen.hpp @@ -29,8 +29,8 @@ public: void renderSlot(int index, int x, int y, float f); void selectSlotAndClose(); - virtual void init() override; - virtual void render(int x, int y, float f) override; + virtual void onInit() override; + virtual void onRender(int x, int y, float f) override; virtual void mouseClicked(int x, int y, int type) override; virtual void mouseReleased(int x, int y, int type) override; virtual void removed() override; diff --git a/source/client/gui/screens/InvalidLicenseScreen.cpp b/source/client/gui/screens/InvalidLicenseScreen.cpp index e804c40..f40e3b7 100644 --- a/source/client/gui/screens/InvalidLicenseScreen.cpp +++ b/source/client/gui/screens/InvalidLicenseScreen.cpp @@ -32,7 +32,7 @@ void InvalidLicenseScreen::buttonClicked(Button* pButton) } } -void InvalidLicenseScreen::init() +void InvalidLicenseScreen::onInit() { field_E4 = m_height / 3; if (m_bHasQuitButton) @@ -57,14 +57,10 @@ void InvalidLicenseScreen::init() m_buttonTabList.push_back(&m_btnBuy); } -void InvalidLicenseScreen::tick() -{ -} - -void InvalidLicenseScreen::render(int mouseX, int mouseY, float f) +void InvalidLicenseScreen::onRender(int mouseX, int mouseY, float f) { renderDirtBackground(0); drawCenteredString(m_pMinecraft->m_pFont, m_textLine1, m_width / 2, field_E4, 0xFFFFFF); drawCenteredString(m_pMinecraft->m_pFont, m_textLine2, m_width / 2, field_E4 + 24, 0xFFFFFF); - Screen::render(mouseX, mouseY, f); + Screen::onRender(mouseX, mouseY, f); } diff --git a/source/client/gui/screens/InvalidLicenseScreen.hpp b/source/client/gui/screens/InvalidLicenseScreen.hpp index 4e1e6de..dbfa73b 100644 --- a/source/client/gui/screens/InvalidLicenseScreen.hpp +++ b/source/client/gui/screens/InvalidLicenseScreen.hpp @@ -15,9 +15,8 @@ class InvalidLicenseScreen : public Screen public: InvalidLicenseScreen(int error, bool bHasQuitButton); void buttonClicked(Button* pButton) override; - void init() override; - void tick() override; - void render(int mouseX, int mouseY, float f) override; + void onInit() override; + void onRender(int mouseX, int mouseY, float f) override; private: int m_error; diff --git a/source/client/gui/screens/JoinGameScreen.cpp b/source/client/gui/screens/JoinGameScreen.cpp index e153a40..bc8db45 100644 --- a/source/client/gui/screens/JoinGameScreen.cpp +++ b/source/client/gui/screens/JoinGameScreen.cpp @@ -61,7 +61,7 @@ bool JoinGameScreen::handleBackEvent(bool b) return true; } -void JoinGameScreen::init() +void JoinGameScreen::onInit() { const int BUTTON_WIDTH = 100; @@ -92,16 +92,16 @@ bool JoinGameScreen::isInGameScreen() return false; } -void JoinGameScreen::render(int mouseX, int mouseY, float f) +void JoinGameScreen::onRender(int mouseX, int mouseY, float f) { renderBackground(); - m_pAvailableGamesList->render(mouseX, mouseY, f); - Screen::render(mouseX, mouseY, f); + m_pAvailableGamesList->onRender(mouseX, mouseY, f); + Screen::onRender(mouseX, mouseY, f); drawCenteredString(m_pMinecraft->m_pFont, "Scanning for Games...", m_width / 2, 8, 0xFFFFFFFF); } -void JoinGameScreen::tick() +void JoinGameScreen::onTick() { std::vector *serverList, serverListFiltered; serverList = m_pMinecraft->m_pRakNetInstance->getServerList(); diff --git a/source/client/gui/screens/JoinGameScreen.hpp b/source/client/gui/screens/JoinGameScreen.hpp index db363dc..47f0641 100644 --- a/source/client/gui/screens/JoinGameScreen.hpp +++ b/source/client/gui/screens/JoinGameScreen.hpp @@ -18,10 +18,10 @@ public: ~JoinGameScreen(); void buttonClicked(Button* pButton) override; bool handleBackEvent(bool b) override; - void init() override; + void onInit() override; bool isInGameScreen() override; - void render(int mouseX, int mouseY, float f) override; - void tick() override; + void onRender(int mouseX, int mouseY, float f) override; + void onTick() override; virtual bool isIndexValid(int idx); diff --git a/source/client/gui/screens/OptionsScreen.cpp b/source/client/gui/screens/OptionsScreen.cpp index 455344f..8753a32 100644 --- a/source/client/gui/screens/OptionsScreen.cpp +++ b/source/client/gui/screens/OptionsScreen.cpp @@ -23,7 +23,7 @@ OptionsScreen::~OptionsScreen() SAFE_DELETE(m_pList); } -void OptionsScreen::init() +void OptionsScreen::onInit() { if (m_pList) SAFE_DELETE(m_pList); @@ -41,14 +41,14 @@ void OptionsScreen::init() m_buttonTabList.push_back(&m_backButton); } -void OptionsScreen::render(int mouseX, int mouseY, float f) +void OptionsScreen::onRender(int mouseX, int mouseY, float f) { if (!m_pList) return; - m_pList->render(mouseX, mouseY, f); + m_pList->onRender(mouseX, mouseY, f); - Screen::render(mouseX, mouseY, f); + Screen::onRender(mouseX, mouseY, f); drawCenteredString(m_pFont, "Options", m_width / 2, 10, 0xFFFFFF); } @@ -275,7 +275,7 @@ void OptionsScreen::init() #endif } -void OptionsScreen::render(int a, int b, float c) +void OptionsScreen::onRender(int a, int b, float c) { if (!m_pMinecraft->isLevelGenerated()) renderMenuBackground(c); @@ -290,7 +290,7 @@ void OptionsScreen::render(int a, int b, float c) #ifndef ORIGINAL_CODE drawCenteredString(m_pFont, "Options", m_width / 2, isCramped() ? 5 : 20, 0xFFFFFF); - Screen::render(a, b, c); + Screen::onRender(a, b, c); #endif } diff --git a/source/client/gui/screens/OptionsScreen.hpp b/source/client/gui/screens/OptionsScreen.hpp index 023dc7d..df9a55b 100644 --- a/source/client/gui/screens/OptionsScreen.hpp +++ b/source/client/gui/screens/OptionsScreen.hpp @@ -19,8 +19,8 @@ class OptionsScreen : public Screen public: OptionsScreen(); ~OptionsScreen(); - void init() override; - void render(int, int, float) override; + void onInit() override; + void onRender(int, int, float) override; void removed() override; void buttonClicked(Button* pButton) override; @@ -37,7 +37,7 @@ class OptionsScreen : public Screen public: OptionsScreen(); void init() override; - void render(int, int, float) override; + void onRender(int, int, float) override; void removed() override; #ifndef ORIGINAL_CODE diff --git a/source/client/gui/screens/PauseScreen.cpp b/source/client/gui/screens/PauseScreen.cpp index 7f155f5..871bfac 100644 --- a/source/client/gui/screens/PauseScreen.cpp +++ b/source/client/gui/screens/PauseScreen.cpp @@ -23,7 +23,7 @@ PauseScreen::PauseScreen() : { } -void PauseScreen::init() +void PauseScreen::onInit() { bool bAddVisibleButton = m_pMinecraft->m_pRakNetInstance && m_pMinecraft->m_pRakNetInstance->m_bIsHost; @@ -108,17 +108,17 @@ void PauseScreen::updateServerVisibilityText() m_btnVisible.m_text = "Server is invisible"; } -void PauseScreen::tick() +void PauseScreen::onTick() { field_40++; } -void PauseScreen::render(int a, int b, float c) +void PauseScreen::onRender(int a, int b, float c) { renderBackground(); drawCenteredString(m_pFont, "Game menu", m_width / 2, 24, 0xFFFFFF); - Screen::render(a, b, c); + Screen::onRender(a, b, c); } void PauseScreen::buttonClicked(Button* pButton) diff --git a/source/client/gui/screens/PauseScreen.hpp b/source/client/gui/screens/PauseScreen.hpp index 878b9a5..4ab4ef2 100644 --- a/source/client/gui/screens/PauseScreen.hpp +++ b/source/client/gui/screens/PauseScreen.hpp @@ -14,9 +14,9 @@ class PauseScreen : public Screen { public: PauseScreen(); - virtual void init() override; - virtual void tick() override; - virtual void render(int a, int b, float c) override; + virtual void onInit() override; + virtual void onTick() override; + virtual void onRender(int a, int b, float c) override; virtual void buttonClicked(Button*) override; void updateServerVisibilityText(); diff --git a/source/client/gui/screens/ProgressScreen.cpp b/source/client/gui/screens/ProgressScreen.cpp index f9a25f8..230cc2f 100644 --- a/source/client/gui/screens/ProgressScreen.cpp +++ b/source/client/gui/screens/ProgressScreen.cpp @@ -13,7 +13,7 @@ bool ProgressScreen::isInGameScreen() return false; } -void ProgressScreen::render(int a, int b, float c) +void ProgressScreen::onRender(int a, int b, float c) { renderBackground(); diff --git a/source/client/gui/screens/ProgressScreen.hpp b/source/client/gui/screens/ProgressScreen.hpp index 2febf79..da0d69f 100644 --- a/source/client/gui/screens/ProgressScreen.hpp +++ b/source/client/gui/screens/ProgressScreen.hpp @@ -13,7 +13,7 @@ class ProgressScreen : public Screen { public: - void render(int, int, float) override; + void onRender(int, int, float) override; void onEvents() override; bool isInGameScreen() override; }; diff --git a/source/client/gui/screens/RenameMPLevelScreen.cpp b/source/client/gui/screens/RenameMPLevelScreen.cpp index 61833ec..b2463eb 100644 --- a/source/client/gui/screens/RenameMPLevelScreen.cpp +++ b/source/client/gui/screens/RenameMPLevelScreen.cpp @@ -13,13 +13,13 @@ RenameMPLevelScreen::RenameMPLevelScreen(const std::string& levelName) : m_level { } -void RenameMPLevelScreen::init() +void RenameMPLevelScreen::onInit() { m_pMinecraft->platform()->showDialog(AppPlatform::DLG_RENAME_MP_WORLD); m_pMinecraft->platform()->createUserInput(); } -void RenameMPLevelScreen::render(int mouseX, int mouseY, float f) +void RenameMPLevelScreen::onRender(int mouseX, int mouseY, float f) { int userInputStatus = m_pMinecraft->platform()->getUserInputStatus(); if (userInputStatus < 0) diff --git a/source/client/gui/screens/RenameMPLevelScreen.hpp b/source/client/gui/screens/RenameMPLevelScreen.hpp index 1246797..ae78efe 100644 --- a/source/client/gui/screens/RenameMPLevelScreen.hpp +++ b/source/client/gui/screens/RenameMPLevelScreen.hpp @@ -14,8 +14,8 @@ class RenameMPLevelScreen : public Screen { public: RenameMPLevelScreen(const std::string& levelName); - void init() override; - void render(int mouseX, int mouseY, float f) override; + void onInit() override; + void onRender(int mouseX, int mouseY, float f) override; private: std::string m_levelName; diff --git a/source/client/gui/screens/SavingWorldScreen.cpp b/source/client/gui/screens/SavingWorldScreen.cpp index f24ca1f..3416e7a 100644 --- a/source/client/gui/screens/SavingWorldScreen.cpp +++ b/source/client/gui/screens/SavingWorldScreen.cpp @@ -19,7 +19,7 @@ SavingWorldScreen::SavingWorldScreen(bool bCopyMap, Entity *pEnt) m_pEntityToDeleteAfterSave = pEnt; } -void SavingWorldScreen::render(int mouseX, int mouseY, float f) +void SavingWorldScreen::onRender(int mouseX, int mouseY, float f) { renderDirtBackground(0); @@ -32,7 +32,7 @@ void SavingWorldScreen::render(int mouseX, int mouseY, float f) m_pFont->drawShadow("Saving chunks", (x_width - width) / 2, yPos, 0xFFFFFF); } -void SavingWorldScreen::tick() +void SavingWorldScreen::onTick() { if (m_timer < 0) return; diff --git a/source/client/gui/screens/SavingWorldScreen.hpp b/source/client/gui/screens/SavingWorldScreen.hpp index de500af..4fc98f1 100644 --- a/source/client/gui/screens/SavingWorldScreen.hpp +++ b/source/client/gui/screens/SavingWorldScreen.hpp @@ -19,8 +19,8 @@ class SavingWorldScreen : public Screen public: SavingWorldScreen(bool bCopyMap, Entity* pEntityToDeleteAfterSave); - void render(int mouseX, int mouseY, float f) override; - void tick() override; + void onRender(int mouseX, int mouseY, float f) override; + void onTick() override; public: bool m_bCopyMapAtEnd; diff --git a/source/client/gui/screens/SelectWorldScreen.cpp b/source/client/gui/screens/SelectWorldScreen.cpp index 5cd0a44..f37d0d9 100644 --- a/source/client/gui/screens/SelectWorldScreen.cpp +++ b/source/client/gui/screens/SelectWorldScreen.cpp @@ -25,7 +25,7 @@ SelectWorldScreen::SelectWorldScreen() : field_130 = 0; } -void SelectWorldScreen::init() +void SelectWorldScreen::onInit() { SAFE_DELETE(m_pWorldSelectionList); @@ -81,7 +81,7 @@ void SelectWorldScreen::keyPressed(int code) static char g_SelectWorldFilterArray[] = { '/','\n','\r','\x09','\0','\xC','`','?','*','\\','<','>','|','"',':'}; -void SelectWorldScreen::tick() +void SelectWorldScreen::onTick() { #ifndef ORIGINAL_CODE m_btnUnknown.field_36 = true; @@ -141,7 +141,7 @@ void SelectWorldScreen::tick() return; } - m_pWorldSelectionList->tick(); + m_pWorldSelectionList->onTick(); if (m_pWorldSelectionList->field_90) { LevelSummary& ls = m_pWorldSelectionList->m_levelSummary; @@ -159,7 +159,7 @@ void SelectWorldScreen::tick() m_btnDelete.m_bEnabled = isIndexValid(m_pWorldSelectionList->m_selectedIndex); } -void SelectWorldScreen::render(int mouseX, int mouseY, float f) +void SelectWorldScreen::onRender(int mouseX, int mouseY, float f) { renderBackground(); #ifndef ORIGINAL_CODE @@ -168,15 +168,15 @@ void SelectWorldScreen::render(int mouseX, int mouseY, float f) m_pWorldSelectionList->setComponentSelected(m_btnUnknown.field_36); if (field_12C) { - m_pWorldSelectionList->render(mouseX, mouseY, f); + m_pWorldSelectionList->onRender(mouseX, mouseY, f); } else { - m_pWorldSelectionList->render(0, 0, f); + m_pWorldSelectionList->onRender(0, 0, f); field_12C = Mouse::getButtonState(BUTTON_LEFT); } - Screen::render(mouseX, mouseY, f); + Screen::onRender(mouseX, mouseY, f); drawCenteredString(m_pMinecraft->m_pFont, "Select world", m_width / 2, 8, 0xFFFFFFFF); } diff --git a/source/client/gui/screens/SelectWorldScreen.hpp b/source/client/gui/screens/SelectWorldScreen.hpp index b4daaea..e004f5c 100644 --- a/source/client/gui/screens/SelectWorldScreen.hpp +++ b/source/client/gui/screens/SelectWorldScreen.hpp @@ -16,11 +16,11 @@ class SelectWorldScreen : public Screen public: SelectWorldScreen(); - void init() override; + void onInit() override; bool isInGameScreen() override; void keyPressed(int code) override; - void tick() override; - void render(int mouseX, int mouseY, float f) override; + void onTick() override; + void onRender(int mouseX, int mouseY, float f) override; bool handleBackEvent(bool b) override; void buttonClicked(Button* pButton) override; diff --git a/source/client/gui/screens/StartMenuScreen.cpp b/source/client/gui/screens/StartMenuScreen.cpp index bd04bc6..8fa1a5a 100644 --- a/source/client/gui/screens/StartMenuScreen.cpp +++ b/source/client/gui/screens/StartMenuScreen.cpp @@ -397,7 +397,7 @@ void StartMenuScreen::buttonClicked(Button* pButton) } } -void StartMenuScreen::init() +void StartMenuScreen::onInit() { int yPos = m_height / 2; @@ -455,7 +455,7 @@ bool StartMenuScreen::isInGameScreen() return false; } -void StartMenuScreen::render(int a, int b, float c) +void StartMenuScreen::onRender(int a, int b, float c) { //renderBackground(); renderMenuBackground(c); @@ -506,12 +506,12 @@ void StartMenuScreen::render(int a, int b, float c) if (!crampedMode) drawSplash(); - Screen::render(a, b, c); + Screen::onRender(a, b, c); } -void StartMenuScreen::tick() +void StartMenuScreen::onTick() { - Screen::tick(); + Screen::onTick(); _updateLicense(); } diff --git a/source/client/gui/screens/StartMenuScreen.hpp b/source/client/gui/screens/StartMenuScreen.hpp index ec4ac31..d6c684d 100644 --- a/source/client/gui/screens/StartMenuScreen.hpp +++ b/source/client/gui/screens/StartMenuScreen.hpp @@ -16,11 +16,11 @@ public: StartMenuScreen(); void _updateLicense(); - void init() override; + void onInit() override; void buttonClicked(Button*) override; bool isInGameScreen() override; - void render(int, int, float) override; - void tick() override; + void onRender(int, int, float) override; + void onTick() override; void drawSplash(); diff --git a/source/client/newui/CMakeLists.txt b/source/client/newui/CMakeLists.txt new file mode 100644 index 0000000..aac320d --- /dev/null +++ b/source/client/newui/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(reminecraftpe-gui STATIC + Drawer.cpp Drawer.hpp + Gui.cpp Gui.hpp + Screen.cpp Screen.hpp + controls/Button.cpp controls/Button.hpp + controls/IControl.hpp + screens/MainScreen.cpp screens/MainScreen.hpp +) +target_link_libraries(reminecraftpe-gui PUBLIC reminecraftpe-common reminecraftpe-client) diff --git a/source/client/newui/Drawer.cpp b/source/client/newui/Drawer.cpp new file mode 100644 index 0000000..990a036 --- /dev/null +++ b/source/client/newui/Drawer.cpp @@ -0,0 +1,92 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#include "Drawer.hpp" +#include "client/renderer/Font.hpp" +#include "client/renderer/Tesselator.hpp" + +Drawer::Drawer() +{ +} + +void Drawer::blit(int dstX, int dstY, int srcX, int srcY, int dstWidth, int dstHeight, int srcWidth, int srcHeight) +{ + Tesselator& t = Tesselator::instance; + + if (!srcHeight) + srcHeight = dstHeight; + if (!srcWidth) + srcWidth = dstWidth; + + t.begin(); + t.vertexUV(dstX, dstY + dstHeight, 0, float(srcX) / 256.0f, float(srcY + srcHeight) / 256.0f); + t.vertexUV(dstX + dstWidth, dstY + dstHeight, 0, float(srcX + srcWidth) / 256.0f, float(srcY + srcHeight) / 256.0f); + t.vertexUV(dstX + dstWidth, dstY, 0, float(srcX + srcWidth) / 256.0f, float(srcY) / 256.0f); + t.vertexUV(dstX, dstY, 0, float(srcX) / 256.0f, float(srcY) / 256.0f); + t.draw(); +} + +void Drawer::fill(int left, int top, int right, int bottom, int color) +{ + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(float(GET_RED(color)) / 255.0f, float(GET_GREEN(color)) / 255.0f, float(GET_BLUE(color)) / 255.0f, float(GET_ALPHA(color)) / 255.0f); + + Tesselator& t = Tesselator::instance; + t.begin(); + + t.vertex(left, bottom, 0.0f); + t.vertex(right, bottom, 0.0f); + t.vertex(right, top, 0.0f); + t.vertex(left, top, 0.0f); + + t.draw(); + + glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); +} + +void Drawer::fillGradient(int left, int top, int right, int bottom, int colorUp, int colorDown) +{ + glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glShadeModel(GL_SMOOTH); + + Tesselator& t = Tesselator::instance; + t.begin(); + + // note: for some stupid reason OG uses the float overload. + t.color(float(GET_RED(colorUp)) / 255.0f, float(GET_GREEN(colorUp)) / 255.0f, float(GET_BLUE(colorUp)) / 255.0f, float(GET_ALPHA(colorUp)) / 255.0f); + t.vertex(left, bottom, 0.0f); + t.vertex(right, bottom, 0.0f); + t.color(float(GET_RED(colorDown)) / 255.0f, float(GET_GREEN(colorDown)) / 255.0f, float(GET_BLUE(colorDown)) / 255.0f, float(GET_ALPHA(colorDown)) / 255.0f); + t.vertex(right, top, 0.0f); + t.vertex(left, top, 0.0f); + + t.draw(); + + glShadeModel(GL_FLAT); + glDisable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + glEnable(GL_TEXTURE_2D); +} + +void Drawer::drawCenteredText(Font* pFont, const std::string text, int cx, int cy, int color) +{ + int width = pFont->width(text); + int height = pFont->height(text); + pFont->drawShadow(text, cx - width / 2, cy - height / 2, color); +} + +void Drawer::drawText(Font* pFont, const std::string text, int cx, int cy, int color) +{ + pFont->drawShadow(text, cx, cy, color); +} diff --git a/source/client/newui/Drawer.hpp b/source/client/newui/Drawer.hpp new file mode 100644 index 0000000..46ca30a --- /dev/null +++ b/source/client/newui/Drawer.hpp @@ -0,0 +1,25 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#pragma once +#include + +class Font; + +class Drawer +{ +public: + Drawer(); + virtual ~Drawer() {} + + void blit(int dstX, int dstY, int srcX, int srcY, int dstWidth, int dstHeight, int srcWidth, int srcHeight); + void fill(int left, int top, int right, int bottom, int color); + void fillGradient(int left, int top, int right, int bottom, int colorUp, int colorDown); + void drawCenteredText(Font* pFont, const std::string text, int cx, int cy, int color); + void drawText(Font* pFont, const std::string text, int cx, int cy, int color); +}; diff --git a/source/client/newui/Gui.cpp b/source/client/newui/Gui.cpp new file mode 100644 index 0000000..24f9cb7 --- /dev/null +++ b/source/client/newui/Gui.cpp @@ -0,0 +1,80 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#include "Gui.hpp" +#include "client/app/Minecraft.hpp" + +Gui::Gui(Minecraft* pMinecraft) : IGui(pMinecraft) +{ +} + +void Gui::addMessage(const std::string& s) +{ +} + +void Gui::onInventoryUpdated() +{ +} + +void Gui::onTick() +{ +} + +void Gui::onRender(float f, bool bHaveScreen, int mouseX, int mouseY) +{ +} + +bool Gui::isInside(int mouseX, int mouseY) +{ + return false; +} + +void Gui::handleClick(int clickID, int mouseX, int mouseY) +{ +} + +void Gui::handleKeyPressed(int keyCode) +{ +} + +void Gui::renderChatMessages(bool bShowAll) +{ +} + +int Gui::getNumSlots() +{ + return 9; +} + +int Gui::getNumUsableSlots() +{ + return getNumSlots() - m_pMinecraft->isTouchscreen(); +} + +// screens +#include "screens/MainScreen.hpp" +IScreen* Gui::screenMain() +{ + return new MainScreen(); +} +IScreen* Gui::screenDeath() +{ + return nullptr; +} +IScreen* Gui::screenPause() +{ + return nullptr; +} +IScreen* Gui::screenSaveWorld(bool bCopyMap, Entity *pEnt) +{ + return nullptr; +} +IScreen* Gui::screenRenameMPWorld(std::string name) +{ + return nullptr; +} diff --git a/source/client/newui/Gui.hpp b/source/client/newui/Gui.hpp new file mode 100644 index 0000000..5913272 --- /dev/null +++ b/source/client/newui/Gui.hpp @@ -0,0 +1,35 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#pragma once +#include "client/app/IGui.hpp" + +class Gui : public IGui +{ +public: + Gui(Minecraft* pMinecraft); + + void addMessage(const std::string& str) override; + + void onInventoryUpdated() override; + void onTick() override; + void onRender(float f, bool bHaveScreen, int mouseX, int mouseY) override; + + bool isInside(int mx, int my) override; + void handleClick(int id, int mx, int my) override; + void handleKeyPressed(int keyCode) override; + void renderChatMessages(bool bShowAll) override; + int getNumSlots() override; // Gets the number of slots in the inventory. Includes the '...' if in touch mode. + int getNumUsableSlots() override; // Gets the number of usable slots in the inventory. Does not include the '...' if in touch mode. + + IScreen* screenMain() override; + IScreen* screenDeath() override; + IScreen* screenPause() override; + IScreen* screenSaveWorld(bool bCopyMap, Entity *pEnt) override; + IScreen* screenRenameMPWorld(std::string name) override; +}; diff --git a/source/client/newui/Screen.cpp b/source/client/newui/Screen.cpp new file mode 100644 index 0000000..f797ebd --- /dev/null +++ b/source/client/newui/Screen.cpp @@ -0,0 +1,160 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#include "Screen.hpp" +#include "client/player/input/Mouse.hpp" + +Screen::Screen() : IScreen() +{ +} + +Screen::~Screen() +{ +} + +void Screen::init(Minecraft* pMinecraft, int a3, int a4) +{ + IScreen::init(pMinecraft, a3, a4); +} + +void Screen::onInit() +{ + m_pFocusedControl = nullptr; +} + +void Screen::setSize(int width, int height) +{ + IScreen::setSize(width, height); +} + +int Screen::getYOffset() +{ + return 0; +} + +void Screen::onRender(int xPos, int yPos, float unused) +{ + renderBackground(); + for (IControl *control : m_controls) + { + if (control->m_bVisible) + control->onDraw(m_pMinecraft, xPos, yPos); + } +} + +void Screen::onEvents() +{ +} + +void Screen::mouseClicked(int xPos, int yPos, int d) // d = clicked? +{ + if (!d) return; + + for (IControl *control : m_controls) + { + if (control->onClick(m_pMinecraft, xPos, yPos)) + { + m_pMinecraft->m_pSoundEngine->play("random.click"); + m_pFocusedControl = control; + break; // no other buttons should be handled? + } + } + +#if 0 +#ifndef ORIGINAL_CODE + // if the keyboard is shown: + if (m_pMinecraft->platform()->getKeyboardUpOffset()) + { + // if there are none focused at the moment: + bool areAnyFocused = false; + for (int i = 0; i < int(m_textInputs.size()); i++) + { + TextInputBox* textInput = m_textInputs[i]; + if (textInput->m_bFocused) + { + areAnyFocused = true; + break; + } + } + + if (!areAnyFocused) + m_pMinecraft->platform()->showKeyboard(false); + } +#endif +#endif +} + +void Screen::mouseReleased(int xPos, int yPos, int d) +{ + if (!d) return; + + if (m_pFocusedControl) + { + m_pFocusedControl->onUnpress(m_pMinecraft, xPos, yPos); + m_pFocusedControl = nullptr; + } +} + +void Screen::mouseEvent() +{ + MouseAction* pAction = Mouse::getEvent(); + if (pAction->isButton()) + { + if (Mouse::getEventButtonState()) + mouseClicked (m_width * pAction->_posX / Minecraft::width, m_height * pAction->_posY / Minecraft::height - 1 + getYOffset(), Mouse::getEventButton()); + else + mouseReleased(m_width * pAction->_posX / Minecraft::width, m_height * pAction->_posY / Minecraft::height - 1 + getYOffset(), Mouse::getEventButton()); + } +} + +void Screen::keyboardEvent() +{ +} + +void Screen::onTick() +{ + for (IControl *control : m_controls) + control->onTick(); +} + +void Screen::removed() +{ +} + +bool Screen::handleBackEvent(bool b) +{ + return false; +} + +void Screen::renderBackground() +{ + fill(0, 0, m_width, m_height, 0xFF333333); +} + +bool Screen::isPauseScreen() +{ + return true; +} + +bool Screen::isErrorScreen() +{ + return false; +} + +bool Screen::isInGameScreen() +{ + return true; +} + +void Screen::confirmResult(bool b, int i) +{ +} + +void Screen::charInput(char ch) +{ +} diff --git a/source/client/newui/Screen.hpp b/source/client/newui/Screen.hpp new file mode 100644 index 0000000..abbb2dd --- /dev/null +++ b/source/client/newui/Screen.hpp @@ -0,0 +1,49 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#pragma once +#include "client/app/IScreen.hpp" +#include "controls/IControl.hpp" +#include "Drawer.hpp" + +class Screen : public IScreen, public Drawer +{ +public: + Screen(); + virtual ~Screen(); + + void init(Minecraft*, int, int) override; + void setSize(int width, int height) override; + int getYOffset() override; + + virtual void onInit() override; + virtual void onRender(int mouseX, int mouseY, float f) override; + virtual void onEvents() override; + virtual void onTick() override; + + virtual void mouseEvent() override; + virtual void keyboardEvent() override; + virtual bool handleBackEvent(bool) override; + virtual void removed() override; + virtual void renderBackground() override; + virtual bool isPauseScreen() override; + virtual bool isErrorScreen() override; + virtual bool isInGameScreen() override; + virtual void confirmResult(bool, int) override; + virtual void charInput(char) override; + + virtual void mouseClicked(int, int, int); + virtual void mouseReleased(int, int, int); + + // ported from 0.8 + //virtual void renderMenuBackground(float f); + +protected: + std::vector m_controls; + IControl *m_pFocusedControl; +}; diff --git a/source/client/newui/controls/Button.cpp b/source/client/newui/controls/Button.cpp new file mode 100644 index 0000000..61c9161 --- /dev/null +++ b/source/client/newui/controls/Button.cpp @@ -0,0 +1,78 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#include "Button.hpp" + +bool Button::onClick(Minecraft* pMinecraft, int x, int y) +{ + return true; +} + +void Button::onUnpress(Minecraft* pMinecraft, int x, int y) +{ +} + +int Button::getYImage(bool bHovered) +{ + if (!m_bEnabled) return 0; + if (bHovered) return 2; + return 1; +} + +bool Button::isHovered(int xPos, int yPos) +{ + if (!m_bEnabled) return false; + if (xPos < m_xPos) return false; + if (yPos < m_yPos) return false; + if (xPos >= m_xPos + m_width) return false; + if (yPos >= m_yPos + m_height) return false; + + return true; +} + +//#define NEWGUI +void Button::onDraw(Minecraft* pMinecraft, int x, int y) +{ +#ifdef ENH_HIGHLIGHT_BY_HOVER + m_bHovered = isHovered(x, y); +#endif + + Font* pFont = pMinecraft->m_pFont; + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); +#ifdef NEWGUI + // FIXME + pMinecraft->m_pTextures->loadAndBindTexture("gui/newgui/buttonNew.png"); + //pMinecraft->m_pTextures->loadAndBindTexture("gui/newgui/play_screen/HoverButtonThinNewBevel.png"); + + blit(m_xPos, m_yPos, 0, 0, 2, 2, 2, 2); + blit(m_xPos + m_width - 2, m_yPos, 2, 0, 2, 2, 2, 2); + blit(m_xPos, m_yPos + m_height - 2, 0, 2, 2, 2, 2, 2); + blit(m_xPos + m_width - 2, m_yPos + m_height - 2, 2, 2, 2, 2, 2, 2); + blit(m_xPos + 2, m_yPos, 2, 2, m_width - 4, m_height, 1, 4); +#else + pMinecraft->m_pTextures->loadAndBindTexture("gui/gui.png"); + + int iYPos = 20 * getYImage(m_bHovered) + 46; + + blit(m_xPos, m_yPos, 0, iYPos, m_width / 2, m_height, 0, 20); + blit(m_xPos + m_width / 2, m_yPos, 200 - m_width / 2, iYPos, m_width / 2, m_height, 0, 20); +#endif + + //renderBg(pMinecraft, x, y); + + int textColor; + if (!m_bEnabled) + textColor = int(0xFFA0A0A0U); + else if (m_bHovered) + textColor = int(0xFFFFA0U); + else + textColor = int(0xE0E0E0U); + + drawCenteredText(pFont, m_text, m_xPos + m_width / 2, m_yPos + (m_height - 8) / 2, textColor); +} diff --git a/source/client/newui/controls/Button.hpp b/source/client/newui/controls/Button.hpp new file mode 100644 index 0000000..5f50be3 --- /dev/null +++ b/source/client/newui/controls/Button.hpp @@ -0,0 +1,41 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#pragma once +#include "IControl.hpp" + +class Button : public IControl +{ +public: + Button(int x, int y, int width = 200, int height = 24, const std::string text = "", bool enabled = true) : + m_xPos(x), + m_yPos(y), + m_width(width), + m_height(height), + m_text(text), + m_bEnabled(enabled) + { + } + + bool onClick(Minecraft* pMinecraft, int x, int y) override; + void onUnpress(Minecraft* pMinecraft, int x, int y) override; + void onDraw(Minecraft* pMinecraft, int x, int y) override; + +private: + int getYImage(bool bHovered); + bool isHovered(int xPos, int yPos); + +public: + bool m_bEnabled; + bool m_bHovered; + int m_xPos; + int m_yPos; + int m_width; + int m_height; + std::string m_text; +}; diff --git a/source/client/newui/controls/IControl.hpp b/source/client/newui/controls/IControl.hpp new file mode 100644 index 0000000..11cfded --- /dev/null +++ b/source/client/newui/controls/IControl.hpp @@ -0,0 +1,29 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#pragma once +#include "client/app/Minecraft.hpp" +#include "../Drawer.hpp" + +class IControl : public Drawer +{ +public: + IControl() : Drawer(), + m_bVisible(true) + { + } + + virtual void onTick() {} + virtual bool onClick(Minecraft* pMinecraft, int x, int y) { return false; } + virtual void onUnpress(Minecraft* pMinecraft, int x, int y) {} + virtual void onDraw(Minecraft* pMinecraft, int x, int y) {} + virtual void onKeyPressed(Minecraft* pMinecraft, int key) {} + virtual void onCharPressed(Minecraft* pMinecraft, int chr) {} + + bool m_bVisible; +}; diff --git a/source/client/newui/screens/MainScreen.cpp b/source/client/newui/screens/MainScreen.cpp new file mode 100644 index 0000000..5ba659e --- /dev/null +++ b/source/client/newui/screens/MainScreen.cpp @@ -0,0 +1,17 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#include "MainScreen.hpp" +#include "../controls/Button.hpp" + +// TODO: Read splashes from splashes.json + +MainScreen::MainScreen() : Screen() +{ + m_controls.push_back(new Button(1, 1, 100, 24, "Hello, world!")); +} diff --git a/source/client/newui/screens/MainScreen.hpp b/source/client/newui/screens/MainScreen.hpp new file mode 100644 index 0000000..90d13ac --- /dev/null +++ b/source/client/newui/screens/MainScreen.hpp @@ -0,0 +1,16 @@ +/******************************************************************** + Minecraft: Pocket Edition - Decompilation Project + Copyright (C) 2023 iProgramInCpp + + The following code is licensed under the BSD 1 clause license. + SPDX-License-Identifier: BSD-1-Clause + ********************************************************************/ + +#pragma once +#include "../Screen.hpp" + +class MainScreen : public Screen +{ +public: + MainScreen(); +}; diff --git a/source/client/player/LocalPlayer.cpp b/source/client/player/LocalPlayer.cpp index b34a589..e06ee56 100644 --- a/source/client/player/LocalPlayer.cpp +++ b/source/client/player/LocalPlayer.cpp @@ -50,7 +50,7 @@ LocalPlayer::~LocalPlayer() void LocalPlayer::aiStep() { - m_pMoveInput->tick(this); + m_pMoveInput->onTick(this); if (m_pMoveInput->m_bSneakButton && field_A4 < 0.2f) field_A4 = 0.2f; diff --git a/source/client/player/input/CMakeLists.txt b/source/client/player/input/CMakeLists.txt deleted file mode 100644 index 47e3c56..0000000 --- a/source/client/player/input/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -add_library(reminecraftpe-input STATIC - Controller.cpp Controller.hpp - ControllerTurnInput.cpp ControllerTurnInput.hpp - CustomInputHolder.cpp CustomInputHolder.hpp - IBuildInput.cpp IBuildInput.hpp - IInputHolder.cpp IInputHolder.hpp - IMoveInput.cpp IMoveInput.hpp - ITouchScreenModel.cpp ITouchScreenModel.hpp - ITurnInput.cpp ITurnInput.hpp - IncludeExcludeArea.cpp IncludeExcludeArea.hpp - Keyboard.cpp Keyboard.hpp - KeyboardInput.cpp KeyboardInput.hpp - Mouse.cpp Mouse.hpp - MouseDevice.cpp MouseDevice.hpp - MouseHandler.cpp MouseHandler.hpp - MouseTurnInput.cpp MouseTurnInput.hpp - Multitouch.cpp Multitouch.hpp - PolygonArea.cpp PolygonArea.hpp - RectangleArea.cpp RectangleArea.hpp - TouchAreaModel.cpp TouchAreaModel.hpp - TouchInputHolder.cpp TouchInputHolder.hpp - TouchscreenInput_TestFps.cpp TouchscreenInput_TestFps.hpp - UnifiedTurnBuild.cpp UnifiedTurnBuild.hpp -) -target_link_libraries(reminecraftpe-input PRIVATE reminecraftpe-client) diff --git a/source/client/player/input/IMoveInput.cpp b/source/client/player/input/IMoveInput.cpp index 3ad063a..318ee6f 100644 --- a/source/client/player/input/IMoveInput.cpp +++ b/source/client/player/input/IMoveInput.cpp @@ -25,7 +25,7 @@ void IMoveInput::releaseAllKeys() { } -void IMoveInput::render(float f) +void IMoveInput::onRender(float f) { } @@ -37,6 +37,6 @@ void IMoveInput::setScreenSize(int width, int height) { } -void IMoveInput::tick(Player* pPlayer) +void IMoveInput::onTick(Player* pPlayer) { } diff --git a/source/client/player/input/IMoveInput.hpp b/source/client/player/input/IMoveInput.hpp index 89c3e73..f2e60d0 100644 --- a/source/client/player/input/IMoveInput.hpp +++ b/source/client/player/input/IMoveInput.hpp @@ -27,10 +27,10 @@ public: virtual ~IMoveInput(); virtual void releaseAllKeys(); - virtual void render(float f); + virtual void onRender(float f); virtual void setKey(int key, bool state); virtual void setScreenSize(int width, int height); - virtual void tick(Player*); + virtual void onTick(Player*); public: float m_horzInput; diff --git a/source/client/player/input/KeyboardInput.cpp b/source/client/player/input/KeyboardInput.cpp index 107bba8..4ed3882 100644 --- a/source/client/player/input/KeyboardInput.cpp +++ b/source/client/player/input/KeyboardInput.cpp @@ -45,7 +45,7 @@ void KeyboardInput::setKey(int keyCode, bool b) m_keys[index] = b; } -void KeyboardInput::tick(Player* pPlayer) +void KeyboardInput::onTick(Player* pPlayer) { m_horzInput = 0.0f; m_vertInput = 0.0f; diff --git a/source/client/player/input/KeyboardInput.hpp b/source/client/player/input/KeyboardInput.hpp index 0427cb9..22aa890 100644 --- a/source/client/player/input/KeyboardInput.hpp +++ b/source/client/player/input/KeyboardInput.hpp @@ -21,7 +21,7 @@ public: void releaseAllKeys() override; void setKey(int index, bool b) override; - void tick(Player*) override; + void onTick(Player*) override; public: bool m_keys[10]; diff --git a/source/client/player/input/TouchInputHolder.hpp b/source/client/player/input/TouchInputHolder.hpp index 551ccd4..994564f 100644 --- a/source/client/player/input/TouchInputHolder.hpp +++ b/source/client/player/input/TouchInputHolder.hpp @@ -10,7 +10,6 @@ #include "client/app/Minecraft.hpp" #include "IInputHolder.hpp" -#include "TouchscreenInput_TestFps.hpp" #include "UnifiedTurnBuild.hpp" class Minecraft; @@ -27,6 +26,27 @@ static inline RectangleArea getRectangleArea(IGui *gui, bool b) Minecraft::height); } +class TouchInput : public IMoveInput, public IScreen +{ +public: + TouchInput(Minecraft* pMinecraft, Options* pOptions) : + m_pMinecraft(pMinecraft), + m_pOptions(pOptions), + m_rectArea(0, 0, 0, 0) + { + } + + RectangleArea getRectangleArea() + { + return m_rectArea; + } + +private: + Minecraft* m_pMinecraft; + Options* m_pOptions; + RectangleArea m_rectArea; +}; + class TouchInputHolder : public IInputHolder { public: @@ -38,7 +58,7 @@ public: void setScreenSize(int width, int height) override; public: - TouchscreenInput_TestFps m_touchScreenInput; + TouchInput m_touchScreenInput; UnifiedTurnBuild m_unifiedTurnBuild; Minecraft* m_pMinecraft; }; diff --git a/source/client/renderer/GameRenderer.cpp b/source/client/renderer/GameRenderer.cpp index ceebc62..d3901c2 100644 --- a/source/client/renderer/GameRenderer.cpp +++ b/source/client/renderer/GameRenderer.cpp @@ -641,7 +641,7 @@ void GameRenderer::render(float f) return; } - m_pMinecraft->m_pGui->render(f, m_pMinecraft->m_pScreen != nullptr, mouseX, mouseY); + m_pMinecraft->m_pGui->onRender(f, m_pMinecraft->m_pScreen != nullptr, mouseX, mouseY); } } else @@ -656,13 +656,25 @@ void GameRenderer::render(float f) if (m_pMinecraft->m_pLocalPlayer && m_pMinecraft->m_pLocalPlayer->m_pMoveInput) - m_pMinecraft->m_pLocalPlayer->m_pMoveInput->render(f); + m_pMinecraft->m_pLocalPlayer->m_pMoveInput->onRender(f); if (m_pMinecraft->m_pScreen) { glClear(GL_DEPTH_BUFFER_BIT); + + int offset = m_pMinecraft->m_pScreen->getYOffset(); + if (offset != 0) + { + // push the entire screen up + glPushMatrix(); + glTranslatef(0.0f, -float(offset), 0.0f); + } + m_pMinecraft->m_pScreen->onRender(mouseX, mouseY, f); + if (offset != 0) + glPopMatrix(); + if (m_pMinecraft->m_pScreen && !m_pMinecraft->m_pScreen->isInGameScreen()) { #ifdef ORIGINAL_CODE