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