-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathstartup_info_selector.lua
More file actions
111 lines (93 loc) · 4.08 KB
/
Copy pathstartup_info_selector.lua
File metadata and controls
111 lines (93 loc) · 4.08 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
--all these will be used in LuaUI\Widgets\gui_startup_info_selector.lua
-- Changelog --
-- versus666 (30oct2010) : Added selector to remplace tooltip which is now shown by chili_selection.
-- Added long description of commanders strengths et weakness to tooltip.
-- Commented a lot for easier modification.
local function ReturnFalse()
return false
end
local noCustomComms = ((Spring.GetModOptions().commandertypes == nil or Spring.GetModOptions().commandertypes == '') and true) or false
local function ReturnNoCustomComms()
return noCustomComms
end
local optionData = {}
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- most of the data processing was moved to api_modularcomms.lua
local commDataOrdered = {}
local numComms = 0
for profileID, data in pairs( WG.ModularCommAPI.GetPlayerCommProfiles(Spring.GetMyPlayerID(), true)) do
numComms = numComms + 1
commDataOrdered[numComms] = data
commDataOrdered[numComms].profileID = profileID
end
--Spring.Echo("wololo", "Player " .. Spring.GetMyPlayerID() .. " has " .. numComms .. " comms")
table.sort(commDataOrdered, function(a,b) return a.profileID < b.profileID end)
local chassisImages = {
armcom = "LuaUI/Images/startup_info_selector/chassis_armcom.png",
corcom = "LuaUI/Images/startup_info_selector/chassis_corcom.png",
commrecon = "LuaUI/Images/startup_info_selector/chassis_commrecon.png",
commsupport = "LuaUI/Images/startup_info_selector/chassis_commsupport.png",
benzcom = "LuaUI/Images/startup_info_selector/chassis_benzcom.png",
cremcom = "LuaUI/Images/startup_info_selector/chassis_cremcom.png",
recon = "LuaUI/Images/startup_info_selector/chassis_commrecon.png",
support = "LuaUI/Images/startup_info_selector/chassis_commsupport.png",
assault = "LuaUI/Images/startup_info_selector/chassis_benzcom.png",
strike = "LuaUI/Images/startup_info_selector/chassis_commstrike.png",
knight = "LuaUI/Images/startup_info_selector/chassis_cremcom.png"
}
local moduleDefs, chassisDefs, upgradeUtilities, LEVEL_BOUND, chassisDefByBaseDef, moduleDefNames, chassisDefNames = VFS.Include("LuaRules/Configs/dynamic_comm_defs.lua")
for key, value in pairs(chassisDefs) do
chassisImages[value.name] = value.chassisImage or chassisImages[value.name]
end
local colorWeapon = "\255\255\32\32"
local colorConversion = "\255\255\96\0"
local colorWeaponMod = "\255\255\0\255"
local colorModule = "\255\128\128\255"
local function WriteTooltip(profileID)
local commData = WG.ModularCommAPI.GetCommProfileInfo(profileID)
local str = ''
for i=1,#commData.modules do
str = str .. "\nLEVEL "..(i + 1) .. "\n\tModules:" -- TODO calculate metal cost
for j, modulename in pairs(commData.modules[i]) do
local chassisModuleDefs = moduleDefNames[commData.chassis] or {}
if chassisModuleDefs[modulename] then
local moduleDef = moduleDefs[chassisModuleDefs[modulename]]
local substr = moduleDef.humanName
-- assign color
if (modulename):find("commweapon_") then
substr = colorWeapon..substr
elseif (modulename):find("conversion_") then
substr = colorConversion..substr
elseif (modulename):find("weaponmod_") then
substr = colorWeaponMod..substr
else
substr = colorModule..substr
end
str = str.."\n\t\t"..substr.."\008"
end
end
end
return str
end
local function GetCommSelectTemplate(num, data)
local commProfileID = data.profileID
local option = {
name = data.name,
tooltip = "Select "..data.name..WriteTooltip(commProfileID),
image = chassisImages[data.chassis],
cmd = "customcomm:"..commProfileID,
unitname = comm1Name,
commProfile = commProfileID,
trainer = string.find(commProfileID, "trainer") ~= nil, -- FIXME should probably be in the def table
}
return option
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local i = 0
for i = 1, numComms do
local option = GetCommSelectTemplate(i, commDataOrdered[i])
optionData[#optionData+1] = option
end
return optionData