the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 257 lines 6.0 kB view raw
1#include "stdafx.h" 2#include "Screen.h" 3#include "Button.h" 4#include "GuiParticles.h" 5#include "Tesselator.h" 6#include "Textures.h" 7#include "..\Minecraft.World\SoundTypes.h" 8#ifdef _WINDOWS64 9#include "Windows64\KeyboardMouseInput.h" 10#endif 11 12 13 14Screen::Screen() // 4J added 15{ 16 minecraft = NULL; 17 width = 0; 18 height = 0; 19 passEvents = false; 20 font = NULL; 21 particles = NULL; 22 clickedButton = NULL; 23} 24 25void Screen::render(int xm, int ym, float a) 26{ 27 AUTO_VAR(itEnd, buttons.end()); 28 for (AUTO_VAR(it, buttons.begin()); it != itEnd; it++) 29 { 30 Button *button = *it; //buttons[i]; 31 button->render(minecraft, xm, ym); 32 } 33} 34 35void Screen::keyPressed(wchar_t eventCharacter, int eventKey) 36{ 37 if (eventKey == Keyboard::KEY_ESCAPE) 38 { 39 minecraft->setScreen(NULL); 40// minecraft->grabMouse(); // 4J - removed 41 } 42} 43 44wstring Screen::getClipboard() 45{ 46 // 4J - removed 47 return NULL; 48} 49 50void Screen::setClipboard(const wstring& str) 51{ 52 // 4J - removed 53} 54 55void Screen::mouseClicked(int x, int y, int buttonNum) 56{ 57 if (buttonNum == 0) 58 { 59 AUTO_VAR(itEnd, buttons.end()); 60 for (AUTO_VAR(it, buttons.begin()); it != itEnd; it++) 61 { 62 Button *button = *it; //buttons[i]; 63 if (button->clicked(minecraft, x, y)) 64 { 65 clickedButton = button; 66 minecraft->soundEngine->playUI(eSoundType_RANDOM_CLICK, 1, 1); 67 buttonClicked(button); 68 } 69 } 70 } 71} 72 73void Screen::mouseReleased(int x, int y, int buttonNum) 74{ 75 if (clickedButton!=NULL && buttonNum==0) 76 { 77 clickedButton->released(x, y); 78 clickedButton = NULL; 79 } 80} 81 82void Screen::buttonClicked(Button *button) 83{ 84} 85 86void Screen::init(Minecraft *minecraft, int width, int height) 87{ 88 particles = new GuiParticles(minecraft); 89 this->minecraft = minecraft; 90 this->font = minecraft->font; 91 this->width = width; 92 this->height = height; 93 buttons.clear(); 94 init(); 95} 96 97void Screen::setSize(int width, int height) 98{ 99 this->width = width; 100 this->height = height; 101} 102 103void Screen::init() 104{ 105} 106 107void Screen::updateEvents() 108{ 109#ifdef _WINDOWS64 110 // Poll mouse button state and dispatch click/release events 111 for (int btn = 0; btn < 3; btn++) 112 { 113 if (KMInput.ConsumeMousePress(btn)) 114 { 115 int xm = Mouse::getX() * width / minecraft->width; 116 int ym = height - Mouse::getY() * height / minecraft->height - 1; 117 mouseClicked(xm, ym, btn); 118 } 119 if (KMInput.ConsumeMouseRelease(btn)) 120 { 121 int xm = Mouse::getX() * width / minecraft->width; 122 int ym = height - Mouse::getY() * height / minecraft->height - 1; 123 mouseReleased(xm, ym, btn); 124 } 125 } 126 127 // Poll keyboard events 128 for (int vk = 0; vk < 256; vk++) 129 { 130 if (KMInput.ConsumeKeyPress(vk)) 131 { 132 // Map Windows virtual key to the Keyboard constants used by Screen::keyPressed 133 int mappedKey = -1; 134 wchar_t ch = 0; 135 if (vk == VK_ESCAPE) mappedKey = Keyboard::KEY_ESCAPE; 136 else if (vk == VK_RETURN) mappedKey = Keyboard::KEY_RETURN; 137 else if (vk == VK_BACK) mappedKey = Keyboard::KEY_BACK; 138 else if (vk == VK_UP) mappedKey = Keyboard::KEY_UP; 139 else if (vk == VK_DOWN) mappedKey = Keyboard::KEY_DOWN; 140 else if (vk == VK_LEFT) mappedKey = Keyboard::KEY_LEFT; 141 else if (vk == VK_RIGHT) mappedKey = Keyboard::KEY_RIGHT; 142 else if (vk == VK_LSHIFT || vk == VK_RSHIFT) mappedKey = Keyboard::KEY_LSHIFT; 143 else if (vk == VK_TAB) mappedKey = Keyboard::KEY_TAB; 144 else if (vk >= 'A' && vk <= 'Z') 145 { 146 ch = (wchar_t)(vk - 'A' + L'a'); 147 if (KMInput.IsKeyDown(VK_SHIFT)) ch = (wchar_t)vk; 148 } 149 else if (vk >= '0' && vk <= '9') ch = (wchar_t)vk; 150 else if (vk == VK_SPACE) ch = L' '; 151 152 if (mappedKey != -1) keyPressed(ch, mappedKey); 153 else if (ch != 0) keyPressed(ch, -1); 154 } 155 } 156#else 157 /* 4J - TODO 158 while (Mouse.next()) { 159 mouseEvent(); 160 } 161 162 while (Keyboard.next()) { 163 keyboardEvent(); 164 } 165 */ 166#endif 167} 168 169void Screen::mouseEvent() 170{ 171#ifdef _WINDOWS64 172 // Mouse event dispatching is handled directly in updateEvents() for Windows 173#else 174 /* 4J - TODO 175 if (Mouse.getEventButtonState()) { 176 int xm = Mouse.getEventX() * width / minecraft.width; 177 int ym = height - Mouse.getEventY() * height / minecraft.height - 1; 178 mouseClicked(xm, ym, Mouse.getEventButton()); 179 } else { 180 int xm = Mouse.getEventX() * width / minecraft.width; 181 int ym = height - Mouse.getEventY() * height / minecraft.height - 1; 182 mouseReleased(xm, ym, Mouse.getEventButton()); 183 } 184 */ 185#endif 186} 187 188void Screen::keyboardEvent() 189{ 190 /* 4J - TODO 191 if (Keyboard.getEventKeyState()) { 192 if (Keyboard.getEventKey() == Keyboard.KEY_F11) { 193 minecraft.toggleFullScreen(); 194 return; 195 } 196 keyPressed(Keyboard.getEventCharacter(), Keyboard.getEventKey()); 197 } 198 */ 199} 200 201void Screen::tick() 202{ 203} 204 205void Screen::removed() 206{ 207} 208 209void Screen::renderBackground() 210{ 211 renderBackground(0); 212} 213 214void Screen::renderBackground(int vo) 215{ 216 if (minecraft->level != NULL) 217 { 218 fillGradient(0, 0, width, height, 0xc0101010, 0xd0101010); 219 } 220 else 221 { 222 renderDirtBackground(vo); 223 } 224} 225 226void Screen::renderDirtBackground(int vo) 227{ 228 // 4J Unused 229#if 0 230 glDisable(GL_LIGHTING); 231 glDisable(GL_FOG); 232 Tesselator *t = Tesselator::getInstance(); 233 glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture(L"/gui/background.png")); 234 glColor4f(1, 1, 1, 1); 235 float s = 32; 236 t->begin(); 237 t->color(0x404040); 238 t->vertexUV((float)(0), (float)( height), (float)( 0), (float)( 0), (float)( height / s + vo)); 239 t->vertexUV((float)(width), (float)( height), (float)( 0), (float)( width / s), (float)( height / s + vo)); 240 t->vertexUV((float)(width), (float)( 0), (float)( 0), (float)( width / s), (float)( 0 + vo)); 241 t->vertexUV((float)(0), (float)( 0), (float)( 0), (float)( 0), (float)( 0 + vo)); 242 t->end(); 243#endif 244} 245 246bool Screen::isPauseScreen() 247{ 248 return true; 249} 250 251void Screen::confirmResult(bool result, int id) 252{ 253} 254 255void Screen::tabPressed() 256{ 257}