Gamedev:MouseCursors: Difference between revisions

From Spring
Jump to navigationJump to search
Jk (talk | contribs)
m Created page with "Cursors for Spring are stored in the <code>Anims</code> subdirectory. They are simply in Windows .BMP format. To make animated cursors, just make a sequence where the filenames ..."
 
Flozi (talk | contribs)
m Flozi moved page MouseCursors to Gamedev:MouseCursors
 
(38 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Cursors for Spring are stored in the <code>Anims</code>
[[Engine_Development|Development]] < [[Mod_and_Unit_development|Game Development]] < {{FULLPAGENAME}}


subdirectory. They are simply in Windows .BMP format. To make animated cursors, just make a sequence where the filenames start with '_0' at the end of the first in the sequence, going on sequentially until the last frame.
=Mouse Cursors=
==Location==
Cursors for Spring are stored in the <code>Anims/</code> directory.


Here's a list of the various cursor names used in the game:
==Supported Image Formats==
The cursors have to be in either:
* png
* tga
* bmp
To make transparent sections in bmp's use RGB(84, 84, 252).<br/>
The images don't have to be squared neither power-of-two, but those are preferred and the size should be <=128.


==Filename==
Even if your cursor isn't animated, it must have the _0 at the end of its name.
Only when using a .txt this isn't needed.
==Animated Cursors==
===Via Filenames===
To make animated cursors, just make a sequence where the filenames start with '_0' at the end of the first in the sequence, going on sequentially until the last frame. This uses the default `frame time` (= the time each sprite is visible) of 0.1sec.
===Via .txt===
You can also create a .txt file with further specifications for your cursor:
<code>cursorattack.txt:</code>
<div>
<code><pre>
hotspot %hotspot
frame %filename_0 %timespan_0
frame %filename_1 %timespan_1
frame %filename_2 %timespan_2
...
</pre></code>
</div>
The <code>hotspot</code> tag is optional and can be either <code>topleft</code> or <code>center</code>.<br/>
Note, the filenames have to contain the full path, e.g. <code>Anims/CursorMove.png</code>.
=Engine Cursors=
Spring itself just needs one cursor and that's <code>cursornormal</code>, <span class=warning>if this isn't present in your game Spring will crash with an ContentError</span>.
Still there are additional cursors the engine will use when present:<br/>
<span class=note>(When cursors are double named in the table, it means that the following ones are fallbacks.)</span>
<div align="center">
<div align="center">
<table width="50%" border="1">
<table width="60%" border="1" cellspacing=0>
  <tr>
    <th style="background: #CCC; color:#444">Cursor Name</th>
    <th style="background: #CCC; color:#444">Internal Name/Usage</th>
    <th style="background: #CCC; color:#444">Def. Hot Spot</th>
  </tr>
 
  <tr>
    <td>cursornormal</td>
    <td></td>
    <td>TopLeft</td>
  </tr>
 
  <tr>
    <td>cursorareaattack</td>
    <td>Area attack</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorattack</td>
    <td>Area attack</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorattack</td>
    <td>Attack</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorattackbad</td>
    <td>AttackBad</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorattack</td>
    <td>AttackBad</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorbuildbad</td>
    <td>BuildBad</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorbuildgood</td>
    <td>BuildGood</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorcapture</td>
    <td>Capture</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorcentroid</td>
    <td>Centroid</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursordwatch</td>
    <td>DeathWait</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorwait</td>
    <td>DeathWait</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursordgun</td>
    <td>DGun</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorattack</td>
    <td>DGun</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorfight</td>
    <td>Fight</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorattack</td>
    <td>Fight</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorgather</td>
    <td>GatherWait</td>
    <td>Center</td>
  </tr>
 
   <tr>
   <tr>
     <th valign="top" height="19" width="30%" bgcolor="#C0C0C0">Sequence name</th>
     <td>cursorwait</td>
     <th valign="top" height="19" width="70%" bgcolor="#C0C0C0">Description</th>
     <td>GatherWait</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursorattack_0</td>
     <td>cursordefend</td>
     <td valign="top" height="19" width="70%">Attack Command Cursor</td>
     <td>Guard</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursorcapture_0</td>
     <td>cursorpickup</td>
     <td valign="top" height="19" width="70%">Capture Command Cursor</td>
     <td>Load units</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursordefend_0</td>
     <td>cursormove</td>
     <td valign="top" height="19" width="70%">Guard Command Cursor</td>
     <td>Move</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursormove_0</td>
     <td>cursorpatrol</td>
     <td valign="top" height="19" width="70%">Move Command Cursor</td>
     <td>Patrol</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursornormal_0</td>
     <td>cursorreclamate</td>
     <td valign="top" height="19" width="70%">Default (unactive) cursor</td>
     <td>Reclaim</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursorpatrol_0</td>
     <td>cursorrepair</td>
     <td valign="top" height="19" width="70%">Patrol Command Cursor</td>
     <td>Repair</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursorpickup_0</td>
     <td>cursorrevive</td>
     <td valign="top" height="19" width="70%">Load Command Cursor</td>
     <td>Resurrect</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursorreclamate_0</td>
     <td>cursorrepair</td>
     <td valign="top" height="19" width="70%">Reclaim Command Cursor</td>
     <td>Resurrect</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursorrepair_0</td>
     <td>cursorrestore</td>
     <td valign="top" height="19" width="70%">Repair Command Cursor</td>
     <td>Restore</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursorrevive_0</td>
     <td>cursorrepair</td>
     <td valign="top" height="19" width="70%">Revive (resurrect) Command Cursor</td>
     <td>Restore</td>
    <td>Center</td>
   </tr>
   </tr>
   <tr>
   <tr>
     <td valign="top" height="19" width="30%">cursorunload_0</td>
     <td>cursorselfd</td>
     <td valign="top" height="19" width="70%">Unload Command Cursor</td>
    <td>SelfD</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursornumber</td>
    <td>SquadWait</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorwait</td>
    <td>SquadWait</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursortime</td>
    <td>TimeWait</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorwait</td>
    <td>TimeWait</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorunload</td>
     <td>Unload units</td>
    <td>Center</td>
  </tr>
 
  <tr>
    <td>cursorwait</td>
    <td>Wait</td>
    <td>Center</td>
   </tr>
   </tr>
</table>
</table>
</div>
</div>


Cursors should generally be limited to 16x16 to 32x32 pixels in size, but there is no limit. To make transparent sections, use the color RGB(84, 84, 252). Even if there is only one cursor in your sequence, it must have the _0 at the end of its name. All cursors must also be present in one form or another, even if they are not used by your mod or else Spring will whine.
Example: A <code>cursorattack_0.bmp</code> (same for <code>cursorattack.txt</code>) in your <code>Anims/</code> dir will automatically used for attack commands.
 
=Lua/Custom Cursors=
==Runtime Replacing Default Cursors==
To runtime change cursors (e.g. per-faction cursors or user-configurable ones) you may want to use [[Lua_UnsyncedCtrl#GUI_2 | Spring.ReplaceMouseCursor]]. Example:
 
<code><pre>
Spring.ReplaceMouseCursor("cursorattack", "faction2_subdir/cursorattack")
Spring.ReplaceMouseCursor("cursormove", "faction2_subdir/cursormove")
...
</pre></code>
 
==Give Custom Commands a Cursor==
First you need to register your custom cursor with <code>Spring.AssignMouseCursor</code>. After that you can use it in <code>Spring.EditUnitCmdDesc/Spring.InsertUnitCmdDesc</code>:
<code><pre>
--loads cursor from foo_cursor.txt, foo_cursor_0.bmp, ...
Spring.AssignMouseCursor("mahcursor", "foo_cursor", false)
 
--NOTE: this is SYNCED code!
--add custom cmddesc
Spring.InsertUnitCmdDesc(unitID, {
  ...
  cursor = "mahcursor",
  ...
})
</pre></code>
 


[[Category:Game development]]
[[Category:Game Dev]]

Latest revision as of 23:33, 26 October 2013

Development < Game Development < Gamedev:MouseCursors

Mouse Cursors

Location

Cursors for Spring are stored in the Anims/ directory.

Supported Image Formats

The cursors have to be in either:

  • png
  • tga
  • bmp

To make transparent sections in bmp's use RGB(84, 84, 252).
The images don't have to be squared neither power-of-two, but those are preferred and the size should be <=128.

Filename

Even if your cursor isn't animated, it must have the _0 at the end of its name. Only when using a .txt this isn't needed.

Animated Cursors

Via Filenames

To make animated cursors, just make a sequence where the filenames start with '_0' at the end of the first in the sequence, going on sequentially until the last frame. This uses the default `frame time` (= the time each sprite is visible) of 0.1sec.

Via .txt

You can also create a .txt file with further specifications for your cursor:

cursorattack.txt:

hotspot %hotspot
frame %filename_0 %timespan_0
frame %filename_1 %timespan_1
frame %filename_2 %timespan_2
...

The hotspot tag is optional and can be either topleft or center.
Note, the filenames have to contain the full path, e.g. Anims/CursorMove.png.

Engine Cursors

Spring itself just needs one cursor and that's cursornormal, if this isn't present in your game Spring will crash with an ContentError.

Still there are additional cursors the engine will use when present:
(When cursors are double named in the table, it means that the following ones are fallbacks.)

Cursor Name Internal Name/Usage Def. Hot Spot
cursornormal TopLeft
cursorareaattack Area attack Center
cursorattack Area attack Center
cursorattack Attack Center
cursorattackbad AttackBad Center
cursorattack AttackBad Center
cursorbuildbad BuildBad Center
cursorbuildgood BuildGood Center
cursorcapture Capture Center
cursorcentroid Centroid Center
cursordwatch DeathWait Center
cursorwait DeathWait Center
cursordgun DGun Center
cursorattack DGun Center
cursorfight Fight Center
cursorattack Fight Center
cursorgather GatherWait Center
cursorwait GatherWait Center
cursordefend Guard Center
cursorpickup Load units Center
cursormove Move Center
cursorpatrol Patrol Center
cursorreclamate Reclaim Center
cursorrepair Repair Center
cursorrevive Resurrect Center
cursorrepair Resurrect Center
cursorrestore Restore Center
cursorrepair Restore Center
cursorselfd SelfD Center
cursornumber SquadWait Center
cursorwait SquadWait Center
cursortime TimeWait Center
cursorwait TimeWait Center
cursorunload Unload units Center
cursorwait Wait Center

Example: A cursorattack_0.bmp (same for cursorattack.txt) in your Anims/ dir will automatically used for attack commands.

Lua/Custom Cursors

Runtime Replacing Default Cursors

To runtime change cursors (e.g. per-faction cursors or user-configurable ones) you may want to use Spring.ReplaceMouseCursor. Example:

Spring.ReplaceMouseCursor("cursorattack", "faction2_subdir/cursorattack")
Spring.ReplaceMouseCursor("cursormove", "faction2_subdir/cursormove")
...

Give Custom Commands a Cursor

First you need to register your custom cursor with Spring.AssignMouseCursor. After that you can use it in Spring.EditUnitCmdDesc/Spring.InsertUnitCmdDesc:

--loads cursor from foo_cursor.txt, foo_cursor_0.bmp, ...
Spring.AssignMouseCursor("mahcursor", "foo_cursor", false)

--NOTE: this is SYNCED code!
--add custom cmddesc
Spring.InsertUnitCmdDesc(unitID, {
  ...
  cursor = "mahcursor",
  ...
})