Custom Unit Icons: Difference between revisions

From Spring
Jump to navigationJump to search
Knorke (talk | contribs)
icontypes.lua example
Flozi (talk | contribs)
No edit summary
Line 1: Line 1:
==Custom Unit Icons==
==Location==
<code>icontypes.lua</code> is a file in the <code>Gamedata/</code> directory of a Spring Game. It defines the icons used to represent units on the minimap and rendered in place of 3d geometry when zoomed out.


[[Image:Minimap icons.jpg]]
==Source==
The engine source code which parses the data from this file is viewable here:
https://github.com/spring/spring/blob/master/rts/Rendering/IconHandler.cpp


===About===
==Details==


On the minimap the units are displayed as icons, which also appear when you zoom out. Mod developers can set icons for different types of units (such as in the picture above, with different icons for land, air, sea, and commanders), or go so far as to give every unit its own icon.
Game developers can set icons for different types of units, (such as land, air, sea), or go so far as to give every unit its own icon. The different types icons will be shown for friendly units, and enemy units within Line Of Sight. For enemy units in radar range Spring will use the 'default' icon.


The different types icons will be shown for friendly units, and enemy units within Line Of Sight. For enemy units in radar range Spring will use the 'default' icon.
===IconType Properties===
* <code>bitmap</code> is the location of the custom icon bitmap. If it is missing or incorrect, Spring replaces it with the standard radar dot. The bitmap will get blended with the team color, so there is no special team color channel. In order to look nice, the bitmap will need to have an alpha channel for transparency.


===How to specify different types of icons===
* <code>size</code> is a number that acts as multiplier for the icon size. The bigger the number, the bigger the icon will be. Default is 1.


The custom icons specification, gamedata/icontypes.tdf, should look like this:
* <code>distance</code> is a number that acts as a multiplier for the distance at which the unit will show up as an icon. The bigger the number, the further away the camera has to be from the unit for it to turn into an icon. Default is 1.


[icontypes]
* <code>radiusadjust</code> is a boolean that tells Spring whether or not the icon should scale with the unit radius. Default is false.
{
[default]
{
// Spring replaces missing or incorrect bitmaps by the radar dot.
size=1;
radiusadjust=1;
distance=1;
}
[type1]
{
bitmap=icons/type1.bmp;
size=2;
radiusadjust=0;
distance=3;
}
[type2]
{
bitmap=icons/type2.bmp;
size=2;
radiusadjust=0;
distance=0.5;
}
// other type definitions may follow
}


