* Fix errors caused by #30

This commit is contained in:
iProgramInCpp
2023-08-06 12:59:46 +03:00
parent 9e9d2110e3
commit 2b105fe1eb
14 changed files with 137 additions and 90 deletions

View File

@@ -8,12 +8,11 @@
#pragma once
#ifndef ORIGINAL_CODE
#ifdef _WIN32
#define NOMINMAX
#include "Utils.hpp"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
enum
{
@@ -55,11 +54,13 @@ enum
AKEYCODE_APOSTROPHE = VK_OEM_7, // ''"'
AKEYCODE_SPACE = VK_SPACE,
AKEYCODE_1 = '1',
AKEYCODE_0 = '0',
AKEYCODE_1 = '1',
//...
AKEYCODE_9 = '9',
AKEYCODE_ENTER = VK_RETURN,
// note: You have to add these here instead of using the
// characters themselves, otherwise android won't pick it up
AKEYCODE_A = 'A',
@@ -125,7 +126,8 @@ enum
AKEYCODE_Z,
AKEYCODE_F4,
AKEYCODE_ARROW_LEFT,
AKEYCODE_ARROW_RIGHT
AKEYCODE_ARROW_RIGHT,
AKEYCODE_ENTER,
};
static inline int translate_sdl_key_to_mcpe(int key) {
@@ -173,15 +175,12 @@ static inline int translate_sdl_key_to_mcpe(int key) {
case SDLK_F4: return AKEYCODE_F4;
case SDLK_LEFT: return AKEYCODE_ARROW_LEFT;
case SDLK_RIGHT: return AKEYCODE_ARROW_RIGHT;
case SDLK_RETURN: return AKEYCODE_ENTER;
default: return AKEYCODE_UNKNOWN;
}
}
#else
#error "Add AKEYCODEs for your platform!"
#endif
#else
#elif defined(PLATFORM_ANDROID)
enum
{
@@ -481,4 +480,8 @@ enum
#define AKEYCODE_ARROW_LEFT AKEYCODE_DPAD_LEFT
#define AKEYCODE_ARROW_RIGHT AKEYCODE_DPAD_RIGHT
#else
#error "Provide key codes for your platform!"
#endif

View File

@@ -259,38 +259,10 @@ void Gui::render(float f, bool bHaveScreen, int mouseX, int mouseY)
#endif
// render messages
int topEdge = height - 49;
for (auto& msg : m_guiMessages)
if (m_bRenderMessages)
{
if (msg.field_18 > 199)
continue;
int bkgdColor = 0x7F000000, textColor = 0xFFFFFFFF;
float fade = 10.0f * (1.0f - (float(msg.field_18) / 200.0f));
if (fade <= 0.0f)
continue;
if (fade < 1.0f)
{
int x = int(fade * fade * 255.0f);
if (x == 0)
continue;
bkgdColor = (x / 2) << 24;
textColor = (x << 24) + 0xFFFFFF;
}
fill(2, topEdge, 322, topEdge + 9, bkgdColor);
glEnable(GL_BLEND);
m->m_pFont->drawShadow(msg.msg, 2, topEdge + 1, textColor);
topEdge -= 9;
renderMessages(false);
}
glDisable(GL_BLEND);
}
void Gui::tick()
@@ -414,3 +386,41 @@ void Gui::handleKeyPressed(int keyCode)
}
}
}
void Gui::renderMessages(bool bShowAll)
{
int width = Minecraft::width * InvGuiScale,
height = Minecraft::height * InvGuiScale;
int topEdge = height - 49;
for (auto& msg : m_guiMessages)
{
if (!bShowAll && msg.field_18 > 199)
continue;
int bkgdColor = 0x7F000000, textColor = 0xFFFFFFFF;
float fade = 10.0f * (1.0f - (float(msg.field_18) / 200.0f));
if (fade <= 0.0f)
continue;
if (fade < 1.0f)
{
int x = int(fade * fade * 255.0f);
if (x == 0)
continue;
bkgdColor = (x / 2) << 24;
textColor = (x << 24) + 0xFFFFFF;
}
fill(2, topEdge, 322, topEdge + 9, bkgdColor);
glEnable(GL_BLEND);
m_pMinecraft->m_pFont->drawShadow(msg.msg, 2, topEdge + 1, textColor);
topEdge -= 9;
}
glDisable(GL_BLEND);
}

