Skip to content

Commit

Permalink
Try a more modding-friendly way of adding commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogleFrog committed Sep 24, 2024
1 parent 638f8b2 commit efc1f87
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Anims/cursortechup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hotspot topleft
frame cursortechup_0.png 5
Binary file added Anims/cursortechup_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions LuaRules/Configs/ModCommands/tech_up.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

local data = {
name = "TECH_UP",
cmdID = 38412,

commandType = CMDTYPE.ICON_UNIT_OR_AREA,
isState = false, -- Hold fire etc
isInstant = false, -- Such as Stop, Self-D etc
humanName = "Tech Up",
actionName = "techup",
cursor = "Techup",
image = "LuaUI/Images/commands/Bold/tech_up.png", -- If a state, then this should be a list of images.

onCommandMenuByDefault = true,
position = {pos = 7, priority = 0.1},
stateNames = nil, -- A list of what the states are called.
stateTooltip = nil, -- A list of tooltips to use for each state.
tooltip = "Tech Up: Upgrade the constructor's factory to the next tech level, or any other structure to the current tech level.",
}

return data
10 changes: 9 additions & 1 deletion LuaRules/Configs/customcmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
obvious where the extra commands are coming from). ]]

-- if you add a command, please order it by ID!
return {
local commands = {
RETREAT_ZONE = 10001,
RESETFIRE = 10003,
RESETMOVE = 10004,
Expand Down Expand Up @@ -112,3 +112,11 @@ return {
--[[ WARNING!! Only BASE VANILLA ZK commands belong here!
See the bigass chunk of text at the top of the file. ]]
}

local commandFiles = VFS.DirList('LuaRules/Configs/ModCommands')
for i = 1, #commandFiles do
local fileData = VFS.Include(commandFiles[i])
commands[fileData.name] = fileData.cmdID
end

return commands
20 changes: 20 additions & 0 deletions LuaRules/Configs/modCommandsDefs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

local commands = {}
local commandsMap = {}
local commandFiles = VFS.DirList('LuaRules/Configs/ModCommands')
for i = 1, #commandFiles do
local fileData = VFS.Include(commandFiles[i])
fileData.cmdDesc = {
id = fileData.cmdID,
type = fileData.commandType,
tooltip = fileData.name, -- Overridden by luaUI
name = fileData.humanName,
cursor = fileData.cursor,
action = fileData.actionName,
params = {},
}
commands[#commands + 1] = fileData
commandsMap[fileData.cmdID] = fileData
end

return commands, commandsMap
15 changes: 15 additions & 0 deletions LuaRules/Gadgets/unit_tech_k.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ function gadget:GetInfo()
}
end

if not ((modoption == "1") or (modoption == 1)) then
return
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local CMD_TECH_UP = Spring.Utilities.CMD.TECH_UP
local modCommands, modCmdMap = VFS.Include("LuaRules/Configs/modCommandsDefs.lua")
local techCommandData = modCmdMap[CMD_TECH_UP]

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Expand All @@ -23,6 +34,9 @@ local deathCloneDefID = {}
local Vector = Spring.Utilities.Vector

if not gadgetHandler:IsSyncedCode() then
function gadget:Initialize()
Spring.AssignMouseCursor(techCommandData.cursor, "cursortechup", true, true)
end
return
end

Expand Down Expand Up @@ -129,6 +143,7 @@ local tech = 1
function gadget:UnitCreated(unitID, unitDefID)
SetUnitTechLevel(unitID, tech)
tech = tech%10 + 1
Spring.InsertUnitCmdDesc(unitID, techCommandData.cmdDesc)
end

function gadget:UnitDestroyed(unitID, unitDefID, teamID)
Expand Down
8 changes: 7 additions & 1 deletion LuaUI/Configs/border_menu_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ local overrides = {
[CMD_UNIT_FLOAT_STATE] = { texture = {imageDir .. 'states/amph_sink.png', imageDir .. 'states/amph_attack.png', imageDir .. 'states/amph_float.png'}, caption=''},
[CMD_SELECTION_RANK] = { texture = {imageDir .. 'states/selection_rank_0.png', imageDir .. 'states/selection_rank_1.png', imageDir .. 'states/selection_rank_2.png', imageDir .. 'states/selection_rank_3.png'}, text=''},
[CMD_FORMATION_RANK] = { texture = {imageDir .. 'states/formation_rank_0.png', imageDir .. 'states/formation_rank_1.png', imageDir .. 'states/formation_rank_2.png', imageDir .. 'states/formation_rank_3.png'}, text=''},
}
}

-- noone really knows what this table does but it's needed for epic menu to get the hotkey
local custom_cmd_actions = { -- states are 2, not states are 1
Expand Down Expand Up @@ -367,5 +367,11 @@ local custom_cmd_actions = { -- states are 2, not states are 1
formation_rank = 2,
}

local modCommands = VFS.Include("LuaRules/Configs/modCommandsDefs.lua")
for i = 1, #modCommands do
local cmd = modCommands[i]
custom_cmd_actions[cmd.actionName] = cmd.isState and 2 or 1
overrides[cmd.cmdID] = {caption = '', tooltip = cmd.tooltip, texture = cmd.image}
end

return common_commands, states_commands, land_commands, sea_commands, advland_commands, advsea_commands, special_commands, globalCommands, overrides, custom_cmd_actions
17 changes: 17 additions & 0 deletions LuaUI/Configs/customCmdTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,21 @@ for name, data in pairs(custom_cmd_actions) do
fullCustomCmdActions[name] = data
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local modCommands = VFS.Include("LuaRules/Configs/modCommandsDefs.lua")
for i = 1, #modCommands do
local cmd = modCommands[i]
custom_cmd_actions[cmd.cmdID] = {
cmdType = (cmd.isState and 2) or (cmd.isInstant and 3) or 1,
cmdID = cmd.cmdID,
name = cmd.humanName,
states = cmd.stateNames,
}
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

return fullCustomCmdActions
9 changes: 9 additions & 0 deletions LuaUI/Configs/integral_menu_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ local special_commands = {
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local modCommands = VFS.Include("LuaRules/Configs/modCommandsDefs.lua")
for i = 1, #modCommands do
local cmd = modCommands[i]
cmdPosDef[cmd.cmdID] = cmd.position
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

return cmdPosDef, factoryUnitPosDef, factory_commands, econ_commands, defense_commands, special_commands

--------------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions LuaUI/Configs/integral_menu_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,15 @@ end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local modCommands = VFS.Include("LuaRules/Configs/modCommandsDefs.lua")
for i = 1, #modCommands do
local cmd = modCommands[i]
commandDisplayConfig[cmd.cmdID] = {tooltip = cmd.tooltip, texture = cmd.image, stateTooltip = cmd.stateTooltip}
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

return commandPanels, commandPanelMap, commandDisplayConfig, widgetSpaceHidden, textConfig, buttonLayoutConfig, instantCommands, cmdPosDef

--------------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions LuaUI/Configs/integral_menu_culling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,17 @@ local defaultValues = {
--[CMD_FIRE_TOWARDS_ENEMY] = true,
}


local modCommands = VFS.Include("LuaRules/Configs/modCommandsDefs.lua")
for i = 1, #modCommands do
local cmd = modCommands[i]
configList[#configList + 1] = {
cmdID = cmd.cmdID,
default = cmd.onCommandMenuByDefault,
name = cmd.humanName,
state = cmd.isState
}
defaultValues[cmd.cmdID] = not cmd.onCommandMenuByDefault
end

return configList, defaultValues
Binary file added LuaUI/Images/commands/Bold/tech_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit efc1f87

Please sign in to comment.