the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 217 lines 5.7 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "UIControl_EnchantmentButton.h" 4#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h" 5#include "..\..\Minecraft.h" 6#include "..\..\MultiplayerLocalPlayer.h" 7#include "..\..\..\Minecraft.World\StringHelpers.h" 8 9UIControl_EnchantmentButton::UIControl_EnchantmentButton() 10{ 11 m_index = 0; 12 m_lastState = eState_Inactive; 13 m_lastCost = 0; 14 m_enchantmentString = L""; 15 m_bHasFocus = false; 16 17 m_textColour = app.GetHTMLColour(eTextColor_Enchant); 18 m_textFocusColour = app.GetHTMLColour(eTextColor_EnchantFocus); 19 m_textDisabledColour = app.GetHTMLColour(eTextColor_EnchantDisabled); 20} 21 22bool UIControl_EnchantmentButton::setupControl(UIScene *scene, IggyValuePath *parent, const string &controlName) 23{ 24 UIControl::setControlType(UIControl::eEnchantmentButton); 25 bool success = UIControl_Button::setupControl(scene,parent,controlName); 26 27 //Button specific initialisers 28 m_funcChangeState = registerFastName(L"ChangeState"); 29 30 return success; 31} 32 33void UIControl_EnchantmentButton::init(int index) 34{ 35 m_index = index; 36} 37 38 39void UIControl_EnchantmentButton::ReInit() 40{ 41 UIControl_Button::ReInit(); 42 43 44 m_lastState = eState_Inactive; 45 m_lastCost = 0; 46 m_bHasFocus = false; 47 updateState(); 48} 49 50void UIControl_EnchantmentButton::tick() 51{ 52 updateState(); 53 UIControl_Button::tick(); 54} 55 56void UIControl_EnchantmentButton::render(IggyCustomDrawCallbackRegion *region) 57{ 58 UIScene_EnchantingMenu *enchantingScene = (UIScene_EnchantingMenu *)m_parentScene; 59 EnchantmentMenu *menu = enchantingScene->getMenu(); 60 61 float width = region->x1 - region->x0; 62 float height = region->y1 - region->y0; 63 float xo = width/2; 64 float yo = height; 65 //glTranslatef(xo, yo, 50.0f); 66 67 // Revert the scale from the setup 68 float ssX = width/m_width; 69 float ssY = height/m_height; 70 glScalef(ssX, ssY,1.0f); 71 72 float ss = 1.0f; 73 74#if TO_BE_IMPLEMENTED 75 if(!enchantingScene->m_bSplitscreen) 76#endif 77 { 78 switch(enchantingScene->getSceneResolution()) 79 { 80 case UIScene::eSceneResolution_1080: 81 ss = 3.0f; 82 break; 83 default: 84 ss = 2.0f; 85 break; 86 } 87 } 88 89 glScalef(ss, ss, ss); 90 91 int cost = menu->costs[m_index]; 92 93 //if(cost != m_lastCost) 94 //{ 95 // updateState(); 96 //} 97 98 glColor4f(1, 1, 1, 1); 99 if (cost != 0) 100 { 101 glEnable(GL_ALPHA_TEST); 102 glAlphaFunc(GL_GREATER, 0.1f); 103 Minecraft *pMinecraft = Minecraft::GetInstance(); 104 wstring line = _toString<int>(cost); 105 Font *font = pMinecraft->altFont; 106 //int col = 0x685E4A; 107 unsigned int col = m_textColour; 108 if (pMinecraft->localplayers[enchantingScene->getPad()]->experienceLevel < cost && !pMinecraft->localplayers[enchantingScene->getPad()]->abilities.instabuild) 109 { 110 col = m_textDisabledColour; 111 font->drawWordWrap(m_enchantmentString, 0, 0, (float)m_width/ss, col, (float)m_height/ss); 112 font = pMinecraft->font; 113 //col = (0x80ff20 & 0xfefefe) >> 1; 114 //font->drawShadow(line, (bwidth - font->width(line))/ss, 7, col); 115 } 116 else 117 { 118 if (m_bHasFocus) 119 { 120 //col = 0xffff80; 121 col = m_textFocusColour; 122 } 123 font->drawWordWrap(m_enchantmentString, 0, 0, (float)m_width/ss, col, (float)m_height/ss); 124 font = pMinecraft->font; 125 //col = 0x80ff20; 126 //font->drawShadow(line, (bwidth - font->width(line))/ss, 7, col); 127 } 128 glDisable(GL_ALPHA_TEST); 129 } 130 else 131 { 132 } 133 134 //Lighting::turnOff(); 135 glDisable(GL_RESCALE_NORMAL); 136} 137 138void UIControl_EnchantmentButton::updateState() 139{ 140 UIScene_EnchantingMenu *enchantingScene = (UIScene_EnchantingMenu *)m_parentScene; 141 EnchantmentMenu *menu = enchantingScene->getMenu(); 142 143 EState state = eState_Inactive; 144 145 int cost = menu->costs[m_index]; 146 147 Minecraft *pMinecraft = Minecraft::GetInstance(); 148 if(cost > pMinecraft->localplayers[enchantingScene->getPad()]->experienceLevel && !pMinecraft->localplayers[enchantingScene->getPad()]->abilities.instabuild) 149 { 150 // Dark background 151 state = eState_Inactive; 152 } 153 else 154 { 155 // Light background and focus background 156 if(m_bHasFocus) 157 { 158 state = eState_Selected; 159 } 160 else 161 { 162 state = eState_Active; 163 } 164 } 165 166 if(cost != m_lastCost) 167 { 168 setLabel( _toString<int>(cost) ); 169 m_lastCost = cost; 170 m_enchantmentString = EnchantmentNames::instance.getRandomName(); 171 } 172 if(cost == 0) 173 { 174 // Dark background 175 state = eState_Inactive; 176 setLabel(L""); 177 } 178 179 if(state != m_lastState) 180 { 181 IggyDataValue result; 182 IggyDataValue value[1]; 183 184 value[0].type = IGGY_DATATYPE_number; 185 value[0].number = (int)state; 186 IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_funcChangeState , 1 , value ); 187 188 if(out == IGGY_RESULT_SUCCESS) m_lastState = state; 189 } 190} 191 192void UIControl_EnchantmentButton::setFocus(bool focus) 193{ 194 m_bHasFocus = focus; 195 updateState(); 196} 197 198UIControl_EnchantmentButton::EnchantmentNames UIControl_EnchantmentButton::EnchantmentNames::instance; 199 200UIControl_EnchantmentButton::EnchantmentNames::EnchantmentNames() 201{ 202 wstring allWords = L"the elder scrolls klaatu berata niktu xyzzy bless curse light darkness fire air earth water hot dry cold wet ignite snuff embiggen twist shorten stretch fiddle destroy imbue galvanize enchant free limited range of towards inside sphere cube self other ball mental physical grow shrink demon elemental spirit animal creature beast humanoid undead fresh stale "; 203 std::wistringstream iss(allWords); 204 std::copy(std::istream_iterator< std::wstring, wchar_t, std::char_traits<wchar_t> >(iss), std::istream_iterator< std::wstring, wchar_t, std::char_traits<wchar_t> >(),std::back_inserter(words)); 205} 206 207wstring UIControl_EnchantmentButton::EnchantmentNames::getRandomName() 208{ 209 int wordCount = random.nextInt(2) + 3; 210 wstring word = L""; 211 for (int i = 0; i < wordCount; i++) 212 { 213 if (i > 0) word += L" "; 214 word += words[random.nextInt(words.size())]; 215 } 216 return word; 217}