-
Notifications
You must be signed in to change notification settings - Fork 20
/
uiListItem.lua
220 lines (174 loc) · 7.05 KB
/
uiListItem.lua
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
--[[
Copyright © 2024, Tylas
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of XivParty nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <your name> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]
-- windower library imports
local res = require('resources')
-- imports
local classes = require('classes')
local uiContainer = require('uiContainer')
local uiJobIcon = require('uiJobIcon')
local uiStatusBar = require('uiStatusBar')
local uiLeader= require('uiLeader')
local uiRange = require('uiRange')
local uiBuffIcons = require('uiBuffIcons')
local uiText = require('uiText')
local uiImage = require('uiImage')
local const = require('const')
-- create the class, derive from uiContainer
local uiListItem = classes.class(uiContainer)
local isDebug = false
function uiListItem:init(layout, player, isUiLocked, itemWidth, itemHeight)
if self.super:init(layout) then
self.layout = layout
self.player = player
self.isUiLocked = isUiLocked
self.hover = self:addChild(uiImage.new(layout.hover))
self.hover:hide(const.visFeature)
self.cursor = self:addChild(uiImage.new(layout.cursor))
self.cursor:opacity(0)
self.hpBar = self:addChild(uiStatusBar.new(layout.hp, const.barTypeHp, player))
self.mpBar = self:addChild(uiStatusBar.new(layout.mp, const.barTypeMp, player))
self.tpBar = self:addChild(uiStatusBar.new(layout.tp, const.barTypeTp, player))
self.jobIcon = self:addChild(uiJobIcon.new(layout.jobIcon, player))
self.txtName = self:addChild(uiText.new(layout.txtName))
self.txtZone = self:addChild(uiText.new(layout.txtZone))
self.txtJob = self:addChild(uiText.new(layout.txtJob))
self.txtSubJob = self:addChild(uiText.new(layout.txtSubJob))
self.leader = self:addChild(uiLeader.new(layout.leader, player))
self.range = self:addChild(uiRange.new(layout.range, player))
self.buffIcons = self:addChild(uiBuffIcons.new(layout.buffIcons, player))
self.imgMouse = self:addChild(uiImage.create())
self.imgMouse:size(math.max(0, itemWidth - 1), math.max(0, itemHeight - 1)) -- reduce size by 1 to prevent hovering over two neighboring items at the same time
self.imgMouse:alpha(isDebug and 32 or 0)
self.mouseHandlerId = windower.register_event('mouse', function(type, x, y, delta, blocked)
return self:handleWindowerMouse(type, x, y, delta, blocked)
end)
end
end
function uiListItem:dispose()
if not self.isEnabled then return end
if self.mouseHandlerId then
windower.unregister_event(self.mouseHandlerId)
self.mouseHandlerId = nil
end
self.super:dispose()
end
function uiListItem:setPlayer(player)
if not self.isEnabled then return end
if self.player == player then return end
self.player = player
self.hpBar:setPlayer(player)
self.mpBar:setPlayer(player)
self.tpBar:setPlayer(player)
self.jobIcon:setPlayer(player)
self.leader:setPlayer(player)
self.range:setPlayer(player)
self.buffIcons:setPlayer(player)
end
function uiListItem:setUiLocked(isUiLocked)
if not self.isEnabled then return end
self.isUiLocked = isUiLocked
if not isUiLocked then
self.hover:hide(const.visFeature)
end
end
function uiListItem:update()
if not self.isEnabled or not self.player then return end
if self.player.name then
self.txtName:update(self.player.name)
else
self.txtName:update('???')
end
self:updateZone()
self:updateJob()
self:updateCursor()
self.super:update()
end
function uiListItem:updateZone()
local zoneString = ''
if self.player.zone and self.player.isOutsideZone then
if self.layout.txtZone.short then
zoneString = '('..res.zones[self.player.zone]['search']..')'
else
zoneString = '('..res.zones[self.player.zone].name..')'
end
end
self.txtZone:update(zoneString)
end
function uiListItem:updateJob()
local jobString = ''
local subJobString = ''
if not self.player.isOutsideZone then
if self.player.job then
jobString = self.player.job
if self.player.jobLvl then
jobString = jobString .. ' ' .. tostring(self.player.jobLvl)
end
end
if self.player.subJob and self.player.subJob ~= 'MON' then
subJobString = self.player.subJob
if self.player.subJobLvl then
subJobString = subJobString .. ' ' .. tostring(self.player.subJobLvl)
end
end
end
self.txtJob:update(jobString)
self.txtSubJob:update(subJobString)
end
function uiListItem:updateCursor()
local opacity = 0
if not self.player.isOutsideZone then
if self.player.isSelected then
opacity = 1
elseif self.player.isSubTarget then
opacity = 0.5
end
end
self.cursor:opacity(opacity)
end
-- handle mouse interaction
function uiListItem:handleWindowerMouse(type, x, y, delta, blocked)
if blocked then return end
if self.isUiLocked and Settings.mouseTargeting then
if self.imgMouse:hover(x, y) and not self.player.isOutsideZone and self.player.isInTargetingRange then
-- mouse move
if type == 0 then
self.hover:show(const.visFeature)
-- mouse left click
elseif type == 1 then
return true
-- mouse left release
elseif type == 2 then
windower.send_command('input /ta ' .. self.player.name)
return true
end
else
self.hover:hide(const.visFeature)
end
else
self.hover:hide(const.visFeature)
end
return false
end
return uiListItem