-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerSlot.qml
More file actions
403 lines (350 loc) · 12.7 KB
/
ContainerSlot.qml
File metadata and controls
403 lines (350 loc) · 12.7 KB
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
import QtQuick
import qmlcomponents
Item {
id: containerSlot
property int slotID
property alias slotText: slotTextItem.text
property alias slotTooltip: itemTooltip.text
property alias managedContainerTooltipText: managedContainerTooltip.text
property string slotBackgroundImageSource
property bool showGoldenBorder: false
property bool showSelectionBorder: false
property bool isInManualSortMode: false
property bool containsDrag
property bool containsMouse: false
property int tutorialMarkerID: 0;
property alias mouseAreaEnabled: containerMouseArea.enabled
property alias slotBackgroundVisible: containerSlotBorder.visible
property string lootvalueImageSourceUnderItem: ""
property string lootvalueImageSourceOverItem: ""
property int objectAppearanceInstanceTypeId: 0
property int objectAppearanceInstanceUpgradeTier: 0
property int objectAppearanceInstanceCumulativeCount: 0
property int objectAppearanceInstanceLiquidType: ObjectAppearanceInstance.EMPTY
property int objectAppearanceInstanceHookDirection: ObjectAppearanceInstance.NONE
property int objectAppearanceInstanceDecoItemObjectID: 0
property bool acceptsDrop: false
property bool isUpdatable: true
property bool showPointingHandCursor: false
property bool forceShowDropMarker: false
property bool showProficiencyLevel: false
property bool hasProficiencyMastery: false
property int proficiencyLevel: 0
property bool mirrorImage: false
property bool _highlightBorderVisible: false
onAcceptsDropChanged: {
slotDropAreaLoader.sourceComponent = acceptsDrop ? dropAreaComponent : null
if (!acceptsDrop) {
containerSlot._highlightBorderVisible = false;
containerSlot.containsDrag = false;
}
} //onAcceptsDropChanged
onTutorialMarkerIDChanged: {
tutorialMarkerLoader.sourceComponent = tutorialMarkerID != 0 ? tutorialMarkerComponent : null
} //onAcceptsDropChanged
signal clicked(int SlotID, int MouseButton, int KeyboardModifier)
signal doubleClicked(int SlotID, int MouseButton, int KeyboardModifier)
signal entered(int SlotID)
signal exited(int SlotID)
signal targetSelected(int SlotID)
signal startDrag(int SlotID, QtObject Source)
signal dragDropped(int SlotID)
implicitHeight: TibiaStyle.containerSlotSize
implicitWidth: implicitHeight
Loader {
Component {
id: highlightBorderComponent
Rectangle {
id: highlightBorder
color: "transparent"
border.color: isUpdatable ? "white" : "red"
border.width: 1
} //Rectangle
}
z: 999
anchors.fill: parent
sourceComponent: forceShowDropMarker || showSelectionBorder || _highlightBorderVisible ? highlightBorderComponent : undefined
}
property real lastMouseX: 0
property real lastMouseY: 0
property int lastPressedX: -1
property int lastPressedY: -1
property bool alreadyStartedDragging: false
function onSlotEntered() {
containerSlot.entered(slotID);
if (showPointingHandCursor && tibiaMouseCursorController != null) {
tibiaMouseCursorController.setPointingHand(true);
containsMouse = true;
}
} //function onSlotEntered()
function onSlotExited() {
containerSlot.exited(slotID);
if (showPointingHandCursor && tibiaMouseCursorController != null) {
tibiaMouseCursorController.setPointingHand(false);
containsMouse = false;
}
} //function onSlotExited()
function isDecoItemKit() {
return objectAppearanceInstanceDecoItemObjectID > 0;
}
Component {
id: dropAreaComponent
TibiaObjectDropArea {
id: slotDropArea
anchors.fill: parent
anchors.leftMargin: -1 * TibiaStyle.containerSlotsMargin
anchors.topMargin: -1 * TibiaStyle.containerSlotsMargin
onDropped: {
if (isUpdatable) {
containerSlot.dragDropped(slotID);
}
} //onDropped
onEntered: {
containerSlot.onSlotEntered()
} //onEntered
onExited: {
containerSlot.onSlotExited();
} //onExited
Component.onCompleted: {
containerSlot._highlightBorderVisible = Qt.binding(function() { return containsDrag; });
containerSlot.containsDrag = Qt.binding(function() { return containsDrag; });
} //Component.onCompleted
} //TibiaObjectDropArea
} //Component
Component {
id: tutorialMarkerComponent
TibiaTutorialMarker {
anchors.fill: parent
markerID: containerSlot.tutorialMarkerID
} //TibiaTutorialMarker
} //Component
MouseArea {
id: containerMouseArea
anchors.fill: parent
drag.threshold: TibiaStyle.dragThreshold
acceptedButtons: Qt.RightButton | Qt.LeftButton
property bool dualMouseClickEmulationActive: false
onClicked: (mouse) => {
if (!alreadyStartedDragging && mouse.buttons == 0) {
if (!dualMouseClickEmulationActive) {
containerSlot.clicked(slotID, mouse.button, mouse.modifiers);
} else {
// Left+Right is mapped to MiddleMouse
containerSlot.clicked(slotID, Qt.MiddleButton, Qt.NoModifier);
}
}
} //onClicked
onDoubleClicked: (mouse) => {
containerSlot.doubleClicked(slotID, mouse.button, mouse.modifiers);
} //onClicked
onPressed: (mouse) => {
lastPressedX = mouse.x;
lastPressedY = mouse.y;
alreadyStartedDragging = false;
if (mouse.buttons == (Qt.LeftButton | Qt.RightButton)) {
dualMouseClickEmulationActive = true;
} else {
dualMouseClickEmulationActive = false;
}
} //onPressed
onPositionChanged: (mouse) => {
if (mouse.buttons == Qt.LeftButton && !alreadyStartedDragging) {
var dragDistance = Math.sqrt(Math.pow(lastPressedX - mouse.x, 2) + Math.pow(lastPressedY - mouse.y, 2));
if (dragDistance >= drag.threshold) {
alreadyStartedDragging = true;
containerSlot.startDrag(slotID, containerMouseArea);
}
}
} //onPositionChanged
hoverEnabled: !dummyLenshelpToDetectLenshelpMode.enabled
onEntered: {
containerSlot.onSlotEntered();
} //onEntered
onExited: {
containerSlot.onSlotExited();
} //onExited
Tooltip {
id: itemTooltip
anchors.fill: parent
enabled: text != null && text != ""
onHoverEnter: { if (showPointingHandCursor && tibiaMouseCursorController != null) { tibiaMouseCursorController.setPointingHand(true); } }
onHoverLeave: { if (showPointingHandCursor && tibiaMouseCursorController != null) { tibiaMouseCursorController.setPointingHand(false); } }
} // Tooltip
} //MouseArea
Lenshelp {
// The MouseArea above interferes with the lenshelp mechanism due to ist "hoverEnabled: true" property.
// This zero-size Lenshelp element exists to detect when the lenshelp mode becomes active. When that happens,
// the hoverEnabled property of the MouseArea above gets deactivated, in order to stop interfering with other
// Lenshelp elements' mouse-hover detection mechanism.
id: dummyLenshelpToDetectLenshelpMode
} //Lenshelp
Loader {
id: slotDropAreaLoader
anchors.fill: parent
} //Loader
TibiaTargetSelection {
anchors.fill: parent
onTargetSelected: {
containerSlot.targetSelected(slotID);
} //onTargetSelected
} //TibiaTargetSelection
Loader {
id: tutorialMarkerLoader
anchors.fill: parent
onLoaded: {
item.markerID = Qt.binding(function() { return tutorialMarkerID });
} //onLoaded
z: 999
} //Loader
Optimized1PixelBorderImage {
id: containerSlotBorder
anchors.fill: parent
borderimagesource: "/images/containerslot.png"
} // OptimizedBorderImage1PixelBorder
Loader {
Component {
id: goldenBorderComponent
BorderImage {
id: goldenBorder
border { left: 1; top: 1; right: 1; bottom: 1 }
horizontalTileMode: BorderImage.Stretch
verticalTileMode: BorderImage.Stretch
source: "/images/containerslot-goldenborder.png"
smooth: false
} //BorderImage
} // Component
sourceComponent: showGoldenBorder ? goldenBorderComponent : undefined
anchors.fill: parent
}
Item {
id: slotInner
anchors.fill: parent
anchors.margins: containerSlot.slotBackgroundVisible ? 1 : 0
Loader {
Component {
id: lootvalueImageUnderItemComponent
Image {
id: glowBorder
source: lootvalueImageSourceUnderItem
smooth: false
} //BorderImage
}
sourceComponent: lootvalueImageSourceUnderItem != "" ? lootvalueImageUnderItemComponent : undefined
}
Image {
id: slotEmptyPicture
anchors.fill: parent
source: slotBackgroundImageSource
visible: appearanceLoader.sourceComponent == undefined
smooth: false
} //Image
Loader {
id: appearanceLoader
anchors.fill: parent
sourceComponent: containerSlot.objectAppearanceInstanceTypeId != 0 ? appearanceInstanceRendererComponent
: undefined
Component {
id: appearanceInstanceRendererComponent
SingleObjectAppearanceInstanceRenderer {
id: bodyslotRenderer
animated: true
typeid: containerSlot.objectAppearanceInstanceTypeId
cumulativeCount: containerSlot.objectAppearanceInstanceCumulativeCount
liquidType: containerSlot.objectAppearanceInstanceLiquidType
hookDirection: containerSlot.objectAppearanceInstanceHookDirection
decoItemObjectID: containerSlot.objectAppearanceInstanceDecoItemObjectID
transform: [
Matrix4x4 {
matrix: mirrorImage ? Qt.matrix4x4(-1, 0, 0, bodyslotRenderer.width, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) : Qt.matrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
}
]
} //SingleObjectAppearanceInstanceRenderer
} //Component
} //Loader
TibiaCachedOutlineText {
id: slotTextItem
anchors { left: parent.left; leftMargin: -1;
right: parent.right;
bottom: parent.bottom }
styleType: "InventoryOverlay"
horizontalAlignment: Text.AlignRight
font: slotTextItemSizeMeasurement.truncated ? TibiaStyle.defaultTightFont : TibiaStyle.defaultTextFont
TibiaTextBase {
id: slotTextItemSizeMeasurement
anchors.fill: parent
visible: false
text: parent.text
styleType: parent.styleType
horizontalAlignment: parent.horizontalAlignment
font: TibiaStyle.defaultTextFont
} //TibiaTextBase
} //TibiaCachedOutlineText
Image {
id: lootContainerIcon
anchors { right: parent.right; bottom: parent.bottom; top: undefined}
anchors.margins: 1
source: containerSlot.isDecoItemKit() ? "/images/icon-boxed.png" : "/images/icon-loot-container.png"
visible: managedContainerTooltip.text != "" || containerSlot.isDecoItemKit()
smooth: false
Tooltip {
id: managedContainerTooltip
anchors.fill: parent
} //Tooltip
states: State {
name: "anchoredToTop"
when: slotTextItem.text.length > 0
AnchorChanges {
target: lootContainerIcon
anchors.bottom: undefined
anchors.top: lootContainerIcon.parent.top
}
} // State
} // Image
Loader {
Component {
id: lootvalueImageOverItemComponent
Image {
id: glowBorder
source: lootvalueImageSourceOverItem
smooth: false
} //BorderImage
} //Component
sourceComponent: lootvalueImageSourceOverItem != "" ? lootvalueImageOverItemComponent : undefined
} //Loader
Loader {
anchors.top: parent.top
anchors.right: parent.right
Component {
id: upgradeTierComponent
Image {
source: "image://upgrade-tiers/" + (objectAppearanceInstanceUpgradeTier-1)
smooth: false
} //Image
} //Component
sourceComponent: objectAppearanceInstanceUpgradeTier > 0 ? upgradeTierComponent : undefined
} //Loader
Loader {
id: proficiencyLevelLoader
anchors.fill: slotInner
anchors.leftMargin: 1
anchors.bottomMargin: 1
Component {
id: proficiencyLevelComponent
Repeater {
model: containerSlot.proficiencyLevel
Image {
required property int index
anchors.bottom: parent.bottom
x: index * sourceSize.width - index
source: containerSlot.hasProficiencyMastery
? "/images/proficiency/icon-star-tiny-gold.png"
: "/images/proficiency/icon-star-tiny-silver.png"
visible: (index + 1) <= containerSlot.proficiencyLevel
smooth: false
} //Image
} //Repeater
} //Component
sourceComponent: containerSlot.showProficiencyLevel ? proficiencyLevelComponent : undefined
} //Loader
} //Item
} // Item