the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 96 lines 2.7 kB view raw
1#include "stdafx.h" 2#include "RenameWorldScreen.h" 3#include "EditBox.h" 4#include "Button.h" 5#include "..\Minecraft.World\net.minecraft.locale.h" 6#include "..\Minecraft.World\net.minecraft.world.level.h" 7#include "..\Minecraft.World\net.minecraft.world.level.storage.h" 8 9RenameWorldScreen::RenameWorldScreen(Screen *lastScreen, const wstring& levelId) 10{ 11 nameEdit = NULL; 12 this->lastScreen = lastScreen; 13 this->levelId = levelId; 14} 15 16void RenameWorldScreen::tick() 17{ 18 nameEdit->tick(); 19} 20 21void RenameWorldScreen::init() 22{ 23 // 4J Stu - Removed this as we don't need the screen. Changed to how we pass save data around stopped this compiling 24#if 0 25 Language *language = Language::getInstance(); 26 27 Keyboard::enableRepeatEvents(true); 28 buttons.clear(); 29 buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 4 + 12, language->getElement(L"selectWorld.renameButton"))); 30 buttons.push_back(new Button(1, width / 2 - 100, height / 4 + 24 * 5 + 12, language->getElement(L"gui.cancel"))); 31 32 LevelStorageSource *levelSource = minecraft->getLevelSource(); 33 LevelData *levelData = levelSource->getDataTagFor(levelId); 34 wstring currentName = levelData->getLevelName(); 35 36 nameEdit = new EditBox(this, font, width / 2 - 100, 60, 200, 20, currentName); 37 nameEdit->inFocus = true; 38 nameEdit->setMaxLength(32); 39#endif 40} 41 42void RenameWorldScreen::removed() 43{ 44 Keyboard::enableRepeatEvents(false); 45} 46 47void RenameWorldScreen::buttonClicked(Button *button) 48{ 49 if (!button->active) return; 50 if (button->id == 1) 51 { 52 minecraft->setScreen(lastScreen); 53 } 54 else if (button->id == 0) 55 { 56 57 LevelStorageSource *levelSource = minecraft->getLevelSource(); 58 levelSource->renameLevel(levelId, trimString(nameEdit->getValue())); 59 60 minecraft->setScreen(lastScreen); 61 } 62} 63 64void RenameWorldScreen::keyPressed(wchar_t ch, int eventKey) 65{ 66 nameEdit->keyPressed(ch, eventKey); 67 buttons[0]->active = trimString(nameEdit->getValue()).length() > 0; 68 69 if (ch == 13) 70 { 71 buttonClicked(buttons[0]); 72 } 73} 74 75void RenameWorldScreen::mouseClicked(int x, int y, int buttonNum) 76{ 77 Screen::mouseClicked(x, y, buttonNum); 78 79 nameEdit->mouseClicked(x, y, buttonNum); 80} 81 82void RenameWorldScreen::render(int xm, int ym, float a) 83{ 84 Language *language = Language::getInstance(); 85 86 // fill(0, 0, width, height, 0x40000000); 87 renderBackground(); 88 89 drawCenteredString(font, language->getElement(L"selectWorld.renameTitle"), width / 2, height / 4 - 60 + 20, 0xffffff); 90 drawString(font, language->getElement(L"selectWorld.enterName"), width / 2 - 100, 47, 0xa0a0a0); 91 92 nameEdit->render(); 93 94 Screen::render(xm, ym, a); 95 96}