the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 89 lines 2.1 kB view raw
1#include "stdafx.h" 2#include "ChatScreen.h" 3#include "MultiplayerLocalPlayer.h" 4#include "..\Minecraft.World\SharedConstants.h" 5#include "..\Minecraft.World\StringHelpers.h" 6 7const wstring ChatScreen::allowedChars = SharedConstants::acceptableLetters; 8 9ChatScreen::ChatScreen() 10{ 11 frame = 0; 12} 13 14void ChatScreen::init() 15{ 16 Keyboard::enableRepeatEvents(true); 17} 18 19void ChatScreen::removed() 20{ 21 Keyboard::enableRepeatEvents(false); 22} 23 24void ChatScreen::tick() 25{ 26 frame++; 27} 28 29void ChatScreen::keyPressed(wchar_t ch, int eventKey) 30{ 31 if (eventKey == Keyboard::KEY_ESCAPE) 32 { 33 minecraft->setScreen(NULL); 34 return; 35 } 36 if (eventKey == Keyboard::KEY_RETURN) 37 { 38 wstring msg = trimString(message); 39 if (msg.length() > 0) 40 { 41 wstring trim = trimString(message); 42 if (!minecraft->handleClientSideCommand(trim)) 43 { 44 minecraft->player->chat(trim); 45 } 46 } 47 minecraft->setScreen(NULL); 48 return; 49 } 50 if (eventKey == Keyboard::KEY_BACK && message.length() > 0) message = message.substr(0, message.length() - 1); 51 if (allowedChars.find(ch) >= 0 && message.length() < SharedConstants::maxChatLength) 52 { 53 message += ch; 54 } 55 56} 57 58void ChatScreen::render(int xm, int ym, float a) 59{ 60 fill(2, height - 14, width - 2, height - 2, 0x80000000); 61 drawString(font, L"> " + message + (frame / 6 % 2 == 0 ? L"_" : L""), 4, height - 12, 0xe0e0e0); 62 63 Screen::render(xm, ym, a); 64} 65 66void ChatScreen::mouseClicked(int x, int y, int buttonNum) 67{ 68 if (buttonNum == 0) 69 { 70 if (minecraft->gui->selectedName != L"") // 4J - was NULL comparison 71 { 72 if (message.length() > 0 && message[message.length()-1]!=L' ') 73 { 74 message += L" "; 75 } 76 message += minecraft->gui->selectedName; 77 unsigned int maxLength = SharedConstants::maxChatLength; 78 if (message.length() > maxLength) 79 { 80 message = message.substr(0, maxLength); 81 } 82 } 83 else 84 { 85 Screen::mouseClicked(x, y, buttonNum); 86 } 87 } 88 89}