Files
mcpe/source/client/gui/Screen.cpp
Brent a0f71c7b27 C++03 Support & Partial Xbox 360 Support (#37)
* WIP C++03 + Xbox 360 Support

* math.h & _USE_MATH_DEFINES on Level.hpp
Updated Xenon vcxproj file for new file structure.

* * Fix bad GUI scale setup.

* * Gui: Use ratios instead of hardcoded sub-1 floating point values, to make the mechanism more clear.

* Add Direct Connect Button and Screen (#30)

* Add Direct Connect Button and Screen

* Remove accidental extra build directories for wasm

* Add DirectConnectScreen.cpp to the CMake

* Use Hungarian coding style notation

* * Fix errors caused by #30

* * Improve the Chat Screen

* * Improve the DirectConnectScreen, among other things.

* * Update the game title once again.

* * Add build-wasm.bat.

* * Add info about compiling for wasm

* * Fix send to specific GUID actually broadcasting to everyone

* * Add command manager.

* * Add writeable configuration.

* * Allow dynamic screen size change on windows

* * Allow the same thing on the emscripten version.

* WIP C++03 + Xbox 360 Support

* Fixed a possible merging issue that broke RakNet?

* Additional Xbox 360 compatability fixes

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
Co-authored-by: iProgramInCpp <iprogramincpp@gmail.com>
Co-authored-by: ts <124226059+uniformization@users.noreply.github.com>
2023-08-07 15:48:52 +03:00

275 lines
5.2 KiB
C++

/********************************************************************
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"
Screen::Screen()
{
m_width = 1;
m_height = 1;
field_10 = false;
m_tabButtonIndex = 0;
m_pClickedButton = 0;
}
Screen::~Screen()
{
m_pClickedButton = nullptr;
m_buttons.clear();
}
void Screen::init(Minecraft* pMinecraft, int a3, int a4)
{
m_width = a3;
m_height = a4;
m_pMinecraft = pMinecraft;
m_pFont = pMinecraft->m_pFont;
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)
{
if (key == AKEYCODE_MENU)//escape
{
m_pMinecraft->setScreen(nullptr);
}
if (m_buttonTabList.size())
{
#ifndef ENH_HIGHLIGHT_BY_HOVER
if (m_pMinecraft->m_options.m_keyBinds[Options::MENU_NEXT].value == key)
{
m_tabButtonIndex++;
if (m_tabButtonIndex == int(m_buttonTabList.size()))
m_tabButtonIndex = 0;
}
if (m_pMinecraft->m_options.m_keyBinds[Options::MENU_PREVIOUS].value == key)
{
m_tabButtonIndex--;
if (m_tabButtonIndex == -1)
m_tabButtonIndex = int(m_buttonTabList.size() - 1);
}
if (m_pMinecraft->m_options.m_keyBinds[Options::MENU_OK].value == key)
{
if (m_buttonTabList[m_tabButtonIndex]->m_bEnabled)
{
m_pMinecraft->m_pSoundEngine->play("random.click");
buttonClicked(m_buttonTabList[m_tabButtonIndex]);
}
}
updateTabButtonSelection();
#endif
}
for (auto textInput : m_textInputs)
{
textInput->keyPressed(m_pMinecraft, key);
}
}
void Screen::charInput(char chr)
{
for (auto textInput : m_textInputs)
textInput->charPressed(chr);
}
void Screen::mouseClicked(int xPos, int yPos, int d) // d = clicked?
{
if (!d) return;
for (auto button : m_buttons)
{
if (button->clicked(m_pMinecraft, xPos, yPos))
{
m_pClickedButton = button;
m_pMinecraft->m_pSoundEngine->play("random.click");
buttonClicked(button);
}
}
#ifndef ORIGINAL_CODE
for (auto textInput : m_textInputs)
{
textInput->onClick(xPos, yPos);
}
#endif
}
void Screen::mouseReleased(int xPos, int yPos, int d)
{
if (!d) return;
if (m_pClickedButton)
{
m_pClickedButton->released(xPos, yPos);
m_pClickedButton = nullptr;
}
}
void Screen::render(int xPos, int yPos, float unused)
{
for (auto button : m_buttons)
{
button->render(m_pMinecraft, xPos, yPos);
}
#ifndef ORIGINAL_CODE
for (auto textInput : m_textInputs)
{
textInput->tick();
textInput->render();
}
#endif
}
void Screen::tick()
{
}
void Screen::removed()
{
}
void Screen::setSize(int width, int height)
{
m_width = width;
m_height = height;
// not original code. Will need to re-init again
m_buttons.clear();
m_textInputs.clear();
init();
}
void Screen::updateEvents()
{
if (field_10) return;
for (int i = Mouse::_index + 1; i<int(Mouse::_inputs.size()); i++)
{
Mouse::_index = i;
mouseEvent();
}
for (int i = Keyboard::_index + 1; i<int(Keyboard::_inputs.size()); i++)
{
Keyboard::_index = i;
keyboardEvent();
}
}
void Screen::keyboardEvent()
{
// @UB: This probably behaves in an unexpected way if _inputs is empty
#ifndef ORIGINAL_CODE
if (Keyboard::_inputs.empty() || Keyboard::_index < 0)
return;
#endif
if (Keyboard::_inputs[Keyboard::_index].field_0)
keyPressed(Keyboard::_inputs[Keyboard::_index].field_4);
}
void Screen::mouseEvent()
{
MouseInput& inp = Mouse::_inputs[Mouse::_index];
if (1 <= inp.field_0 && inp.field_0 <= 2)
{
if (inp.field_4 == 1)
mouseClicked(m_width * Mouse::_x / Minecraft::width, m_height * Mouse::_y / Minecraft::height - 1, inp.field_0);
else
mouseReleased(m_width * Mouse::_x / Minecraft::width, m_height * Mouse::_y / Minecraft::height - 1, inp.field_0);
}
}
void Screen::renderBackground(int unk)
{
if (m_pMinecraft->isLevelGenerated())
{
fillGradient(0, 0, m_width, m_height, 0xC0101010, 0xD0101010);
}
else
{
renderDirtBackground(unk);
}
}
void Screen::renderBackground()
{
renderBackground(0);
}
void Screen::renderDirtBackground(int unk)
{
glDisable(GL_FOG);
m_pMinecraft->m_pTextures->loadAndBindTexture("gui/background.png");
glColor4f(1, 1, 1, 1);
Tesselator& t = Tesselator::instance;
t.begin();
t.color(0x404040);
t.vertexUV(0.0f, float(m_height), 0, 0, float(unk) + float(m_height) / 32.0f);
t.vertexUV(float(m_width), float(m_height), 0, float(unk) + float(m_width) / 32.0f, float(unk) + float(m_height) / 32.0f);
t.vertexUV(float(m_width), 0, 0, float(unk) + float(m_width) / 32.0f, 0);
t.vertexUV(0.0f, 0, 0, 0, 0);
t.draw();
}
void Screen::updateTabButtonSelection()
{
#ifndef ENH_HIGHLIGHT_BY_HOVER
for (int i = 0; i < int(m_buttonTabList.size()); i++)
{
m_buttonTabList[i]->field_36 = m_tabButtonIndex == i;
}
#endif
}