View File

@@ -40,6 +40,7 @@ public:
bool isInside(int mx, int my);
void handleClick(int id, int mx, int my);
void handleKeyPressed(int keyCode);
void renderMessages(bool bShowAll);
public:
static float InvGuiScale;
@@ -60,5 +61,6 @@ public:
float field_A20 = 1.0f;
RenderChunk m_renderChunk;
bool field_A3C = true;
bool m_bRenderMessages = true;
};

View File

@@ -10,31 +10,54 @@
// @NOTE: This is unused.
ChatScreen::ChatScreen() : m_textChat(1, 0, 0), m_btnSend(2, 0, 0, "Send")
{
}
void ChatScreen::buttonClicked(Button* pButton)
{
if (pButton->m_buttonId == m_btnSend.m_buttonId)
sendMessageAndExit();
}
void ChatScreen::init()
{
m_pMinecraft->platform()->showDialog(AppPlatform::DLG_CHAT);
m_pMinecraft->platform()->createUserInput();
m_textChat.m_xPos = 0;
m_textChat.m_yPos = m_height - 20;
m_textChat.m_width = m_width - 60;
m_textChat.m_height = 20;
m_btnSend.m_height = 20;
m_btnSend.m_width = 60;
m_btnSend.m_yPos = m_textChat.m_yPos;
m_btnSend.m_xPos = m_textChat.m_xPos + m_textChat.m_width;
}
void ChatScreen::removed()
{
// Now let them be rendered.
m_pMinecraft->m_gui.m_bRenderMessages = true;
}
void ChatScreen::render(int mouseX, int mouseY, float f)
{
int userInputStatus = m_pMinecraft->platform()->getUserInputStatus();
if (userInputStatus < 0)
return;
renderBackground();
if (userInputStatus == 1)
{
std::vector<std::string> userInput = m_pMinecraft->platform()->getUserInput();
if (userInput.size() >= 1)
{
// @NOTE: No sending multiplayer chats. Weird
m_pMinecraft->m_gui.addMessage(userInput[0]);
}
}
// override the default behavior of rendering chat messages
m_pMinecraft->m_gui.m_bRenderMessages = false;
m_pMinecraft->m_gui.renderMessages(true);
Screen::render(mouseX, mouseY, f);
}
void ChatScreen::keyPressed(int keyCode)
{
if (keyCode == AKEYCODE_ENTER)
sendMessageAndExit();
}
void ChatScreen::sendMessageAndExit()
{
m_pMinecraft->m_gui.addMessage(m_textChat.m_text);
m_pMinecraft->setScreen(nullptr);
}

View File

@@ -13,8 +13,17 @@
class ChatScreen : public Screen
{
public:
ChatScreen();
void buttonClicked(Button*) override;
void init() override;
void removed() override;
void render(int mouseX, int mouseY, float f) override;
void keyPressed(int keyCode) override;
void sendMessageAndExit();
private:
TextInputBox m_textChat;
Button m_btnSend;
};

View File

