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_Ctrl_4JEdit.h"
3
4
5
6HRESULT CXuiCtrl4JEdit::OnInit(XUIMessageInit* pInitData, BOOL& rfHandled)
7{
8 HRESULT hr=S_OK;
9
10 // set a limit for the text box
11 m_uTextLimit=XUI_4JEDIT_MAX_CHARS-1;
12 XuiEditSetTextLimit(m_hObj,m_uTextLimit);
13 // Find the text limit. (Add one for NULL terminator)
14 //m_uTextLimit = min( XuiEditGetTextLimit(m_hObj) + 1, XUI_4JEDIT_MAX_CHARS);
15
16 ZeroMemory( wchText , sizeof(WCHAR)*(m_uTextLimit+1) );
17
18 m_bReadOnly = false;
19 m_uiTitle = 0;
20 m_uiText =0;
21 m_eKeyboardMode=C_4JInput::EKeyboardMode_Default;
22 return hr;
23}
24
25
26HRESULT CXuiCtrl4JEdit::SetTextLimit(int iLimit)
27{
28 CXuiCtrl4JEdit *pThis;
29 HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
30 if (FAILED(hr))
31 return hr;
32 if(iLimit<XUI_4JEDIT_MAX_CHARS)
33 {
34 pThis->m_uTextLimit=iLimit;
35 XuiEditSetTextLimit(pThis->m_hObj,iLimit);
36 ZeroMemory( pThis->wchText , sizeof(WCHAR)*XUI_4JEDIT_MAX_CHARS );
37 }
38 return S_OK;
39}
40HRESULT CXuiCtrl4JEdit::SetCaretPosition(int iPos)
41{
42 CXuiCtrl4JEdit *pThis;
43 HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
44 if (FAILED(hr))
45 return hr;
46 XuiEditSetCaretPosition(pThis->m_hObj,iPos);
47 return S_OK;
48}
49
50HRESULT CXuiCtrl4JEdit::SetTitleAndText(unsigned int uiTitle, unsigned int uiText)
51{
52 CXuiCtrl4JEdit *pThis;
53 HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
54 if (FAILED(hr))
55 return hr;
56 pThis->m_uiTitle=uiTitle;
57 pThis->m_uiText=uiText;
58
59 return S_OK;
60}
61
62HRESULT CXuiCtrl4JEdit::SetReadOnly(bool bReadOnly)
63{
64 // Attempt to make the change on the actual original version of this object that XUI made itself, rather
65 // than the copy we make ourselves and then map to it, which shares the same handle
66 CXuiCtrl4JEdit *pThis;
67 HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
68 if (FAILED(hr))
69 return hr;
70 pThis->m_bReadOnly = bReadOnly;
71
72 return S_OK;
73}
74
75HRESULT CXuiCtrl4JEdit::SetKeyboardType(C_4JInput::EKeyboardMode eKeyboardMode)
76{
77 CXuiCtrl4JEdit *pThis;
78 HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
79 if (FAILED(hr))
80 return hr;
81 pThis->m_eKeyboardMode= eKeyboardMode;
82 return S_OK;
83}
84
85// HRESULT CXuiCtrl4JEdit::SetIPMode(bool bIPMode)
86// {
87// // Attempt to make the change on the actual original version of this object that XUI made itself, rather
88// // than the copy we make ourselves and then map to it, which shares the same handle
89// CXuiCtrl4JEdit *pThis;
90// HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
91// if (FAILED(hr))
92// return hr;
93// pThis->m_bIPMode= bIPMode;
94//
95// return S_OK;
96// }
97
98// HRESULT CXuiCtrl4JEdit::SetExtendedMode(bool bExtendedMode)
99// {
100// // Attempt to make the change on the actual original version of this object that XUI made itself, rather
101// // than the copy we make ourselves and then map to it, which shares the same handle
102// CXuiCtrl4JEdit *pThis;
103// HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
104// if (FAILED(hr))
105// return hr;
106// pThis->m_bExtendedMode= bExtendedMode;
107//
108// return S_OK;
109// }
110
111HRESULT CXuiCtrl4JEdit::OnChar(XUIMessageChar* pInputData, BOOL& rfHandled)
112{
113 CXuiCtrl4JEdit *pThis;
114 HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
115 if (FAILED(hr))
116 return hr;
117
118 HXUIOBJ hBaseObj;
119
120 // need to send the key down to the base object, so that when we notify the parent, the edit control has been updated with the right text
121 hr=XuiGetBaseObject(pThis->m_hObj,&hBaseObj);
122
123 XUIMessage xuiMsg;
124 XUIMessageChar xuiMsgChar;
125 XuiMessageChar( &xuiMsg, &xuiMsgChar, pInputData->wch, pInputData->dwFlags, pInputData->UserIndex );
126 // Send the XM_CHAR message.
127 XuiSendMessage( hBaseObj, &xuiMsg );
128
129 rfHandled = TRUE;
130 SendNotifyValueChanged((int)pInputData->wch);
131
132 return hr;
133}
134
135HRESULT CXuiCtrl4JEdit::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled)
136{
137 CXuiCtrl4JEdit *pThis;
138 HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
139 if (FAILED(hr))
140 return hr;
141
142 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode);
143
144 //HRESULT hr = S_OK;
145
146 if( pThis->m_bReadOnly ) return hr;
147
148 // Find the text limit. (Add one for NULL terminator)
149 //m_uTextLimit = min( XuiEditGetTextLimit(m_hObj) + 1, XUI_4JEDIT_MAX_CHARS);
150
151 if((((pInputData->dwKeyCode == VK_PAD_A) && (pInputData->wch == 0)) || (pInputData->dwKeyCode == VK_PAD_START)) && !(pInputData->dwFlags & XUI_INPUT_FLAG_REPEAT))
152 {
153 pThis->RequestKeyboard(pInputData->UserIndex);
154 rfHandled = TRUE;
155 }
156
157 return hr;
158}
159
160void CXuiCtrl4JEdit::RequestKeyboard(int iPad)
161{
162 InputManager.RequestKeyboard(m_uiTitle,GetText(),m_uiText,iPad,wchText,m_uTextLimit+1,&CXuiCtrl4JEdit::KeyboardReturned,this,m_eKeyboardMode,app.GetStringTable());
163}
164
165
166//-----------------------------------------------------------------------------
167HRESULT CXuiCtrl4JEdit::SendNotifyValueChanged(int iValue)
168{
169 CXuiCtrl4JEdit *pThis;
170 HRESULT hr = XuiObjectFromHandle(m_hObj, (void **) &pThis);
171 if (FAILED(hr))
172 return hr;
173 HXUIOBJ hParent;
174 //HRESULT hr=S_OK;
175 XUIMessage msg;
176 XUINotify msgNotify;
177 XUINotifyValueChanged msgNotifyValueChanged;
178
179 XuiElementGetParent(pThis->m_hObj, &hParent);
180 XuiNotifyValueChanged(&msg, &msgNotify, &msgNotifyValueChanged, XuiGetOuter(pThis->m_hObj), iValue);
181 XuiBubbleMessage(XuiGetOuter(hParent), &msg);
182
183 return hr;
184}
185
186int CXuiCtrl4JEdit::KeyboardReturned(void *pParam,bool bSet)
187{
188 CXuiCtrl4JEdit* pClass = (CXuiCtrl4JEdit*)pParam;
189 HRESULT hr = S_OK;
190
191 if(bSet)
192 {
193 pClass->SetText(pClass->wchText);
194 // need to move the caret to the end of the newly set text
195 XuiEditSetCaretPosition(pClass->m_hObj, (int)wcsnlen(pClass->wchText, 50));
196 pClass->SendNotifyValueChanged(10); // 10 for a return
197 }
198
199 return hr;
200}