diff --git a/JGE/src/pc/JSocket.cpp b/JGE/src/pc/JSocket.cpp index adcaffaf4..eccc5f616 100644 --- a/JGE/src/pc/JSocket.cpp +++ b/JGE/src/pc/JSocket.cpp @@ -28,7 +28,7 @@ JSocket::JSocket(string ipAddr) mfd(-1) { int result; - struct hostent *hostentptr; + struct hostent *hostentptr = 0; #ifdef WIN32 SOCKADDR_IN Adresse_Socket_Server; WORD wVersionRequested; diff --git a/projects/mtg/include/GameApp.h b/projects/mtg/include/GameApp.h index b0bc158ef..7c0c996d7 100644 --- a/projects/mtg/include/GameApp.h +++ b/projects/mtg/include/GameApp.h @@ -51,6 +51,7 @@ public: Rules * rules; CardEffect *effect; #ifdef NETWORK_SUPPORT + string mServerAddress; JNetwork* mpNetwork; #endif //NETWORK_SUPPORT diff --git a/projects/mtg/include/SimplePad.h b/projects/mtg/include/SimplePad.h index 42edf26eb..e7fae34b7 100644 --- a/projects/mtg/include/SimplePad.h +++ b/projects/mtg/include/SimplePad.h @@ -13,7 +13,7 @@ enum SIMPLE_KEYS{ KPD_S, KPD_T, KPD_U, KPD_V, KPD_W, KPD_X, KPD_Y, KPD_Z, KPD_SPACE, KPD_OK, KPD_CANCEL, KPD_DEL, KPD_CAPS, KPD_0, KPD_1, KPD_2, KPD_3, - KPD_4, KPD_5, KPD_6, KPD_7, KPD_8, KPD_9, + KPD_4, KPD_5, KPD_6, KPD_7, KPD_8, KPD_9, KPD_DOT, KPD_MAX, KPD_NOWHERE = 254, KPD_INPUT = 255, diff --git a/projects/mtg/src/GameApp.cpp b/projects/mtg/src/GameApp.cpp index 674b36898..53a2406b0 100644 --- a/projects/mtg/src/GameApp.cpp +++ b/projects/mtg/src/GameApp.cpp @@ -52,6 +52,7 @@ GameApp::GameApp() : JApp() #ifdef NETWORK_SUPPORT ,mpNetwork(NULL) + , mServerAddress("") #endif //NETWORK_SUPPORT { #ifdef DEBUG diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index f9e6d1b3a..528cd5ea3 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -455,6 +455,35 @@ void GameStateMenu::ensureMGuiController() void GameStateMenu::Update(float dt) { +#ifdef NETWORK_SUPPORT + if (options.keypadActive()) + { + options.keypadUpdate(dt); + + if (mParent->mServerAddress != "") + { + mParent->mServerAddress = options.keypadFinish(); + + if (mParent->mServerAddress != "") + { + mParent->mpNetwork = new JNetwork(); + + mParent->mpNetwork->connect(mParent->mServerAddress); + // we let the server choose the game mode + mParent->gameType = GAME_TYPE_SLAVE; + // just to select one, the HOST is in control here. + mParent->rules = Rules::getRulesByFilename("classic.txt"); + hasChosenGameType = true; + subMenuController->Close(); + currentState = MENU_STATE_NETWORK_WAIT | MENU_STATE_MINOR_SUBMENU_CLOSING; + } + mParent->mServerAddress = ""; + } + //Prevent screen from updating. + return; + } +#endif //NETWORK_SUPPORT + timeIndex += dt * 2; switch (MENU_STATE_MAJOR & currentState) { @@ -766,6 +795,8 @@ void GameStateMenu::Render() { subMenuController->Render(); } + + if (options.keypadActive()) options.keypadRender(); } void GameStateMenu::ButtonPressed(int controllerId, int controlId) @@ -843,7 +874,7 @@ void GameStateMenu::ButtonPressed(int controllerId, int controlId) { if(!mParent->mpNetwork) { - mParent->mpNetwork = new JNetwork(); + mParent->mpNetwork = new JNetwork(); } mParent->mpNetwork->connect(); subMenuController->Close(); @@ -854,17 +885,9 @@ void GameStateMenu::ButtonPressed(int controllerId, int controlId) { if(!mParent->mpNetwork) { - mParent->mpNetwork = new JNetwork(); + options.keypadStart("127.0.0.1", &(mParent->mServerAddress), true, true); + options.keypadTitle("Enter device address to connect"); } - // FIXME needs to be able to specify the server ip - mParent->mpNetwork->connect("127.0.0.1"); - // we let the server choose the game mode - mParent->gameType = GAME_TYPE_SLAVE; - // just to select one, the HOST is in control here. - mParent->rules = Rules::getRulesByFilename("classic.txt"); - hasChosenGameType = true; - subMenuController->Close(); - currentState = MENU_STATE_NETWORK_WAIT | MENU_STATE_MINOR_SUBMENU_CLOSING; break; } #endif //NETWORK_SUPPORT diff --git a/projects/mtg/src/SimplePad.cpp b/projects/mtg/src/SimplePad.cpp index 387fd3d96..a8e9db5a1 100644 --- a/projects/mtg/src/SimplePad.cpp +++ b/projects/mtg/src/SimplePad.cpp @@ -112,6 +112,9 @@ SimplePad::SimplePad() if (x < 8) linkKeys(KPD_0 + x, KPD_A + x, KPD_DOWN); if (x > 0) linkKeys(KPD_0 + x, KPD_0 + x - 1, KPD_LEFT); } + k = Add(_("."), KPD_DOT); + linkKeys(KPD_DOT, KPD_9, KPD_LEFT); + keys[KPD_DOT]->adjacency[KPD_DOWN] = KPD_DEL; keys[KPD_8]->adjacency[KPD_DOWN] = KPD_DEL; keys[KPD_9]->adjacency[KPD_DOWN] = KPD_DEL; @@ -158,6 +161,17 @@ void SimplePad::pressKey(unsigned char key) //Auto swap capitalization if (bCapslock && buffer.size() == 1) bCapslock = !bCapslock; } + else if (key >= KPD_0 && key <= KPD_9) + { + input += ('0' + key - KPD_0); + if (cursor < buffer.size()) cursor++; + buffer.insert(cursor, input); + } + else if (key == KPD_DOT) + { + if (cursor < buffer.size()) cursor++; + buffer.insert(cursor, "."); + } else if (key == KPD_SPACE) { if (cursor < buffer.size()) cursor++; @@ -392,7 +406,7 @@ void SimplePad::Render() if (keys[x]) { - if ((x == KPD_CANCEL && !bShowCancel) || (x >= KPD_0 && x <= KPD_9 && !bShowNumpad)) continue; + if ((x == KPD_CANCEL && !bShowCancel) || (x >= KPD_0 && x <= KPD_DOT && !bShowNumpad)) continue; switch (x) {