@@ -32,7 +32,7 @@ ConfirmScreen::ConfirmScreen(Screen* pScreen, const std::string& line1, const st
void ConfirmScreen::buttonClicked(Button* pButton)
{
postResult(pButton->buttonId == 0);
postResult(pButton->m_buttonId == 0);
}
bool ConfirmScreen::handleBackEvent(bool b)

View File

@@ -68,12 +68,12 @@ static std::string GetUniqueLevelName(LevelStorageSource* pSource, const std::st
void CreateWorldScreen::buttonClicked(Button* pButton)
{
if (pButton->buttonId == m_btnBack.buttonId)
if (pButton->m_buttonId == m_btnBack.m_buttonId)
{
m_pMinecraft->setScreen(new SelectWorldScreen);
}
if (pButton->buttonId == m_btnCreate.buttonId)
if (pButton->m_buttonId == m_btnCreate.m_buttonId)
{
std::string nameStr = m_textName.m_text;
std::string seedStr = m_textSeed.m_text;

View File

@@ -59,7 +59,7 @@ void DirectConnectScreen::render(int x, int y, float f)
void DirectConnectScreen::buttonClicked(Button* pButton)
{
if (pButton->buttonId == m_btnJoin.buttonId)
if (pButton->m_buttonId == m_btnJoin.m_buttonId)
{
if (!m_textAddress.m_text.empty())
{
@@ -76,7 +76,7 @@ void DirectConnectScreen::buttonClicked(Button* pButton)
m_textAddress.m_bEnabled = false;
}
}
else if (pButton->buttonId == m_btnQuit.buttonId)
else if (pButton->m_buttonId == m_btnQuit.m_buttonId)
{
m_pMinecraft->setScreen(new JoinGameScreen);
}

View File

@@ -15,17 +15,17 @@ InvalidLicenseScreen::InvalidLicenseScreen(int error, bool bHasQuitButton) :
m_bHasQuitButton(bHasQuitButton)
{
if (bHasQuitButton)
m_btnOk.field_18 = "Quit";
m_btnOk.m_text = "Quit";
}
void InvalidLicenseScreen::buttonClicked(Button* pButton)
{
if (pButton->buttonId == m_btnOk.buttonId)
if (pButton->m_buttonId == m_btnOk.m_buttonId)
{
m_pMinecraft->quit();
}
if (pButton->buttonId == m_btnBuy.buttonId)
if (pButton->m_buttonId == m_btnBuy.m_buttonId)
{
m_pMinecraft->platform()->buyGame();
}

View File

@@ -26,7 +26,7 @@ JoinGameScreen::~JoinGameScreen()
void JoinGameScreen::buttonClicked(Button* pButton)
{
if (pButton->buttonId == m_btnJoin.buttonId)
if (pButton->m_buttonId == m_btnJoin.m_buttonId)
{
if (isIndexValid(m_pAvailableGamesList->m_selectedIndex))
{
@@ -39,12 +39,12 @@ void JoinGameScreen::buttonClicked(Button* pButton)
}
}
if (pButton->buttonId == m_btnDirectConnect.buttonId)
if (pButton->m_buttonId == m_btnDirectConnect.m_buttonId)
{
m_pMinecraft->setScreen(new DirectConnectScreen);
}
if (pButton->buttonId == m_btnBack.buttonId)
if (pButton->m_buttonId == m_btnBack.m_buttonId)
{
m_pMinecraft->setScreen(new StartMenuScreen);
}

View File

@@ -65,14 +65,14 @@ void OptionsScreen::UpdateTexts()
{
Options& o = m_pMinecraft->m_options;
m_AOButton.field_18 = "Smooth lighting: " + BoolOptionStr(o.field_18);
m_invertYButton.field_18 = "Invert Y-axis: " + BoolOptionStr(o.m_bInvertMouse);
m_viewBobButton.field_18 = "View bobbing: " + BoolOptionStr(o.field_14);
m_anaglyphsButton.field_18 = "3d Anaglyphs: " + BoolOptionStr(o.m_bAnaglyphs);
m_fancyGfxButton.field_18 = "Fancy graphics: " + BoolOptionStr(o.m_bFancyGraphics);
m_flightHaxButton.field_18 = "Flight hax: " + BoolOptionStr(o.m_bFlyCheat);
m_viewDistButton.field_18 = "View distance: " + ViewDistanceStr(o.field_10);
m_srvVisButton.field_18 = "Server " + std::string(o.m_bServerVisibleDefault ? "visible" : "invisible") + " by default";
m_AOButton.m_text = "Smooth lighting: " + BoolOptionStr(o.field_18);
m_invertYButton.m_text = "Invert Y-axis: " + BoolOptionStr(o.m_bInvertMouse);
m_viewBobButton.m_text = "View bobbing: " + BoolOptionStr(o.field_14);
m_anaglyphsButton.m_text = "3d Anaglyphs: " + BoolOptionStr(o.m_bAnaglyphs);
m_fancyGfxButton.m_text = "Fancy graphics: " + BoolOptionStr(o.m_bFancyGraphics);
m_flightHaxButton.m_text = "Flight hax: " + BoolOptionStr(o.m_bFlyCheat);
m_viewDistButton.m_text = "View distance: " + ViewDistanceStr(o.field_10);
m_srvVisButton.m_text = "Server " + std::string(o.m_bServerVisibleDefault ? "visible" : "invisible") + " by default";
}
#endif
@@ -161,7 +161,7 @@ void OptionsScreen::buttonClicked(Button* pButton)
Options& o = m_pMinecraft->m_options;
bool* pOption = nullptr;
switch (pButton->buttonId)
switch (pButton->m_buttonId)
{
case OB_BACK:
if (m_pMinecraft->isLevelGenerated())

View File

@@ -80,9 +80,9 @@ void PauseScreen::updateServerVisibilityText()
ServerSideNetworkHandler* pSSNH = (ServerSideNetworkHandler*)m_pMinecraft->m_pNetEventCallback;
if (pSSNH->m_bAllowIncoming)
m_btnVisible.field_18 = "Server is visible";
m_btnVisible.m_text = "Server is visible";
else
m_btnVisible.field_18 = "Server is invisible";
m_btnVisible.m_text = "Server is invisible";
}
void PauseScreen::tick()
@@ -100,16 +100,16 @@ void PauseScreen::render(int a, int b, float c)
void PauseScreen::buttonClicked(Button* pButton)
{
if (pButton->buttonId == m_btnBack.buttonId)
if (pButton->m_buttonId == m_btnBack.m_buttonId)
m_pMinecraft->setScreen(nullptr);
if (pButton->buttonId == m_btnQuit.buttonId)
if (pButton->m_buttonId == m_btnQuit.m_buttonId)
m_pMinecraft->leaveGame(false);
if (pButton->buttonId == m_btnQuitAndCopy.buttonId)
if (pButton->m_buttonId == m_btnQuitAndCopy.m_buttonId)
m_pMinecraft->leaveGame(true);
if (pButton->buttonId == m_btnVisible.buttonId)
if (pButton->m_buttonId == m_btnVisible.m_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->buttonId == m_btnOptions.buttonId)
if (pButton->m_buttonId == m_btnOptions.m_buttonId)
m_pMinecraft->setScreen(new OptionsScreen);
#endif
}

View File

@@ -188,7 +188,7 @@ bool SelectWorldScreen::handleBackEvent(bool b)
void SelectWorldScreen::buttonClicked(Button* pButton)
{
if (pButton->buttonId == m_btnCreateNew.buttonId)
if (pButton->m_buttonId == m_btnCreateNew.m_buttonId)
{
#ifndef ORIGINAL_CODE
m_pMinecraft->setScreen(new CreateWorldScreen);
@@ -199,19 +199,19 @@ void SelectWorldScreen::buttonClicked(Button* pButton)
#endif
}
if (pButton->buttonId == m_btnDelete.buttonId)
if (pButton->m_buttonId == m_btnDelete.m_buttonId)
{
LevelSummary ls(m_pWorldSelectionList->m_items[m_pWorldSelectionList->m_selectedIndex]);
m_pMinecraft->setScreen(new DeleteWorldScreen(ls));
}
if (pButton->buttonId == m_btnBack.buttonId)
if (pButton->m_buttonId == m_btnBack.m_buttonId)
{
// @TODO: m_pMinecraft->cancelLocateMultiplayer();
m_pMinecraft->setScreen(new StartMenuScreen);
}
if (pButton->buttonId == m_btnUnknown.buttonId)
if (pButton->m_buttonId == m_btnUnknown.m_buttonId)
{
m_pWorldSelectionList->selectItem(m_pWorldSelectionList->getItemAtPosition(m_width / 2, m_height / 2), false);
}

View File

@@ -54,7 +54,7 @@ void StartMenuScreen::_updateLicense()
void StartMenuScreen::buttonClicked(Button* pButton)
{
if (pButton->buttonId == m_startButton.buttonId)
if (pButton->m_buttonId == m_startButton.m_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->buttonId == m_joinButton.buttonId)
else if (pButton->m_buttonId == m_joinButton.m_buttonId)
{
m_pMinecraft->locateMultiplayer();
m_pMinecraft->setScreen(new JoinGameScreen);
}
else if (pButton->buttonId == m_buyButton.buttonId)
else if (pButton->m_buttonId == m_buyButton.m_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->buttonId == m_optionsButton.buttonId)
else if (pButton->m_buttonId == m_optionsButton.m_buttonId)
{
m_pMinecraft->setScreen(new OptionsScreen);
}
@@ -130,7 +130,7 @@ void StartMenuScreen::init()
field_188 = (m_width - m_pFont->width(field_170)) / 2;
#if !defined(DEMO) && defined(CAN_QUIT)
m_buyButton.field_18 = "Quit";
m_buyButton.m_text = "Quit";
#endif
//m_testBox.init(m_pFont);