the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 128 lines 3.5 kB view raw
1#include "stdafx.h" 2#include "JoinMultiplayerScreen.h" 3#include "Button.h" 4#include "EditBox.h" 5#include "Options.h" 6#include "..\Minecraft.World\net.minecraft.locale.h" 7 8JoinMultiplayerScreen::JoinMultiplayerScreen(Screen *lastScreen) 9{ 10 ipEdit = NULL; 11 this->lastScreen = lastScreen; 12} 13 14void JoinMultiplayerScreen::tick() 15{ 16 ipEdit->tick(); 17} 18 19void JoinMultiplayerScreen::init() 20{ 21 Language *language = Language::getInstance(); 22 23 Keyboard::enableRepeatEvents(true); 24 buttons.clear(); 25 buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 4 + 12, language->getElement(L"multiplayer.connect"))); 26 buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 5 + 12, language->getElement(L"gui.cancel"))); 27 wstring ip = replaceAll(minecraft->options->lastMpIp,L"_", L":"); 28 buttons[0]->active = ip.length() > 0; 29 30 ipEdit = new EditBox(this, font, width / 2 - 100, height / 4 - 10 + 50 + 18, 200, 20, ip); 31 ipEdit->inFocus = true; 32 ipEdit->setMaxLength(128); 33 34} 35 36void JoinMultiplayerScreen::removed() 37{ 38 Keyboard::enableRepeatEvents(false); 39} 40 41void JoinMultiplayerScreen::buttonClicked(Button *button) 42{ 43 if (!button->active) return; 44 if (button->id == 1) 45 { 46 minecraft->setScreen(lastScreen); 47 } 48 else if (button->id == 0) 49 { 50 wstring ip = trimString(ipEdit->getValue()); 51 52 minecraft->options->lastMpIp = replaceAll(ip,L":", L"_"); 53 minecraft->options->save(); 54 55 vector<wstring> parts = stringSplit(ip,L'L'); 56 if (ip[0]==L'[') 57 { 58 int pos = (int)ip.find(L"]"); 59 if (pos != wstring::npos) 60 { 61 wstring path = ip.substr(1, pos); 62 wstring port = trimString(ip.substr(pos + 1)); 63 if (port[0]==L':' && port.length() > 0) 64 { 65 port = port.substr(1); 66 parts.clear(); 67 parts.push_back(path); 68 parts.push_back(port); 69 } 70 else 71 { 72 parts.clear(); 73 parts.push_back(path); 74 } 75 } 76 77 } 78 if (parts.size() > 2) 79 { 80 parts.clear(); 81 parts.push_back(ip); 82 } 83 84 // 4J - TODO 85// minecraft->setScreen(new ConnectScreen(minecraft, parts[0], parts.length > 1 ? parseInt(parts[1], 25565) : 25565)); 86 } 87} 88 89int JoinMultiplayerScreen::parseInt(const wstring& str, int def) 90{ 91 return _fromString<int>(str); 92} 93 94void JoinMultiplayerScreen::keyPressed(wchar_t ch, int eventKey) 95{ 96 ipEdit->keyPressed(ch, eventKey); 97 98 if (ch == 13) 99 { 100 buttonClicked(buttons[0]); 101 } 102 buttons[0]->active = ipEdit->getValue().length() > 0; 103} 104 105void JoinMultiplayerScreen::mouseClicked(int x, int y, int buttonNum) 106{ 107 Screen::mouseClicked(x, y, buttonNum); 108 109 ipEdit->mouseClicked(x, y, buttonNum); 110} 111 112void JoinMultiplayerScreen::render(int xm, int ym, float a) 113{ 114 Language *language = Language::getInstance(); 115 116 // fill(0, 0, width, height, 0x40000000); 117 renderBackground(); 118 119 drawCenteredString(font, language->getElement(L"multiplayer.title"), width / 2, height / 4 - 60 + 20, 0xffffff); 120 drawString(font, language->getElement(L"multiplayer.info1"), width / 2 - 140, height / 4 - 60 + 60 + 9 * 0, 0xa0a0a0); 121 drawString(font, language->getElement(L"multiplayer.info2"), width / 2 - 140, height / 4 - 60 + 60 + 9 * 1, 0xa0a0a0); 122 drawString(font, language->getElement(L"multiplayer.ipinfo"), width / 2 - 140, height / 4 - 60 + 60 + 9 * 4, 0xa0a0a0); 123 124 ipEdit->render(); 125 126 Screen::render(xm, ym, a); 127 128}