the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 302 lines 8.6 kB view raw
1// Minecraft.cpp : Defines the entry point for the application. 2// 3 4#include "stdafx.h" 5#include "..\..\Minecraft.h" 6#include "..\..\Common\Tutorial\TutorialMode.h" 7#include "..\..\Font.h" 8#include "..\..\..\Minecraft.World\Random.h" 9#include "..\..\..\Minecraft.World\SharedConstants.h" 10#include "..\..\..\Minecraft.World\StringHelpers.h" 11#include "..\..\MultiplayerLocalPlayer.h" 12#include "XUI_Scene_Win.h" 13 14BYTE CScene_Win::s_winUserIndex = 0; 15 16const float CScene_Win::AUTO_SCROLL_SPEED = 1.0f; 17const float CScene_Win::PLAYER_SCROLL_SPEED = 3.0f; 18 19//---------------------------------------------------------------------------------- 20// Performs initialization tasks - retrieves controls. 21//---------------------------------------------------------------------------------- 22HRESULT CScene_Win::OnInit( XUIMessageInit* pInitData, BOOL& bHandled ) 23{ 24 m_iPad = *(int *)pInitData->pvInitData; 25 26 m_bIgnoreInput = false; 27 28 MapChildControls(); 29 30 // Display the tooltips 31 ui.SetTooltips( m_iPad, -1, IDS_TOOLTIPS_CONTINUE); 32 33 wstring halfScreenLineBreaks; 34 35 if(RenderManager.IsHiDef()) 36 { 37 // HD - 17 line page 38 halfScreenLineBreaks = L"<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>"; 39 } 40 else 41 { 42 // 480 - 14 line page 43 halfScreenLineBreaks = L"<br/><br/><br/><br/><br/><br/><br/><br/>"; 44 } 45 46 noNoiseString = L"<font size=\"24\"><ds>"; 47 noNoiseString.append(halfScreenLineBreaks); 48 noNoiseString.append(halfScreenLineBreaks); 49 noNoiseString.append( app.GetString(IDS_WIN_TEXT) ); 50 noNoiseString.append( app.GetString(IDS_WIN_TEXT_PART_2) ); 51 noNoiseString.append( app.GetString(IDS_WIN_TEXT_PART_3) ); 52 53 noNoiseString.append(halfScreenLineBreaks); 54 55 noNoiseString.append( L"</ds></font>" ); 56 57 noNoiseString = app.FormatHTMLString(m_iPad, noNoiseString, 0xff000000); 58 59 Random random(8124371); 60 int found=(int)noNoiseString.find_first_of(L"{"); 61 int length; 62 while (found!=string::npos) 63 { 64 length = random.nextInt(4) + 3; 65 m_noiseLengths.push_back(length); 66 found=(int)noNoiseString.find_first_of(L"{",found+1); 67 } 68 69 Minecraft *pMinecraft = Minecraft::GetInstance(); 70 71 if(pMinecraft->localplayers[s_winUserIndex] != NULL) 72 { 73 noNoiseString = replaceAll(noNoiseString,L"{*PLAYER*}",pMinecraft->localplayers[s_winUserIndex]->name); 74 } 75 else 76 { 77 noNoiseString = replaceAll(noNoiseString,L"{*PLAYER*}",pMinecraft->localplayers[ProfileManager.GetPrimaryPad()]->name); 78 } 79 80 updateNoise(); 81 82 m_htmlControl.SetText(noiseString.c_str()); 83 84 //wstring result = m_htmlControl.GetText(); 85 86 //wcout << result.c_str(); 87 88 m_scrollDir = 1; 89 HRESULT hr = XuiHtmlControlSetSmoothScroll(m_htmlControl.m_hObj, XUI_SMOOTHSCROLL_VERTICAL,TRUE,AUTO_SCROLL_SPEED,1.0f,AUTO_SCROLL_SPEED); 90 XuiHtmlControlVScrollBy(m_htmlControl.m_hObj,m_scrollDir * 1000); 91 92 SetTimer(0,200); 93 94 return S_OK; 95} 96 97HRESULT CScene_Win::OnTimer( XUIMessageTimer *pXUIMessageTimer, BOOL &bHandled) 98{ 99 if(!TreeHasFocus()) return S_OK; 100 101 // This is required to animate the "noise" strings in the text, however this makes scrolling really jumpy 102 // as well as causing line lengths to change as we do not have a monspaced font. Disabling for now. 103#if 0 104 updateNoise(); 105 106 XUIHtmlScrollInfo scrollInfo; 107 HRESULT hr = m_htmlControl.GetVScrollInfo(&scrollInfo); 108 m_htmlControl.SetText(noiseString.c_str()); 109 //wcout << noiseString.c_str(); 110 //hr = m_htmlControl.SetVScrollPos(scrollInfo.nPos+2); 111 hr = m_htmlControl.SetVScrollPos(scrollInfo.nPos); 112#endif 113 XuiHtmlControlVScrollBy(m_htmlControl.m_hObj,m_scrollDir * 1000); 114 115 return S_OK; 116} 117 118HRESULT CScene_Win::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled) 119{ 120 if(m_bIgnoreInput) return S_OK; 121 122 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode); 123 124 switch(pInputData->dwKeyCode) 125 { 126 127 case VK_PAD_B: 128 case VK_PAD_START: 129 case VK_ESCAPE: 130 { 131 KillTimer(0); 132 m_bIgnoreInput = true; 133 Minecraft *pMinecraft = Minecraft::GetInstance(); 134 app.CloseAllPlayersXuiScenes(); 135 for(unsigned int i = 0; i < XUSER_MAX_COUNT; ++i) 136 { 137 if(pMinecraft->localplayers[i] != NULL) 138 { 139 app.SetAction(i,eAppAction_Respawn); 140 } 141 } 142 143 // Show the other players scenes 144 CXuiSceneBase::ShowOtherPlayersBaseScene(pInputData->UserIndex, true); 145 // This just allows it to be shown 146 if(pMinecraft->localgameModes[ProfileManager.GetPrimaryPad()] != NULL) pMinecraft->localgameModes[ProfileManager.GetPrimaryPad()]->getTutorial()->showTutorialPopup(true); 147 ui.UpdatePlayerBasePositions(); 148 149 rfHandled = TRUE; 150 } 151 break; 152 case VK_PAD_RTHUMB_UP: 153 case VK_PAD_LTHUMB_UP: 154 m_scrollDir = -1; 155 // Fall through 156 case VK_PAD_RTHUMB_DOWN: 157 case VK_PAD_LTHUMB_DOWN: 158 { 159 HRESULT hr = XuiHtmlControlSetSmoothScroll(m_htmlControl.m_hObj, XUI_SMOOTHSCROLL_VERTICAL,TRUE,AUTO_SCROLL_SPEED,1.0f,PLAYER_SCROLL_SPEED); 160 } 161 break; 162 } 163 164 return S_OK; 165} 166 167HRESULT CScene_Win::OnKeyUp(XUIMessageInput* pInputData, BOOL& rfHandled) 168{ 169 if(m_bIgnoreInput) return S_OK; 170 171 switch(pInputData->dwKeyCode) 172 { 173 case VK_PAD_RTHUMB_UP: 174 case VK_PAD_LTHUMB_UP: 175 case VK_PAD_RTHUMB_DOWN: 176 case VK_PAD_LTHUMB_DOWN: 177 { 178 m_scrollDir = 1; 179 HRESULT hr = XuiHtmlControlSetSmoothScroll(m_htmlControl.m_hObj, XUI_SMOOTHSCROLL_VERTICAL,TRUE,AUTO_SCROLL_SPEED,1.0f,AUTO_SCROLL_SPEED); 180 } 181 break; 182 } 183 184 return S_OK; 185} 186 187HRESULT CScene_Win::OnCustomMessage_Splitscreenplayer(bool bJoining, BOOL& bHandled) 188{ 189 bHandled=true; 190 return app.AdjustSplitscreenScene_PlayerChanged(m_hObj,&m_OriginalPosition,m_iPad,bJoining); 191} 192 193void CScene_Win::updateNoise() 194{ 195 Minecraft *pMinecraft = Minecraft::GetInstance(); 196 noiseString = noNoiseString; 197 198 int length = 0; 199 wchar_t replacements[64]; 200 wstring replaceString = L""; 201 wchar_t randomChar = L'a'; 202 Random *random = pMinecraft->font->random; 203 204 bool darken = false; 205 206 wstring tag = L"{*NOISE*}"; 207 208 AUTO_VAR(it, m_noiseLengths.begin()); 209 int found=(int)noiseString.find_first_of(L"{"); 210 while (found!=string::npos && it != m_noiseLengths.end() ) 211 { 212 length = *it; 213 ++it; 214 215 replaceString = L""; 216 for(int i = 0; i < length; ++i) 217 { 218 randomChar = SharedConstants::acceptableLetters[random->nextInt((int)SharedConstants::acceptableLetters.length())]; 219 220 wstring randomCharStr = L""; 221 randomCharStr.push_back(randomChar); 222 if(randomChar == L'<') 223 { 224 randomCharStr = L"&lt;"; 225 } 226 else if (randomChar == L'>' ) 227 { 228 randomCharStr = L"&gt;"; 229 } 230 else if(randomChar == L'"') 231 { 232 randomCharStr = L"&quot;"; 233 } 234 else if(randomChar == L'&') 235 { 236 randomCharStr = L"&amp;"; 237 } 238 else if(randomChar == L'\\') 239 { 240 randomCharStr = L"\\\\"; 241 } 242 else if(randomChar == L'{') 243 { 244 randomCharStr = L"}"; 245 } 246 247 int randomVal = random->nextInt(2); 248 eMinecraftColour colour = eHTMLColor_8; 249 if(randomVal == 1) colour = eHTMLColor_9; 250 else if(randomVal == 2) colour = eHTMLColor_a; 251 ZeroMemory(replacements,64*sizeof(wchar_t)); 252 swprintf(replacements,64,L"<font color=\"#%08x\" shadowcolor=\"#80000000\">%ls</font>",app.GetHTMLColour(colour),randomCharStr.c_str()); 253 replaceString.append(replacements); 254 } 255 256 noiseString.replace( found, tag.length(), replaceString ); 257 258 //int pos = 0; 259 //do { 260 // pos = random->nextInt(SharedConstants::acceptableLetters.length()); 261 //} while (pMinecraft->font->charWidths[ch + 32] != pMinecraft->font->charWidths[pos + 32]); 262 //ib.put(listPos + 256 + random->nextInt(2) + 8 + (darken ? 16 : 0)); 263 //ib.put(listPos + pos + 32); 264 265 found=(int)noiseString.find_first_of(L"{",found+1); 266 } 267} 268 269HRESULT CScene_Win::OnNavReturn(HXUIOBJ hObj,BOOL& rfHandled) 270{ 271 SetTimer(0,200); 272 273 // turn off the gamertags in splitscreen for the primary player, since they are about to be made fullscreen 274 CXuiSceneBase::HideAllGameUIElements(); 275 276 // Hide the other players scenes 277 CXuiSceneBase::ShowOtherPlayersBaseScene(ProfileManager.GetPrimaryPad(), false); 278 279 // This just allows it to be shown 280 if(Minecraft::GetInstance()->localgameModes[ProfileManager.GetPrimaryPad()] != NULL) Minecraft::GetInstance()->localgameModes[ProfileManager.GetPrimaryPad()]->getTutorial()->showTutorialPopup(false); 281 282 // Temporarily make this scene fullscreen 283 CXuiSceneBase::SetPlayerBaseScenePosition( ProfileManager.GetPrimaryPad(), CXuiSceneBase::e_BaseScene_Fullscreen ); 284 285 // Display the tooltips 286 ui.SetTooltips( m_iPad, -1, IDS_TOOLTIPS_CONTINUE); 287 288 XuiHtmlControlVScrollBy(m_htmlControl.m_hObj,m_scrollDir * 1000); 289 290 return S_OK; 291} 292 293HRESULT CScene_Win::OnNavForward(XUIMessageNavForward *pNavForwardData, BOOL& bHandled) 294{ 295 XuiHtmlControlVScrollBy(m_htmlControl.m_hObj,0); 296 XUIHtmlScrollInfo scrollInfo; 297 HRESULT hr = m_htmlControl.GetVScrollInfo(&scrollInfo); 298 hr = m_htmlControl.SetVScrollPos(scrollInfo.nPos); 299 KillTimer(0); 300 301 return S_OK; 302}