Please give code with examples, especially if it's using the spring commands (never learned that
mouse cursor icon
Moderator: Moderators
mouse cursor icon
How can I programatically change the mouse cursor icon with Lua?
Please give code with examples, especially if it's using the spring commands (never learned that
).
Please give code with examples, especially if it's using the spring commands (never learned that
Re: mouse cursor icon
From unsynced code:
Note, that iconFileName is not the full filename instead it is like this:
filename: Anims/cursorattack_0.bmp
iconFileName: cursorattack
Example of latter for a custom command: https://sourceforge.net/p/spring1944/co ... eClear.lua
Hopefully would work with a native engine command also.
Code: Select all
Spring.SetMouseCursor
( string cursorName [, number scale ] ) -> nilCode: Select all
Spring.AssignMouseCursor changes/creates the cursor of a single CursorCmd
( string "cmdName", string "iconFileName"
[, boolean overwrite = true [, boolean hotSpotTopLeft = false] ] ) -> nil | booleanfilename: Anims/cursorattack_0.bmp
iconFileName: cursorattack
Example of latter for a custom command: https://sourceforge.net/p/spring1944/co ... eClear.lua
Hopefully would work with a native engine command also.
Re: mouse cursor icon
So in order to change the mouse icon I must use a custom command which I have to create in a synced gadget?
Re: mouse cursor icon
No, you can just use the first API function there to change it whenever you wish to whatever you wish. 
Re: mouse cursor icon
I think I wasn't specific enough when I asked the question.
But I want to change the cursor to a custom icon, one not specified by one of the existing (default or mod) commands.
As you answered this I took a look at the code when I tried this some 1~year ago now, and it's mostly similar, except I'm not sure how you got the CMD_CLEARMINES in
A running version I have is this:
gadget:
(don't have anything anymore in the unsynced widget, but it would be something like this)
But I want to change the cursor to a custom icon, one not specified by one of the existing (default or mod) commands.
As you answered this I took a look at the code when I tried this some 1~year ago now, and it's mostly similar, except I'm not sure how you got the CMD_CLEARMINES in
Code: Select all
Spring.SetCustomCommandDrawData(CMD_CLEARMINES, "Clear Mines", {1,0.5,0,.8}, false)
gadget:
Code: Select all
CMD_RESIZE_X = 30521
local myCustomDesc = {
name = "resize-x",
action = "resize-x",
id = CMD_RESIZE_X,
type = CMDTYPE.ICON_MAP, -- or whatever is suitable
tooltip = "resizes x",
cursor = "resize-x",
}
function gadget:Initialize()
gadgetHandler:RegisterCMDID(CMD_RESIZE_X)
Spring.AssignMouseCursor("resize-x", "cursor-x", true, true)
Spring.SetCustomCommandDrawData(CMD_RESIZE_X, "resize-x", {1,1,1,0.5}, false)
end
Code: Select all
Spring.SetMouseCursor("resize-x")
Re: mouse cursor icon
S44 generates custom command IDs on the fly as requested;
https://sourceforge.net/p/spring1944/co ... andler.lua
https://sourceforge.net/p/spring1944/co ... andler.lua
