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 "UI.h"
3#include "UIScene_SignEntryMenu.h"
4#include "..\..\Minecraft.h"
5#include "..\..\MultiPlayerLocalPlayer.h"
6#include "..\..\MultiPlayerLevel.h"
7#include "..\..\ClientConnection.h"
8#include "..\..\..\Minecraft.World\net.minecraft.world.level.h"
9#include "..\..\..\Minecraft.World\net.minecraft.world.level.tile.entity.h"
10
11UIScene_SignEntryMenu::UIScene_SignEntryMenu(int iPad, void *_initData, UILayer *parentLayer) : UIScene(iPad, parentLayer)
12{
13 // Setup all the Iggy references we need for this scene
14 initialiseMovie();
15
16 SignEntryScreenInput* initData = (SignEntryScreenInput*)_initData;
17 m_sign = initData->sign;
18
19 m_bConfirmed = false;
20 m_bIgnoreInput = false;
21
22 m_buttonConfirm.init(app.GetString(IDS_DONE), eControl_Confirm);
23 m_labelMessage.init(app.GetString(IDS_EDIT_SIGN_MESSAGE));
24
25 for(unsigned int i = 0; i<4; ++i)
26 {
27#if TO_BE_IMPLEMENTED
28 // Have to have the Latin alphabet here, since that's what we have on the sign in-game
29 // but because the JAP/KOR/CHN fonts don't have extended European characters, let's restrict those languages to not having the extended character set, since they can't see what they are typing
30 switch(XGetLanguage())
31 {
32 case XC_LANGUAGE_JAPANESE:
33 case XC_LANGUAGE_TCHINESE:
34 case XC_LANGUAGE_KOREAN:
35 case XC_LANGUAGE_RUSSIAN:
36 m_signRows[i].SetKeyboardType(C_4JInput::EKeyboardMode_Alphabet);
37 break;
38 default:
39 m_signRows[i].SetKeyboardType(C_4JInput::EKeyboardMode_Full);
40 break;
41 }
42
43 m_signRows[i].SetText( m_sign->GetMessage(i).c_str() );
44 m_signRows[i].SetTextLimit(15);
45 // Set the title and desc for the edit keyboard popup
46 m_signRows[i].SetTitleAndText(IDS_SIGN_TITLE,IDS_SIGN_TITLE_TEXT);
47#endif
48 m_textInputLines[i].init(m_sign->GetMessage(i).c_str(), i);
49 }
50
51 parentLayer->addComponent(iPad,eUIComponent_MenuBackground);
52}
53
54UIScene_SignEntryMenu::~UIScene_SignEntryMenu()
55{
56 m_parentLayer->removeComponent(eUIComponent_MenuBackground);
57}
58
59wstring UIScene_SignEntryMenu::getMoviePath()
60{
61 if(app.GetLocalPlayerCount() > 1)
62 {
63 return L"SignEntryMenuSplit";
64 }
65 else
66 {
67 return L"SignEntryMenu";
68 }
69}
70
71void UIScene_SignEntryMenu::updateTooltips()
72{
73 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
74}
75
76void UIScene_SignEntryMenu::tick()
77{
78 UIScene::tick();
79
80 if(m_bConfirmed)
81 {
82 m_bConfirmed = false;
83
84 // Set the sign text here so we on;y call the verify once it has been set, not while we're typing in to it
85 for(int i=0;i<4;i++)
86 {
87 wstring temp=m_textInputLines[i].getLabel();
88 m_sign->SetMessage(i,temp);
89 }
90
91 m_sign->setChanged();
92
93 Minecraft *pMinecraft=Minecraft::GetInstance();
94 // need to send the new data
95 if (pMinecraft->level->isClientSide)
96 {
97 shared_ptr<MultiplayerLocalPlayer> player = pMinecraft->localplayers[m_iPad];
98 if(player != NULL && player->connection && player->connection->isStarted())
99 {
100 player->connection->send( shared_ptr<SignUpdatePacket>( new SignUpdatePacket(m_sign->x, m_sign->y, m_sign->z, m_sign->IsVerified(), m_sign->IsCensored(), m_sign->GetMessages()) ) );
101 }
102 }
103 ui.CloseUIScenes(m_iPad);
104 }
105}
106
107void UIScene_SignEntryMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
108{
109 if(m_bConfirmed || m_bIgnoreInput) return;
110
111 ui.AnimateKeyPress(iPad, key, repeat, pressed, released);
112
113 switch(key)
114 {
115 case ACTION_MENU_CANCEL:
116 if(pressed)
117 {
118 // user backed out, so wipe the sign
119 wstring temp=L"";
120
121 for(int i=0;i<4;i++)
122 {
123 m_sign->SetMessage(i,temp);
124 }
125
126 navigateBack();
127 ui.PlayUISFX(eSFX_Back);
128 handled = true;
129 }
130 break;
131 case ACTION_MENU_OK:
132#ifdef __ORBIS__
133 case ACTION_MENU_TOUCHPAD_PRESS:
134#endif
135 case ACTION_MENU_UP:
136 case ACTION_MENU_DOWN:
137 sendInputToMovie(key, repeat, pressed, released);
138 handled = true;
139 break;
140 }
141}
142
143int UIScene_SignEntryMenu::KeyboardCompleteCallback(LPVOID lpParam,bool bRes)
144{
145 // 4J HEG - No reason to set value if keyboard was cancelled
146 UIScene_SignEntryMenu *pClass=(UIScene_SignEntryMenu *)lpParam;
147 pClass->m_bIgnoreInput = false;
148 if (bRes)
149 {
150 uint16_t pchText[128];
151 ZeroMemory(pchText, 128 * sizeof(uint16_t) );
152 InputManager.GetText(pchText);
153 pClass->m_textInputLines[pClass->m_iEditingLine].setLabel((wchar_t *)pchText);
154 }
155 return 0;
156}
157
158void UIScene_SignEntryMenu::handlePress(F64 controlId, F64 childId)
159{
160 switch((int)controlId)
161 {
162 case eControl_Confirm:
163 {
164 m_bConfirmed = true;
165 }
166 break;
167 case eControl_Line1:
168 case eControl_Line2:
169 case eControl_Line3:
170 case eControl_Line4:
171 {
172 m_iEditingLine = (int)controlId;
173 m_bIgnoreInput = true;
174#ifdef _XBOX_ONE
175 // 4J-PB - Xbox One uses the Windows virtual keyboard, and doesn't have the Xbox 360 Latin keyboard type, so we can't restrict the input set to alphanumeric. The closest we get is the emailSmtpAddress type.
176 int language = XGetLanguage();
177 switch(language)
178 {
179 case XC_LANGUAGE_JAPANESE:
180 case XC_LANGUAGE_KOREAN:
181 case XC_LANGUAGE_TCHINESE:
182 InputManager.RequestKeyboard(app.GetString(IDS_SIGN_TITLE),m_textInputLines[m_iEditingLine].getLabel(),(DWORD)m_iPad,15,&UIScene_SignEntryMenu::KeyboardCompleteCallback,this,C_4JInput::EKeyboardMode_Email);
183 break;
184 default:
185 InputManager.RequestKeyboard(app.GetString(IDS_SIGN_TITLE),m_textInputLines[m_iEditingLine].getLabel(),(DWORD)m_iPad,15,&UIScene_SignEntryMenu::KeyboardCompleteCallback,this,C_4JInput::EKeyboardMode_Alphabet);
186 break;
187 }
188#else
189 InputManager.RequestKeyboard(app.GetString(IDS_SIGN_TITLE),m_textInputLines[m_iEditingLine].getLabel(),(DWORD)m_iPad,15,&UIScene_SignEntryMenu::KeyboardCompleteCallback,this,C_4JInput::EKeyboardMode_Alphabet);
190#endif
191 }
192 break;
193 }
194}
195
196void UIScene_SignEntryMenu::handleDestroy()
197{
198#ifdef __PSVITA__
199 app.DebugPrintf("missing InputManager.DestroyKeyboard on Vita !!!!!!\n");
200#endif
201
202 // another player destroyed the anvil, so shut down the keyboard if it is displayed
203#if ( defined __PS3__ || defined __ORBIS__ || defined _DURANGO)
204 InputManager.DestroyKeyboard();
205#endif
206}