mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-19 22:43:32 +00:00
Join by ip screen
This commit is contained in:
@@ -55,7 +55,6 @@
|
||||
#include "player/input/XperiaPlayInput.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "player/input/MouseTurnInput.h"
|
||||
#include "../world/entity/MobFactory.h"
|
||||
#include "../world/level/MobSpawner.h"
|
||||
@@ -1288,6 +1287,30 @@ bool Minecraft::joinMultiplayer( const PingedCompatibleServer& server )
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Minecraft::joinMultiplayerFromString( const std::string& server )
|
||||
{
|
||||
std::string ip = "";
|
||||
std::string port = "19132";
|
||||
|
||||
size_t pos = server.find(":");
|
||||
|
||||
if (pos != std::string::npos) {
|
||||
ip = server.substr(0, pos);
|
||||
port = server.substr(pos + 1);
|
||||
} else {
|
||||
ip = server;
|
||||
}
|
||||
|
||||
printf("%s \n", port.c_str());
|
||||
|
||||
if (isLookingForMultiplayer && netCallback) {
|
||||
isLookingForMultiplayer = false;
|
||||
printf("test");
|
||||
return raknetInstance->connect(ip.c_str(), std::stoi(port));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Minecraft::hostMultiplayer(int port) {
|
||||
// Tear down last instance
|
||||
raknetInstance->disconnect();
|
||||
@@ -1455,6 +1478,12 @@ LevelStorageSource* Minecraft::getLevelSource()
|
||||
return storageSource;
|
||||
}
|
||||
|
||||
// int Minecraft::getLicenseId() {
|
||||
// if (!LicenseCodes::isReady(_licenseId))
|
||||
// _licenseId = platform()->checkLicense();
|
||||
// return _licenseId;
|
||||
// }
|
||||
|
||||
void Minecraft::audioEngineOn() {
|
||||
#ifndef STANDALONE_SERVER
|
||||
soundEngine->enable(true);
|
||||
|
||||
@@ -80,6 +80,7 @@ public:
|
||||
void locateMultiplayer();
|
||||
void cancelLocateMultiplayer();
|
||||
bool joinMultiplayer(const PingedCompatibleServer& server);
|
||||
bool joinMultiplayerFromString(const std::string& server);
|
||||
void hostMultiplayer(int port=19132);
|
||||
Player* respawnPlayer(int playerId);
|
||||
void respawnPlayer();
|
||||
|
||||
140
src/client/gui/screens/JoinByIPScreen.cpp
Normal file
140
src/client/gui/screens/JoinByIPScreen.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
#include "JoinByIPScreen.h"
|
||||
|
||||
#include "JoinGameScreen.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "ProgressScreen.h"
|
||||
#include "../Font.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
#include "client/gui/components/TextBox.h"
|
||||
#include "network/ClientSideNetworkHandler.h"
|
||||
|
||||
JoinByIPScreen::JoinByIPScreen() :
|
||||
tIP(0, "Server IP"),
|
||||
bHeader(1, "Join on server"),
|
||||
bJoin( 2, "Join Game"),
|
||||
bBack( 3, "")
|
||||
{
|
||||
bJoin.active = false;
|
||||
//gamesList->yInertia = 0.5f;
|
||||
}
|
||||
|
||||
JoinByIPScreen::~JoinByIPScreen()
|
||||
{
|
||||
}
|
||||
|
||||
void JoinByIPScreen::buttonClicked(Button* button)
|
||||
{
|
||||
if (button->id == bJoin.id)
|
||||
{
|
||||
minecraft->isLookingForMultiplayer = true;
|
||||
minecraft->netCallback = new ClientSideNetworkHandler(minecraft, minecraft->raknetInstance);
|
||||
|
||||
minecraft->joinMultiplayerFromString(tIP.text);
|
||||
{
|
||||
|
||||
bJoin.active = false;
|
||||
bBack.active = false;
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
}
|
||||
}
|
||||
if (button->id == bBack.id)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
}
|
||||
|
||||
bool JoinByIPScreen::handleBackEvent(bool isDown)
|
||||
{
|
||||
if (!isDown)
|
||||
{
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void JoinByIPScreen::tick()
|
||||
{
|
||||
bJoin.active = !tIP.text.empty();
|
||||
}
|
||||
|
||||
void JoinByIPScreen::init()
|
||||
{
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
bBack.setImageDef(def, true);
|
||||
|
||||
buttons.push_back(&bJoin);
|
||||
buttons.push_back(&bBack);
|
||||
buttons.push_back(&bHeader);
|
||||
|
||||
textBoxes.push_back(&tIP);
|
||||
#ifdef ANDROID
|
||||
tabButtons.push_back(&bJoin);
|
||||
tabButtons.push_back(&bBack);
|
||||
tabButtons.push_back(&bHeader);
|
||||
#endif
|
||||
}
|
||||
|
||||
void JoinByIPScreen::setupPositions() {
|
||||
int tIpDiff = 40;
|
||||
|
||||
bJoin.y = height * 2 / 3;
|
||||
bBack.y = 0;
|
||||
bHeader.y = 0;
|
||||
|
||||
// Center buttons
|
||||
//bJoin.x = width / 2 - 4 - bJoin.w;
|
||||
bBack.x = width - bBack.width;//width / 2 + 4;
|
||||
|
||||
bJoin.x = (width - bJoin.width) / 2;
|
||||
|
||||
bHeader.x = 0;
|
||||
bHeader.width = width - bBack.width;
|
||||
|
||||
tIP.width = bJoin.width + tIpDiff;
|
||||
tIP.height = 16;
|
||||
tIP.x = bJoin.x - tIpDiff / 2;
|
||||
tIP.y = ((height - bJoin.height) / 2) - tIP.height - 4;
|
||||
}
|
||||
|
||||
void JoinByIPScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
int lvlTop = tIP.y - (Font::DefaultLineHeight + 4);
|
||||
int lvlBottom = tIP.y + tIP.height;
|
||||
int lvlLeft = tIP.x;
|
||||
int lvlRight = tIP.x + tIP.width;
|
||||
bool clickedIP = x >= lvlLeft && x < lvlRight && y >= lvlTop && y < lvlBottom;
|
||||
|
||||
if (clickedIP) {
|
||||
tIP.setFocus(minecraft);
|
||||
} else {
|
||||
tIP.loseFocus(minecraft);
|
||||
}
|
||||
|
||||
Screen::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
void JoinByIPScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
renderBackground();
|
||||
Screen::render(xm, ym, a);
|
||||
}
|
||||
|
||||
void JoinByIPScreen::keyPressed(int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard::KEY_ESCAPE) {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
return;
|
||||
}
|
||||
// let base class handle navigation and text box keys
|
||||
Screen::keyPressed(eventKey);
|
||||
}
|
||||
|
||||
void JoinByIPScreen::keyboardNewChar(char inputChar)
|
||||
{
|
||||
// forward character input to focused textbox(s)
|
||||
for (auto* tb : textBoxes) tb->handleChar(inputChar);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "client/gui/components/ImageButton.h"
|
||||
#include "client/gui/components/TextBox.h"
|
||||
|
||||
class JoinByIPScreen: public Screen
|
||||
{
|
||||
public:
|
||||
JoinByIPScreen();
|
||||
virtual ~JoinByIPScreen();
|
||||
|
||||
void init();
|
||||
void setupPositions();
|
||||
|
||||
virtual void tick();
|
||||
void render(int xm, int ym, float a);
|
||||
|
||||
virtual void keyPressed(int eventKey);
|
||||
virtual void keyboardNewChar(char inputChar);
|
||||
void buttonClicked(Button* button);
|
||||
virtual void mouseClicked(int x, int y, int buttonNum);
|
||||
virtual bool handleBackEvent(bool isDown);
|
||||
private:
|
||||
TextBox tIP;
|
||||
Touch::THeader bHeader;
|
||||
Touch::TButton bJoin;
|
||||
ImageButton bBack;
|
||||
};
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "PauseScreen.h"
|
||||
#include "RenameMPLevelScreen.h"
|
||||
#include "IngameBlockSelectionScreen.h"
|
||||
#include "JoinByIPScreen.h"
|
||||
#include "touch/TouchStartMenuScreen.h"
|
||||
#include "touch/TouchSelectWorldScreen.h"
|
||||
#include "touch/TouchJoinGameScreen.h"
|
||||
@@ -18,13 +19,13 @@ Screen* ScreenChooser::createScreen( ScreenId id )
|
||||
|
||||
if (_mc->useTouchscreen()) {
|
||||
switch (id) {
|
||||
case SCREEN_STARTMENU: screen = new Touch::StartMenuScreen(); break;
|
||||
case SCREEN_SELECTWORLD:screen = new Touch::SelectWorldScreen();break;
|
||||
case SCREEN_JOINGAME: screen = new Touch::JoinGameScreen(); break;
|
||||
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
|
||||
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
|
||||
case SCREEN_BLOCKSELECTION: screen = new Touch::IngameBlockSelectionScreen(); break;
|
||||
|
||||
case SCREEN_STARTMENU: screen = new Touch::StartMenuScreen(); break;
|
||||
case SCREEN_SELECTWORLD: screen = new Touch::SelectWorldScreen();break;
|
||||
case SCREEN_JOINGAME: screen = new Touch::JoinGameScreen(); break;
|
||||
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
|
||||
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
|
||||
case SCREEN_BLOCKSELECTION: screen = new Touch::IngameBlockSelectionScreen(); break;
|
||||
case SCREEN_JOINBYIP: screen = new JoinByIPScreen(); break;
|
||||
case SCREEN_NONE:
|
||||
default:
|
||||
// Do nothing
|
||||
@@ -32,12 +33,13 @@ Screen* ScreenChooser::createScreen( ScreenId id )
|
||||
}
|
||||
} else {
|
||||
switch (id) {
|
||||
case SCREEN_STARTMENU: screen = new StartMenuScreen(); break;
|
||||
case SCREEN_SELECTWORLD:screen = new SelectWorldScreen();break;
|
||||
case SCREEN_JOINGAME: screen = new JoinGameScreen(); break;
|
||||
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
|
||||
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
|
||||
case SCREEN_BLOCKSELECTION: screen = new IngameBlockSelectionScreen(); break;
|
||||
case SCREEN_STARTMENU: screen = new StartMenuScreen(); break;
|
||||
case SCREEN_SELECTWORLD: screen = new SelectWorldScreen();break;
|
||||
case SCREEN_JOINGAME: screen = new JoinGameScreen(); break;
|
||||
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
|
||||
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
|
||||
case SCREEN_BLOCKSELECTION: screen = new IngameBlockSelectionScreen(); break;
|
||||
case SCREEN_JOINBYIP: screen = new JoinByIPScreen(); break;
|
||||
|
||||
case SCREEN_NONE:
|
||||
default:
|
||||
|
||||
@@ -8,7 +8,8 @@ enum ScreenId {
|
||||
SCREEN_PAUSE,
|
||||
SCREEN_PAUSEPREV,
|
||||
SCREEN_SELECTWORLD,
|
||||
SCREEN_BLOCKSELECTION
|
||||
SCREEN_BLOCKSELECTION,
|
||||
SCREEN_JOINBYIP
|
||||
};
|
||||
|
||||
class Screen;
|
||||
|
||||
@@ -129,6 +129,11 @@ void JoinGameScreen::buttonClicked(Button* button)
|
||||
//minecraft->locateMultiplayer();
|
||||
//minecraft->setScreen(new JoinGameScreen());
|
||||
}
|
||||
if(button->id == bJoinByIp.id) {
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_JOINBYIP);
|
||||
}
|
||||
|
||||
if (button->id == bBack.id)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
|
||||
Reference in New Issue
Block a user