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 "..\..\..\Minecraft.World\net.minecraft.world.inventory.h"
3#include "..\..\..\Minecraft.World\StringHelpers.h"
4#include "..\..\Font.h"
5#include "..\..\Lighting.h"
6#include "..\..\MultiPlayerLocalPlayer.h"
7#include "XUI_Scene_Enchant.h"
8#include "XUI_Ctrl_EnchantButton.h"
9#include "XUI_Ctrl_EnchantmentButtonText.h"
10#include "..\..\Minecraft.h"
11#include "..\..\TexturePackRepository.h"
12#include "..\..\TexturePack.h"
13
14#include <iostream>
15#include <string>
16#include <sstream>
17#include <algorithm>
18#include <iterator>
19
20//-----------------------------------------------------------------------------
21HRESULT CXuiCtrlEnchantmentButtonText::OnInit(XUIMessageInit* pInitData, BOOL& rfHandled)
22{
23 HRESULT hr=S_OK;
24
25 Minecraft *pMinecraft=Minecraft::GetInstance();
26
27 ScreenSizeCalculator ssc(pMinecraft->options, pMinecraft->width_phys, pMinecraft->height_phys);
28 m_fScreenWidth=(float)pMinecraft->width_phys;
29 m_fRawWidth=(float)ssc.rawWidth;
30 m_fScreenHeight=(float)pMinecraft->height_phys;
31 m_fRawHeight=(float)ssc.rawHeight;
32
33 HXUIOBJ parent = m_hObj;
34 HXUICLASS hcInventoryClass = XuiFindClass( L"CXuiCtrlEnchantmentButton" );
35 HXUICLASS currentClass;
36
37 do
38 {
39 XuiElementGetParent(parent,&parent);
40 currentClass = XuiGetObjectClass( parent );
41 } while (parent != NULL && !XuiClassDerivesFrom( currentClass, hcInventoryClass ) );
42
43 assert( parent != NULL );
44
45 VOID *pObj;
46 XuiObjectFromHandle( parent, &pObj );
47 m_parentControl = (CXuiCtrlEnchantmentButton *)pObj;
48
49 m_lastCost = 0;
50 m_enchantmentString = L"";
51
52 m_textColour = app.GetHTMLColour(eTextColor_Enchant);
53 m_textFocusColour = app.GetHTMLColour(eTextColor_EnchantFocus);
54 m_textDisabledColour = app.GetHTMLColour(eTextColor_EnchantDisabled);
55
56 return hr;
57}
58
59HRESULT CXuiCtrlEnchantmentButtonText::OnRender(XUIMessageRender *pRenderData, BOOL &bHandled )
60{
61 HXUIDC hDC = pRenderData->hDC;
62 CXuiControl xuiControl(m_hObj);
63
64 // build and render with the game call
65
66 RenderManager.Set_matrixDirty();
67
68 Minecraft *pMinecraft=Minecraft::GetInstance();
69
70 D3DXMATRIX matrix;
71 xuiControl.GetFullXForm(&matrix);
72 float bwidth,bheight;
73 xuiControl.GetBounds(&bwidth,&bheight);
74
75 // Annoyingly, XUI renders everything to a z of 0 so if we want to render anything that needs the z-buffer on top of it, then we need to clear it.
76 // Clear just the region required for this control.
77 D3DRECT clearRect;
78 clearRect.x1 = (int)(matrix._41) - 2;
79 clearRect.y1 = (int)(matrix._42) - 2;
80 clearRect.x2 = (int)(matrix._41 + ( bwidth * matrix._11 )) + 2;
81 clearRect.y2 = (int)(matrix._42 + ( bheight * matrix._22 )) + 2;
82
83 RenderManager.Clear(GL_DEPTH_BUFFER_BIT, &clearRect);
84 // glClear(GL_DEPTH_BUFFER_BIT);
85 glMatrixMode(GL_PROJECTION);
86 glLoadIdentity();
87 glOrtho(0, m_fScreenWidth, m_fScreenHeight, 0, 1000, 3000);
88 glMatrixMode(GL_MODELVIEW);
89 glLoadIdentity();
90 glTranslatef(0, 0, -2000);
91
92
93 glEnable(GL_RESCALE_NORMAL);
94 glPushMatrix();
95 glRotatef(120, 1, 0, 0);
96 //Lighting::turnOnGui();
97 glPopMatrix();
98
99
100
101 EnchantmentMenu *menu = m_parentControl->m_containerScene->getMenu();
102
103 float xo = matrix._41;
104 float yo = matrix._42;
105 glTranslatef(xo, yo, 50.0f);
106
107 float ss = 1;
108
109 if(!m_parentControl->m_containerScene->m_bSplitscreen)
110 {
111 ss = 2;
112 }
113
114 glScalef(ss, ss, ss);
115
116 int cost = menu->costs[m_parentControl->m_index];
117
118 if(cost != m_lastCost)
119 {
120 m_lastCost = cost;
121 m_enchantmentString = EnchantmentNames::instance.getRandomName();
122 }
123
124 glColor4f(1, 1, 1, 1);
125 if (cost != 0)
126 {
127 wstring line = _toString<int>(cost);
128 Font *font = pMinecraft->altFont;
129 //int col = 0x685E4A;
130 unsigned int col = m_textColour;
131 if (pMinecraft->localplayers[m_parentControl->m_iPad]->experienceLevel < cost && !pMinecraft->localplayers[m_parentControl->m_iPad]->abilities.instabuild)
132 {
133 col = m_textDisabledColour;
134 font->drawWordWrap(m_enchantmentString, 0, 0, bwidth/ss, col, bheight/ss);
135 font = pMinecraft->font;
136 //col = (0x80ff20 & 0xfefefe) >> 1;
137 //font->drawShadow(line, (bwidth - font->width(line))/ss, 7, col);
138 }
139 else
140 {
141 if (m_parentControl->HasFocus())
142 {
143 //col = 0xffff80;
144 col = m_textFocusColour;
145 }
146 font->drawWordWrap(m_enchantmentString, 0, 0, bwidth/ss, col, bheight/ss);
147 font = pMinecraft->font;
148 //col = 0x80ff20;
149 //font->drawShadow(line, (bwidth - font->width(line))/ss, 7, col);
150 }
151 }
152 else
153 {
154 }
155
156 //Lighting::turnOff();
157 glDisable(GL_RESCALE_NORMAL);
158
159 XuiRenderRestoreState(hDC);
160
161 bHandled = TRUE;
162
163 return S_OK;
164}
165
166CXuiCtrlEnchantmentButtonText::EnchantmentNames CXuiCtrlEnchantmentButtonText::EnchantmentNames::instance;
167
168CXuiCtrlEnchantmentButtonText::EnchantmentNames::EnchantmentNames()
169{
170 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 ";
171 std::wistringstream iss(allWords);
172 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));
173}
174
175wstring CXuiCtrlEnchantmentButtonText::EnchantmentNames::getRandomName()
176{
177 int wordCount = random.nextInt(2) + 3;
178 wstring word = L"";
179 for (int i = 0; i < wordCount; i++)
180 {
181 if (i > 0) word += L" ";
182 word += words[random.nextInt(words.size())];
183 }
184 return word;
185}