diff --git a/.gitignore b/.gitignore index b5bf872..926e18e 100644 --- a/.gitignore +++ b/.gitignore @@ -382,4 +382,4 @@ FodyWeavers.xsd /wasm -/assets/ +/assets/ \ No newline at end of file diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index d12fe12..87688a6 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -56,6 +56,7 @@ add_library(reminecraftpe-core STATIC client/gui/screens/OptionsScreen.cpp client/gui/screens/StartMenuScreen.cpp client/gui/screens/CreateWorldScreen.cpp + client/gui/screens/DirectConnectScreen.cpp client/gui/screens/SelectWorldScreen.cpp client/gui/screens/SavingWorldScreen.cpp client/gui/screens/InvalidLicenseScreen.cpp diff --git a/source/client/gui/components/Button.cpp b/source/client/gui/components/Button.cpp index 2de604a..52eee6d 100644 --- a/source/client/gui/components/Button.cpp +++ b/source/client/gui/components/Button.cpp @@ -8,30 +8,30 @@ #include "Button.hpp" -Button::Button(int a2, int xPos, int yPos, int btnWidth, int btnHeight, const std::string& text) +Button::Button(int buttonId, int xPos, int yPos, int btnWidth, int btnHeight, const std::string& text) { - field_30 = a2; + m_buttonId = buttonId; m_xPos = xPos; m_yPos = yPos; - field_18 = text; + m_text = text; m_width = btnWidth; m_height = btnHeight; } -Button::Button(int a2, int xPos, int yPos, const std::string& text) +Button::Button(int buttonId, int xPos, int yPos, const std::string& text) { - field_30 = a2; + m_buttonId = buttonId; m_xPos = xPos; m_yPos = yPos; - field_18 = text; + m_text = text; m_width = 200; m_height = 24; } -Button::Button(int a2, const std::string& text) +Button::Button(int buttonId, const std::string& text) { - field_30 = a2; - field_18 = text; + m_buttonId = buttonId; + m_text = text; m_width = 200; m_height = 24; } @@ -93,5 +93,5 @@ void Button::render(Minecraft* pMinecraft, int xPos, int yPos) else textColor = int(0xE0E0E0U); - drawCenteredString(pFont, field_18, m_xPos + m_width / 2, m_yPos + (m_height - 8) / 2, textColor); + drawCenteredString(pFont, m_text, m_xPos + m_width / 2, m_yPos + (m_height - 8) / 2, textColor); } diff --git a/source/client/gui/components/Button.hpp b/source/client/gui/components/Button.hpp index e57fa02..d812046 100644 --- a/source/client/gui/components/Button.hpp +++ b/source/client/gui/components/Button.hpp @@ -32,8 +32,8 @@ public: int m_height = 0; int m_xPos = 0; int m_yPos = 0; - std::string field_18 = ""; - int field_30; + std::string m_text = ""; + int m_buttonId; bool m_bEnabled = true; bool m_bVisible = true; bool field_36 = false; diff --git a/source/client/gui/components/TextInputBox.cpp b/source/client/gui/components/TextInputBox.cpp index dcf6506..457918a 100644 --- a/source/client/gui/components/TextInputBox.cpp +++ b/source/client/gui/components/TextInputBox.cpp @@ -262,13 +262,13 @@ void TextInputBox::render() int textYPos = (m_height - 8) / 2; if (m_text.empty()) - drawString(m_pFont, m_placeholder, m_xPos + 2, m_yPos + 2, 0x404040); + drawString(m_pFont, m_placeholder, m_xPos + 5, m_yPos + textYPos, 0x404040); else - drawString(m_pFont, m_text, m_xPos + 2, m_yPos + textYPos, 0xFFFFFF); + drawString(m_pFont, m_text, m_xPos + 5, m_yPos + textYPos, 0xFFFFFF); if (m_bCursorOn) { - int xPos = 2; + int xPos = 5; std::string substr = m_text.substr(0, m_insertHead); xPos += m_pFont->width(substr); diff --git a/source/client/gui/screens/ConfirmScreen.cpp b/source/client/gui/screens/ConfirmScreen.cpp index 34bb612..1daa3a5 100644 --- a/source/client/gui/screens/ConfirmScreen.cpp +++ b/source/client/gui/screens/ConfirmScreen.cpp @@ -32,7 +32,7 @@ ConfirmScreen::ConfirmScreen(Screen* pScreen, const std::string& line1, const st void ConfirmScreen::buttonClicked(Button* pButton) { - postResult(pButton->field_30 == 0); + postResult(pButton->buttonId == 0); } bool ConfirmScreen::handleBackEvent(bool b) diff --git a/source/client/gui/screens/CreateWorldScreen.cpp b/source/client/gui/screens/CreateWorldScreen.cpp index dbedeca..c531d28 100644 --- a/source/client/gui/screens/CreateWorldScreen.cpp +++ b/source/client/gui/screens/CreateWorldScreen.cpp @@ -68,12 +68,12 @@ static std::string GetUniqueLevelName(LevelStorageSource* pSource, const std::st void CreateWorldScreen::buttonClicked(Button* pButton) { - if (pButton->field_30 == m_btnBack.field_30) + if (pButton->buttonId == m_btnBack.buttonId) { m_pMinecraft->setScreen(new SelectWorldScreen); } - if (pButton->field_30 == m_btnCreate.field_30) + if (pButton->buttonId == m_btnCreate.buttonId) { std::string nameStr = m_textName.m_text; std::string seedStr = m_textSeed.m_text; diff --git a/source/client/gui/screens/DirectConnectScreen.cpp b/source/client/gui/screens/DirectConnectScreen.cpp new file mode 100644 index 0000000..a3c91cd --- /dev/null +++ b/source/client/gui/screens/DirectConnectScreen.cpp @@ -0,0 +1,83 @@ +/******************************************************************** + 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 "DirectConnectScreen.hpp" +#include "ProgressScreen.hpp" +#include "JoinGameScreen.hpp" +#include "client/common/Util.hpp" + +DirectConnectScreen::DirectConnectScreen() : + m_textAddress(1, 0, 0, 0, 0, "Server address"), + m_btnJoin(2, "Join Game"), + m_btnQuit(3, "Cancel") +{} + +void DirectConnectScreen::init() +{ + const int CONTAINER_PADDING = 5; + const int BUTTON_CONTAINER_PADDING = 5; + const int BUTTON_CONTAINER_WIDTH = 200; + + m_textAddress.m_width = 200; + m_textAddress.m_height = 20; + + m_btnJoin.m_width = (BUTTON_CONTAINER_WIDTH / 2) - (BUTTON_CONTAINER_PADDING / 2); + m_btnJoin.m_height = 20; + + m_btnQuit.m_width = (BUTTON_CONTAINER_WIDTH / 2) - (BUTTON_CONTAINER_PADDING / 2); + m_btnQuit.m_height = 20; + + m_textAddress.m_xPos = (m_width / 2) - (m_textAddress.m_width / 2); + m_textAddress.m_yPos = (m_height / 2) - m_btnJoin.m_height - CONTAINER_PADDING; + + m_btnJoin.m_xPos = (m_width / 2) - (m_btnJoin.m_width) - (BUTTON_CONTAINER_PADDING / 2); + m_btnJoin.m_yPos = (m_height / 2) + CONTAINER_PADDING + m_textAddress.m_height; + + m_btnQuit.m_xPos = (m_width / 2) + (BUTTON_CONTAINER_PADDING / 2); + m_btnQuit.m_yPos = (m_height / 2) + CONTAINER_PADDING + m_textAddress.m_height; + + m_textInputs.push_back(&m_textAddress); + m_buttons.push_back(&m_btnQuit); + m_buttons.push_back(&m_btnJoin); + + m_textAddress.init(m_pFont); +} + +void DirectConnectScreen::render(int x, int y, float f) +{ + renderBackground(); + Screen::render(x, y, f); + + drawCenteredString(m_pFont, "Direct Connect", m_width / 2, 30, 0xFFFFFF); + drawString(m_pFont, "Server address", m_textAddress.m_xPos, m_textAddress.m_yPos - 10, 0xDDDDDD); +} + +void DirectConnectScreen::buttonClicked(Button* pButton) +{ + if (pButton->buttonId == m_btnJoin.buttonId) + { + if (!m_textAddress.m_text.empty()) + { + PingedCompatibleServer newPgs; + RakNet::SystemAddress sysAddress; + + sysAddress.FromString(m_textAddress.m_text.c_str()); + newPgs.m_address = sysAddress; + + m_pMinecraft->joinMultiplayer(newPgs); + m_pMinecraft->setScreen(new ProgressScreen); + + m_btnJoin.m_bEnabled = false; + m_textAddress.m_bEnabled = false; + } + } + else if (pButton->buttonId == m_btnQuit.buttonId) + { + m_pMinecraft->setScreen(new JoinGameScreen); + } +} diff --git a/source/client/gui/screens/DirectConnectScreen.hpp b/source/client/gui/screens/DirectConnectScreen.hpp new file mode 100644 index 0000000..b237b71 --- /dev/null +++ b/source/client/gui/screens/DirectConnectScreen.hpp @@ -0,0 +1,26 @@ +/******************************************************************** + 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 DirectConnectScreen : public Screen +{ +public: + DirectConnectScreen(); + + virtual void init() override; + virtual void buttonClicked(Button* pButton) override; + virtual void render(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/InvalidLicenseScreen.cpp b/source/client/gui/screens/InvalidLicenseScreen.cpp index 365713f..d71d4c1 100644 --- a/source/client/gui/screens/InvalidLicenseScreen.cpp +++ b/source/client/gui/screens/InvalidLicenseScreen.cpp @@ -20,12 +20,12 @@ InvalidLicenseScreen::InvalidLicenseScreen(int error, bool bHasQuitButton) : void InvalidLicenseScreen::buttonClicked(Button* pButton) { - if (pButton->field_30 == m_btnOk.field_30) + if (pButton->buttonId == m_btnOk.buttonId) { m_pMinecraft->quit(); } - if (pButton->field_30 == m_btnBuy.field_30) + if (pButton->buttonId == m_btnBuy.buttonId) { m_pMinecraft->platform()->buyGame(); } diff --git a/source/client/gui/screens/JoinGameScreen.cpp b/source/client/gui/screens/JoinGameScreen.cpp index a979bd3..79a5b90 100644 --- a/source/client/gui/screens/JoinGameScreen.cpp +++ b/source/client/gui/screens/JoinGameScreen.cpp @@ -7,12 +7,14 @@ ********************************************************************/ #include "JoinGameScreen.hpp" +#include "DirectConnectScreen.hpp" #include "ProgressScreen.hpp" #include "StartMenuScreen.hpp" JoinGameScreen::JoinGameScreen() : m_btnJoin(2, "Join Game"), - m_btnBack(3, "Back") + m_btnDirectConnect(3, "Direct Connect"), + m_btnBack(4, "Back") { } @@ -24,7 +26,7 @@ JoinGameScreen::~JoinGameScreen() void JoinGameScreen::buttonClicked(Button* pButton) { - if (pButton->field_30 == m_btnJoin.field_30) + if (pButton->buttonId == m_btnJoin.buttonId) { if (isIndexValid(m_pAvailableGamesList->m_selectedIndex)) { @@ -32,11 +34,17 @@ void JoinGameScreen::buttonClicked(Button* pButton) m_pMinecraft->setScreen(new ProgressScreen); m_btnJoin.m_bEnabled = false; + m_btnDirectConnect.m_bEnabled = false; m_btnBack.m_bEnabled = false; } } - if (pButton->field_30 == m_btnBack.field_30) + if (pButton->buttonId == m_btnDirectConnect.buttonId) + { + m_pMinecraft->setScreen(new DirectConnectScreen); + } + + if (pButton->buttonId == m_btnBack.buttonId) { m_pMinecraft->setScreen(new StartMenuScreen); } @@ -55,13 +63,19 @@ bool JoinGameScreen::handleBackEvent(bool b) void JoinGameScreen::init() { - m_btnBack.m_yPos = m_btnJoin.m_yPos = m_height - 26; - m_btnBack.m_width = m_btnJoin.m_width = 120; + const int BUTTON_WIDTH = 120; - m_btnJoin.m_xPos = m_width / 2 - 124; - m_btnBack.m_xPos = m_width / 2 + 4; + m_btnBack.m_yPos = m_btnJoin.m_yPos = m_btnDirectConnect.m_yPos = m_height - 27; + m_btnBack.m_width = m_btnJoin.m_width = BUTTON_WIDTH; + + m_btnJoin.m_xPos = m_width / 2 - (BUTTON_WIDTH + (BUTTON_WIDTH / 2)) - 4; + m_btnDirectConnect.m_xPos = (m_width / 2) - (BUTTON_WIDTH / 2); + m_btnBack.m_xPos = m_width / 2 + 4 + (BUTTON_WIDTH / 2); + + m_btnDirectConnect.m_width = 120; m_buttons.push_back(&m_btnJoin); + m_buttons.push_back(&m_btnDirectConnect); m_buttons.push_back(&m_btnBack); m_pMinecraft->m_pRakNetInstance->clearServerList(); @@ -69,6 +83,7 @@ void JoinGameScreen::init() m_pAvailableGamesList = new AvailableGamesList(m_pMinecraft, m_width, m_height, 24, m_height - 30, 28); m_buttonTabList.push_back(&m_btnJoin); + m_buttonTabList.push_back(&m_btnDirectConnect); m_buttonTabList.push_back(&m_btnBack); } diff --git a/source/client/gui/screens/JoinGameScreen.hpp b/source/client/gui/screens/JoinGameScreen.hpp index 6342bc5..9c7ee97 100644 --- a/source/client/gui/screens/JoinGameScreen.hpp +++ b/source/client/gui/screens/JoinGameScreen.hpp @@ -27,6 +27,7 @@ public: public: Button m_btnJoin; + Button m_btnDirectConnect; Button m_btnBack; AvailableGamesList* m_pAvailableGamesList = nullptr; }; diff --git a/source/client/gui/screens/OptionsScreen.cpp b/source/client/gui/screens/OptionsScreen.cpp index 6d31406..3775efe 100644 --- a/source/client/gui/screens/OptionsScreen.cpp +++ b/source/client/gui/screens/OptionsScreen.cpp @@ -161,7 +161,7 @@ void OptionsScreen::buttonClicked(Button* pButton) Options& o = m_pMinecraft->m_options; bool* pOption = nullptr; - switch (pButton->field_30) + switch (pButton->buttonId) { case OB_BACK: if (m_pMinecraft->isLevelGenerated()) diff --git a/source/client/gui/screens/PauseScreen.cpp b/source/client/gui/screens/PauseScreen.cpp index 9fc49e4..d4ea1c5 100644 --- a/source/client/gui/screens/PauseScreen.cpp +++ b/source/client/gui/screens/PauseScreen.cpp @@ -100,16 +100,16 @@ void PauseScreen::render(int a, int b, float c) void PauseScreen::buttonClicked(Button* pButton) { - if (pButton->field_30 == m_btnBack.field_30) + if (pButton->buttonId == m_btnBack.buttonId) m_pMinecraft->setScreen(nullptr); - if (pButton->field_30 == m_btnQuit.field_30) + if (pButton->buttonId == m_btnQuit.buttonId) m_pMinecraft->leaveGame(false); - if (pButton->field_30 == m_btnQuitAndCopy.field_30) + if (pButton->buttonId == m_btnQuitAndCopy.buttonId) m_pMinecraft->leaveGame(true); - if (pButton->field_30 == m_btnVisible.field_30) + if (pButton->buttonId == m_btnVisible.buttonId) { if (m_pMinecraft->m_pRakNetInstance && m_pMinecraft->m_pRakNetInstance->m_bIsHost) { @@ -121,7 +121,7 @@ void PauseScreen::buttonClicked(Button* pButton) } #ifdef ENH_ADD_OPTIONS_PAUSE - if (pButton->field_30 == m_btnOptions.field_30) + if (pButton->buttonId == m_btnOptions.buttonId) m_pMinecraft->setScreen(new OptionsScreen); #endif } diff --git a/source/client/gui/screens/SelectWorldScreen.cpp b/source/client/gui/screens/SelectWorldScreen.cpp index 708ca18..c97937a 100644 --- a/source/client/gui/screens/SelectWorldScreen.cpp +++ b/source/client/gui/screens/SelectWorldScreen.cpp @@ -188,7 +188,7 @@ bool SelectWorldScreen::handleBackEvent(bool b) void SelectWorldScreen::buttonClicked(Button* pButton) { - if (pButton->field_30 == m_btnCreateNew.field_30) + if (pButton->buttonId == m_btnCreateNew.buttonId) { #ifndef ORIGINAL_CODE m_pMinecraft->setScreen(new CreateWorldScreen); @@ -199,19 +199,19 @@ void SelectWorldScreen::buttonClicked(Button* pButton) #endif } - if (pButton->field_30 == m_btnDelete.field_30) + if (pButton->buttonId == m_btnDelete.buttonId) { LevelSummary ls(m_pWorldSelectionList->m_items[m_pWorldSelectionList->m_selectedIndex]); m_pMinecraft->setScreen(new DeleteWorldScreen(ls)); } - if (pButton->field_30 == m_btnBack.field_30) + if (pButton->buttonId == m_btnBack.buttonId) { // @TODO: m_pMinecraft->cancelLocateMultiplayer(); m_pMinecraft->setScreen(new StartMenuScreen); } - if (pButton->field_30 == m_btnUnknown.field_30) + if (pButton->buttonId == m_btnUnknown.buttonId) { m_pWorldSelectionList->selectItem(m_pWorldSelectionList->getItemAtPosition(m_width / 2, m_height / 2), false); } diff --git a/source/client/gui/screens/StartMenuScreen.cpp b/source/client/gui/screens/StartMenuScreen.cpp index 2b46f76..6643af6 100644 --- a/source/client/gui/screens/StartMenuScreen.cpp +++ b/source/client/gui/screens/StartMenuScreen.cpp @@ -54,7 +54,7 @@ void StartMenuScreen::_updateLicense() void StartMenuScreen::buttonClicked(Button* pButton) { - if (pButton->field_30 == m_startButton.field_30) + if (pButton->buttonId == m_startButton.buttonId) { #if defined(DEMO) m_pMinecraft->selectLevel("_DemoLevel", "_DemoLevel", int(getEpochTimeS())); @@ -64,12 +64,12 @@ void StartMenuScreen::buttonClicked(Button* pButton) m_pMinecraft->setScreen(new SelectWorldScreen); #endif } - else if (pButton->field_30 == m_joinButton.field_30) + else if (pButton->buttonId == m_joinButton.buttonId) { m_pMinecraft->locateMultiplayer(); m_pMinecraft->setScreen(new JoinGameScreen); } - else if (pButton->field_30 == m_buyButton.field_30) + else if (pButton->buttonId == m_buyButton.buttonId) { #if !defined(DEMO) && defined(CAN_QUIT) m_pMinecraft->quit(); @@ -77,7 +77,7 @@ void StartMenuScreen::buttonClicked(Button* pButton) m_pMinecraft->platform()->buyGame(); #endif } - else if (pButton->field_30 == m_optionsButton.field_30) + else if (pButton->buttonId == m_optionsButton.buttonId) { m_pMinecraft->setScreen(new OptionsScreen); } diff --git a/windows_vs/minecraftcpp.vcxproj b/windows_vs/minecraftcpp.vcxproj index d48dbcd..d2732b4 100644 --- a/windows_vs/minecraftcpp.vcxproj +++ b/windows_vs/minecraftcpp.vcxproj @@ -61,6 +61,7 @@ + @@ -360,6 +361,7 @@ + diff --git a/windows_vs/minecraftcpp.vcxproj.filters b/windows_vs/minecraftcpp.vcxproj.filters index 8a2c1ce..9d9c778 100644 --- a/windows_vs/minecraftcpp.vcxproj.filters +++ b/windows_vs/minecraftcpp.vcxproj.filters @@ -660,6 +660,9 @@ source\client\gui\screens + + source\client\gui\screens + source\client\gui\screens @@ -1415,6 +1418,9 @@ source\client\gui\screens + + source\client\gui\screens + source\client\gui\screens