I am trying to add a new state to the custom formations widget.
local formationRankCmdDesc = {
id = CMD_FORMATION_RANK,
type = CMDTYPE.ICON_MODE,
name = 'formation Rank',
action = 'formation_rank',
tooltip = 'Formation rank: units of lower rank line up in front of units of higher rank.',
params = {0, 'Lowest', 'Low', 'Medium', 'High'}
}
The new state is not showing up in the Chili Integral menu. How do I get it to show up?
I have also added it to the custom commands:
function widget:CommandsChanged()
local selectedUnits = Spring.GetSelectedUnits()
local unitID = selectedUnits and selectedUnits[1]
local unitDefID = unitID and Spring.GetUnitDefID(unitID)
if not unitDefID then
return
end
local rank = formationRank[unitID] or defaultRank[unitDefID] or 2
local customCommands = widgetHandler.customCommands
formationRankCmdDesc.params[1] = rank
table.insert(customCommands, selectionRankCmdDesc)
end
function widget:CommandNotify(id, params, options)
if id ~= CMD_FORMATION_RANK then
return false
end
local newRank = params[1]
if options.right then
newRank = (newRank + 2)%4
end
local selectedUnits = Spring.GetSelectedUnits()
for i = 1, #selectedUnits do
formationRank[selectedUnits[i]] = newRank
end
if WG.noises and selectedUnits[1] then
WG.noises.PlayResponse(selectedUnits[1], CMD_SELECTION_RANK)
end
return true
end
What are the requirements to add a state command?
(form formatting should have a code option.)