aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/UI/UIControl_ButtonList.cpp
blob: 4f0e5ca086af4eb3d83587ad2adc4a19f7fabc3d (plain)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include "stdafx.h"
#include "UI.h"
#include "UIControl_ButtonList.h"

UIControl_ButtonList::UIControl_ButtonList()
{
	m_itemCount = 0;
	m_iCurrentSelection = 0;
}

bool UIControl_ButtonList::setupControl(UIScene *scene, IggyValuePath *parent, const string &controlName)
{
	UIControl::setControlType(UIControl::eButtonList);
	bool success = UIControl_Base::setupControl(scene,parent,controlName);

	//SlotList specific initialisers
	m_addNewItemFunc = registerFastName(L"addNewItem");
	m_removeAllItemsFunc = registerFastName(L"removeAllItems");
	m_funcHighlightItem = registerFastName(L"HighlightItem");
	m_funcRemoveItem = registerFastName(L"RemoveItem");
	m_funcSetButtonLabel = registerFastName(L"SetButtonLabel");
	m_funcSetTouchFocus = registerFastName(L"SetTouchFocus");
	m_funcCanTouchTrigger = registerFastName(L"CanTouchTrigger");

	return success;
}

void UIControl_ButtonList::init(int id)
{
	m_id = id;

	IggyDataValue result;
	IggyDataValue value[1];
	value[0].type = IGGY_DATATYPE_number;
	value[0].number = id;
	IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_initFunc , 1 , value );

 #ifdef __PSVITA__
 	// 4J-PB - add this buttonlist to the vita touch box list
 
 	switch(m_parentScene->GetParentLayer()->m_iLayer)
 	{
 	case eUILayer_Fullscreen:
 	case eUILayer_Scene:
 	case eUILayer_HUD:
 		ui.TouchBoxAdd(this,m_parentScene);
 		break;
}
 #endif
}

void UIControl_ButtonList::ReInit()
{
	UIControl_Base::ReInit();
	init(m_id);
	m_itemCount = 0;
	m_iCurrentSelection = 0;
}

void UIControl_ButtonList::clearList()
{
	IggyDataValue result;
	IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_removeAllItemsFunc , 0 , nullptr );

	m_itemCount = 0;
}

void UIControl_ButtonList::addItem(const string &label)
{
	addItem(label, m_itemCount);
}

void UIControl_ButtonList::addItem(const wstring &label)
{
	addItem(label, m_itemCount);
}

void UIControl_ButtonList::addItem(const string &label, int data)
{
	IggyDataValue result;
	IggyDataValue value[2];

	IggyStringUTF8 stringVal;
	stringVal.string = (char*)label.c_str();
	stringVal.length = static_cast<S32>(label.length());
	value[0].type = IGGY_DATATYPE_string_UTF8;
	value[0].string8 = stringVal;

	value[1].type = IGGY_DATATYPE_number;
	value[1].number = data;
	IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_addNewItemFunc , 2 , value );

	++m_itemCount;
}

void UIControl_ButtonList::addItem(const wstring &label, int data)
{
	IggyDataValue result;
	IggyDataValue value[2];

	IggyStringUTF16 stringVal;
	stringVal.string = (IggyUTF16*)label.c_str();
	stringVal.length = label.length();
	value[0].type = IGGY_DATATYPE_string_UTF16;
	value[0].string16 = stringVal;

	value[1].type = IGGY_DATATYPE_number;
	value[1].number = data;
	IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_addNewItemFunc , 2 , value );

	++m_itemCount;
}

void UIControl_ButtonList::removeItem(int index)
{
	IggyDataValue result;
	IggyDataValue value[1];

	value[0].type = IGGY_DATATYPE_number;
	value[0].number = index;
	IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_funcRemoveItem , 1 , value );

	--m_itemCount;
}

void UIControl_ButtonList::setCurrentSelection(int iSelection)
{
	IggyDataValue result;
	IggyDataValue value[1];

	value[0].type = IGGY_DATATYPE_number;
	value[0].number = iSelection;
	IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_funcHighlightItem , 1 , value );
}

int UIControl_ButtonList::getCurrentSelection()
{
	return m_iCurrentSelection;
}

void UIControl_ButtonList::updateChildFocus(int iChild)
{
	m_iCurrentSelection = iChild;
}

void UIControl_ButtonList::setButtonLabel(int iButtonId, const wstring &label)
{
	IggyDataValue result;
	IggyDataValue value[2];

	value[0].type = IGGY_DATATYPE_number;
	value[0].number = iButtonId;

	IggyStringUTF16 stringVal;
	stringVal.string = (IggyUTF16*)label.c_str();
	stringVal.length = label.length();
	value[1].type = IGGY_DATATYPE_string_UTF16;
	value[1].string16 = stringVal;
	IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie(), &result, getIggyValuePath(), m_funcSetButtonLabel, 2 , value );
}

#if defined(__PSVITA__) || defined(_WINDOWS64)
void UIControl_ButtonList::SetTouchFocus(S32 iX, S32 iY, bool bRepeat)
{
	IggyDataValue result;
	IggyDataValue value[3];

	value[0].type = IGGY_DATATYPE_number;
	value[0].number = iX;
	value[1].type = IGGY_DATATYPE_number;
	value[1].number = iY;
	value[2].type = IGGY_DATATYPE_boolean;
	value[2].boolval = bRepeat;

	IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie(), &result, getIggyValuePath(), m_funcSetTouchFocus, 3 , value );
}

bool UIControl_ButtonList::CanTouchTrigger(S32 iX, S32 iY)
{
	IggyDataValue result;
	IggyDataValue value[2];

	value[0].type = IGGY_DATATYPE_number;
	value[0].number = iX;
	value[1].type = IGGY_DATATYPE_number;
	value[1].number = iY;

	IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie(), &result, getIggyValuePath(), m_funcCanTouchTrigger, 2 , value );

	S32 bCanTouchTrigger = false;
	if(result.type == IGGY_DATATYPE_boolean)
	{
		bCanTouchTrigger = (bool)result.boolval;
	}
	return bCanTouchTrigger;
}
#endif


void UIControl_DynamicButtonList::tick()
{
	UIControl_ButtonList::tick();

	int buttonIndex = 0;
	vector<UIString>::iterator itr;
	for (itr = m_labels.begin(); itr != m_labels.end(); itr++)
	{
		if ( itr->needsUpdating() )
		{
			setButtonLabel(buttonIndex, itr->getString());
			itr->setUpdated();
		}
		buttonIndex++;
	}
}

void UIControl_DynamicButtonList::addItem(UIString label, int data)
{
	if (data < 0) data = m_itemCount;

	if (data < m_labels.size())
	{
		m_labels[data] = label;
	}
	else
	{
		while (data > m_labels.size()) 
		{
			m_labels.push_back(UIString());
		}
		m_labels.push_back(label);
	}

	UIControl_ButtonList::addItem(label.getString(), data);
}

void UIControl_DynamicButtonList::removeItem(int index)
{
	m_labels.erase( m_labels.begin() + index );
	UIControl_ButtonList::removeItem(index);
}