mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-17 20:10:23 +03:00
* Improve the DirectConnectScreen, among other things.
This commit is contained in:
@@ -13,33 +13,29 @@
|
||||
|
||||
DirectConnectScreen::DirectConnectScreen() :
|
||||
m_textAddress(1, 0, 0, 0, 0, "Server address"),
|
||||
m_btnJoin(2, "Join Game"),
|
||||
m_btnJoin(2, "Connect"),
|
||||
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_width = 200;
|
||||
m_btnJoin.m_height = 20;
|
||||
|
||||
m_btnQuit.m_width = (BUTTON_CONTAINER_WIDTH / 2) - (BUTTON_CONTAINER_PADDING / 2);
|
||||
m_btnQuit.m_width = 200;
|
||||
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_textAddress.m_yPos = m_height / 2 - 20;
|
||||
|
||||
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_btnJoin.m_xPos = (m_width / 2) - (m_btnJoin.m_width / 2);
|
||||
m_btnJoin.m_yPos = m_height - 55;
|
||||
|
||||
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_btnQuit.m_xPos = (m_width / 2) - (m_btnQuit.m_width / 2);
|
||||
m_btnQuit.m_yPos = m_height - 30;
|
||||
|
||||
m_textInputs.push_back(&m_textAddress);
|
||||
m_buttons.push_back(&m_btnQuit);
|
||||
@@ -53,28 +49,33 @@ 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);
|
||||
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);
|
||||
}
|
||||
|
||||
void DirectConnectScreen::buttonClicked(Button* pButton)
|
||||
{
|
||||
if (pButton->m_buttonId == m_btnJoin.m_buttonId)
|
||||
{
|
||||
if (!m_textAddress.m_text.empty())
|
||||
{
|
||||
PingedCompatibleServer newPgs;
|
||||
RakNet::SystemAddress sysAddress;
|
||||
if (m_textAddress.m_text.empty())
|
||||
return;
|
||||
|
||||
sysAddress.FromString(m_textAddress.m_text.c_str());
|
||||
newPgs.m_address = sysAddress;
|
||||
PingedCompatibleServer newPgs;
|
||||
RakNet::SystemAddress sysAddress;
|
||||
|
||||
m_pMinecraft->joinMultiplayer(newPgs);
|
||||
m_pMinecraft->setScreen(new ProgressScreen);
|
||||
if (!sysAddress.FromString(m_textAddress.m_text.c_str()))
|
||||
return;
|
||||
|
||||
m_btnJoin.m_bEnabled = false;
|
||||
m_textAddress.m_bEnabled = false;
|
||||
}
|
||||
if (sysAddress.GetPort() == 0)
|
||||
sysAddress.SetPortHostOrder(C_DEFAULT_PORT);
|
||||
|
||||
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->m_buttonId == m_btnQuit.m_buttonId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user