the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#include <assert.h>
4#include "..\XUI\XUI_HelpHowToPlay.h"
5#include "..\..\..\Minecraft.World\StringHelpers.h"
6
7static SHowToPlayPageDef gs_aPageDefs[ eHowToPlay_NumPages ] =
8{
9 { eHowToPlay_WhatsNew, IDS_HOW_TO_PLAY_WHATSNEW, eHowToPlay_ImageNone, 0, 0}, // eHowToPlay_WhatsNew
10 { eHowToPlay_TextBasics, IDS_HOW_TO_PLAY_BASICS, eHowToPlay_ImageNone, 0, 0}, // eHowToPlay_Basics
11 { eHowToPlay_TextMultiplayer, IDS_HOW_TO_PLAY_MULTIPLAYER, eHowToPlay_ImageNone, 0, 0}, // eHowToPlay_Multiplayer
12 { eHowToPlay_TextHUD, IDS_HOW_TO_PLAY_HUD, eHowToPlay_ImageHUD, 0, 0}, // eHowToPlay_HUD
13 { eHowToPlay_TextCreative, IDS_HOW_TO_PLAY_CREATIVE, eHowToPlay_ImageCreative, eHowToPlay_LabelCreativeInventory, 1}, // eHowToPlay_Creative
14 { eHowToPlay_TextInventory, IDS_HOW_TO_PLAY_INVENTORY, eHowToPlay_ImageInventory, eHowToPlay_LabelIInventory, 1}, // eHowToPlay_Inventory
15 { eHowToPlay_TextSmallChest, IDS_HOW_TO_PLAY_CHEST, eHowToPlay_ImageChest, eHowToPlay_LabelSCInventory, 2}, // eHowToPlay_Chest
16 { eHowToPlay_TextLargeChest, IDS_HOW_TO_PLAY_LARGECHEST, eHowToPlay_ImageLargeChest, eHowToPlay_LabelLCInventory, 2}, // eHowToPlay_LargeChest
17 { eHowToPlay_TextEnderchest, IDS_HOW_TO_PLAY_ENDERCHEST, eHowToPlay_ImageEnderChest, 0, 0}, // eHowToPlay_EnderChest
18 { eHowToPlay_TextCrafting, IDS_HOW_TO_PLAY_CRAFTING, eHowToPlay_ImageInventoryCrafting, eHowToPlay_LabelCItem, 3}, // eHowToPlay_InventoryCrafting
19 { eHowToPlay_TextCraftTable, IDS_HOW_TO_PLAY_CRAFT_TABLE, eHowToPlay_ImageCraftingTable, eHowToPlay_LabelCTItem, 3}, // eHowToPlay_CraftTable
20 { eHowToPlay_TextFurnace, IDS_HOW_TO_PLAY_FURNACE, eHowToPlay_ImageFurnace, eHowToPlay_LabelFFuel, 4}, // eHowToPlay_Furnace
21 { eHowToPlay_TextDispenser, IDS_HOW_TO_PLAY_DISPENSER, eHowToPlay_ImageDispenser, eHowToPlay_LabelDText, 2}, // eHowToPlay_Dispenser
22 { eHowToPlay_TextBrewing, IDS_HOW_TO_PLAY_BREWING, eHowToPlay_ImageBrewing, eHowToPlay_LabelBBrew, 2}, // eHowToPlay_Brewing
23 { eHowToPlay_TextEnchantment, IDS_HOW_TO_PLAY_ENCHANTMENT, eHowToPlay_ImageEnchantment, eHowToPlay_LabelEEnchant, 2}, // eHowToPlay_Enchantment
24 { eHowToPlay_TextAnvil, IDS_HOW_TO_PLAY_ANVIL, eHowToPlay_ImageAnvil, eHowToPlay_LabelAnvil_Inventory, 3}, // eHowToPlay_Anvil
25 { eHowToPlay_TextFarmingAnimals,IDS_HOW_TO_PLAY_FARMANIMALS, eHowToPlay_ImageFarmingAnimals, 0, 0}, // eHowToPlay_Farming
26 { eHowToPlay_TextBreeding, IDS_HOW_TO_PLAY_BREEDANIMALS, eHowToPlay_ImageBreeding, 0, 0}, // eHowToPlay_Breeding
27 { eHowToPlay_TextTrading, IDS_HOW_TO_PLAY_TRADING, eHowToPlay_ImageTrading, eHowToPlay_LabelTrading_Inventory, 5}, // eHowToPlay_Trading
28 { eHowToPlay_TextNetherPortal, IDS_HOW_TO_PLAY_NETHERPORTAL, eHowToPlay_ImageNetherPortal, 0, 0}, // eHowToPlay_NetherPortal
29 { eHowToPlay_TextTheEnd, IDS_HOW_TO_PLAY_THEEND, eHowToPlay_ImageTheEnd, 0, 0}, // eHowToPlay_TheEnd
30 { eHowToPlay_TextSocialMedia, IDS_HOW_TO_PLAY_SOCIALMEDIA, eHowToPlay_ImageNone, 0, 0}, // eHowToPlay_SocialMedia
31 { eHowToPlay_TextBanList, IDS_HOW_TO_PLAY_BANLIST, eHowToPlay_ImageNone, 0, 0}, // eHowToPlay_BanList
32 { eHowToPlay_TextHostOptions, IDS_HOW_TO_PLAY_HOSTOPTIONS, eHowToPlay_ImageNone, 0, 0}, // eHowToPlay_HostOptions
33};
34
35
36//----------------------------------------------------------------------------------
37// Performs initialization tasks - retrieves controls.
38//----------------------------------------------------------------------------------
39HRESULT CScene_HowToPlay::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
40{
41 // Extract pad and required page from init data. We just put the data into the pointer rather than using it as an address.
42 size_t uiInitData = ( size_t )( pInitData->pvInitData );
43
44 m_iPad = ( int )( ( short )( uiInitData & 0xFFFF ) );
45 EHowToPlayPage eStartPage = ( EHowToPlayPage )( ( uiInitData >> 16 ) & 0xFFF ); // Ignores MSB which is set to 1!
46
47 TelemetryManager->RecordMenuShown(m_iPad, eUIScene_HowToPlay, (ETelemetry_HowToPlay_SubMenuId)eStartPage);
48
49 MapChildControls();
50
51 wstring wsTemp, inventoryString = app.GetString(IDS_INVENTORY);
52 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelCTItem],app.GetString(IDS_ITEM_HATCHET_WOOD));
53 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelCTGroup],app.GetString(IDS_GROUPNAME_TOOLS));
54 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelCTInventory3x3],inventoryString.c_str());
55 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelCItem],app.GetString(IDS_TILE_WORKBENCH));
56 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelCGroup],app.GetString(IDS_GROUPNAME_STRUCTURES));
57 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelCInventory2x2],inventoryString.c_str());
58 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelFFuel],app.GetString(IDS_FUEL));
59 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelFInventory],inventoryString.c_str());
60 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelFIngredient],app.GetString(IDS_INGREDIENT));
61 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelFChest],app.GetString(IDS_FURNACE));
62 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelLCInventory],inventoryString.c_str());
63 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelCreativeInventory],app.GetString(IDS_GROUPNAME_BUILDING_BLOCKS));
64 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelLCChest],app.GetString(IDS_CHEST));
65 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelSCInventory],inventoryString.c_str());
66 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelSCChest],app.GetString(IDS_CHEST));
67 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelIInventory],inventoryString.c_str());
68 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelDInventory],inventoryString.c_str());
69 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelDText],app.GetString(IDS_DISPENSER));
70 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelEEnchant],app.GetString(IDS_ENCHANT));
71 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelEInventory],inventoryString.c_str());
72 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelBBrew],app.GetString(IDS_BREWING_STAND));
73 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelBInventory],inventoryString.c_str());
74 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelAnvil_Inventory], inventoryString.c_str());
75
76 wsTemp = app.GetString(IDS_REPAIR_COST);
77 wsTemp.replace( wsTemp.find(L"%d"), 2, wstring(L"8") );
78 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelAnvil_Cost], wsTemp.c_str());
79
80 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelAnvil_ARepairAndName], app.GetString(IDS_REPAIR_AND_NAME));
81 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelTrading_Inventory], inventoryString.c_str());
82 //XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelTrading_Offer2], app.GetString(IDS_ITEM_HATCHET_DIAMOND));
83 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelTrading_Offer1], app.GetString(IDS_ITEM_EMERALD));
84 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelTrading_NeededForTrade], app.GetString(IDS_REQUIRED_ITEMS_FOR_TRADE));
85
86 wsTemp = app.GetString(IDS_VILLAGER_OFFERS_ITEM);
87 wsTemp = replaceAll(wsTemp,L"{*VILLAGER_TYPE*}",app.GetString(IDS_VILLAGER_PRIEST));
88 wsTemp.replace(wsTemp.find(L"%s"),2, app.GetString(IDS_TILE_LIGHT_GEM));
89 XuiControlSetText(m_aLabelControls[ eHowToPlay_LabelTrading_VillagerOffers], wsTemp.c_str());
90
91 if(app.GetLocalPlayerCount()>1)
92 {
93 app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad);
94 }
95
96
97 StartPage( eStartPage );
98
99 return S_OK;
100}
101
102HRESULT CScene_HowToPlay::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled)
103{
104 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode);
105
106 // Explicitly handle B button presses
107 switch(pInputData->dwKeyCode)
108 {
109 case VK_PAD_B:
110 case VK_ESCAPE:
111 {
112 app.NavigateBack(pInputData->UserIndex);
113 rfHandled = TRUE;
114 }
115 break;
116 case VK_PAD_A:
117 {
118 // Next page
119 int iNextPage = ( int )( m_eCurrPage ) + 1;
120 if ( iNextPage != eHowToPlay_NumPages )
121 {
122 StartPage( ( EHowToPlayPage )( iNextPage ) );
123 CXuiSceneBase::PlayUISFX(eSFX_Press);
124 }
125 rfHandled = TRUE;
126 }
127 break;
128 case VK_PAD_X:
129 {
130 // Next page
131 int iPrevPage = ( int )( m_eCurrPage ) - 1;
132 if ( iPrevPage >= 0 )
133 {
134 StartPage( ( EHowToPlayPage )( iPrevPage ) );
135 CXuiSceneBase::PlayUISFX(eSFX_Press);
136 }
137 rfHandled = TRUE;
138 }
139 break;
140 }
141 return S_OK;
142}
143
144
145void CScene_HowToPlay::StartPage( EHowToPlayPage ePage )
146{
147 int iBaseSceneUser;
148 // if we're not in the game, we need to use basescene 0
149 if(Minecraft::GetInstance()->level==NULL)
150 {
151 iBaseSceneUser=DEFAULT_XUI_MENU_USER;
152 }
153 else
154 {
155 iBaseSceneUser=m_iPad;
156 }
157 m_eCurrPage = ePage;
158
159 // Turn off everything.
160 for ( int i = 0; i < eHowToPlay_NumTexts; ++i )
161 {
162 m_aTextControls[ i ].SetShow( FALSE );
163 }
164 for ( int i = 0; i < eHowToPlay_NumImages; ++i )
165 {
166 m_aImageControls[ i ].SetShow( FALSE );
167 }
168 for ( int i = 0; i < eHowToPlay_NumLabels; ++i )
169 {
170 m_aLabelControls[ i ].SetShow( FALSE );
171 }
172
173 // Turn on just what we need for this screen.
174 SHowToPlayPageDef* pDef = &( gs_aPageDefs[ m_eCurrPage ] );
175
176 if ( pDef->m_iTextControlIndex != eHowToPlay_TextNone )
177 {
178 // Replace button identifiers in the text with actual button images.
179 wstring replacedText = app.FormatHTMLString(m_iPad, app.GetString( pDef->m_iTextStringID ));
180
181 // 4J-PB - replace the title with the platform specific title, and the platform name
182 replacedText = replaceAll(replacedText,L"{*PLATFORM_NAME*}",app.GetString(IDS_PLATFORM_NAME));
183 replacedText = replaceAll(replacedText,L"{*BACK_BUTTON*}",app.GetString(IDS_BACK_BUTTON));
184 replacedText = replaceAll(replacedText,L"{*DISABLES_ACHIEVEMENTS*}",app.GetString(IDS_HOST_OPTION_DISABLES_ACHIEVEMENTS));
185
186 // Set the text colour
187 wstring finalText(replacedText.c_str() );
188 wchar_t startTags[64];
189 swprintf(startTags,64,L"<font color=\"#%08x\">",app.GetHTMLColour(eHTMLColor_White));
190 finalText = startTags + finalText;
191
192 // Set the text in the xui scene.
193 m_aTextControls[ pDef->m_iTextControlIndex ].SetText( finalText.c_str() );
194
195 // Make it visible.
196 m_aTextControls[ pDef->m_iTextControlIndex ].SetShow( TRUE );
197
198 XuiElementSetUserFocus(m_aTextControls[ pDef->m_iTextControlIndex ].m_hObj, m_iPad);
199 }
200
201 if(pDef->m_iLabelCount!=0)
202 {
203 for(int i=pDef->m_iLabelStartIndex;i<(pDef->m_iLabelStartIndex+pDef->m_iLabelCount);i++)
204 {
205 m_aLabelControls[i].SetShow( TRUE );
206 }
207 }
208
209 if ( pDef->m_iImageControlIndex != eHowToPlay_ImageNone )
210 {
211 m_aImageControls[ pDef->m_iImageControlIndex ].SetShow( TRUE );
212 }
213
214 // Tool tips.
215 int iPage = ( int )( m_eCurrPage );
216 if ( iPage == 0 )
217 {
218 // No previous page.
219 ui.SetTooltips( iBaseSceneUser, IDS_HOW_TO_PLAY_NEXT, IDS_TOOLTIPS_BACK, -1 );
220 }
221 else if ( ( iPage + 1 ) == eHowToPlay_NumPages )
222 {
223 // No next page.
224 ui.SetTooltips( iBaseSceneUser, -1, IDS_TOOLTIPS_BACK, IDS_HOW_TO_PLAY_PREV );
225 }
226 else
227 {
228 ui.SetTooltips( iBaseSceneUser, IDS_HOW_TO_PLAY_NEXT, IDS_TOOLTIPS_BACK, IDS_HOW_TO_PLAY_PREV );
229 }
230
231 TelemetryManager->RecordMenuShown(m_iPad, eUIScene_HowToPlay, (ETelemetry_HowToPlay_SubMenuId)ePage);
232}
233
234HRESULT CScene_HowToPlay::OnCustomMessage_Splitscreenplayer(bool bJoining, BOOL& bHandled)
235{
236 bHandled=true;
237 return app.AdjustSplitscreenScene_PlayerChanged(m_hObj,&m_OriginalPosition,m_iPad,bJoining);
238}