'''bitmap''' is the location of the custom icon bitmap. If it is missing or incorrect, Spring replaces it with the standard radar dot. The bitmap will get blended with the team color, so there is no special team color channel.
===Assigning IconTypes===
In order to look nice, the bitmap will need to have an alpha channel for transparancy.
To assign units to a specific icon type, set the <code>iconType</code> attribute of their UnitDef to the type name set in <code>icontypes.lua</code> (see [[#Example]])


'''size''' is a number that acts as multiplier for the icon size. The bigger the number, the bigger the icon will be. Default is 1.
<code><pre>
...
iconType = "circle",
...
</pre></code>


'''radiusadjust''' is a boolean (0 or 1) that tells Spring whether or not the icon should scale with the unit radius. Default is 0 (false).
If the <code>iconType</code> tag is missing, Spring sets it to the "default" icontype. If the "default" type is not specified, Spring will create it with the default values. Furthermore, enemy units that are within radar range, but not in your Line Of Sight, will be shown as the default icon. Thus if there is a bitmap specified for the "default" icon type it will override the standard radar blip.


'''distance''' is a number that acts as a multiplier for the distance at which the unit will show up as an icon. The bigger the number, the further away the camera has to be from the unit for it to turn into an icon. Default is 1.
==Example==
 
<code><pre>
The "default" icon type is a bit special; every unit that misses an 'iconType' tag (see below) or has one that doesn't match a type specified in gamedate/icontypes.tdf gets assigned to the "default" type. If the "default" type is not specified, Spring will create it with the default values.
local iconTypes = {
 
default = {
Furthermore, enemy units that are within radar range, but not in your Line Of Sight, will be shown as the default icon. Thus if there is a bitmap specified for the "default" icon type it will override the standard radar blip.
size = 1,
 
radiusadjust = true,
=== How to assign icon types to units ===
},
 
flag = {
To assign units to a specific icon type, add the following line to their FBI file:
bitmap = "icons/flag.png",
 
size = 6,
iconType=type1;
radiusadjust = true,
 
distance = 100,
You can replace "type1" with icontypes defined in gamedata/icontypes.tdf. If the tag "iconType" is missing, Spring sets it to the icontype "default".
},
 
circle = {
 
bitmap = "icons/circle.png",
===Example files===
size = 4,
 
radiusadjust = true,
You can grab
distance = 100,
http://teake.home.fmf.nl/temp/unit_icons.zip
},
as a starting set for unit icons.
...
 
The screenshot above was taken using these icons.
 
====icontypes.lua====
example of an icontypes.lua:
<pre>
local icontypes = {
  default = {
    size=1,
    radiusadjust=1,
  },
  flag = {
bitmap = "icons/flag.png",
size = 6,
radiusadjust = 1,
-- distance = 100,
  },
  circle = {
bitmap = "icons/circle.png",
size = 4,
radiusadjust = 1,
-- distance = 100,
  },
  circlecross = {
bitmap = "icons/circlecross.png",
size = 4,
radiusadjust = 1,
-- distance = 100,
  },
  square = {
bitmap = "icons/square.png",
size = 4,
radiusadjust = 1,
-- distance = 100,
  }, 
  circlepie = {
bitmap = "icons/circlepie.png",
size = 3,
radiusadjust = 1,
-- distance = 100,
  },
}
}
return icontypes
</pre>


return iconTypes
</pre></code>


[[Category:Gamedata]]
[[Category:Game development]]
[[Category:Game development]]

Revision as of 21:38, 2 April 2011

Location

icontypes.lua is a file in the Gamedata/ directory of a Spring Game. It defines the icons used to represent units on the minimap and rendered in place of 3d geometry when zoomed out.

Source

The engine source code which parses the data from this file is viewable here: https://github.com/spring/spring/blob/master/rts/Rendering/IconHandler.cpp

Details

Game developers can set icons for different types of units, (such as land, air, sea), or go so far as to give every unit its own icon. The different types icons will be shown for friendly units, and enemy units within Line Of Sight. For enemy units in radar range Spring will use the 'default' icon.

IconType Properties

  • bitmap is the location of the custom icon bitmap. If it is missing or incorrect, Spring replaces it with the standard radar dot. The bitmap will get blended with the team color, so there is no special team color channel. In order to look nice, the bitmap will need to have an alpha channel for transparency.
  • size is a number that acts as multiplier for the icon size. The bigger the number, the bigger the icon will be. Default is 1.
  • distance is a number that acts as a multiplier for the distance at which the unit will show up as an icon. The bigger the number, the further away the camera has to be from the unit for it to turn into an icon. Default is 1.
  • radiusadjust is a boolean that tells Spring whether or not the icon should scale with the unit radius. Default is false.

Assigning IconTypes

To assign units to a specific icon type, set the iconType attribute of their UnitDef to the type name set in icontypes.lua (see #Example)

...
iconType = "circle",
...

If the iconType tag is missing, Spring sets it to the "default" icontype. If the "default" type is not specified, Spring will create it with the default values. Furthermore, enemy units that are within radar range, but not in your Line Of Sight, will be shown as the default icon. Thus if there is a bitmap specified for the "default" icon type it will override the standard radar blip.

Example

local iconTypes = {
	default = {
		size			= 1,
		radiusadjust	=	true,
	},
	flag = {
		bitmap			= "icons/flag.png",
		size			= 6,
		radiusadjust	= true,
		distance		= 100,
	},
	circle = {
		bitmap			= "icons/circle.png",
		size			= 4,
		radiusadjust	= true,
		distance		= 100,
	},
	...
}

return iconTypes