Repository navigation
Expand file tree
/
Copy pathMain.lua
More file actions
480 lines (447 loc) · 16.8 KB
/
Copy pathMain.lua
File metadata and controls
480 lines (447 loc) · 16.8 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
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
ReUI.Require
{
"ReUI.Core >= 1.0.0",
"ReUI.Actions >= 1.3.0",
"ReUI.LINQ >= 1.1.0",
}
function Main()
ReUI.Core.OnPostCreateUI(function(isReplay)
local GetUnitCommandData = GetUnitCommandData
local CategoryMatcher = ReUI.Actions.CategoryMatcher
local CategoryAction = ReUI.Actions.CategoryAction
local IPairsEnumerator = ReUI.LINQ.IPairsEnumerator
local Hotbuild = ReUI.Exists "ReUI.Hotbuild >= 1.1.0" --[[@as ReUI.Hotbuild?]]
local CM = import("/lua/ui/game/commandmode.lua")
local Misc = import("/lua/keymap/misckeyactions.lua")
local Orders = import("/lua/ui/game/orders.lua")
local attackMoveModeData = {
name = "RULEUCC_Script",
AbilityName = 'AttackMove',
TaskName = 'AttackMove',
Cursor = 'ATTACK_MOVE',
}
local Contains = IPairsEnumerator:Contains()
local AllRepeatQueue = IPairsEnumerator
---@param unit UserUnit
:All(function(unit)
return unit:IsRepeatQueue()
end)
---@param selection UserUnit[]?
local function ToggleRepeatQueue(selection)
if not selection then
return
end
local isRepeatBuild = AllRepeatQueue(selection)
and 'false'
or 'true'
---@param unit UserUnit
for _, unit in selection do
unit:ProcessInfo('SetRepeatQueue', isRepeatBuild)
if EntityCategoryContains(categories.EXTERNALFACTORY + categories.EXTERNALFACTORYUNIT, unit) then
unit:GetCreator():ProcessInfo('SetRepeatQueue', isRepeatBuild)
end
end
end
---@param selection UserUnit[]?
local function TogglePause(selection)
if table.empty(selection) then
return
end
---@cast selection -nil
local paused = not GetIsPaused(selection)
SetPaused(selection, paused)
local checkedS = paused and "true" or "false"
-- If we have exFacs platforms or exFac units selected, we'll pause their counterparts as well
for _, exFac in EntityCategoryFilterDown(categories.EXTERNALFACTORY +
categories.EXTERNALFACTORYUNIT,
selection) do
exFac:GetCreator():ProcessInfo('SetPaused', checkedS)
end
end
local ReConstruction = ReUI.Exists "ReUI.Construction >= 1.2.0" --[[@as ReUI.Construction?]]
if ReConstruction then
CategoryMatcher "Pause / Append unit for transportation"
:Modifiers { shift = true }
{
CategoryAction(categories.TRANSPORTATION)
:Action(function(selection)
ReUI.Actions.ProcessAction "reui_construction_append_transport_cargo"
end),
CategoryAction()
:Match(function(selection, category)
return true
end)
:Action(TogglePause),
}
end
CategoryMatcher "Transportation / Overcharge / Repeat queue"
:Modifiers { shift = true }
{
CategoryAction(), -- do nothing if no selection
CategoryAction(categories.TRANSPORTATION)
:Action "StartCommandMode order RULEUCC_Transport",
CategoryAction(categories.COMMAND + categories.SUBCOMMANDER)
:Action(Orders.EnterOverchargeMode),
-- CategoryAction(categories.xrl0302)
-- :Action(function() Misc.toggleScript "Production" end),
CategoryAction(categories.FACTORY + categories.EXTERNALFACTORY)
:Action(ToggleRepeatQueue)
}
CategoryMatcher "Transportation / Overcharge / Repeat queue / Explode Fire Beetle"
:Modifiers { shift = true }
{
CategoryAction(), -- do nothing if no selection
-- :Action(Misc.AddNearestIdleEngineersSeq),
CategoryAction(categories.TRANSPORTATION)
:Action "StartCommandMode order RULEUCC_Transport",
CategoryAction()
:Match(function(selection)
local orders, _, _ = GetUnitCommandData(selection)
return Contains(orders, "RULEUCC_Overcharge")
end)
:Action(Orders.EnterOverchargeMode),
-- CategoryAction(categories.ENGINEER)
-- :Action(Misc.AddNearestIdleEngineersSeq),
CategoryAction(categories.xrl0302)
:Action(function() Misc.toggleScript "Production" end),
CategoryAction(categories.FACTORY + categories.EXTERNALFACTORY)
:Action(ToggleRepeatQueue)
}
CategoryMatcher "Launch missile / attack-reclaim / attack order"
:Modifiers { shift = true }
{
CategoryAction(categories.SILO * categories.STRUCTURE * categories.TECH3 + categories.xsb2401)
:Action 'StartCommandMode order RULEUCC_Nuke',
CategoryAction(categories.SILO * categories.STRUCTURE * categories.TECH2)
:Action 'StartCommandMode order RULEUCC_Tactical',
CategoryAction(categories.ENGINEER * (categories.TECH1 + categories.TECH2 + categories.TECH3)
+ categories.FACTORY * categories.STRUCTURE - categories.SUBCOMMANDER)
:Action(function(selection)
CM.StartCommandMode("order", attackMoveModeData)
end),
CategoryAction()
:Match(function(selection, category)
return true
end)
:Action 'StartCommandMode order RULEUCC_Attack',
}
CategoryMatcher "Select nearest idle t1 engineer / reclaim / toggle shields / toggle stealth / toggle jamming"
:Modifiers { shift = true }
{
CategoryAction()
:Action "UI_SelectByCategory +inview +nearest +idle ENGINEER TECH1",
CategoryAction(categories.RECLAIM)
:Action "StartCommandMode order RULEUCC_Reclaim",
CategoryAction()
:Match(function(selection)
local orders, toggles, _ = GetUnitCommandData(selection)
return Contains(toggles, "RULEUTC_ShieldToggle")
end)
:Action(function() Misc.toggleScript "Shield" end),
CategoryAction()
:Match(function(selection)
local orders, toggles, _ = GetUnitCommandData(selection)
return Contains(toggles, "RULEUTC_JammingToggle")
end)
:Action(function() Misc.toggleScript "Jamming" end),
CategoryAction()
:Match(function(selection)
local orders, toggles, _ = GetUnitCommandData(selection)
return Contains(toggles, "RULEUTC_StealthToggle")
end)
:Action(function() Misc.toggleScript "Stealth" end),
}
CategoryMatcher "Move / Select nearest transport"
:Modifiers { shift = true }
{
CategoryAction()
:Action "UI_SelectByCategory +nearest +idle AIR TRANSPORTATION",
CategoryAction()
:Match(function(selection, category)
return true
end)
:Action "StartCommandMode order RULEUCC_Move",
}
local BuildSensorsF
if Hotbuild then
Hotbuild.AddHotbuild("SensorsAKA", {
-- Air scouts
'uea0101',
'xsa0101',
'ura0101',
'uaa0101',
-- Land scouts
'uel0101',
'xsl0101',
'url0101',
'ual0101',
-- Omni sensors with pgens
{
templateData = {
6,
6,
{
'ueb3104',
1318,
0,
0
},
{
'ueb1101',
1362,
2,
0
},
{
'ueb1101',
1364,
0,
2
},
{
'ueb1101',
1367,
-2,
0
},
{
'ueb1101',
1370,
0,
-2
}
},
name = 'Omni Sensor Array',
icon = 'ueb3104',
templateID = 15
},
{
templateData = {
6,
6,
{
'xsb3104',
1318,
0,
0
},
{
'xsb1101',
1362,
2,
0
},
{
'xsb1101',
1364,
0,
2
},
{
'xsb1101',
1367,
-2,
0
},
{
'xsb1101',
1370,
0,
-2
}
},
name = 'Omni Sensor Array',
icon = 'xsb3104',
templateID = 15
},
{
templateData = {
6,
6,
{
'urb3104',
1318,
0,
0
},
{
'urb1101',
1362,
2,
0
},
{
'urb1101',
1364,
0,
2
},
{
'urb1101',
1367,
-2,
0
},
{
'urb1101',
1370,
0,
-2
}
},
name = 'Omni Sensor Array',
icon = 'urb3104',
templateID = 15
},
{
templateData = {
6,
6,
{
'uab3104',
1318,
0,
0
},
{
'uab1101',
1362,
2,
0
},
{
'uab1101',
1364,
0,
2
},
{
'uab1101',
1367,
-2,
0
},
{
'uab1101',
1370,
0,
-2
}
},
name = 'Omni Sensor Array',
icon = 'uab3104',
templateID = 15
},
-- t2 radars
'ueb3201',
'xsb3201',
'urb3201',
'uab3201',
-- t1 radars
'ueb3101',
'xsb3101',
'urb3101',
'uab3101',
-- t3 sonars
'urs0305',
'ues0305',
'uas0305',
-- t2 sonars
'ueb3202',
'xsb3202',
'urb3202',
'uab3202',
-- t1 sonars
'ueb3102',
'xsb3102',
'urb3102',
'uab3102',
-- Eye and Soothsayer
'xrb3301',
'xab3301',
})
BuildSensorsF = function()
Hotbuild.ProcessHotbuild "SensorsAKA"
end
else
BuildSensorsF = function()
import("/lua/keymap/hotbuild.lua").buildAction "Sensors"
end
end
CategoryMatcher "Select nearest air scout / build sensors"
:Modifiers { shift = true }
{
CategoryAction()
:Action "UI_SelectByCategory +nearest AIR INTELLIGENCE",
CategoryAction(categories.AIR * categories.INTELLIGENCE)
:Action "UI_SelectByCategory AIR INTELLIGENCE",
CategoryAction()
:Match(function(selection, category)
return true
end)
:Action(BuildSensorsF),
}
local selectionChanged = true
import("/lua/ui/game/gamemain.lua").ObserveSelection:AddObserver(function(info)
selectionChanged = not table.empty(info.added)
end)
---@type UserCameraSettings?
local defaultSettings
---@type UserCameraSettings?
local lastSettings
---@param v1 Vector
---@param v2 Vector
---@return boolean
local function CompareVectors(v1, v2)
return v1[1] == v2[1] and v1[2] == v2[2] and v1[3] == v2[3]
end
local function ZoomToggle()
local worldCamera = GetCamera('WorldCamera')
if defaultSettings == nil then
lastSettings = worldCamera:SaveSettings()
worldCamera:Reset()
defaultSettings = worldCamera:SaveSettings()
return
end
local current = worldCamera:SaveSettings()
if not CompareVectors(current.Focus, defaultSettings.Focus)
or current.Heading ~= defaultSettings.Heading
or current.Pitch ~= defaultSettings.Pitch
or current.Zoom ~= defaultSettings.Zoom
or lastSettings == nil then
worldCamera:Reset()
lastSettings = current
else
worldCamera:RestoreSettings(lastSettings)
lastSettings = nil
end
end
CategoryMatcher "Zoom out / Soft stop / Hard stop"
{
CategoryAction()
:Action(ZoomToggle),
CategoryAction()
:Match(function(selection, category)
return true
end)
:Action(function(selection)
if selectionChanged then
Orders.SoftStop(selection)
else
Orders.Stop(selection)
end
selectionChanged = false
end),
}
CategoryMatcher "Zoom out / Hard stop"
{
CategoryAction()
:Action(ZoomToggle),
CategoryAction()
:Match(function(selection, category)
return true
end)
:Action(Orders.Stop),
}
end)
end