the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 181 lines 5.1 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "UIScene_Keyboard.h" 4 5#define KEYBOARD_DONE_TIMER_ID 0 6#define KEYBOARD_DONE_TIMER_TIME 100 7 8UIScene_Keyboard::UIScene_Keyboard(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) 9{ 10 // Setup all the Iggy references we need for this scene 11 initialiseMovie(); 12 13 m_EnterTextLabel.init(L"Enter Sign Text"); 14 15 m_KeyboardTextInput.init(L"", -1); 16 m_KeyboardTextInput.SetCharLimit(15); 17 18 m_ButtonSpace.init(L"Space", -1); 19 m_ButtonCursorLeft.init(L"Cursor Left", -1); 20 m_ButtonCursorRight.init(L"Cursor Right", -1); 21 m_ButtonCaps.init(L"Caps", -1); 22 m_ButtonDone.init(L"Done", 0); // only the done button needs an id, the others will never call back! 23 m_ButtonSymbols.init(L"Symbols", -1); 24 m_ButtonBackspace.init(L"Backspace", -1); 25 26 // Initialise function keyboard Buttons and set alternative symbol button string 27 wstring label = L"Abc"; 28 IggyStringUTF16 stringVal; 29 stringVal.string = (IggyUTF16*)label.c_str(); 30 stringVal.length = label.length(); 31 32 IggyDataValue result; 33 IggyDataValue value[1]; 34 value[0].type = IGGY_DATATYPE_string_UTF16; 35 value[0].string16 = stringVal; 36 37 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcInitFunctionButtons , 1 , value ); 38 39 m_bKeyboardDonePressed = false; 40 41 parentLayer->addComponent(iPad,eUIComponent_MenuBackground); 42} 43 44UIScene_Keyboard::~UIScene_Keyboard() 45{ 46 m_parentLayer->removeComponent(eUIComponent_MenuBackground); 47} 48 49wstring UIScene_Keyboard::getMoviePath() 50{ 51 if(app.GetLocalPlayerCount() > 1 && !m_parentLayer->IsFullscreenGroup()) 52 { 53 return L"KeyboardSplit"; 54 } 55 else 56 { 57 return L"Keyboard"; 58 } 59} 60 61void UIScene_Keyboard::updateTooltips() 62{ 63 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK, -1, -1); 64} 65 66bool UIScene_Keyboard::allowRepeat(int key) 67{ 68 // 4J - TomK - we want to allow X and Y repeats! 69 switch(key) 70 { 71 case ACTION_MENU_OK: 72 case ACTION_MENU_CANCEL: 73 case ACTION_MENU_A: 74 case ACTION_MENU_B: 75 case ACTION_MENU_PAUSEMENU: 76 //case ACTION_MENU_X: 77 //case ACTION_MENU_Y: 78 return false; 79 } 80 return true; 81} 82 83void UIScene_Keyboard::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) 84{ 85 IggyDataValue result; 86 IggyResult out; 87 88 if(repeat || pressed) 89 { 90 switch(key) 91 { 92 case ACTION_MENU_CANCEL: 93 navigateBack(); 94 handled = true; 95 break; 96 case ACTION_MENU_X: // X 97 out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcBackspaceButtonPressed, 0 , NULL ); 98 handled = true; 99 break; 100 case ACTION_MENU_PAGEUP: // LT 101 out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSymbolButtonPressed, 0 , NULL ); 102 handled = true; 103 break; 104 case ACTION_MENU_Y: // Y 105 out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSpaceButtonPressed, 0 , NULL ); 106 handled = true; 107 break; 108 case ACTION_MENU_STICK_PRESS: // LS 109 out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcCapsButtonPressed, 0 , NULL ); 110 handled = true; 111 break; 112 case ACTION_MENU_LEFT_SCROLL: // LB 113 out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcCursorLeftButtonPressed, 0 , NULL ); 114 handled = true; 115 break; 116 case ACTION_MENU_RIGHT_SCROLL: // RB 117 out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcCursorRightButtonPressed, 0 , NULL ); 118 handled = true; 119 break; 120 case ACTION_MENU_PAUSEMENU: // Start 121 if(!m_bKeyboardDonePressed) 122 { 123 out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcDoneButtonPressed, 0 , NULL ); 124 125 // kick off done timer 126 addTimer(KEYBOARD_DONE_TIMER_ID,KEYBOARD_DONE_TIMER_TIME); 127 m_bKeyboardDonePressed = true; 128 } 129 handled = true; 130 break; 131 } 132 } 133 134 switch(key) 135 { 136 case ACTION_MENU_OK: 137 case ACTION_MENU_LEFT: 138 case ACTION_MENU_RIGHT: 139 case ACTION_MENU_UP: 140 case ACTION_MENU_DOWN: 141 sendInputToMovie(key, repeat, pressed, released); 142 handled = true; 143 break; 144 } 145} 146 147void UIScene_Keyboard::handlePress(F64 controlId, F64 childId) 148{ 149 if((int)controlId == 0) 150 { 151 // Done has been pressed. At this point we can query for the input string and pass it on to wherever it is needed. 152 // we can not query for m_KeyboardTextInput.getLabel() here because we're in an iggy callback so we need to wait a frame. 153 if(!m_bKeyboardDonePressed) 154 { 155 // kick off done timer 156 addTimer(KEYBOARD_DONE_TIMER_ID,KEYBOARD_DONE_TIMER_TIME); 157 m_bKeyboardDonePressed = true; 158 } 159 } 160} 161 162void UIScene_Keyboard::handleTimerComplete(int id) 163{ 164 if(id == KEYBOARD_DONE_TIMER_ID) 165 { 166 // remove timer 167 killTimer(KEYBOARD_DONE_TIMER_ID); 168 169 // we're done here! 170 KeyboardDonePressed(); 171 } 172} 173 174void UIScene_Keyboard::KeyboardDonePressed() 175{ 176 // Debug 177 app.DebugPrintf("UI Keyboard - DONE - [%ls]\n", m_KeyboardTextInput.getLabel()); 178 179 // ToDo: Keyboard can now pass on its final string value and close itself down 180 navigateBack(); 181}