-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNStatCounter.qml
323 lines (271 loc) · 8.69 KB
/
NStatCounter.qml
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.0
import "utilities.js" as Util
ApplicationWindow {
id: mainWindow
title: "NStatCounter"
width: 400
height: 450
minimumWidth: 400
minimumHeight: 375
visible: true
property alias level: levelSpinner.value
property alias strength: strSlider.value
property alias dexterity: dexSlider.value
property alias intelligence: intSlider.value
property alias charisma: chaSlider.value
property int ap: level*6
property int usedAp: strength + dexterity + intelligence + charisma - 6 // 6 is the total AP already assigned at creation
property bool usedAllAp: (usedAp < ap)
property int remainingAp: ap - usedAp
onLevelChanged: {
// Can't use the ap prop because it depends on level
var diff = (level*6) - (strength + dexterity + intelligence + charisma - 6);
// Only matters when more than the available ap is used
if(diff >= 0 || !strSlider) {
return;
}
// Reduce stats until there is no diff (an expensive operation!)
var iterator = 0;
var strOk = true,
dexOk = true,
intOk = true,
chaOk = true;
for(; diff < 0; diff++) {
if(strOk && strSlider.value <= strSlider.min) {
strOk = false;
}
if(dexOk && dexSlider.value <= dexSlider.min) {
dexOk = false;
}
if(intOk && intSlider.value <= intSlider.min) {
intOk = false;
}
if(chaOk && chaSlider.value <= chaSlider.min) {
chaOk = false;
}
if(iterator == 0) {
iterator++;
if(strOk) {
strSlider.value--;
continue;
}
}
if(iterator == 1) {
iterator++;
if(dexOk) {
dexSlider.value--;
continue;
}
}
if(iterator == 2) {
iterator++;
if(intOk) {
intSlider.value--;
continue;
}
}
if(iterator == 3) {
iterator = 0;
if(chaOk) {
chaSlider.value--;
continue;
} else {
// Note that we need to go through again to make the value propagate
diff--;
}
}
}
}
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("Open")
}
MenuItem {
text: qsTr("Save")
}
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
Menu {
title: qsTr("Help")
MenuItem {
text: qsTr("About NStatCounter...")
}
}
}
GridLayout {
id: gridlayout1
anchors.fill: parent
columns: 1
GroupBox {
id: statsBox
width: 630
height: 197
anchors.left: parent.left
anchors.leftMargin: 5
anchors.right: parent.right
anchors.rightMargin: 5
anchors.top: parent.top
anchors.topMargin: 5
transformOrigin: Item.Center
title: "Stats"
Item {
id: levelItem
width: 122
height: 31
anchors.top: parent.top
anchors.topMargin: 3
anchors.left: parent.left
anchors.leftMargin: 3
Label {
id: levelLabel
x: 8
y: 8
text: "Level"
font.bold: true
}
SpinBox {
id: levelSpinner
x: 53
y: 4
width: 60
minimumValue: 1
maximumValue: 9999
value: 1
}
}
ActionPointBox {
id: apItem
width: 162
height: 31
anchors.left: levelItem.right
anchors.leftMargin: 3
anchors.top: parent.top
anchors.topMargin: 3
usedAP: mainWindow.usedAp
totalAP: mainWindow.ap
}
ColumnLayout {
id: statLayout
height: 124
anchors.top: levelItem.bottom
anchors.topMargin: 3
anchors.right: parent.right
anchors.rightMargin: 3
anchors.left: parent.left
anchors.leftMargin: 3
StatSlider {
id: strSlider
height: 25
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
name: "Strength"
max: mainWindow.ap + 2
min: 2
value: 2
remainingValues: mainWindow.remainingAp
}
StatSlider {
id: dexSlider
height: 25
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
name: "Dexterity"
max: mainWindow.ap + 2
min: 2
value: 2
remainingValues: mainWindow.remainingAp
}
StatSlider {
id: intSlider
height: 25
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
name: "Intelligence"
max: mainWindow.ap + 1
min: 1
value: 1
remainingValues: mainWindow.remainingAp
}
StatSlider {
id: chaSlider
height: 25
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
name: "Charisma"
max: mainWindow.ap + 1
min: 1
value: 1
remainingValues: mainWindow.remainingAp
}
}
}
GroupBox {
id: effectsBox
x: 2
y: 208
width: 636
height: 227
anchors.top: parent.top
anchors.topMargin: 208
anchors.left: parent.left
anchors.leftMargin: 5
anchors.right: parent.right
anchors.rightMargin: 5
title: qsTr("Effects")
Column {
id: column1
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
spacing: 2
StatDisplay {
id: maxHpDisplay
name: "Max Health"
value: Util.calcMaxHealth(strSlider.value)
}
StatDisplay {
id: maxManaDisplay
name: "Max Mana"
value: Util.calcMaxMana(intSlider.value)
}
StatDisplay {
id: maxPetDisplay
name: "Max Pet Level"
value: Util.calcPetLevel(levelSpinner.value, chaSlider.value)
}
StatDisplay {
id: maxDamageDisplay
name: "Max Damage"
value: Util.calcMaxDamage(strSlider.value, dexSlider.value)
}
StatDisplay {
id: hitChanceDisplay
name: "Hit Chance"
value: Util.calcHitChance(dexSlider.value, levelSpinner.value)+"%"
}
}
}
}
}