forked from SirEdeonX/FFXIAddons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xivhotbar.lua
432 lines (357 loc) · 14 KB
/
xivhotbar.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
--[[ BSD License Disclaimer
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.
]]
require 'bit'
-- Addon description
_addon.name = 'XIV Hotbar'
_addon.author = 'Edeon'
_addon.version = '0.1'
_addon.language = 'english'
_addon.commands = {'xivhotbar', 'htb'}
-- Libs
config = require('config')
file = require('files')
texts = require('texts')
images = require('images')
tables = require('tables')
resources = require('resources')
xml = require('libs/xml2') -- TODO: REMOVE
-- User settings
local defaults = require('defaults')
local settings = config.load(defaults)
config.save(settings)
-- Load theme options according to settings
local theme = require('theme')
local theme_options = theme.apply(settings)
-- Addon Dependencies
local action_manager = require('action_manager')
local keyboard = require('keyboard_mapper')
local player = require('player')
local ui = require('ui')
local xivhotbar = require('variables')
local ignorekey = false
-----------------------------
-- Main
-----------------------------
-- initialize addon
function initialize()
local windower_player = windower.ffxi.get_player()
local server = resources.servers[windower.ffxi.get_info().server].en
--print("Player "..windower_player.name)
--print("Server "..server)
if windower_player == nil then return end
player:initialize(windower_player, server, theme_options)
player:load_hotbar()
ui:setup(theme_options)
ui:load_player_hotbar(player.hotbar, player.vitals, player.hotbar_settings.active_environment)
xivhotbar.ready = true
xivhotbar.initialized = true
end
-- trigger hotbar action
function trigger_action(slot)
if player:execute_action(slot) then
ui:trigger_feedback(player.hotbar_settings.active_hotbar, slot)
end
end
-- toggle between field and battle hotbars
function toggle_environment()
player:toggle_environment()
ui:load_player_hotbar(player.hotbar, player.vitals, player.hotbar_settings.active_environment)
end
-- set battle environment
function set_battle_environment(in_battle)
player:set_battle_environment(in_battle)
ui:load_player_hotbar(player.hotbar, player.vitals, player.hotbar_settings.active_environment)
end
-- reload hotbar
function reload_hotbar()
player:load_hotbar()
ui:load_player_hotbar(player.hotbar, player.vitals, player.hotbar_settings.active_environment)
end
-- change active hotbar
function change_active_hotbar(new_hotbar)
player:change_active_hotbar(new_hotbar)
end
-----------------------------
-- Addon Commands
-----------------------------
-- command to set an action in a hotbar
function set_action_command(args)
if not args[5] then
print('XIVHOTBAR: Invalid arguments: set <mode> <hotbar> <slot> <action_type> <action> <target (optional)> <alias (optional)> <icon (optional)>')
return
end
local environment = args[1]:lower()
local hotbar = tonumber(args[2]) or 0
local slot = tonumber(args[3]) or 0
local action_type = args[4]:lower()
local action = args[5]
local target = args[6] or nil
local alias = args[7] or nil
local icon = args[8] or nil
if environment ~= 'battle' and environment ~= 'field' and environment ~= 'b' and environment ~= 'f' then
print('XIVHOTBAR: Invalid mode. Available modes are "Battle" (b) and "Field" (f).')
return
end
if hotbar < 1 or hotbar > 3 then
print('XIVHOTBAR: Invalid hotbar. Please use a number between 1 and 3.')
return
end
if slot < 1 or slot > 10 then
print('XIVHOTBAR: Invalid slot. Please use a number between 1 and 10.')
return
end
if target ~= nil then target = target:lower() end
local new_action = action_manager:build(action_type, action, target, alias, icon)
player:add_action(new_action, environment, hotbar, slot)
player:save_hotbar()
reload_hotbar()
end
-- command to delete an action from an hotbar
function delete_action_command(args)
if not args[3] then
print('XIVHOTBAR: Invalid arguments: del <mode> <hotbar> <slot>')
return
end
local environment = args[1]:lower()
local hotbar = tonumber(args[2]) or 0
local slot = tonumber(args[3]) or 0
if environment ~= 'battle' and environment ~= 'field' and environment ~= 'b' and environment ~= 'f' then
print('XIVHOTBAR: Invalid mode. Available modes are "Battle" (b) and "Field" (f).')
return
end
if hotbar < 1 or hotbar > 3 then
print('XIVHOTBAR: Invalid hotbar. Please use a number between 1 and 3.')
return
end
if slot < 1 or slot > 10 then
print('XIVHOTBAR: Invalid slot. Please use a number between 1 and 10.')
return
end
player:remove_action(environment, hotbar, slot)
player:save_hotbar()
reload_hotbar()
end
-- command to copy an action to another slot
function copy_action_command(args, is_moving)
local command = 'copy'
if is_moving then command = 'move' end
if not args[6] then
print('XIVHOTBAR: Invalid arguments: ' .. command .. ' <mode> <hotbar> <slot> <to_mode> <to_hotbar> <to_slot>')
return
end
local environment = args[1]:lower()
local hotbar = tonumber(args[2]) or 0
local slot = tonumber(args[3]) or 0
local to_environment = args[4]:lower()
local to_hotbar = tonumber(args[5]) or 0
local to_slot = tonumber(args[6]) or 0
if (environment ~= 'battle' and environment ~= 'field' and environment ~= 'b' and environment ~= 'f') or
(to_environment ~= 'battle' and to_environment ~= 'field' and to_environment ~= 'b' and to_environment ~= 'f') then
print('XIVHOTBAR: Invalid mode. Available modes are "Battle" (b) and "Field" (f).')
return
end
if hotbar < 1 or hotbar > 3 or to_hotbar < 1 or to_hotbar > 3 then
print('XIVHOTBAR: Invalid hotbar. Please use a number between 1 and 3.')
return
end
if slot < 1 or slot > 10 or to_slot < 1 or to_slot > 10 then
print('XIVHOTBAR: Invalid slot. Please use a number between 1 and 10.')
return
end
player:copy_action(environment, hotbar, slot, to_environment, to_hotbar, to_slot, is_moving)
player:save_hotbar()
reload_hotbar()
end
-- command to update action alias
function update_alias_command(args)
if not args[4] then
print('XIVHOTBAR: Invalid arguments: alias <mode> <hotbar> <slot> <alias>')
return
end
local environment = args[1]:lower()
local hotbar = tonumber(args[2]) or 0
local slot = tonumber(args[3]) or 0
local alias = args[4]
if environment ~= 'battle' and environment ~= 'field' and environment ~= 'b' and environment ~= 'f' then
print('XIVHOTBAR: Invalid mode. Available modes are "Battle" (b) and "Field" (f).')
return
end
if hotbar < 1 or hotbar > 3 then
print('XIVHOTBAR: Invalid hotbar. Please use a number between 1 and 3.')
return
end
if slot < 1 or slot > 10 then
print('XIVHOTBAR: Invalid slot. Please use a number between 1 and 10.')
return
end
player:set_action_alias(environment, hotbar, slot, alias)
player:save_hotbar()
reload_hotbar()
end
-- command to update action icon
function update_icon_command(args)
if not args[4] then
print('XIVHOTBAR: Invalid arguments: icon <mode> <hotbar> <slot> <icon>')
return
end
local environment = args[1]:lower()
local hotbar = tonumber(args[2]) or 0
local slot = tonumber(args[3]) or 0
local icon = args[4]
if environment ~= 'battle' and environment ~= 'field' and environment ~= 'b' and environment ~= 'f' then
print('XIVHOTBAR: Invalid mode. Available modes are "Battle" (b) and "Field" (f).')
return
end
if hotbar < 1 or hotbar > 3 then
print('XIVHOTBAR: Invalid hotbar. Please use a number between 1 and 3.')
return
end
if slot < 1 or slot > 10 then
print('XIVHOTBAR: Invalid slot. Please use a number between 1 and 10.')
return
end
player:set_action_icon(environment, hotbar, slot, icon)
player:save_hotbar()
reload_hotbar()
end
-----------------------------
-- Bind Events
-----------------------------
-- ON LOAD
windower.register_event('load',function()
if windower.ffxi.get_info().logged_in then
initialize()
end
end)
-- ON LOGIN
windower.register_event('login',function()
--The server (windower.ffxi.get_info().server) is not properly populated
--until shortly after this event so, we have to wait half a second.
--If you don't wait, it defaults to Asura (interestingly)
coroutine.schedule(initialize, 1)
end)
-- ON LOGOUT
windower.register_event('logout', function()
ui:hide()
end)
-- ON COMMAND
windower.register_event('addon command', function(command, ...)
command = command and command:lower() or 'help'
local args = {...}
if command == 'reload' then
return reload_hotbar()
elseif command == 'set' then
set_action_command(args)
elseif command == 'del' or command == 'delete' then
delete_action_command(args)
elseif command == 'cp' or command == 'copy' then
copy_action_command(args, false)
elseif command == 'mv' or command == 'move' then
copy_action_command(args, true)
elseif command == 'ic' or command == 'icon' then
update_icon_command(args)
elseif command == 'al' or command == 'alias' then
update_alias_command(args)
end
end)
-- ON KEY
windower.register_event('keyboard', function(dik, pressed, flags)
if xivhotbar.ready == false or windower.ffxi.get_info().chat_open then
return
end
if xivhotbar.hide_hotbars then
return
end
shiftDown = bit.band(bit.rshift(flags, 0), 1) == 1;
altDown = bit.band(bit.rshift(flags, 1), 1) == 1;
controlDown = bit.band(bit.rshift(flags, 2), 1) == 1;
if shiftDown and not altDown and not controlDown then
change_active_hotbar(2)
else
change_active_hotbar(1)
end
if dik == theme_options.controls_battle_mode and pressed == true then
toggle_environment()
end
if pressed == true and not altDown and not controlDown then
if dik == keyboard.key_1 then trigger_action(1); return false; end
if dik == keyboard.key_2 then trigger_action(2); return false; end
if dik == keyboard.key_3 then trigger_action(3); return false; end
if dik == keyboard.key_4 then trigger_action(4); return false; end
if dik == keyboard.key_5 then trigger_action(5); return false; end
if dik == keyboard.key_6 then trigger_action(6); return false; end
if dik == keyboard.key_7 then trigger_action(7); return false; end
if dik == keyboard.key_8 then trigger_action(8); return false; end
if dik == keyboard.key_9 then trigger_action(9); return false; end
if dik == keyboard.key_0 then trigger_action(0); return false; end
end
--return false
end)
-- ON PRERENDER
windower.register_event('prerender',function()
if xivhotbar.ready == false then
return
end
if ui.feedback.is_active then
ui:show_feedback()
end
if ui.is_setup and xivhotbar.hide_hotbars == false then
ui:check_recasts(player.hotbar, player.vitals, player.hotbar_settings.active_environment)
end
end)
-- ON MP CHANGE
windower.register_event('mp change', function(new, old)
player.vitals.mp = new
ui:check_vitals(player.hotbar, player.vitals, player.hotbar_settings.active_environment)
end)
-- OM TP CHANGE
windower.register_event('tp change', function(new, old)
player.vitals.tp = new
ui:check_vitals(player.hotbar, player.vitals, player.hotbar_settings.active_environment)
end)
-- ON STATUS CHANGE
windower.register_event('status change', function(new_status_id)
-- hide/show bar in cutscenes
if xivhotbar.hide_hotbars == false and new_status_id == 4 then -- 4 = Zoning
xivhotbar.hide_hotbars = true
ui:hide()
elseif xivhotbar.hide_hotbars and new_status_id ~= 4 then -- 4 = Zoning
xivhotbar.hide_hotbars = false
ui:show(player.hotbar, player.hotbar_settings.active_environment)
end
-- alternate environment on battle
if xivhotbar.in_battle == false and (new_status_id == 1 or new_status_id == 3) then -- 1 = engaged, 3 = dead
xivhotbar.in_battle = true
set_battle_environment(true)
--elseif xivhotbar.in_battle and new_status_id ~= 1 and new_status_id ~= 3 then -- 1 = engaged, 3 = dead
-- xivhotbar.in_battle = false
-- set_battle_environment(false)
end
end)
-- ON JOB CHANGE
windower.register_event('job change',function(main_job, main_job_level, sub_job, sub_job_level)
player:update_jobs(resources.jobs[main_job].ens, resources.jobs[sub_job].ens)
reload_hotbar()
end)