From 5e311cbbb3d225a12ddef2a147b36559f6036f7a Mon Sep 17 00:00:00 2001 From: Er2 Date: Sat, 9 Dec 2023 13:58:05 +0300 Subject: [PATCH] GUI: Split gui to interface, potentially new ui interface is possible --- source/client/CMakeLists.txt | 2 + source/client/app/IGui.cpp | 87 +++++++++++++++ source/client/app/IGui.hpp | 42 +++++++ source/client/app/IScreen.cpp | 99 +++++++++++++++++ source/client/app/IScreen.hpp | 47 ++++++++ source/client/app/Minecraft.cpp | 51 +++++---- source/client/app/Minecraft.hpp | 16 +-- source/client/app/NinecraftApp.cpp | 3 +- source/client/gui/Gui.cpp | 104 +++++++++--------- source/client/gui/Gui.hpp | 44 ++++---- source/client/gui/Screen.cpp | 47 +------- source/client/gui/Screen.hpp | 15 +-- source/client/gui/components/OptionList.cpp | 2 +- .../gui/components/RolledSelectionList.cpp | 1 + .../gui/components/RolledSelectionList.hpp | 1 + .../gui/components/ScrolledSelectionList.cpp | 4 +- .../gui/components/ScrolledSelectionList.hpp | 2 + source/client/gui/screens/ChatScreen.cpp | 5 +- .../screens/IngameBlockSelectionScreen.cpp | 4 +- source/client/gui/screens/ProgressScreen.cpp | 8 +- source/client/gui/screens/ProgressScreen.hpp | 2 +- .../client/gui/screens/SavingWorldScreen.cpp | 5 +- .../network/ClientSideNetworkHandler.cpp | 9 +- source/client/player/LocalPlayer.cpp | 1 + .../client/player/input/TouchInputHolder.cpp | 2 +- .../client/player/input/TouchInputHolder.hpp | 12 ++ .../player/input/TouchscreenInput_TestFps.cpp | 17 +-- source/client/renderer/GameRenderer.cpp | 14 +-- source/network/ServerSideNetworkHandler.cpp | 8 +- source/world/gamemode/CreativeMode.cpp | 4 +- source/world/gamemode/SurvivalMode.cpp | 4 +- 31 files changed, 460 insertions(+), 202 deletions(-) create mode 100644 source/client/app/IGui.cpp create mode 100644 source/client/app/IGui.hpp create mode 100644 source/client/app/IScreen.cpp create mode 100644 source/client/app/IScreen.hpp diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index a93ea3d..5c8f99b 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -1,6 +1,8 @@ add_library(reminecraftpe-client STATIC app/App.cpp app/App.hpp app/AppPlatform.cpp app/AppPlatform.hpp + app/IGui.cpp app/IGui.hpp + app/IScreen.cpp app/IScreen.hpp app/Minecraft.cpp app/Minecraft.hpp app/NinecraftApp.cpp app/NinecraftApp.hpp model/ChickenModel.cpp model/ChickenModel.hpp diff --git a/source/client/app/IGui.cpp b/source/client/app/IGui.cpp new file mode 100644 index 0000000..205609f --- /dev/null +++ b/source/client/app/IGui.cpp @@ -0,0 +1,87 @@ +/******************************************************************** + 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 "IGui.hpp" +#include "Minecraft.hpp" + +IGui::IGui(Minecraft* pMinecraft) +{ +#ifdef ENH_USE_GUI_SCALE_2 + scale = 1.0f / 2.0f; +#else + scale = 1.0f / 3.0f; +#endif + + m_bRenderChatMessages = true; + m_pMinecraft = pMinecraft; +} + +void IGui::addMessage(const std::string& s) +{ +} + +void IGui::onInventoryUpdated() +{ +} + +void IGui::tick() +{ +} + +void IGui::render(float f, bool bHaveScreen, int mouseX, int mouseY) +{ +} + +bool IGui::isInside(int mouseX, int mouseY) +{ + return false; +} + +void IGui::handleClick(int clickID, int mouseX, int mouseY) +{ +} + +void IGui::handleKeyPressed(int keyCode) +{ +} + +void IGui::renderChatMessages(bool bShowAll) +{ +} + +int IGui::getNumSlots() +{ + return 0; +} + +int IGui::getNumUsableSlots() +{ + return getNumSlots() - m_pMinecraft->isTouchscreen(); +} + +// screens +IScreen* IGui::screenMain() +{ + return nullptr; +} +IScreen* IGui::screenDeath() +{ + return nullptr; +} +IScreen* IGui::screenPause() +{ + return nullptr; +} +IScreen* IGui::screenSaveWorld(bool bCopyMap, Entity *pEnt) +{ + return nullptr; +} +IScreen* IGui::screenRenameMPWorld(std::string name) +{ + return nullptr; +} diff --git a/source/client/app/IGui.hpp b/source/client/app/IGui.hpp new file mode 100644 index 0000000..37805f0 --- /dev/null +++ b/source/client/app/IGui.hpp @@ -0,0 +1,42 @@ +/******************************************************************** + 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 "App.hpp" + +class Minecraft; +class Entity; +class IScreen; + +class IGui +{ +public: + IGui(Minecraft* pMinecraft); + + 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 bool isInside(int mx, int my); + virtual void handleClick(int id, int mx, int my); + virtual void handleKeyPressed(int keyCode); + virtual void renderChatMessages(bool bShowAll); + virtual int getNumSlots(); // Gets the number of slots in the inventory. Includes the '...' if in touch mode. + virtual int getNumUsableSlots(); // Gets the number of usable slots in the inventory. Does not include the '...' if in touch mode. + + virtual IScreen* screenMain(); + virtual IScreen* screenDeath(); + virtual IScreen* screenPause(); + virtual IScreen* screenSaveWorld(bool bCopyMap, Entity *pEnt); + virtual IScreen* screenRenameMPWorld(std::string name); + + float scale; + bool m_bRenderChatMessages; + Minecraft* m_pMinecraft; +}; diff --git a/source/client/app/IScreen.cpp b/source/client/app/IScreen.cpp new file mode 100644 index 0000000..387a8fe --- /dev/null +++ b/source/client/app/IScreen.cpp @@ -0,0 +1,99 @@ +/******************************************************************** + 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 "IScreen.hpp" + +IScreen::IScreen() +{ + m_width = 1; + m_height = 1; + m_bIgnore = false; +} + +void IScreen::init(Minecraft* pMinecraft, int a3, int a4) +{ + m_width = a3; + m_height = a4; + m_pMinecraft = pMinecraft; + init(); +} + +void IScreen::init() +{ +} + +void IScreen::setSize(int width, int height) +{ + m_width = width; + m_height = height; +} + +void IScreen::onRender(int mouseX, int mouseY, float f) +{ +} + +int IScreen::getYOffset() +{ + return 0; +} + +void IScreen::render(int xPos, int yPos, float unused) +{ +} + +void IScreen::onEvents() +{ +} + +void IScreen::mouseEvent() +{ +} + +void IScreen::keyboardEvent() +{ +} + +void IScreen::tick() +{ +} + +void IScreen::removed() +{ +} + +bool IScreen::handleBackEvent(bool b) +{ + return false; +} + +void IScreen::renderBackground() +{ +} + +bool IScreen::isPauseScreen() +{ + return true; +} + +bool IScreen::isErrorScreen() +{ + return false; +} + +bool IScreen::isInGameScreen() +{ + return true; +} + +void IScreen::confirmResult(bool b, int i) +{ +} + +void IScreen::charInput(char ch) +{ +} diff --git a/source/client/app/IScreen.hpp b/source/client/app/IScreen.hpp new file mode 100644 index 0000000..556f2e7 --- /dev/null +++ b/source/client/app/IScreen.hpp @@ -0,0 +1,47 @@ +/******************************************************************** + 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 + +class Minecraft; + +class IScreen +{ +public: + IScreen(); + 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 onEvents(); + virtual void mouseEvent(); + virtual void keyboardEvent(); + virtual bool handleBackEvent(bool); + virtual void tick(); + virtual void removed(); + virtual void renderBackground(); + virtual bool isPauseScreen(); + virtual bool isErrorScreen(); + virtual bool isInGameScreen(); + 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; + Minecraft *m_pMinecraft; +}; diff --git a/source/client/app/Minecraft.cpp b/source/client/app/Minecraft.cpp index 2b024f0..33c874e 100644 --- a/source/client/app/Minecraft.cpp +++ b/source/client/app/Minecraft.cpp @@ -7,16 +7,12 @@ ********************************************************************/ #include "client/app/Minecraft.hpp" -#include "client/gui/screens/PauseScreen.hpp" -#include "client/gui/screens/StartMenuScreen.hpp" -#include "client/gui/screens/RenameMPLevelScreen.hpp" -#include "client/gui/screens/SavingWorldScreen.hpp" -#include "client/gui/screens/DeathScreen.hpp" #include "network/ServerSideNetworkHandler.hpp" #include "client/network/ClientSideNetworkHandler.hpp" #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" @@ -25,6 +21,7 @@ #include "client/player/input/CustomInputHolder.hpp" #include "client/player/input/TouchInputHolder.hpp" #include "client/player/input/Multitouch.hpp" +#include "client/player/input/Keyboard.hpp" #include "world/tile/SandTile.hpp" @@ -52,9 +49,10 @@ const char* Minecraft::progressMessages[] = "Saving chunks", }; -Minecraft::Minecraft() : - m_gui(this) +Minecraft::Minecraft() { + // TODO: Gui selection? + m_pGui = new Gui(this); m_options = nullptr; field_18 = false; field_288 = false; @@ -134,7 +132,7 @@ void Minecraft::grabMouse() platform()->setMouseGrabbed(!isTouchscreen()); } -void Minecraft::setScreen(Screen* pScreen) +void Minecraft::setScreen(IScreen* pScreen) { #ifndef ORIGINAL_CODE if (pScreen == nullptr && !isLevelGenerated()) @@ -167,7 +165,7 @@ void Minecraft::setScreen(Screen* pScreen) if (pScreen) { releaseMouse(); - pScreen->init(this, int(width * Gui::InvGuiScale), int(height * Gui::InvGuiScale)); + pScreen->init(this, std::ceil(width * m_pGui->scale), std::ceil(height * m_pGui->scale)); } else { @@ -338,6 +336,7 @@ void Minecraft::handleBuildAction(BuildActionIntention* pAction) hitSide = HitResult::MINY; } + if (!m_pRakNetInstance) return; // throw std::exception()? m_pRakNetInstance->send(new PlaceBlockPacket(m_pLocalPlayer->m_EntityID, dx, dy, dz, uint8_t(pItem->m_itemID), hitSide)); } } @@ -376,10 +375,10 @@ void Minecraft::tickInput() { if (m_pScreen) { - if (!m_pScreen->field_10) + if (!m_pScreen->m_bIgnore) { m_bUsingScreen = true; - m_pScreen->updateEvents(); + m_pScreen->onEvents(); m_bUsingScreen = false; if (m_bHasQueuedScreen) @@ -395,7 +394,7 @@ void Minecraft::tickInput() if (!m_pLocalPlayer) return; - bool bIsInGUI = m_gui.isInside(Mouse::getX(), Mouse::getY()); + bool bIsInGUI = m_pGui->isInside(Mouse::getX(), Mouse::getY()); while (Mouse::next()) { @@ -403,7 +402,7 @@ void Minecraft::tickInput() continue; if (Mouse::isButtonDown(BUTTON_LEFT)) - m_gui.handleClick(1, Mouse::getX(), Mouse::getY()); + m_pGui->handleClick(1, Mouse::getX(), Mouse::getY()); if (!bIsInGUI && getOptions()->field_19) { @@ -422,7 +421,7 @@ void Minecraft::tickInput() { int slot = m_pLocalPlayer->m_pInventory->m_SelectedHotbarSlot; - int maxItems = m_gui.getNumSlots() - 1; + int maxItems = m_pGui->getNumSlots() - 1; if (isTouchscreen()) maxItems--; @@ -456,9 +455,9 @@ void Minecraft::tickInput() if (bPressed) { - m_gui.handleKeyPressed(keyCode); + m_pGui->handleKeyPressed(keyCode); - for (int i = 0; i < m_gui.getNumSlots(); i++) + for (int i = 0; i < m_pGui->getNumSlots(); i++) { if (getOptions()->isKey(eKeyMappingIndex(KM_SLOT_1 + i), keyCode)) m_pLocalPlayer->m_pInventory->selectSlot(i); @@ -576,7 +575,7 @@ void Minecraft::sendMessage(const std::string& message) if (m_pRakNetInstance) m_pRakNetInstance->send(new MessagePacket(message)); else - m_gui.addMessage("You aren't actually playing multiplayer!"); + m_pGui->addMessage("You aren't actually playing multiplayer!"); } else { @@ -585,7 +584,7 @@ void Minecraft::sendMessage(const std::string& message) if (m_pNetEventCallback && m_pRakNetInstance) m_pNetEventCallback->handle(m_pRakNetInstance->m_pRakPeerInterface->GetMyGUID(), &mp); else - m_gui.addMessage("You aren't hosting a multiplayer server!"); + m_pGui->addMessage("You aren't hosting a multiplayer server!"); } } @@ -680,13 +679,13 @@ void Minecraft::tick() { if (m_pLocalPlayer && m_pLocalPlayer->m_health <= 0) { - setScreen(new DeathScreen); + setScreen(m_pGui->screenDeath()); } } tickInput(); - m_gui.tick(); + m_pGui->tick(); // if the level has been prepared, delete the prep thread if (!m_bPreparingLevel) @@ -967,10 +966,10 @@ void Minecraft::prepareLevel(const std::string& unused) void Minecraft::sizeUpdate(int newWidth, int newHeight) { // re-calculate the GUI scale. - Gui::InvGuiScale = getBestScaleForThisScreenSize(newWidth, newHeight) / guiScaleMultiplier; + m_pGui->scale = getBestScaleForThisScreenSize(newWidth, newHeight) / guiScaleMultiplier; if (m_pScreen) - m_pScreen->setSize(int(Minecraft::width * Gui::InvGuiScale), int(Minecraft::height * Gui::InvGuiScale)); + m_pScreen->setSize(std::ceil(Minecraft::width * m_pGui->scale), std::ceil(Minecraft::height * m_pGui->scale)); if (m_pInputHolder) m_pInputHolder->setScreenSize(newWidth * guiScaleMultiplier, newHeight * guiScaleMultiplier); @@ -1067,7 +1066,7 @@ void Minecraft::pauseGame() { if (m_pScreen) return; m_pLevel->savePlayerData(); - setScreen(new PauseScreen); + setScreen(m_pGui->screenPause()); } void Minecraft::setLevel(Level* pLevel, const std::string& text, LocalPlayer* pLocalPlayer) @@ -1163,7 +1162,7 @@ void Minecraft::leaveGame(bool bCopyMap) #ifdef ENH_IMPROVED_SAVING field_288 = true; - setScreen(new SavingWorldScreen(bCopyMap, m_pLocalPlayer)); + setScreen(m_pGui->screenSaveWorld(bCopyMap, m_pLocalPlayer)); #else if (m_pLevel) { @@ -1188,9 +1187,9 @@ void Minecraft::leaveGame(bool bCopyMap) SAFE_DELETE(m_pLocalPlayer); if (bCopyMap) - setScreen(new RenameMPLevelScreen("_LastJoinedServer")); + setScreen(m_pGui->screenRenameMPWorld("_LastJoinedServer")); else - setScreen(new StartMenuScreen); + setScreen(m_pGui->screenMain()); #endif } diff --git a/source/client/app/Minecraft.hpp b/source/client/app/Minecraft.hpp index a734862..ef866d7 100644 --- a/source/client/app/Minecraft.hpp +++ b/source/client/app/Minecraft.hpp @@ -9,11 +9,11 @@ #pragma once #include "App.hpp" +#include "IGui.hpp" +#include "IScreen.hpp" #include "common/CThread.hpp" #include "common/Mth.hpp" #include "common/Timer.hpp" -#include "client/gui/Gui.hpp" -#include "client/gui/Screen.hpp" #include "network/RakNetInstance.hpp" #include "network/NetEventCallback.hpp" #include "client/player/LocalPlayer.hpp" @@ -28,8 +28,6 @@ #include "world/gamemode/GameMode.hpp" #include "world/particle/ParticleEngine.hpp" -class Screen; // in case we're included from Screen.hpp - class Minecraft : public App { public: @@ -37,7 +35,7 @@ public: virtual ~Minecraft(); int getLicenseId(); - void setScreen(Screen * pScreen); + void setScreen(IScreen * pScreen); void releaseMouse(); void grabMouse(); void tick(); @@ -119,10 +117,10 @@ public: Level* m_pLevel; LocalPlayer* m_pLocalPlayer; Mob* m_pMobPersp; // why is there a duplicate? - Gui m_gui; + IGui *m_pGui; int field_D0C; CThread* m_pPrepThread; - Screen* m_pScreen; + IScreen* m_pScreen; int field_D18; IInputHolder* m_pInputHolder; MouseHandler m_mouseHandler; @@ -141,11 +139,13 @@ public: int field_DAC; bool m_bUsingScreen; bool m_bHasQueuedScreen; - Screen* m_pQueuedScreen; + IScreen* m_pQueuedScreen; int m_licenseID; ItemInstance m_CurrItemInstance; // in 0.8. Offset 3368 double m_fDeltaTime, m_fLastUpdated; + + float m_breakProgress; }; diff --git a/source/client/app/NinecraftApp.cpp b/source/client/app/NinecraftApp.cpp index acb96bb..6da7f79 100644 --- a/source/client/app/NinecraftApp.cpp +++ b/source/client/app/NinecraftApp.cpp @@ -9,7 +9,6 @@ #include "NinecraftApp.hpp" #include "world/item/Item.hpp" #include "client/player/input/Multitouch.hpp" -#include "client/gui/screens/StartMenuScreen.hpp" #ifdef DEMO #include "world/level/storage/MemoryLevelStorageSource.hpp" @@ -94,7 +93,7 @@ void NinecraftApp::init() field_D9C = 0; - setScreen(new StartMenuScreen); + setScreen(m_pGui->screenMain()); } void NinecraftApp::onGraphicsReset() diff --git a/source/client/gui/Gui.cpp b/source/client/gui/Gui.cpp index 0abb9e0..58a4b64 100644 --- a/source/client/gui/Gui.cpp +++ b/source/client/gui/Gui.cpp @@ -6,23 +6,19 @@ SPDX-License-Identifier: BSD-1-Clause ********************************************************************/ +#include "Gui.hpp" +#include "screens/IngameBlockSelectionScreen.hpp" +#include "screens/ChatScreen.hpp" #include "client/app/Minecraft.hpp" -#include "client/gui/screens/IngameBlockSelectionScreen.hpp" -#include "client/gui/screens/ChatScreen.hpp" #include "client/renderer/entity/ItemRenderer.hpp" #ifdef _WIN32 #pragma warning(disable : 4244) #endif -#ifdef ENH_USE_GUI_SCALE_2 -float Gui::InvGuiScale = 1.0f / 2.0f; -#else -float Gui::InvGuiScale = 1.0f / 3.0f; -#endif - -Gui::Gui(Minecraft* pMinecraft) +Gui::Gui(Minecraft* pMinecraft) : IGui(pMinecraft) { + /* field_8 = 0; field_C = ""; field_24 = 0; @@ -32,11 +28,9 @@ Gui::Gui(Minecraft* pMinecraft) field_A00 = ""; field_A18 = 0; field_A1C = false; - field_A20 = 1.0f; - field_A3C = true; - m_bRenderMessages = true; - - m_pMinecraft = pMinecraft; + */ + m_vignetteColor = 1.0f; + //field_A3C = true; // unused xglGenBuffers(1, &m_renderChunk.field_0); } @@ -81,12 +75,14 @@ void Gui::addMessage(const std::string& s) m_guiMessages.insert(m_guiMessages.begin(), GuiMessage(str, 0)); } +/* for jukebox void Gui::setNowPlaying(const std::string& str) { field_A00 = "Now playing: " + str; field_A18 = 60; field_A1C = true; } +*/ void Gui::renderVignette(float a2, int a3, int a4) { @@ -96,11 +92,11 @@ void Gui::renderVignette(float a2, int a3, int a4) if (a2 < 0.0f) a2 = 0.0f; - field_A20 += ((a2 - field_A20) * 0.01f); + m_vignetteColor += ((a2 - m_vignetteColor) * 0.01f); glDisable(GL_DEPTH_TEST); glDepthMask(false); glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); - glColor4f(field_A20, field_A20, field_A20, 1.0f); + glColor4f(m_vignetteColor, m_vignetteColor, m_vignetteColor, 1.0f); //! @BUG: No misc/vignette.png to be found in the original. //! This function is unused anyways @@ -120,9 +116,10 @@ void Gui::renderVignette(float a2, int a3, int a4) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } -void Gui::inventoryUpdated() +void Gui::onInventoryUpdated() { - field_A3C = true; + // unused + //field_A3C = true; } void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) @@ -148,8 +145,8 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) field_4 = -90.0f; - int width = Minecraft::width * InvGuiScale, - height = Minecraft::height * InvGuiScale; + int width = Minecraft::width * scale, + height = Minecraft::height * scale; #ifdef ENH_TRANSPARENT_HOTBAR glEnable(GL_BLEND); @@ -189,7 +186,7 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) // NOTE: real Minecraft PE takes it directly from the gamemode as "current progress" and // "last progress". Well guess what? The game mode in question updates our field_8 with // the pre-interpolated break progress! Isn't that awesome?! - float breakProgress = field_8; + float breakProgress = 0.0f; //field_8; // don't know about this if-structure, it feels like it'd be like // if (field_C >= 0.0f && breakProgress <= 0.0f) @@ -207,7 +204,7 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - blit(InvGuiScale * xPos - 44.0f, InvGuiScale * yPos - 44.0f, 0, 0, 88, 88, 256, 256); + blit(scale * xPos - 44.0f, scale * yPos - 44.0f, 0, 0, 88, 88, 256, 256); glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR); m_pMinecraft->m_pTextures->loadAndBindTexture("gui/feedback_fill.png"); @@ -215,7 +212,7 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) // note: scale starts from 4.0f float halfWidth = (40.0f * breakProgress + 48.0f) / 2.0f; - blit(InvGuiScale * xPos - halfWidth, InvGuiScale * yPos - halfWidth, 0, 0, halfWidth * 2, halfWidth * 2, 256, 256); + blit(scale * xPos - halfWidth, scale * yPos - halfWidth, 0, 0, halfWidth * 2, halfWidth * 2, 256, 256); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glDisable(GL_BLEND); @@ -230,7 +227,7 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) glColor4f(1.0f, 1.0f, 1.0f, Mth::Min(1.0f, m_pMinecraft->m_pInputHolder->m_feedbackAlpha)); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - blit(InvGuiScale * xPos - 44.0f, InvGuiScale * yPos - 44.0f, 0, 0, 88, 88, 256, 256); + blit(scale * xPos - 44.0f, scale * yPos - 44.0f, 0, 0, 88, 88, 256, 256); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glDisable(GL_BLEND); } @@ -245,7 +242,7 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) LocalPlayer* pLP = m_pMinecraft->m_pLocalPlayer; // why?? - m_random.init_genrand(312871 * field_9FC); + m_random.init_genrand(312871 * m_pMinecraft->m_timer.m_ticks); int emptyHeartX = 16; bool b1 = false; @@ -341,9 +338,7 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) slotX += 20; } -#undef DIFF - - field_A3C = false; + //field_A3C = false; // blit the "more items" button if (m->isTouchscreen()) @@ -353,18 +348,18 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY) } // render messages - if (m_bRenderMessages) + if (m_bRenderChatMessages) { - renderMessages(false); + renderChatMessages(false); } } void Gui::tick() { + /* if (field_A18 > 0) field_A18--; - - field_9FC++; + */ for (int i = 0; i < int(m_guiMessages.size()); i++) { @@ -403,8 +398,8 @@ void Gui::renderSlotOverlay(int slot, int x, int y, float f) int Gui::getSlotIdAt(int mouseX, int mouseY) { - int scaledY = int(InvGuiScale * mouseY); - int scaledHeight = int(InvGuiScale * Minecraft::height); + int scaledY = int(scale * mouseY); + int scaledHeight = int(scale * Minecraft::height); if (scaledY >= scaledHeight) return -1; @@ -413,7 +408,7 @@ int Gui::getSlotIdAt(int mouseX, int mouseY) int hotbarOffset = getNumSlots() * 20 / 2 - 2; - int slotX = (int(InvGuiScale * mouseX) - int(InvGuiScale * Minecraft::width) / 2 + hotbarOffset + 20) / 20; + int slotX = (int(scale * mouseX) - int(scale * Minecraft::width) / 2 + hotbarOffset + 20) / 20; if (slotX >= 0) slotX--; @@ -485,10 +480,10 @@ void Gui::handleKeyPressed(int keyCode) } } -void Gui::renderMessages(bool bShowAll) +void Gui::renderChatMessages(bool bShowAll) { - //int width = Minecraft::width * InvGuiScale, - int height = Minecraft::height * InvGuiScale; + //int width = Minecraft::width * scale, + int height = Minecraft::height * scale; int topEdge = height - 49; @@ -537,18 +532,29 @@ int Gui::getNumSlots() return 9; } -int Gui::getNumUsableSlots() +// screens +#include "screens/PauseScreen.hpp" +#include "screens/StartMenuScreen.hpp" +#include "screens/RenameMPLevelScreen.hpp" +#include "screens/SavingWorldScreen.hpp" +#include "screens/DeathScreen.hpp" +IScreen* Gui::screenMain() { - return getNumSlots() - m_pMinecraft->isTouchscreen(); + return new StartMenuScreen(); } - -RectangleArea Gui::getRectangleArea(bool b) +IScreen* Gui::screenDeath() { - float centerX = Minecraft::width / 2; - float hotbarWidthHalf = (10 * getNumSlots() + 5) / InvGuiScale; - return RectangleArea( - b ? (centerX - hotbarWidthHalf) : 0, - Minecraft::height - 24.0f / InvGuiScale, - centerX + hotbarWidthHalf, - Minecraft::height); + return new DeathScreen(); +} +IScreen* Gui::screenPause() +{ + return new PauseScreen(); +} +IScreen* Gui::screenSaveWorld(bool bCopyMap, Entity *pEnt) +{ + return new SavingWorldScreen(bCopyMap, pEnt); +} +IScreen* Gui::screenRenameMPWorld(std::string name) +{ + return new RenameMPLevelScreen(name); } diff --git a/source/client/gui/Gui.hpp b/source/client/gui/Gui.hpp index ddab01f..64d3c60 100644 --- a/source/client/gui/Gui.hpp +++ b/source/client/gui/Gui.hpp @@ -24,47 +24,53 @@ struct GuiMessage GuiMessage(const std::string& x, int a) : msg(x), field_18(a) {} }; -class Gui : public GuiComponent +class Gui : public GuiComponent, public IGui { public: Gui(Minecraft* pMinecraft); + // screens + IScreen* screenMain(); + IScreen* screenDeath(); + IScreen* screenPause(); + IScreen* screenSaveWorld(bool bCopyMap, Entity *pEnt); + IScreen* screenRenameMPWorld(std::string name); + void addMessage(const std::string& str); - void inventoryUpdated(); - void renderVignette(float, int, int); - void setNowPlaying(const std::string& str); - void render(float f, bool bHaveScreen, int mouseX, int mouseY); + void onInventoryUpdated(); void tick(); - void renderSlot(int slot, int x, int y, float f); - void renderSlotOverlay(int slot, int x, int y, float f); - int getSlotIdAt(int mx, int my); + void render(float f, bool bHaveScreen, int mouseX, int mouseY); + bool isInside(int mx, int my); void handleClick(int id, int mx, int my); void handleKeyPressed(int keyCode); - void renderMessages(bool bShowAll); + void renderChatMessages(bool bShowAll); int getNumSlots(); // Gets the number of slots in the inventory. Includes the '...' if in touch mode. - int getNumUsableSlots(); // Gets the number of usable slots in the inventory. Does not include the '...' if in touch mode. - RectangleArea getRectangleArea(bool b); -public: - static float InvGuiScale; + void renderVignette(float a2, int a3, int a4); + void renderSlot(int slot, int x, int y, float f); + void renderSlotOverlay(int slot, int x, int y, float f); + int getSlotIdAt(int mouseX, int mouseY); + std::vector m_guiMessages; + //Minecraft* m_pMinecraft; + Random m_random; + RenderChunk m_renderChunk; + float m_vignetteColor; + // bool field_A3c; // unused + +/* public: float field_8; std::string field_C; - std::vector m_guiMessages; int field_24; int field_28; int field_2C; - Random m_random; - Minecraft* m_pMinecraft; int field_9FC; std::string field_A00; int field_A18; bool field_A1C; - float field_A20; - RenderChunk m_renderChunk; bool field_A3C; - bool m_bRenderMessages; +*/ }; diff --git a/source/client/gui/Screen.cpp b/source/client/gui/Screen.cpp index 4201639..d6ada24 100644 --- a/source/client/gui/Screen.cpp +++ b/source/client/gui/Screen.cpp @@ -8,11 +8,8 @@ #include "Screen.hpp" -Screen::Screen() +Screen::Screen() : IScreen() { - m_width = 1; - m_height = 1; - field_10 = false; m_tabButtonIndex = 0; m_pClickedButton = 0; m_yOffset = -1; @@ -26,47 +23,18 @@ Screen::~Screen() void Screen::init(Minecraft* pMinecraft, int a3, int a4) { - m_width = a3; - m_height = a4; - m_pMinecraft = pMinecraft; m_pFont = pMinecraft->m_pFont; + IScreen::init(pMinecraft, a3, a4); init(); updateTabButtonSelection(); } void Screen::init() { - } void Screen::buttonClicked(Button* pButton) { - -} - -void Screen::confirmResult(bool b, int i) -{ - -} - -bool Screen::handleBackEvent(bool b) -{ - return false; -} - -bool Screen::isPauseScreen() -{ - return true; -} - -bool Screen::isErrorScreen() -{ - return false; -} - -bool Screen::isInGameScreen() -{ - return true; } void Screen::keyPressed(int key) @@ -310,11 +278,6 @@ void Screen::tick() g_panoramaAngle++; } -void Screen::removed() -{ - -} - void Screen::setSize(int width, int height) { m_width = width; @@ -358,7 +321,7 @@ int Screen::getYOffset() if (!pBox->m_bFocused) continue; - int heightLeft = m_height - int(float(keybOffset) * Gui::InvGuiScale); + int heightLeft = m_height - int(float(keybOffset) * m_pMinecraft->m_pGui->scale); // we want to keep the center of the text box in the center of the screen int textCenterY = pBox->m_yPos + pBox->m_height / 2; @@ -379,9 +342,9 @@ int Screen::getYOffset() return offset; } -void Screen::updateEvents() +void Screen::onEvents() { - if (field_10) return; + if (m_bIgnore) return; while (Mouse::next()) mouseEvent(); diff --git a/source/client/gui/Screen.hpp b/source/client/gui/Screen.hpp index 660c28d..a4cddd5 100644 --- a/source/client/gui/Screen.hpp +++ b/source/client/gui/Screen.hpp @@ -8,6 +8,7 @@ #pragma once +#include "client/app/IGui.hpp" #include "client/player/input/Mouse.hpp" #include "client/player/input/Keyboard.hpp" #include "components/Button.hpp" @@ -16,7 +17,7 @@ class Button; class TextInputBox; -class Screen : public GuiComponent +class Screen : public GuiComponent, public IScreen { public: Screen(); @@ -30,19 +31,13 @@ public: virtual void render(int, int, float); virtual void init(); - virtual void updateEvents(); + virtual void onEvents(); virtual void mouseEvent(); virtual void keyboardEvent(); - virtual bool handleBackEvent(bool); virtual void tick(); - virtual void removed(); virtual void renderBackground(int); virtual void renderBackground(); virtual void renderDirtBackground(int); - virtual bool isPauseScreen(); - virtual bool isErrorScreen(); - virtual bool isInGameScreen(); - virtual void confirmResult(bool, int); virtual void buttonClicked(Button*); virtual void mouseClicked(int, int, int); virtual void mouseReleased(int, int, int); @@ -53,10 +48,6 @@ public: virtual void renderMenuBackground(float f); public: - int m_width; - int m_height; - bool field_10; - Minecraft* m_pMinecraft; std::vector m_buttons; std::vector m_buttonTabList; int m_tabButtonIndex; diff --git a/source/client/gui/components/OptionList.cpp b/source/client/gui/components/OptionList.cpp index 59bc8d2..831c0ed 100644 --- a/source/client/gui/components/OptionList.cpp +++ b/source/client/gui/components/OptionList.cpp @@ -242,7 +242,7 @@ void OptionList::renderItem(int index, int x, int y, int height, Tesselator& t) void OptionList::renderBackground(float f) { if (!m_pMinecraft->isLevelGenerated()) - m_pMinecraft->m_pScreen->renderMenuBackground(f); + m_pMinecraft->m_pScreen->renderBackground(); //renderMenuBackground(f); } void OptionList::renderHoleBackground(float a, float b, int c, int d) diff --git a/source/client/gui/components/RolledSelectionList.cpp b/source/client/gui/components/RolledSelectionList.cpp index cac8807..f614d77 100644 --- a/source/client/gui/components/RolledSelectionList.cpp +++ b/source/client/gui/components/RolledSelectionList.cpp @@ -6,6 +6,7 @@ SPDX-License-Identifier: BSD-1-Clause ********************************************************************/ +#include "../Screen.hpp" #include "RolledSelectionList.hpp" static float g_RolledSelectionListUnk, g_RolledSelectionListUnk2; diff --git a/source/client/gui/components/RolledSelectionList.hpp b/source/client/gui/components/RolledSelectionList.hpp index 6d02f78..f2bbdc0 100644 --- a/source/client/gui/components/RolledSelectionList.hpp +++ b/source/client/gui/components/RolledSelectionList.hpp @@ -8,6 +8,7 @@ #pragma once +#include "../Screen.hpp" #include "../GuiComponent.hpp" #include "client/app/Minecraft.hpp" diff --git a/source/client/gui/components/ScrolledSelectionList.cpp b/source/client/gui/components/ScrolledSelectionList.cpp index 3116b41..bdbdf43 100644 --- a/source/client/gui/components/ScrolledSelectionList.cpp +++ b/source/client/gui/components/ScrolledSelectionList.cpp @@ -175,8 +175,8 @@ void ScrolledSelectionList::render(int mouseX, int mouseY, float f) renderHeader(itemX, scrollY, t); // Note, X/Y are the lower left's X/Y coordinates, not the upper left's. - int lowerY = Minecraft::height - int(field_10 / Gui::InvGuiScale); - int upperY = Minecraft::height - int(field_C / Gui::InvGuiScale); + int lowerY = Minecraft::height - int(field_10 / m_pMinecraft->m_pGui->scale); + int upperY = Minecraft::height - int(field_C / m_pMinecraft->m_pGui->scale); glScissor(0, lowerY, Minecraft::width, upperY - lowerY); glEnable(GL_SCISSOR_TEST); diff --git a/source/client/gui/components/ScrolledSelectionList.hpp b/source/client/gui/components/ScrolledSelectionList.hpp index 3c97986..5179b8d 100644 --- a/source/client/gui/components/ScrolledSelectionList.hpp +++ b/source/client/gui/components/ScrolledSelectionList.hpp @@ -8,7 +8,9 @@ #pragma once +#include "../Gui.hpp" #include "../GuiComponent.hpp" +#include "../Screen.hpp" #include "client/app/Minecraft.hpp" #define C_SCROLLED_LIST_ITEM_WIDTH (220) diff --git a/source/client/gui/screens/ChatScreen.cpp b/source/client/gui/screens/ChatScreen.cpp index 9363df8..a163dd4 100644 --- a/source/client/gui/screens/ChatScreen.cpp +++ b/source/client/gui/screens/ChatScreen.cpp @@ -44,7 +44,7 @@ void ChatScreen::init() void ChatScreen::removed() { // Now let them be rendered. - m_pMinecraft->m_gui.m_bRenderMessages = true; + m_pMinecraft->m_pGui->m_bRenderChatMessages = true; } void ChatScreen::render(int mouseX, int mouseY, float f) @@ -52,8 +52,7 @@ void ChatScreen::render(int mouseX, int mouseY, float f) renderBackground(); // override the default behavior of rendering chat messages - m_pMinecraft->m_gui.m_bRenderMessages = false; - m_pMinecraft->m_gui.renderMessages(true); + m_pMinecraft->m_pGui->m_bRenderChatMessages = true; Screen::render(mouseX, mouseY, f); } diff --git a/source/client/gui/screens/IngameBlockSelectionScreen.cpp b/source/client/gui/screens/IngameBlockSelectionScreen.cpp index e5cd004..478f956 100644 --- a/source/client/gui/screens/IngameBlockSelectionScreen.cpp +++ b/source/client/gui/screens/IngameBlockSelectionScreen.cpp @@ -172,14 +172,14 @@ void IngameBlockSelectionScreen::mouseReleased(int x, int y, int type) void IngameBlockSelectionScreen::removed() { - m_pMinecraft->m_gui.inventoryUpdated(); + m_pMinecraft->m_pGui->onInventoryUpdated(); } void IngameBlockSelectionScreen::selectSlotAndClose() { Inventory* pInv = getInventory(); - pInv->selectItem(m_selectedSlot, m_pMinecraft->m_gui.getNumUsableSlots()); + pInv->selectItem(m_selectedSlot, m_pMinecraft->m_pGui->getNumUsableSlots()); m_pMinecraft->m_pSoundEngine->play("random.click"); m_pMinecraft->setScreen(nullptr); diff --git a/source/client/gui/screens/ProgressScreen.cpp b/source/client/gui/screens/ProgressScreen.cpp index 64e3def..f9a25f8 100644 --- a/source/client/gui/screens/ProgressScreen.cpp +++ b/source/client/gui/screens/ProgressScreen.cpp @@ -23,8 +23,8 @@ void ProgressScreen::render(int a, int b, float c) m_pMinecraft->m_pTextures->loadAndBindTexture("gui/background.png"); //! why not use the screen stuff - int x_width = int(Minecraft::width * Gui::InvGuiScale); - int x_height = int(Minecraft::height * Gui::InvGuiScale); + int x_width = int(Minecraft::width * m_pMinecraft->m_pGui->scale); + int x_height = int(Minecraft::height * m_pMinecraft->m_pGui->scale); Tesselator& t = Tesselator::instance; t.begin(); @@ -79,7 +79,7 @@ void ProgressScreen::render(int a, int b, float c) #endif } -void ProgressScreen::updateEvents() +void ProgressScreen::onEvents() { if (m_pMinecraft->isLevelGenerated()) { @@ -87,5 +87,5 @@ void ProgressScreen::updateEvents() return; } - Screen::updateEvents(); + Screen::onEvents(); } diff --git a/source/client/gui/screens/ProgressScreen.hpp b/source/client/gui/screens/ProgressScreen.hpp index a76625c..2febf79 100644 --- a/source/client/gui/screens/ProgressScreen.hpp +++ b/source/client/gui/screens/ProgressScreen.hpp @@ -14,7 +14,7 @@ class ProgressScreen : public Screen { public: void render(int, int, float) override; - void updateEvents() override; + void onEvents() override; bool isInGameScreen() override; }; diff --git a/source/client/gui/screens/SavingWorldScreen.cpp b/source/client/gui/screens/SavingWorldScreen.cpp index bf293fc..f24ca1f 100644 --- a/source/client/gui/screens/SavingWorldScreen.cpp +++ b/source/client/gui/screens/SavingWorldScreen.cpp @@ -23,8 +23,9 @@ void SavingWorldScreen::render(int mouseX, int mouseY, float f) { renderDirtBackground(0); - int x_width = int(Minecraft::width * Gui::InvGuiScale); - int x_height = int(Minecraft::height * Gui::InvGuiScale); + //! why not use the screen stuff + int x_width = int(Minecraft::width * m_pMinecraft->m_pGui->scale); + int x_height = int(Minecraft::height * m_pMinecraft->m_pGui->scale); int yPos = x_height / 2; int width = m_pFont->width("Saving chunks"); diff --git a/source/client/network/ClientSideNetworkHandler.cpp b/source/client/network/ClientSideNetworkHandler.cpp index 58b1473..837b6ef 100644 --- a/source/client/network/ClientSideNetworkHandler.cpp +++ b/source/client/network/ClientSideNetworkHandler.cpp @@ -9,7 +9,6 @@ #include #include "ClientSideNetworkHandler.hpp" #include "common/Utils.hpp" -#include "client/gui/screens/StartMenuScreen.hpp" // This lets you make the client shut up and not log events in the debug console. #define VERBOSE_CLIENT @@ -65,7 +64,7 @@ void ClientSideNetworkHandler::onUnableToConnect() } // throw to the start menu for now - m_pMinecraft->setScreen(new StartMenuScreen); + m_pMinecraft->m_pGui->screenMain(); } void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& rakGuid) @@ -75,14 +74,14 @@ void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& rakGuid) if (m_pLevel) m_pLevel->m_bIsMultiplayer = false; - m_pMinecraft->m_gui.addMessage("Disconnected from server"); + m_pMinecraft->m_pGui->addMessage("Disconnected from server"); } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, MessagePacket* pMsgPkt) { puts_ignorable("MessagePacket"); - m_pMinecraft->m_gui.addMessage(pMsgPkt->m_str.C_String()); + m_pMinecraft->m_pGui->addMessage(pMsgPkt->m_str.C_String()); } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, StartGamePacket* pStartGamePkt) @@ -141,7 +140,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, AddPlay pPlayer->m_pInventory->prepareCreativeInventory(); - m_pMinecraft->m_gui.addMessage(pPlayer->m_name + " joined the game"); + m_pMinecraft->m_pGui->addMessage(pPlayer->m_name + " joined the game"); } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& rakGuid, RemoveEntityPacket* pRemoveEntityPkt) diff --git a/source/client/player/LocalPlayer.cpp b/source/client/player/LocalPlayer.cpp index 0163ce7..b34a589 100644 --- a/source/client/player/LocalPlayer.cpp +++ b/source/client/player/LocalPlayer.cpp @@ -8,6 +8,7 @@ #include "LocalPlayer.hpp" #include "client/app/Minecraft.hpp" +#include "input/Keyboard.hpp" int dword_250ADC, dword_250AE0; diff --git a/source/client/player/input/TouchInputHolder.cpp b/source/client/player/input/TouchInputHolder.cpp index 6decfcc..13a80d1 100644 --- a/source/client/player/input/TouchInputHolder.cpp +++ b/source/client/player/input/TouchInputHolder.cpp @@ -58,6 +58,6 @@ void TouchInputHolder::setScreenSize(int width, int height) { m_touchScreenInput.setScreenSize(width, height); m_unifiedTurnBuild.field_40 = m_touchScreenInput.getRectangleArea(); - m_unifiedTurnBuild.field_58 = m_pMinecraft->m_gui.getRectangleArea(false); + m_unifiedTurnBuild.field_58 = getRectangleArea(m_pMinecraft->m_pGui, false); m_unifiedTurnBuild.setScreenSize(width, height); } diff --git a/source/client/player/input/TouchInputHolder.hpp b/source/client/player/input/TouchInputHolder.hpp index 36ba494..551ccd4 100644 --- a/source/client/player/input/TouchInputHolder.hpp +++ b/source/client/player/input/TouchInputHolder.hpp @@ -8,6 +8,7 @@ #pragma once +#include "client/app/Minecraft.hpp" #include "IInputHolder.hpp" #include "TouchscreenInput_TestFps.hpp" #include "UnifiedTurnBuild.hpp" @@ -15,6 +16,17 @@ class Minecraft; class Options; +static inline RectangleArea getRectangleArea(IGui *gui, bool b) +{ + float centerX = Minecraft::width / 2; + float hotbarWidthHalf = (10 * gui->getNumSlots() + 5) / gui->scale; + return RectangleArea( + b ? (centerX - hotbarWidthHalf) : 0, + Minecraft::height - 24.0f / gui->scale, + centerX + hotbarWidthHalf, + Minecraft::height); +} + class TouchInputHolder : public IInputHolder { public: diff --git a/source/client/player/input/TouchscreenInput_TestFps.cpp b/source/client/player/input/TouchscreenInput_TestFps.cpp index 6eb6420..bc6aa8e 100644 --- a/source/client/player/input/TouchscreenInput_TestFps.cpp +++ b/source/client/player/input/TouchscreenInput_TestFps.cpp @@ -221,7 +221,7 @@ void TouchscreenInput_TestFps::tick(Player* pPlayer) } } -static void RenderTouchButton(Tesselator* t, PolygonArea* pArea, int srcX, int srcY) +static void RenderTouchButton(Tesselator* t, PolygonArea* pArea, int srcX, int srcY, float scale) { float tc[8]; @@ -237,8 +237,8 @@ static void RenderTouchButton(Tesselator* t, PolygonArea* pArea, int srcX, int s for (int i = 0; i < pArea->m_count; i++) { t->vertexUV( - Gui::InvGuiScale * pArea->m_xPos[i], - Gui::InvGuiScale * pArea->m_yPos[i], + scale * pArea->m_xPos[i], + scale * pArea->m_yPos[i], 0.0f, tc[(2 * i) % 8], tc[(2 * i + 1) % 8] @@ -253,24 +253,25 @@ void TouchscreenInput_TestFps::render(float f) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); m_pMinecraft->m_pTextures->loadAndBindTexture("gui/gui.png"); + float scale = m_pMinecraft->m_pGui->scale; Tesselator& t = Tesselator::instance; t.begin(); t.color(isButtonDown(100 + INPUT_LEFT) ? 0xC0C0C0 : 0xFFFFFF, 0x80); - RenderTouchButton(&t, m_pAreaLeft, 64, 112); + RenderTouchButton(&t, m_pAreaLeft, 64, 112, scale); t.color(isButtonDown(100 + INPUT_RIGHT) ? 0xC0C0C0 : 0xFFFFFF, 0x80); - RenderTouchButton(&t, m_pAreaRight, 192, 112); + RenderTouchButton(&t, m_pAreaRight, 192, 112, scale); t.color(isButtonDown(100 + INPUT_FORWARD) ? 0xC0C0C0 : 0xFFFFFF, 0x80); - RenderTouchButton(&t, m_pAreaForward, 0, 112); + RenderTouchButton(&t, m_pAreaForward, 0, 112, scale); t.color(isButtonDown(100 + INPUT_BACKWARD) ? 0xC0C0C0 : 0xFFFFFF, 0x80); - RenderTouchButton(&t, m_pAreaBackward, 128, 112); + RenderTouchButton(&t, m_pAreaBackward, 128, 112, scale); t.color(isButtonDown(100 + INPUT_JUMP) ? 0xC0C0C0 : 0xFFFFFF, 0x80); - RenderTouchButton(&t, m_pAreaJump, 0, 176); + RenderTouchButton(&t, m_pAreaJump, 0, 176, scale); t.draw(); diff --git a/source/client/renderer/GameRenderer.cpp b/source/client/renderer/GameRenderer.cpp index 8f614ab..ceebc62 100644 --- a/source/client/renderer/GameRenderer.cpp +++ b/source/client/renderer/GameRenderer.cpp @@ -214,8 +214,8 @@ void GameRenderer::saveMatrices() void GameRenderer::setupGuiScreen() { - float x = Gui::InvGuiScale * Minecraft::width; - float y = Gui::InvGuiScale * Minecraft::height; + float x = m_pMinecraft->m_pGui->scale * Minecraft::width; + float y = m_pMinecraft->m_pGui->scale * Minecraft::height; glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -612,8 +612,8 @@ void GameRenderer::render(float f) pMC->m_pLocalPlayer->turn(diff_field_84 * field_7C, diff_field_84 * multPitch * field_80); } - int mouseX = int(Mouse::getX() * Gui::InvGuiScale); - int mouseY = int(Mouse::getY() * Gui::InvGuiScale); + int mouseX = int(Mouse::getX() * m_pMinecraft->m_pGui->scale); + int mouseY = int(Mouse::getY() * m_pMinecraft->m_pGui->scale); if (m_pMinecraft->isTouchscreen()) { @@ -625,8 +625,8 @@ void GameRenderer::render(float f) } else { - mouseX = int(float(Multitouch::getX(pointerId)) * Gui::InvGuiScale); - mouseY = int(float(Multitouch::getY(pointerId)) * Gui::InvGuiScale); + mouseX = int(float(Multitouch::getX(pointerId)) * m_pMinecraft->m_pGui->scale); + mouseY = int(float(Multitouch::getY(pointerId)) * m_pMinecraft->m_pGui->scale); } } @@ -641,7 +641,7 @@ void GameRenderer::render(float f) return; } - m_pMinecraft->m_gui.render(f, m_pMinecraft->m_pScreen != nullptr, mouseX, mouseY); + m_pMinecraft->m_pGui->render(f, m_pMinecraft->m_pScreen != nullptr, mouseX, mouseY); } } else diff --git a/source/network/ServerSideNetworkHandler.cpp b/source/network/ServerSideNetworkHandler.cpp index 6fe7d5a..35cf920 100644 --- a/source/network/ServerSideNetworkHandler.cpp +++ b/source/network/ServerSideNetworkHandler.cpp @@ -122,7 +122,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LoginPacke sgp.m_version = 2; sgp.m_time = m_pLevel->getTime(); - RakNet::BitStream *sgpbs; + RakNet::BitStream *sgpbs = nullptr; sgp.write(sgpbs); m_pRakNetPeer->Send(sgpbs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, guid, false); @@ -143,7 +143,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& guid, LoginPacke else pPlayer->m_pInventory->prepareSurvivalInventory(); - m_pMinecraft->m_gui.addMessage(pPlayer->m_name + " joined the game"); + m_pMinecraft->m_pGui->addMessage(pPlayer->m_name + " joined the game"); AddPlayerPacket app(guid, RakNet::RakString(pPlayer->m_name.c_str()), pPlayer->m_EntityID, pPlayer->m_pos.x, pPlayer->m_pos.y - pPlayer->field_84, pPlayer->m_pos.z); RakNet::BitStream appbs; @@ -360,7 +360,7 @@ void ServerSideNetworkHandler::allowIncomingConnections(bool b) void ServerSideNetworkHandler::displayGameMessage(const std::string& msg) { - m_pMinecraft->m_gui.addMessage(msg); + m_pMinecraft->m_pGui->addMessage(msg); m_pRakNetInstance->send(new MessagePacket(msg)); } @@ -368,7 +368,7 @@ void ServerSideNetworkHandler::sendMessage(const RakNet::RakNetGUID& guid, const { if (m_pRakNetPeer->GetMyGUID() == guid) { - m_pMinecraft->m_gui.addMessage(msg); + m_pMinecraft->m_pGui->addMessage(msg); return; } diff --git a/source/world/gamemode/CreativeMode.cpp b/source/world/gamemode/CreativeMode.cpp index e350192..934db4b 100644 --- a/source/world/gamemode/CreativeMode.cpp +++ b/source/world/gamemode/CreativeMode.cpp @@ -133,13 +133,13 @@ void CreativeMode::render(float f) { if (m_destroyProgress <= 0.0f) { - m_pMinecraft->m_gui.field_8 = 0.0f; + m_pMinecraft->m_breakProgress= 0.0f; m_pMinecraft->m_pLevelRenderer->field_10 = 0.0f; } else { float x = m_lastDestroyProgress + (m_destroyProgress - m_lastDestroyProgress) * f; - m_pMinecraft->m_gui.field_8 = x; + m_pMinecraft->m_breakProgress = x; m_pMinecraft->m_pLevelRenderer->field_10 = x; } } diff --git a/source/world/gamemode/SurvivalMode.cpp b/source/world/gamemode/SurvivalMode.cpp index 18318d1..a7a3161 100644 --- a/source/world/gamemode/SurvivalMode.cpp +++ b/source/world/gamemode/SurvivalMode.cpp @@ -135,13 +135,13 @@ void SurvivalMode::render(float f) { if (m_destroyProgress <= 0.0f) { - m_pMinecraft->m_gui.field_8 = 0.0f; + m_pMinecraft->m_breakProgress = 0.0f; m_pMinecraft->m_pLevelRenderer->field_10 = 0.0f; } else { float x = m_lastDestroyProgress + (m_destroyProgress - m_lastDestroyProgress) * f; - m_pMinecraft->m_gui.field_8 = x; + m_pMinecraft->m_breakProgress = x; m_pMinecraft->m_pLevelRenderer->field_10 = x; } }