forked from SirEdeonX/FFXIAddons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.lua
647 lines (544 loc) · 26.6 KB
/
ui.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
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
--[[
Copyright © 2017, SirEdeonX
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 xivhotbar 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 SirEdeonX 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.
]]
local database = require('database') -- TODO: IMPORT FROM RES
local ui = {}
local text_setup = {
flags = {
draggable = false
}
}
local right_text_setup = {
flags = {
right = true,
draggable = false
}
}
local images_setup = {
draggable = false
}
-- ui metrics
ui.hotbar_width = 0
ui.hotbar_spacing = 0
ui.slot_spacing = 0
ui.pos_x = 0
ui.pos_y = 0
-- ui variables
ui.battle_notice = images.new(images_setup)
ui.feedback_icon = nil
ui.hotbars = {}
-- ui theme options
ui.theme = {}
-- ui control
ui.feedback = {}
ui.feedback.is_active = false
ui.feedback.current_opacity = 0
ui.feedback.max_opacity = 0
ui.feedback.speed = 0
ui.disabled_slots = {}
ui.disabled_slots.actions = {}
ui.disabled_slots.no_vitals = {}
ui.disabled_slots.on_cooldown = {}
ui.is_setup = false
-----------------------------
-- Helpers
-----------------------------
-- setup images
function setup_image(image, path)
image:path(path)
image:repeat_xy(1, 1)
image:draggable(false)
image:fit(true)
image:alpha(255)
image:show()
end
-- setup text
function setup_text(text, theme_options)
text:bg_alpha(0)
text:bg_visible(false)
text:font(theme_options.font)
text:size(theme_options.font_size)
text:color(theme_options.font_color_red, theme_options.font_color_green, theme_options.font_color_blue)
text:stroke_alpha(theme_options.font_stroke_alpha)
text:stroke_color(theme_options.font_stroke_color_red, theme_options.font_stroke_color_green, theme_options.font_stroke_color_blue)
text:stroke_width(theme_options.font_stroke_width)
text:show()
end
-- get x position for a given hotbar and slot
function ui:get_slot_x(h, i)
return self.pos_x + 10 + ((40 + self.slot_spacing) * (i - 1))
end
-- get y position for a given hotbar and slot
function ui:get_slot_y(h, i)
return self.pos_y - (((h - 1) * self.hotbar_spacing))
end
-----------------------------
-- Setup UI
-----------------------------
-- setup ui
function ui:setup(theme_options)
database:import()
self.theme.hide_empty_slots = theme_options.hide_empty_slots
self.theme.hide_action_names = theme_options.hide_action_names
self.theme.hide_action_cost = theme_options.hide_action_cost
self.theme.hide_action_element = theme_options.hide_action_element
self.theme.hide_recast_animation = theme_options.hide_recast_animation
self.theme.hide_recast_text = theme_options.hide_recast_text
self.theme.hide_battle_notice = theme_options.hide_battle_notice
self.theme.slot_opacity = theme_options.slot_opacity
self.theme.disabled_slot_opacity = theme_options.disabled_slot_opacity
self.theme.hotbar_number = theme_options.hotbar_number
self.theme.mp_cost_color_red = theme_options.mp_cost_color_red
self.theme.mp_cost_color_green = theme_options.mp_cost_color_green
self.theme.mp_cost_color_blue = theme_options.mp_cost_color_blue
self.theme.tp_cost_color_red = theme_options.tp_cost_color_red
self.theme.tp_cost_color_green = theme_options.tp_cost_color_green
self.theme.tp_cost_color_blue = theme_options.tp_cost_color_blue
self:setup_metrics(theme_options)
self:load(theme_options)
self.is_setup = true
end
-- load the images and text
function ui:load(theme_options)
-- load battle notice
setup_image(self.battle_notice, windower.addon_path .. '/themes/' .. (theme_options.battle_notice_theme:lower()) .. '/notice.png')
self.battle_notice:pos(self.pos_x + self.hotbar_width - 90, self.pos_y - (theme_options.hotbar_spacing * (theme_options.hotbar_number - 2)) - 24)
self.battle_notice:hide()
-- create ui elements for hotbars
for h=1,theme_options.hotbar_number,1 do
self.hotbars[h] = {}
self.hotbars[h].slot_background = {}
self.hotbars[h].slot_icon = {}
self.hotbars[h].slot_recast = {}
self.hotbars[h].slot_frame = {}
self.hotbars[h].slot_element = {}
self.hotbars[h].slot_text = {}
self.hotbars[h].slot_cost = {}
self.hotbars[h].slot_recast_text = {}
self.hotbars[h].slot_key = {}
for i=1,10,1 do
local slot_pos_x = self:get_slot_x(h, i)
local slot_pos_y = self:get_slot_y(h, i)
local right_slot_pos_x = slot_pos_x - windower.get_windower_settings().ui_x_res + 16
self.hotbars[h].slot_background[i] = images.new(images_setup)
self.hotbars[h].slot_icon[i] = images.new(images_setup)
self.hotbars[h].slot_recast[i] = images.new(images_setup)
self.hotbars[h].slot_frame[i] = images.new(images_setup)
self.hotbars[h].slot_element[i] = images.new(images_setup)
self.hotbars[h].slot_text[i] = texts.new(text_setup)
self.hotbars[h].slot_cost[i] = texts.new(right_text_setup)
self.hotbars[h].slot_recast_text[i] = texts.new(right_text_setup)
self.hotbars[h].slot_key[i] = texts.new(text_setup)
setup_image(self.hotbars[h].slot_background[i], windower.addon_path..'/themes/' .. (theme_options.slot_theme:lower()) .. '/slot.png')
setup_image(self.hotbars[h].slot_icon[i], windower.addon_path..'/images/other/blank.png')
setup_image(self.hotbars[h].slot_frame[i], windower.addon_path..'/themes/' .. (theme_options.frame_theme:lower()) .. '/frame.png')
setup_image(self.hotbars[h].slot_element[i], windower.addon_path..'/images/other/blank.png')
setup_text(self.hotbars[h].slot_text[i], theme_options)
setup_text(self.hotbars[h].slot_cost[i], theme_options)
setup_text(self.hotbars[h].slot_recast_text[i], theme_options)
setup_text(self.hotbars[h].slot_key[i], theme_options)
self.hotbars[h].slot_cost[i]:size(8)
self.hotbars[h].slot_cost[i]:stroke_alpha(220)
self.hotbars[h].slot_background[i]:alpha(theme_options.slot_opacity)
self.hotbars[h].slot_background[i]:pos(slot_pos_x, slot_pos_y)
self.hotbars[h].slot_icon[i]:pos(slot_pos_x, slot_pos_y)
self.hotbars[h].slot_frame[i]:pos(slot_pos_x, slot_pos_y)
self.hotbars[h].slot_element[i]:pos(slot_pos_x + 28, slot_pos_y - 4)
self.hotbars[h].slot_text[i]:pos(slot_pos_x - 2, slot_pos_y + 40)
self.hotbars[h].slot_cost[i]:pos(right_slot_pos_x + 30, slot_pos_y + 28)
self.hotbars[h].slot_recast_text[i]:pos(right_slot_pos_x + 20, slot_pos_y + 14)
self.hotbars[h].slot_recast_text[i]:size(9)
self.hotbars[h].slot_key[i]:pos(slot_pos_x - 1, slot_pos_y - 4)
self.hotbars[h].slot_key[i]:size(9)
self.hotbars[h].slot_key[i]:alpha(200)
local key = i
if i == 10 then key = 0 end
if h == 3 then
self.hotbars[h].slot_key[i]:text('c' .. key)
elseif h == 2 then
self.hotbars[h].slot_key[i]:text("↑" .. key)
else
self.hotbars[h].slot_key[i]:text(tostring(key))
end
end
end
-- load feedback icon last so it stays above everything else
self.feedback_icon = images.new(images_setup)
setup_image(self.feedback_icon, windower.addon_path .. '/images/other/feedback.png')
self.feedback.max_opacity = theme_options.feedback_max_opacity
self.feedback.speed = theme_options.feedback_speed
self.feedback.current_opacity = self.feedback.max_opacity
self.feedback_icon:hide()
end
-- setup positions and dimensions for ui
function ui:setup_metrics(theme_options)
self.hotbar_width = (400 + theme_options.slot_spacing * 9)
self.pos_x = (windower.get_windower_settings().ui_x_res / 2) - (self.hotbar_width / 2) + theme_options.offset_x
self.pos_y = (windower.get_windower_settings().ui_y_res - 120) + theme_options.offset_y
self.slot_spacing = theme_options.slot_spacing
if theme_options.hide_action_names == true then
theme_options.hotbar_spacing = theme_options.hotbar_spacing - 10
self.pos_y = self.pos_y + 10
end
self.hotbar_spacing = theme_options.hotbar_spacing
end
-- hide all ui components
function ui:hide()
self.battle_notice:hide()
self.feedback_icon:hide()
for h=1,self.theme.hotbar_number,1 do
for i=1,10,1 do
self.hotbars[h].slot_background[i]:hide()
self.hotbars[h].slot_icon[i]:hide()
self.hotbars[h].slot_frame[i]:hide()
self.hotbars[h].slot_recast[i]:hide()
self.hotbars[h].slot_element[i]:hide()
self.hotbars[h].slot_text[i]:hide()
self.hotbars[h].slot_cost[i]:hide()
self.hotbars[h].slot_recast_text[i]:hide()
self.hotbars[h].slot_key[i]:hide()
end
end
end
-- show ui components
function ui:show(player_hotbar, environment)
--if self.theme.hide_battle_notice == false and environment == 'battle' then player_hotbar[environment]:show() end--self.toggle_environment:show() end
for h=1,self.theme.hotbar_number,1 do
for i=1,10,1 do
local slot = i
if slot == 10 then slot = 0 end
local action = player_hotbar[environment]['hotbar_' .. h]['slot_' .. slot]
if self.theme.hide_empty_slots == false then self.hotbars[h].slot_background[i]:show() end
self.hotbars[h].slot_icon[i]:show()
if action ~= nil then self.hotbars[h].slot_frame[i]:show() end
if self.theme.hide_recast_animation == false then self.hotbars[h].slot_recast[i]:show() end
if self.theme.hide_action_element == false then self.hotbars[h].slot_element[i]:show() end
if self.theme.hide_action_names == false then self.hotbars[h].slot_text[i]:show() end
if self.theme.hide_action_cost == false then self.hotbars[h].slot_cost[i]:show() end
if self.theme.hide_recast_text == false then self.hotbars[h].slot_recast_text[i]:show() end
--if self.theme.hide_empty_slots == false then self.hotbars[h].slot_key[i]:show() end
if action ~= nil then self.hotbars[h].slot_key[i]:show() end
end
end
end
-----------------------------
-- Actions UI
-----------------------------
-- load player hotbar
function ui:load_player_hotbar(player_hotbar, player_vitals, environment)
if environment == 'battle' and self.theme.hide_battle_notice == false then
self.battle_notice:show()
else
self.battle_notice:hide()
end
-- reset disabled slots
self.disabled_slots.actions = {}
self.disabled_slots.no_vitals = {}
self.disabled_slots.on_cooldown = {}
for h=1,self.theme.hotbar_number,1 do
for i=1,10,1 do
local slot = i
if slot == 10 then slot = 0 end
self:load_action(h, i, player_hotbar[environment]['hotbar_' .. h]['slot_' .. slot], player_vitals)
end
end
end
-- load action into a hotbar slot
function ui:load_action(hotbar, slot, action, player_vitals)
local is_disabled = false
self:clear_slot(hotbar, slot)
-- if slot is empty, leave it cleared
if action == nil then
if self.theme.hide_empty_slots == true then
self.hotbars[hotbar].slot_background[slot]:hide()
self.hotbars[hotbar].slot_key[slot]:hide()
else
self.hotbars[hotbar].slot_background[slot]:show()
self.hotbars[hotbar].slot_key[slot]:show()
end
return
end
self.hotbars[hotbar].slot_background[slot]:show()
self.hotbars[hotbar].slot_key[slot]:show()
-- if slot has a skill (ma, ja or ws)
if action.type == 'ma' or action.type == 'ja' or action.type == 'ws' then
local skill = nil
-- if its magic, look for it in spells
if action.type == 'ma' and database.spells[(action.action):lower()] ~= nil then
skill = database.spells[(action.action):lower()]
self.hotbars[hotbar].slot_icon[slot]:path(windower.addon_path .. '/images/icons/spells/' .. (string.format("%05d", skill.icon)) .. '.png')
elseif (action.type == 'ja' or action.type == 'ws') and database.abilities[(action.action):lower()] ~= nil then
skill = database.abilities[(action.action):lower()]
if action.type == 'ja' then
self.hotbars[hotbar].slot_icon[slot]:path(windower.addon_path .. '/images/icons/abilities/' .. string.format("%05d", skill.icon) .. '.png')
else
self.hotbars[hotbar].slot_icon[slot]:path(windower.addon_path .. '/images/icons/weapons/sword.png')
skill.tpcost = '1000'
end
end
self.hotbars[hotbar].slot_background[slot]:alpha(200)
self.hotbars[hotbar].slot_icon[slot]:pos(self:get_slot_x(hotbar, slot) + 4, self:get_slot_y(hotbar, slot) + 4) -- temporary fix for 32 x 32 icons
self.hotbars[hotbar].slot_icon[slot]:show()
if skill ~= nil then
-- display skill element
if skill.element ~= nil and skill.element ~= 'None' and self.theme.hide_action_element == false then
self.hotbars[hotbar].slot_element[slot]:path(windower.addon_path .. '/images/icons/elements/' .. skill.element .. '.png')
self.hotbars[hotbar].slot_element[slot]:show()
end
-- display mp cost
if skill.mpcost ~= nil and skill.mpcost ~= '0' then
self.hotbars[hotbar].slot_cost[slot]:color(self.theme.mp_cost_color_red, self.theme.mp_cost_color_green, self.theme.mp_cost_color_blue)
self.hotbars[hotbar].slot_cost[slot]:text(skill.mpcost)
if player_vitals.mp < tonumber(skill.mpcost) then
self.disabled_slots.no_vitals[action.action] = true
is_disabled = true
end
-- display tp cost
elseif skill.tpcost ~= nil and skill.tpcost ~= '0' then
self.hotbars[hotbar].slot_cost[slot]:color(self.theme.tp_cost_color_red, self.theme.tp_cost_color_green, self.theme.tp_cost_color_blue)
self.hotbars[hotbar].slot_cost[slot]:text(skill.tpcost)
if player_vitals.tp < tonumber(skill.tpcost) then
self.disabled_slots.no_vitals[action.action] = true
is_disabled = true
end
end
end
-- if action is an item
elseif action.type == 'item' then
self.hotbars[hotbar].slot_icon[slot]:pos(self:get_slot_x(hotbar, slot), self:get_slot_y(hotbar, slot))
self.hotbars[hotbar].slot_icon[slot]:path(windower.addon_path .. '/images/icons/custom/item.png')
self.hotbars[hotbar].slot_icon[slot]:show()
else
self.hotbars[hotbar].slot_icon[slot]:pos(self:get_slot_x(hotbar, slot), self:get_slot_y(hotbar, slot))
end
-- if action is custom
if action.icon ~= nil then
self.hotbars[hotbar].slot_background[slot]:alpha(200)
self.hotbars[hotbar].slot_icon[slot]:pos(self:get_slot_x(hotbar, slot), self:get_slot_y(hotbar, slot))
self.hotbars[hotbar].slot_icon[slot]:path(windower.addon_path .. '/images/icons/custom/' .. action.icon .. '.png')
self.hotbars[hotbar].slot_icon[slot]:show()
end
-- check if action is on cooldown
if self.disabled_slots.on_cooldown[action.action] ~= nil then is_disabled = true end
self.hotbars[hotbar].slot_frame[slot]:show()
self.hotbars[hotbar].slot_text[slot]:text(action.alias)
-- hide elements according to settings
if self.theme.hide_action_names == true then self.hotbars[hotbar].slot_text[slot]:hide() else self.hotbars[hotbar].slot_text[slot]:show() end
if self.theme.hide_action_cost == true then self.hotbars[hotbar].slot_cost[slot]:hide() else self.hotbars[hotbar].slot_cost[slot]:show() end
-- if slot is disabled, disable it
if is_disabled == true then
self:toggle_slot(hotbar, slot, false)
self.disabled_slots.actions[action.action] = true
end
end
-- reset slot
function ui:clear_slot(hotbar, slot)
self.hotbars[hotbar].slot_background[slot]:alpha(self.theme.slot_opacity)
self.hotbars[hotbar].slot_frame[slot]:hide()
self.hotbars[hotbar].slot_icon[slot]:path(windower.addon_path .. '/images/other/blank.png')
self.hotbars[hotbar].slot_icon[slot]:hide()
self.hotbars[hotbar].slot_icon[slot]:alpha(255)
self.hotbars[hotbar].slot_icon[slot]:color(255, 255, 255)
self.hotbars[hotbar].slot_element[slot]:path(windower.addon_path .. '/images/other/blank.png')
self.hotbars[hotbar].slot_element[slot]:alpha(255)
self.hotbars[hotbar].slot_element[slot]:hide()
self.hotbars[hotbar].slot_text[slot]:text('')
--self.hotbars[hotbar].slot_cost[slot]:alpha(255)
self.hotbars[hotbar].slot_cost[slot]:text('')
self.hotbars[hotbar].slot_cost[slot]:hide()
end
-----------------------------
-- Disabled Slots
-----------------------------
-- check player vitals
function ui:check_vitals(player_hotbar, player_vitals, environment)
for h=1,self.theme.hotbar_number,1 do
for i=1,10,1 do
local slot = i
if slot == 10 then slot = 0 end
local action = player_hotbar[environment]['hotbar_' .. h]['slot_' .. slot]
if action ~= nil then
local skill = nil
local is_disabled = false
-- if its magic, look for it in spells
if action.type == 'ma' and database.spells[(action.action):lower()] ~= nil then
skill = database.spells[(action.action):lower()]
elseif (action.type == 'ja' or action.type == 'ws') and database.abilities[(action.action):lower()] ~= nil then
skill = database.abilities[(action.action):lower()]
end
if skill ~= nil then
if (skill.mpcost ~= nil and skill.mpcost ~= '0' and player_vitals.mp < tonumber(skill.mpcost)) or (skill.tpcost ~= nil and skill.tpcost ~= '0' and player_vitals.tp < tonumber(skill.tpcost)) then
self.disabled_slots.no_vitals[action.action] = true
is_disabled = true
else
self.disabled_slots.no_vitals[action.action] = nil
end
-- if it's not disabled by vitals nor cooldown, enable slot
if is_disabled == false and self.disabled_slots.actions[action.action] == true and self.disabled_slots.on_cooldown[action.action] == nil then
self.disabled_slots.actions[action.action] = nil
self:toggle_slot(h, i, true)
end
-- if its disabled, disable slot
if is_disabled == true and self.disabled_slots.actions[action.action] == nil then
self.disabled_slots.actions[action.action] = true
self:toggle_slot(h, i, false)
end
end
end
end
end
end
-- check action recasts
function ui:check_recasts(player_hotbar, player_vitals, environment)
for h=1,self.theme.hotbar_number,1 do
for i=1,10,1 do
local slot = i
if slot == 10 then slot = 0 end
local action = player_hotbar[environment]['hotbar_' .. h]['slot_' .. slot]
if action == nil or (action.type ~= 'ma' and action.type ~= 'ja' and action.type ~= 'ws') then
self:clear_recast(h, i)
else
local skill = nil
local skill_recasts = nil
local in_cooldown = false
local is_in_seconds = false
-- if its magic, look for it in spells
if action.type == 'ma' and database.spells[(action.action):lower()] ~= nil then
skill = database.spells[(action.action):lower()]
skill_recasts = windower.ffxi.get_spell_recasts()
elseif (action.type == 'ja' or action.type == 'ws') and database.abilities[(action.action):lower()] ~= nil then
skill = database.abilities[(action.action):lower()]
skill_recasts = windower.ffxi.get_ability_recasts()
is_in_seconds = true
end
-- check if skill is in cooldown
if skill ~= nil and skill_recasts[tonumber(skill.icon)] ~= nil and skill_recasts[tonumber(skill.icon)] > 0 then
-- register first cooldown to calculate percentage
if self.disabled_slots.on_cooldown[action.action] == nil then
self.disabled_slots.on_cooldown[action.action] = skill_recasts[tonumber(skill.icon)]
-- setup recast elements
self.hotbars[h].slot_recast[i]:path(windower.addon_path..'/images/other/black-square.png')
end
in_cooldown = true
end
-- if skill is in cooldown
if in_cooldown == true then
-- disable slot if it's not disabled
if self.disabled_slots.actions[action.action] == nil then
self.disabled_slots.actions[action.action] = true
self:toggle_slot(h, i, false)
end
-- show recast animation
if self.theme.hide_recast_animation == false or self.theme.hide_recast_text == false then
local new_height = 40 * (skill_recasts[tonumber(skill.icon)] / tonumber(self.disabled_slots.on_cooldown[action.action]))
if new_height > 40 then new_height = 40 end -- temporary bug fix
local recast_time = calc_recast_time(skill_recasts[tonumber(skill.icon)], is_in_seconds)
in_cooldown = true
-- show recast if settings allow it
if self.theme.hide_recast_animation == false then
self.hotbars[h].slot_recast[i]:alpha(150)
self.hotbars[h].slot_recast[i]:size(40, new_height)
self.hotbars[h].slot_recast[i]:pos(self:get_slot_x(h, i), self:get_slot_y(h, i) + (40 - new_height))
self.hotbars[h].slot_recast[i]:show()
end
if self.theme.hide_recast_text == false then
self.hotbars[h].slot_recast_text[i]:text(recast_time)
end
end
else
-- clear recast animation
self:clear_recast(h, i)
if self.disabled_slots.on_cooldown[action.action] == true then
self.disabled_slots.on_cooldown[action.action] = nil
end
-- if it's not disabled by vitals nor cooldown, enable slot
if self.disabled_slots.actions[action.action] == true and self.disabled_slots.no_vitals[action.action] == nil then
self.disabled_slots.actions[action.action] = nil
self:toggle_slot(h, i, true)
end
end
end
end
end
end
-- clear recast from a slot
function ui:clear_recast(hotbar, slot)
self.hotbars[hotbar].slot_recast[slot]:hide()
self.hotbars[hotbar].slot_recast_text[slot]:alpha(255)
self.hotbars[hotbar].slot_recast_text[slot]:color(255, 255, 255)
self.hotbars[hotbar].slot_recast_text[slot]:text('')
end
-- calculate recast time
function calc_recast_time(time, in_seconds)
local recast = time / 60
if in_seconds then
if recast >= 60 then
recast = string.format("%dh", recast / 60)
elseif recast >= 1 then
recast = string.format("%dm", recast)
else
recast = string.format("%ds", recast * 60)
end
else
if recast >= 60 then
recast = string.format("%dm", recast / 60)
else
recast = string.format("%ds", math.round(recast * 10)*0.1)
end
end
return recast
end
-- disable slot
function ui:toggle_slot(hotbar, slot, is_enabled)
local opacity = self.theme.disabled_slot_opacity
if is_enabled == true then
opacity = 255
end
self.hotbars[hotbar].slot_element[slot]:alpha(opacity)
self.hotbars[hotbar].slot_cost[slot]:alpha(opacity) -- when you comment this out, the color does not change
self.hotbars[hotbar].slot_icon[slot]:alpha(opacity)
end
-----------------------------
-- Feedback UI
-----------------------------
-- trigger feedback visuals in given hotbar and slot
function ui:trigger_feedback(hotbar, slot)
if slot == 0 then slot = 10 end
self.feedback_icon:pos(self:get_slot_x(hotbar, slot), self:get_slot_y(hotbar, slot))
self.feedback.current_opacity = self.feedback.max_opacity
self.feedback.is_active = true
end
-- show feedback
function ui:show_feedback()
if self.feedback.current_opacity > 0 then
self.feedback.current_opacity = self.feedback.current_opacity - self.feedback.speed
self.feedback_icon:alpha(self.feedback.current_opacity)
self.feedback_icon:show()
elseif self.feedback.current_opacity < 0 then
self.feedback_icon:hide()
self.feedback.current_opacity = self.feedback.max_opacity
self.feedback.is_active= false
end
end
return ui