the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 153 lines 3.8 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "UIControl.h" 4#include "..\..\..\Minecraft.World\StringHelpers.h" 5#include "..\..\..\Minecraft.World\JavaMath.h" 6 7UIControl::UIControl() 8{ 9 m_parentScene = NULL; 10 m_lastOpacity = 1.0f; 11 m_controlName = ""; 12 m_isVisible = true; 13 m_bHidden = false; 14 m_eControlType = eNoControl; 15} 16 17bool UIControl::setupControl(UIScene *scene, IggyValuePath *parent, const string &controlName) 18{ 19 m_parentScene = scene; 20 m_controlName = controlName; 21 22 rrbool res = IggyValuePathMakeNameRef ( &m_iggyPath , parent , controlName.c_str() ); 23 24 m_nameXPos = registerFastName(L"x"); 25 m_nameYPos = registerFastName(L"y"); 26 m_nameWidth = registerFastName(L"width"); 27 m_nameHeight = registerFastName(L"height"); 28 m_funcSetAlpha = registerFastName(L"SetControlAlpha"); 29 m_nameVisible = registerFastName(L"visible"); 30 31 F64 fx, fy, fwidth, fheight; 32 IggyValueGetF64RS( getIggyValuePath() , m_nameXPos , NULL , &fx ); 33 IggyValueGetF64RS( getIggyValuePath() , m_nameYPos , NULL , &fy ); 34 IggyValueGetF64RS( getIggyValuePath() , m_nameWidth , NULL , &fwidth ); 35 IggyValueGetF64RS( getIggyValuePath() , m_nameHeight , NULL , &fheight ); 36 37 m_x = (S32)fx; 38 m_y = (S32)fy; 39 m_width = (S32)Math::round(fwidth); 40 m_height = (S32)Math::round(fheight); 41 42 return res; 43} 44 45#ifdef __PSVITA__ 46void UIControl::UpdateControl() 47{ 48 F64 fx, fy, fwidth, fheight; 49 IggyValueGetF64RS( getIggyValuePath() , m_nameXPos , NULL , &fx ); 50 IggyValueGetF64RS( getIggyValuePath() , m_nameYPos , NULL , &fy ); 51 IggyValueGetF64RS( getIggyValuePath() , m_nameWidth , NULL , &fwidth ); 52 IggyValueGetF64RS( getIggyValuePath() , m_nameHeight , NULL , &fheight ); 53 m_x = (S32)fx; 54 m_y = (S32)fy; 55 m_width = (S32)Math::round(fwidth); 56 m_height = (S32)Math::round(fheight); 57} 58#endif // __PSVITA__ 59 60void UIControl::ReInit() 61{ 62 if(m_lastOpacity != 1.0f) 63 { 64 IggyDataValue result; 65 IggyDataValue value[2]; 66 IggyStringUTF8 stringVal; 67 68 stringVal.string = (char *)m_controlName.c_str(); 69 stringVal.length = m_controlName.length(); 70 value[0].type = IGGY_DATATYPE_string_UTF8; 71 value[0].string8 = stringVal; 72 73 value[1].type = IGGY_DATATYPE_number; 74 value[1].number = m_lastOpacity; 75 76 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, m_parentScene->m_rootPath , m_funcSetAlpha , 2 , value ); 77 } 78 79 IggyValueSetBooleanRS( getIggyValuePath(), m_nameVisible, NULL, m_isVisible ); 80} 81 82IggyValuePath *UIControl::getIggyValuePath() 83{ 84 return &m_iggyPath; 85} 86 87S32 UIControl::getXPos() 88{ 89 return m_x; 90} 91 92S32 UIControl::getYPos() 93{ 94 return m_y; 95} 96 97S32 UIControl::getWidth() 98{ 99 return m_width; 100} 101 102S32 UIControl::getHeight() 103{ 104 return m_height; 105} 106 107void UIControl::setOpacity(float percent) 108{ 109 if(percent != m_lastOpacity) 110 { 111 m_lastOpacity = percent; 112 113 IggyDataValue result; 114 IggyDataValue value[2]; 115 IggyStringUTF8 stringVal; 116 117 stringVal.string = (char *)m_controlName.c_str(); 118 stringVal.length = m_controlName.length(); 119 value[0].type = IGGY_DATATYPE_string_UTF8; 120 value[0].string8 = stringVal; 121 122 value[1].type = IGGY_DATATYPE_number; 123 value[1].number = m_lastOpacity; 124 125 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, m_parentScene->m_rootPath , m_funcSetAlpha , 2 , value ); 126 } 127} 128 129void UIControl::setVisible(bool visible) 130{ 131 if(visible != m_isVisible) 132 { 133 rrbool succ = IggyValueSetBooleanRS( getIggyValuePath(), m_nameVisible, NULL, visible ); 134 if(succ) m_isVisible = visible; 135 else app.DebugPrintf("Failed to set visibility for control\n"); 136 } 137} 138 139bool UIControl::getVisible() 140{ 141 rrbool bVisible = false; 142 143 IggyResult result = IggyValueGetBooleanRS ( getIggyValuePath() , m_nameVisible, NULL, &bVisible ); 144 145 m_isVisible = bVisible; 146 147 return bVisible; 148} 149 150IggyName UIControl::registerFastName(const wstring &name) 151{ 152 return m_parentScene->registerFastName(name); 153}