the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 280 lines 7.5 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "UIScene_EndPoem.h" 4#include "UIBitmapFont.h" 5#include "..\..\Minecraft.h" 6#include "..\..\MultiplayerLocalPlayer.h" 7#include "..\..\..\Minecraft.World\StringHelpers.h" 8 9UIScene_EndPoem::UIScene_EndPoem(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) 10{ 11 12 //ui.setFontCachingCalculationBuffer(20000); 13 14 // Setup all the Iggy references we need for this scene 15 initialiseMovie(); 16 17 m_bIgnoreInput = false; 18 19 // 4J Stu - Don't need these, the AS handles the scrolling and makes it look nice 20#if 0 21 wstring halfScreenLineBreaks; 22 23 if(RenderManager.IsHiDef()) 24 { 25 // HD - 17 line page 26 halfScreenLineBreaks = L"<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />"; 27 } 28 else 29 { 30 // 480 - 14 line page 31 halfScreenLineBreaks = L"<br /><br /><br /><br /><br /><br /><br /><br />"; 32 } 33#endif 34 35 //wchar_t startTags[64]; 36 //swprintf(startTags,64,L"<font size=\"%d\">",app.GetHTMLFontSize(eHTMLSize_EndPoem)); 37 //noNoiseString.append(halfScreenLineBreaks); 38 //noNoiseString.append(halfScreenLineBreaks); 39 noNoiseString.append( app.GetString(IDS_WIN_TEXT) ); 40 noNoiseString.append( app.GetString(IDS_WIN_TEXT_PART_2) ); 41 noNoiseString.append( app.GetString(IDS_WIN_TEXT_PART_3) ); 42 43 //noNoiseString.append(halfScreenLineBreaks); 44 45 // 4J Stu - Iggy seems to strip our trailing linebreaks, so added a space to made sure it scrolls this far 46 noNoiseString.append( L" " ); 47 48 noNoiseString = app.FormatHTMLString(m_iPad, noNoiseString, 0xff000000); 49 50 Minecraft *pMinecraft = Minecraft::GetInstance(); 51 52 wstring playerName = L""; 53 if(pMinecraft->localplayers[ui.GetWinUserIndex()] != NULL) 54 { 55 playerName = escapeXML( pMinecraft->localplayers[ui.GetWinUserIndex()]->getDisplayName() ); 56 } 57 else 58 { 59 playerName = escapeXML( pMinecraft->localplayers[ProfileManager.GetPrimaryPad()]->getDisplayName() ); 60 } 61 noNoiseString = replaceAll(noNoiseString,L"{*PLAYER*}",playerName); 62 63 Random random(8124371); 64 int found=(int)noNoiseString.find(L"{*NOISE*}"); 65 int length; 66 while (found!=string::npos) 67 { 68 length = random.nextInt(4) + 3; 69 m_noiseLengths.push_back(length); 70 found=(int)noNoiseString.find(L"{*NOISE*}",found+1); 71 } 72 73 updateNoise(); 74 75 76 // 4J-JEV: Find paragraph start and end points. 77 m_paragraphs = vector<wstring>(); 78 int lastIndex = 0; 79 for ( int index = 0; 80 index != wstring::npos; 81 index = noiseString.find(L"<br /><br />", index+12, 12) 82 ) 83 { 84 m_paragraphs.push_back( noiseString.substr(lastIndex, index-lastIndex) ); 85 lastIndex = index; 86 } 87 //lastIndex += 12; 88 m_paragraphs.push_back( noiseString.substr( lastIndex, noiseString.length() - lastIndex ) ); 89 90 //m_htmlPoem.init(noiseString.c_str()); 91 //m_htmlPoem.startAutoScroll(); 92 93 //wstring result = m_htmlControl.GetText(); 94 95 //wcout << result.c_str(); 96 97#if TO_BE_IMPLEMENTED 98 m_scrollDir = 1; 99 HRESULT hr = XuiHtmlControlSetSmoothScroll(m_htmlControl.m_hObj, XUI_SMOOTHSCROLL_VERTICAL,TRUE,AUTO_SCROLL_SPEED,1.0f,AUTO_SCROLL_SPEED); 100 XuiHtmlControlVScrollBy(m_htmlControl.m_hObj,m_scrollDir * 1000); 101 102 SetTimer(0,200); 103#endif 104 105 m_requestedLabel = 0; 106} 107 108wstring UIScene_EndPoem::getMoviePath() 109{ 110 return L"EndPoem"; 111} 112 113void UIScene_EndPoem::updateTooltips() 114{ 115 ui.SetTooltips( XUSER_INDEX_ANY, -1, m_bIgnoreInput?-1:IDS_TOOLTIPS_CONTINUE); 116} 117 118void UIScene_EndPoem::tick() 119{ 120 UIScene::tick(); 121 122 if( m_requestedLabel >= 0 && m_requestedLabel < m_paragraphs.size()) 123 { 124 wstring label = m_paragraphs[m_requestedLabel]; 125 126 IggyDataValue result; 127 IggyDataValue value[3]; 128 129 IggyStringUTF16 stringVal; 130 stringVal.string = (IggyUTF16*)label.c_str(); 131 stringVal.length = label.length(); 132 value[0].type = IGGY_DATATYPE_string_UTF16; 133 value[0].string16 = stringVal; 134 135 value[1].type = IGGY_DATATYPE_number; 136 value[1].number = m_requestedLabel; 137 138 value[2].type = IGGY_DATATYPE_boolean; 139 value[2].boolval = (m_requestedLabel == (m_paragraphs.size() - 1)); 140 141 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetNextLabel , 3 , value ); 142 143 m_requestedLabel = -1; 144 } 145} 146 147void UIScene_EndPoem::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) 148{ 149 if(m_bIgnoreInput) return; 150 151 if(pressed) ui.AnimateKeyPress(iPad, key, repeat, pressed, released); 152 153 switch(key) 154 { 155 case ACTION_MENU_CANCEL: 156 if(pressed) 157 { 158 m_bIgnoreInput = true; 159 Minecraft *pMinecraft = Minecraft::GetInstance(); 160 for(unsigned int i = 0; i < XUSER_MAX_COUNT; ++i) 161 { 162 if(pMinecraft->localplayers[i] != NULL) 163 { 164 app.SetAction(i,eAppAction_Respawn); 165 } 166 } 167 168 // This just allows it to be shown 169 if(pMinecraft->localgameModes[ProfileManager.GetPrimaryPad()] != NULL) pMinecraft->localgameModes[ProfileManager.GetPrimaryPad()]->getTutorial()->showTutorialPopup(true); 170 171 updateTooltips(); 172 navigateBack(); 173 174 handled = true; 175 } 176 break; 177 case ACTION_MENU_DOWN: 178 case ACTION_MENU_UP: 179 case ACTION_MENU_OTHER_STICK_DOWN: 180 case ACTION_MENU_OTHER_STICK_UP: 181 sendInputToMovie(key, repeat, pressed, released); 182 break; 183 } 184} 185 186void UIScene_EndPoem::handleDestroy() 187{ 188 189 //ui.setFontCachingCalculationBuffer(-1); 190} 191 192void UIScene_EndPoem::handleRequestMoreData(F64 startIndex, bool up) 193{ 194 m_requestedLabel = (int)startIndex; 195} 196 197void UIScene_EndPoem::updateNoise() 198{ 199 Minecraft *pMinecraft = Minecraft::GetInstance(); 200 noiseString = noNoiseString; 201 202 int length = 0; 203 wchar_t replacements[64]; 204 wstring replaceString = L""; 205 wchar_t randomChar = L'a'; 206 Random *random = pMinecraft->font->random; 207 208 bool darken = false; 209 210 wstring tag = L"{*NOISE*}"; 211 212 AUTO_VAR(it, m_noiseLengths.begin()); 213 int found=(int)noiseString.find(tag); 214 while (found!=string::npos && it != m_noiseLengths.end() ) 215 { 216 length = *it; 217 ++it; 218 219 replaceString = L""; 220 for(int i = 0; i < length; ++i) 221 { 222 if (ui.UsingBitmapFont()) 223 { 224 randomChar = SharedConstants::acceptableLetters[random->nextInt((int)SharedConstants::acceptableLetters.length())]; 225 } 226 else 227 { 228 // 4J-JEV: It'd be nice to avoid null characters when using asian languages. 229 static wstring acceptableLetters = L"!\"#$%&'()*+,-./0123456789:;<=>?@[\\]^_'|}~"; 230 randomChar = acceptableLetters[ random->nextInt((int)acceptableLetters.length()) ]; 231 } 232 233 wstring randomCharStr = L""; 234 randomCharStr.push_back(randomChar); 235 if(randomChar == L'<') 236 { 237 randomCharStr = L"&lt;"; 238 } 239 else if (randomChar == L'>' ) 240 { 241 randomCharStr = L"&gt;"; 242 } 243 else if(randomChar == L'"') 244 { 245 randomCharStr = L"&quot;"; 246 } 247 else if(randomChar == L'&') 248 { 249 randomCharStr = L"&amp;"; 250 } 251 else if(randomChar == L'\\') 252 { 253 randomCharStr = L"\\\\"; 254 } 255 else if(randomChar == L'{') 256 { 257 randomCharStr = L"}"; 258 } 259 260 int randomVal = random->nextInt(2); 261 eMinecraftColour colour = eHTMLColor_8; 262 if(randomVal == 1) colour = eHTMLColor_9; 263 else if(randomVal == 2) colour = eHTMLColor_a; 264 ZeroMemory(replacements,64*sizeof(wchar_t)); 265 swprintf(replacements,64,L"<font color=\"#%08x\" shadowcolor=\"#80000000\">%ls</font>",app.GetHTMLColour(colour),randomCharStr.c_str()); 266 replaceString.append(replacements); 267 } 268 269 noiseString.replace( found, tag.length(), replaceString ); 270 271 //int pos = 0; 272 //do { 273 // pos = random->nextInt(SharedConstants::acceptableLetters.length()); 274 //} while (pMinecraft->font->charWidths[ch + 32] != pMinecraft->font->charWidths[pos + 32]); 275 //ib.put(listPos + 256 + random->nextInt(2) + 8 + (darken ? 16 : 0)); 276 //ib.put(listPos + pos + 32); 277 278 found=(int)noiseString.find(tag,found+1); 279 } 280}