the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "XUI_TextEntry.h"
3#include "..\..\MultiplayerLocalPlayer.h"
4
5
6CScene_TextEntry::CommandParams CScene_TextEntry::CommandA[CScene_TextEntry::eCommand_MAX]=
7{
8 { L"goto", L"%s%c%d%c%d" },
9 { L"give", L"%s%c%s" }
10};
11
12HRESULT CScene_TextEntry::Init_Commands()
13{
14 for(int i=0;i<eCommand_MAX;i++)
15 {
16 m_CommandSet[CommandA[i].wchCommand]=i;
17 }
18 return S_OK;
19}
20
21//----------------------------------------------------------------------------------
22// Performs initialization tasks - retrieves controls.
23//----------------------------------------------------------------------------------
24HRESULT CScene_TextEntry::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
25{
26 MapChildControls();
27 XuiTextInputParams *params = (XuiTextInputParams *)pInitData->pvInitData;
28 m_iPad=params->iPad;
29 m_wchInitialChar=params->wch;
30 delete params;
31
32 WCHAR wchEditText[40];
33
34 Init_Commands();
35
36 ZeroMemory(wchEditText,sizeof(WCHAR)*40);
37 wchEditText[0]=tolower(m_wchInitialChar);
38
39 m_EditText.SetTextLimit(40);
40 m_EditText.SetText(wchEditText);
41 // set the caret to the end of the default text
42 m_EditText.SetCaretPosition(1);
43
44 m_EditText.SetTitleAndText(IDS_NAME_WORLD,IDS_NAME_WORLD_TEXT);
45
46 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_EXECUTE_COMMAND, IDS_TOOLTIPS_BACK);
47 return S_OK;
48}
49
50HRESULT CScene_TextEntry::OnNotifyValueChanged (HXUIOBJ hObjSource, XUINotifyValueChanged* pValueChangedData, BOOL& rfHandled)
51{
52 // If the user presses return, interpret the string, and exit
53 if(pValueChangedData->nValue==10)
54 {
55 LPCWSTR pText = m_EditText.GetText();
56
57 if(pText)
58 {
59 wstring wText = pText;
60 InterpretString(wText);
61 }
62
63 app.NavigateBack(m_iPad);
64 rfHandled = TRUE;
65 }
66
67 return S_OK;
68}
69
70HRESULT CScene_TextEntry::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled)
71{
72 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode);
73
74 // Explicitly handle B button presses
75 switch(pInputData->dwKeyCode)
76 {
77 case VK_PAD_A:
78 {
79 LPCWSTR pText = m_EditText.GetText();
80
81 if(pText)
82 {
83 wstring wText = pText;
84 InterpretString(wText);
85 }
86
87 app.NavigateBack(m_iPad);
88 rfHandled = TRUE;
89 }
90 break;
91
92 case VK_PAD_B:
93 case VK_ESCAPE:
94
95 app.NavigateBack(pInputData->UserIndex);
96 rfHandled = TRUE;
97 break;
98 }
99 return S_OK;
100}
101
102HRESULT CScene_TextEntry::InterpretString(wstring &wsText)
103{
104 wstring wsFormat;
105 WCHAR wchCommand[40];
106 int iCommand=-1;
107 WCHAR wchSep[2];
108
109#ifdef __PS3__
110 // 4J Stu - The Xbox version uses swscanf_s which isn't available in GCC.
111 swscanf(wsText.c_str(), L"%40s", wchCommand);
112#else
113 swscanf_s(wsText.c_str(), L"%s", wchCommand,40);
114#endif
115
116 AUTO_VAR(it, m_CommandSet.find(wchCommand));
117 if(it != m_CommandSet.end())
118 {
119 // found it
120
121 iCommand=it->second;
122
123 switch(iCommand)
124 {
125 case eCommand_Teleport:
126 {
127 int x,z;
128
129#ifdef __PS3__
130 // 4J Stu - The Xbox version uses swscanf_s which isn't available in GCC.
131 swscanf(wsText.c_str(), L"%40s%c%d%c%d", wchCommand,wchSep,&x,wchSep,&z);
132#else
133 swscanf_s(wsText.c_str(), L"%s%c%d%c%d", wchCommand,40,wchSep,2,&x,wchSep,2, &z);
134#endif
135
136 app.DebugPrintf("eCommand_Teleport x=%d z=%d\n",x,z);
137
138 // check the bounds
139 int iBound=54*16;
140 if( (x>-iBound) && (x<iBound) && (z>-iBound) && (z<iBound) )
141 {
142 // valid numbers
143 Minecraft *pMinecraft=Minecraft::GetInstance();
144 pMinecraft->localplayers[m_iPad]->teleportTo(x,pMinecraft->localplayers[m_iPad]->y,z);
145 }
146 }
147 break;
148 case eCommand_Give:
149 {
150 int iItem,iCount;
151
152#ifdef __PS3__
153 // 4J Stu - The Xbox version uses swscanf_s which isn't available in GCC.
154 swscanf(wsText.c_str(), L"%40s%c%d%c%d", wchCommand,wchSep,&iItem,wchSep,&iCount);
155#else
156 swscanf_s(wsText.c_str(), L"%s%c%d%c%d", wchCommand,40,wchSep,2,&iItem,wchSep,2, &iCount);
157#endif
158 app.DebugPrintf("eCommand_Give, item=%d count=%d\n",iItem,iCount);
159 Minecraft *pMinecraft=Minecraft::GetInstance();
160 for(int i=0;i<iCount;i++)
161 pMinecraft->localplayers[m_iPad]->drop(); // shared_ptr<ItemInstance>(new ItemInstance( iItem, 1, 0 )) );
162 }
163
164 break;
165 default:
166 app.DebugPrintf("Unknown command\n");
167 break;
168 }
169 }
170
171 return S_OK;
172}