forked from ThornyFFXI/tCrossBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitializer.lua
More file actions
218 lines (196 loc) · 7.51 KB
/
initializer.lua
File metadata and controls
218 lines (196 loc) · 7.51 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
--Initialize Globals..
require('helpers');
gTextureCache = require('texturecache');
gBindings = require('bindings');
gBindingGUI = require('bindinggui');
gConfigGUI = require('configgui');
gController = require('controller');
gSingleDisplay = require('singledisplay');
gDoubleDisplay = require('doubledisplay');
settings = require('settings');
local d3d8 = require('d3d8');
local ffi = require('ffi');
local scaling = require('scaling');
gToggleHide = false;
--Create directories..
local controllerConfigFolder = string.format('%sconfig/addons/%s/resources/controllers', AshitaCore:GetInstallPath(), addon.name);
if not ashita.fs.exists(controllerConfigFolder) then
ashita.fs.create_directory(controllerConfigFolder);
end
local layoutConfigFolder = string.format('%sconfig/addons/%s/resources/layouts', AshitaCore:GetInstallPath(), addon.name);
if not ashita.fs.exists(layoutConfigFolder) then
ashita.fs.create_directory(layoutConfigFolder);
end
--Initialize settings..
local defaultSettings = T{
--Layouts tab..
SingleLayout = 'classic',
SingleScale = 1.0,
DoubleLayout = 'classic',
DoubleScale = 1.0,
TriggerDuration = 0.25,
ShowEmpty = true,
ShowFrame = true,
ShowCost = true,
ShowCross = true,
ShowFade = true,
ShowName = true,
ShowRecast = true,
ShowHotkey = false,
ShowSkillchainIcon = true,
ShowSkillchainAnimation = true,
ShowTrigger = true,
ShowReadyPulse = true,
ReadyPulseHz = 1.0,
ReadyPulseMinAlpha = 0.45,
ShowPalette = true,
ShowSinglePalette = false,
--Behavior tab..
ClickToActivate = true,
HideWhileZoning = true,
HideWhileCutscene = true,
HideWhileMap = true,
HideWhileChat = true,
DefaultSelectTarget = false,
EnableDoubleTap = true,
EnablePriority = true,
ShowDoubleDisplay = true,
LTRTMode = 'FullDouble',
SwapToSingleDisplay = false,
AllowInventoryPassthrough = true,
--Controller Tab..
Controller = 'dualsense',
BindMenuTimer = 1,
TapTimer = 0.4,
};
gSettings = settings.load(defaultSettings);
local function UpdateSettings()
local version = tonumber(addon.version);
if (gSettings.Version ~= version) then
if (gSettings.SwapToSingleDisplay ~= nil) then
if (gSettings.SwapToSingleDisplay == true) then
gSettings.LTRTMode = 'Single';
else
gSettings.LTRTMode = 'FullDouble';
end
gSettings.SwapToSingleDisplay = nil;
end
if (type(gSettings.Version) ~= 'number') or (gSettings.Version < 2.0) then
for key,val in pairs(gSettings) do
local newVal = defaultSettings[key];
if newVal then
gSettings[key] = newVal;
else
gSettings[key] = nil;
end
end
Message('Settings from a prior incompatible version detected. Updating settings.')
end
gSettings.Version = version;
settings.save();
end
end
UpdateSettings();
local function PrepareLayout(layout, scale)
local tx = layout.Textures[layout.DragHandle.Texture]
layout.DragHandle.Width = tx.Width;
layout.DragHandle.Height = tx.Height;
for _,singleTable in ipairs(T{layout, layout.FixedObjects, layout.Elements, layout.Textures}) do
for _,tableEntry in pairs(singleTable) do
if (type(tableEntry) == 'table') then
if (tableEntry.OffsetX ~= nil) then
tableEntry.OffsetX = tableEntry.OffsetX * scale;
tableEntry.OffsetY = tableEntry.OffsetY * scale;
end
if (tableEntry.Width ~= nil) then
tableEntry.Width = tableEntry.Width * scale;
tableEntry.Height = tableEntry.Height * scale;
end
if (tableEntry.font_height ~= nil) then
tableEntry.font_height = math.max(5, math.floor(tableEntry.font_height * scale));
end
if (tableEntry.outline_width ~= nil) then
tableEntry.outline_width = math.min(3, math.max(1, math.floor(tableEntry.outline_width * scale)));
end
end
end
end
--Prepare textures for efficient rendering..
for _,singleTable in ipairs(T{layout.SkillchainFrames, layout.Textures}) do
for key,entry in pairs(singleTable) do
local tx,dimensions;
if type(entry) == 'table' then
tx = gTextureCache:GetTexture(entry.Path)
dimensions = { Width=entry.Width, Height=entry.Height };
else
tx = gTextureCache:GetTexture(entry)
dimensions = { Width=layout.Icon.Width, Height=layout.Icon.Height };
end
if tx and dimensions then
local preparedTexture = {};
preparedTexture.Texture = tx.Texture;
preparedTexture.Rect = ffi.new('RECT', { 0, 0, tx.Width, tx.Height });
preparedTexture.Scale = ffi.new('D3DXVECTOR2', { dimensions.Width / tx.Width, dimensions.Height / tx.Height });
singleTable[key] = preparedTexture;
else
singleTable[key] = nil;
end
end
end
layout.FadeOpacity = d3d8.D3DCOLOR_ARGB(layout.FadeOpacity, 255, 255, 255);
layout.TriggerOpacity = d3d8.D3DCOLOR_ARGB(layout.TriggerOpacity, 255, 255, 255);
end
local function GetDefaultPosition(layout)
if ((scaling.window.w == -1) or (scaling.window.h == -1) or (scaling.menu.w == -1) or (scaling.menu.h == -1)) then
return { 0, 0 };
else
--Centered horizontally, vertically just above chat log.
return {
(scaling.window.w - layout.Panel.Width) / 2,
scaling.window.h - (scaling.scale_height(136) + layout.Panel.Height)
};
end
end
--Create exports..
local Initializer = {};
function Initializer:ApplyController()
gController:SetLayout(gSettings.Controller);
end
function Initializer:ApplyLayout()
gSingleDisplay:Destroy();
gDoubleDisplay:Destroy();
local singleLayout = LoadFile_s(GetResourcePath('layouts/' .. gSettings.SingleLayout));
if singleLayout then
PrepareLayout(singleLayout.Single, gSettings.SingleScale);
local position = gSettings.SinglePosition;
if position == nil then
gSettings.SinglePosition = GetDefaultPosition(singleLayout.Single);
settings.save();
end
gSingleDisplay:Initialize(singleLayout.Single);
else
Error('Failed to load single layout. Please enter "/tc" to open the menu and select a valid layout.');
end
local doubleLayout = LoadFile_s(GetResourcePath('layouts/' .. gSettings.DoubleLayout));
if doubleLayout then
PrepareLayout(doubleLayout.Double, gSettings.DoubleScale);
local position = gSettings.DoublePosition;
if position == nil then
gSettings.DoublePosition = GetDefaultPosition(doubleLayout.Double);
settings.save();
end
gDoubleDisplay:Initialize(doubleLayout.Double);
else
Error('Failed to load double layout. Please enter "/tc" to open the menu and select a valid layout.');
end
gTextureCache:Clear();
end
settings.register('settings', 'settings_update', function(newSettings)
gSettings = newSettings;
UpdateSettings();
Initializer:ApplyController();
Initializer:ApplyLayout();
end);
Initializer:ApplyController();
Initializer:ApplyLayout();
return Initializer;