the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 119 lines 2.9 kB view raw
1#include "stdafx.h" 2#include "TextEditScreen.h" 3#include "Button.h" 4#include "TileEntityRenderDispatcher.h" 5#include "ClientConnection.h" 6#include "MultiPlayerLevel.h" 7#include "..\Minecraft.World\SignTileEntity.h" 8#include "..\Minecraft.World\SharedConstants.h" 9#include "..\Minecraft.World\net.minecraft.network.packet.h" 10#include "..\Minecraft.World\net.minecraft.world.level.h" 11#include "..\Minecraft.World\net.minecraft.world.level.tile.h" 12 13 14const wstring TextEditScreen::allowedChars = SharedConstants::acceptableLetters;; 15 16TextEditScreen::TextEditScreen(shared_ptr<SignTileEntity> sign) 17{ 18 // 4J - added initialisers 19 line = 0; 20 frame = 0; 21 title = L"Edit sign message:"; 22 23 this->sign = sign; 24} 25 26void TextEditScreen::init() 27{ 28 buttons.clear(); 29 Keyboard::enableRepeatEvents(true); 30 buttons.push_back(new Button(0, width / 2 - 100, height / 4 + 24 * 5, L"Done")); 31} 32 33void TextEditScreen::removed() 34{ 35 Keyboard::enableRepeatEvents(false); 36 if (minecraft->level->isClientSide) 37 { 38 minecraft->getConnection(0)->send( shared_ptr<SignUpdatePacket>( new SignUpdatePacket(sign->x, sign->y, sign->z, sign->IsVerified(), sign->IsCensored(), sign->GetMessages()) ) ); 39 } 40 41} 42 43void TextEditScreen::tick() 44{ 45 frame++; 46} 47 48void TextEditScreen::buttonClicked(Button *button) 49{ 50 if (!button->active) return; 51 52 if (button->id == 0) 53 { 54 sign->setChanged(); 55 minecraft->setScreen(NULL); 56 } 57} 58 59void TextEditScreen::keyPressed(wchar_t ch, int eventKey) 60{ 61 if (eventKey == Keyboard::KEY_UP) line = (line - 1) & 3; 62 if (eventKey == Keyboard::KEY_DOWN || eventKey == Keyboard::KEY_RETURN) line = (line + 1) & 3; 63 64 wstring temp=sign->GetMessage(line); 65 if (eventKey == Keyboard::KEY_BACK && temp.length() > 0) 66 { 67 temp = temp.substr(0, temp.length() - 1); 68 } 69 if (allowedChars.find(ch) != wstring::npos && temp.length() < 15) 70 { 71 temp += ch; 72 } 73 74 sign->SetMessage(line,temp); 75 76} 77 78void TextEditScreen::render(int xm, int ym, float a) 79{ 80 renderBackground(); 81 82 drawCenteredString(font, title, width / 2, 40, 0xffffff); 83 84 glPushMatrix(); 85 glTranslatef((float)width / 2, (float)height / 2, 50); 86 float ss = 60 / (16 / 25.0f); 87 glScalef(-ss, -ss, -ss); 88 glRotatef(180, 0, 1, 0); 89 90 Tile *tile = sign->getTile(); 91 92 if (tile == Tile::sign) 93 { 94 float rot = sign->getData() * 360 / 16.0f; 95 glRotatef(rot, 0, 1, 0); 96 glTranslatef(0, 5 / 16.0f, 0); 97 } 98 else 99 { 100 int face = sign->getData(); 101 float rot = 0; 102 103 if (face == 2) rot = 180; 104 if (face == 4) rot = 90; 105 if (face == 5) rot = -90; 106 glRotatef(rot, 0, 1, 0); 107 glTranslatef(0, 5 / 16.0f, 0); 108 } 109 110 if (frame / 6 % 2 == 0) sign->SetSelectedLine(line); 111 112 TileEntityRenderDispatcher::instance->render(sign, 0 - 0.5f, -0.75f, 0 - 0.5f, 0); 113 sign->SetSelectedLine(-1); 114 115 glPopMatrix(); 116 117 Screen::render(xm, ym, a); 118 119}