the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 241 lines 6.2 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "UIControl_ButtonList.h" 4 5UIControl_ButtonList::UIControl_ButtonList() 6{ 7 m_itemCount = 0; 8 m_iCurrentSelection = 0; 9} 10 11bool UIControl_ButtonList::setupControl(UIScene *scene, IggyValuePath *parent, const string &controlName) 12{ 13 UIControl::setControlType(UIControl::eButtonList); 14 bool success = UIControl_Base::setupControl(scene,parent,controlName); 15 16 //SlotList specific initialisers 17 m_addNewItemFunc = registerFastName(L"addNewItem"); 18 m_removeAllItemsFunc = registerFastName(L"removeAllItems"); 19 m_funcHighlightItem = registerFastName(L"HighlightItem"); 20 m_funcRemoveItem = registerFastName(L"RemoveItem"); 21 m_funcSetButtonLabel = registerFastName(L"SetButtonLabel"); 22 m_funcSetTouchFocus = registerFastName(L"SetTouchFocus"); 23 m_funcCanTouchTrigger = registerFastName(L"CanTouchTrigger"); 24 25 return success; 26} 27 28void UIControl_ButtonList::init(int id) 29{ 30 m_id = id; 31 32 IggyDataValue result; 33 IggyDataValue value[1]; 34 value[0].type = IGGY_DATATYPE_number; 35 value[0].number = id; 36 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_initFunc , 1 , value ); 37 38 #ifdef __PSVITA__ 39 // 4J-PB - add this buttonlist to the vita touch box list 40 41 switch(m_parentScene->GetParentLayer()->m_iLayer) 42 { 43 case eUILayer_Fullscreen: 44 case eUILayer_Scene: 45 case eUILayer_HUD: 46 ui.TouchBoxAdd(this,m_parentScene); 47 break; 48} 49 #endif 50} 51 52void UIControl_ButtonList::ReInit() 53{ 54 UIControl_Base::ReInit(); 55 init(m_id); 56 m_itemCount = 0; 57 m_iCurrentSelection = 0; 58} 59 60void UIControl_ButtonList::clearList() 61{ 62 IggyDataValue result; 63 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_removeAllItemsFunc , 0 , NULL ); 64 65 m_itemCount = 0; 66} 67 68void UIControl_ButtonList::addItem(const string &label) 69{ 70 addItem(label, m_itemCount); 71} 72 73void UIControl_ButtonList::addItem(const wstring &label) 74{ 75 addItem(label, m_itemCount); 76} 77 78void UIControl_ButtonList::addItem(const string &label, int data) 79{ 80 IggyDataValue result; 81 IggyDataValue value[2]; 82 83 IggyStringUTF8 stringVal; 84 stringVal.string = (char*)label.c_str(); 85 stringVal.length = (S32)label.length(); 86 value[0].type = IGGY_DATATYPE_string_UTF8; 87 value[0].string8 = stringVal; 88 89 value[1].type = IGGY_DATATYPE_number; 90 value[1].number = data; 91 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_addNewItemFunc , 2 , value ); 92 93 ++m_itemCount; 94} 95 96void UIControl_ButtonList::addItem(const wstring &label, int data) 97{ 98 IggyDataValue result; 99 IggyDataValue value[2]; 100 101 IggyStringUTF16 stringVal; 102 stringVal.string = (IggyUTF16*)label.c_str(); 103 stringVal.length = label.length(); 104 value[0].type = IGGY_DATATYPE_string_UTF16; 105 value[0].string16 = stringVal; 106 107 value[1].type = IGGY_DATATYPE_number; 108 value[1].number = data; 109 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_addNewItemFunc , 2 , value ); 110 111 ++m_itemCount; 112} 113 114void UIControl_ButtonList::removeItem(int index) 115{ 116 IggyDataValue result; 117 IggyDataValue value[1]; 118 119 value[0].type = IGGY_DATATYPE_number; 120 value[0].number = index; 121 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_funcRemoveItem , 1 , value ); 122 123 --m_itemCount; 124} 125 126void UIControl_ButtonList::setCurrentSelection(int iSelection) 127{ 128 IggyDataValue result; 129 IggyDataValue value[1]; 130 131 value[0].type = IGGY_DATATYPE_number; 132 value[0].number = iSelection; 133 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_funcHighlightItem , 1 , value ); 134} 135 136int UIControl_ButtonList::getCurrentSelection() 137{ 138 return m_iCurrentSelection; 139} 140 141void UIControl_ButtonList::updateChildFocus(int iChild) 142{ 143 m_iCurrentSelection = iChild; 144} 145 146void UIControl_ButtonList::setButtonLabel(int iButtonId, const wstring &label) 147{ 148 IggyDataValue result; 149 IggyDataValue value[2]; 150 151 value[0].type = IGGY_DATATYPE_number; 152 value[0].number = iButtonId; 153 154 IggyStringUTF16 stringVal; 155 stringVal.string = (IggyUTF16*)label.c_str(); 156 stringVal.length = label.length(); 157 value[1].type = IGGY_DATATYPE_string_UTF16; 158 value[1].string16 = stringVal; 159 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie(), &result, getIggyValuePath(), m_funcSetButtonLabel, 2 , value ); 160} 161 162#ifdef __PSVITA__ 163void UIControl_ButtonList::SetTouchFocus(S32 iX, S32 iY, bool bRepeat) 164{ 165 IggyDataValue result; 166 IggyDataValue value[3]; 167 168 value[0].type = IGGY_DATATYPE_number; 169 value[0].number = iX; 170 value[1].type = IGGY_DATATYPE_number; 171 value[1].number = iY; 172 value[2].type = IGGY_DATATYPE_boolean; 173 value[2].boolval = bRepeat; 174 175 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie(), &result, getIggyValuePath(), m_funcSetTouchFocus, 3 , value ); 176} 177 178bool UIControl_ButtonList::CanTouchTrigger(S32 iX, S32 iY) 179{ 180 IggyDataValue result; 181 IggyDataValue value[2]; 182 183 value[0].type = IGGY_DATATYPE_number; 184 value[0].number = iX; 185 value[1].type = IGGY_DATATYPE_number; 186 value[1].number = iY; 187 188 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie(), &result, getIggyValuePath(), m_funcCanTouchTrigger, 2 , value ); 189 190 S32 bCanTouchTrigger = false; 191 if(result.type == IGGY_DATATYPE_boolean) 192 { 193 bCanTouchTrigger = (bool)result.boolval; 194 } 195 return bCanTouchTrigger; 196} 197#endif 198 199 200void UIControl_DynamicButtonList::tick() 201{ 202 UIControl_ButtonList::tick(); 203 204 int buttonIndex = 0; 205 vector<UIString>::iterator itr; 206 for (itr = m_labels.begin(); itr != m_labels.end(); itr++) 207 { 208 if ( itr->needsUpdating() ) 209 { 210 setButtonLabel(buttonIndex, itr->getString()); 211 itr->setUpdated(); 212 } 213 buttonIndex++; 214 } 215} 216 217void UIControl_DynamicButtonList::addItem(UIString label, int data) 218{ 219 if (data < 0) data = m_itemCount; 220 221 if (data < m_labels.size()) 222 { 223 m_labels[data] = label; 224 } 225 else 226 { 227 while (data > m_labels.size()) 228 { 229 m_labels.push_back(UIString()); 230 } 231 m_labels.push_back(label); 232 } 233 234 UIControl_ButtonList::addItem(label.getString(), data); 235} 236 237void UIControl_DynamicButtonList::removeItem(int index) 238{ 239 m_labels.erase( m_labels.begin() + index ); 240 UIControl_ButtonList::removeItem(index); 241}