Page 1 of 1

User Specified Icons

Posted: 23 Nov 2006, 17:52
by trepan
It is now possible for users to specify their own icons (for the minimap,
and when zoomed out). This will override the mod's icon settings. There
is also a new filename that can be used to load user icons, usericons.tdf.
This file is loaded before the usual icontypes.tdf, and the first icon entry
of a particular name is the one that is used.

The user specification can only be done through the LUA UI interface
(so far). It is also possible to create animated icons (you will have to
have the LUA calls change the icon names at the appropriate times).
The LUA callout is Spring.SetUnitDefIcon(number udid, string "icon").

Here is an example of the code that could be used:

Code: Select all

-- Setup the unitdef icons
for udid,ud in pairs(UnitDefs) do
  if ((udid ~= nil) and (ud ~= nil)) then
    if (ud.origIconType == nil) then
      -- save the original name, in case we want to revert
      ud.origIconType = ud.iconType
    end

    if (ud.isCommander) then
      Spring.SetUnitDefIcon(udid, "x.png")
    elseif (ud.canFly) then   
      Spring.SetUnitDefIcon(udid, "triangle-up.png")
    elseif ((ud.radarRadius > 1) and not ud.canMove) then
      Spring.SetUnitDefIcon(udid, "hourglass-side.png")
    elseif (ud.isBuilding or ud.isFactory) then
      Spring.SetUnitDefIcon(udid, "square.png")
    elseif (ud.isBuilder) then 
      Spring.SetUnitDefIcon(udid, "cross.png")
    end
  end
end
P.S. It looks like this (and other recent changes), will make it into 0.74b1.

Posted: 23 Nov 2006, 17:58
by trepan
Note that the mod is AA223 (which usually uses the default icon).
Also, the icons in this screenshot are not that good, they need better
outlines.

Image

Posted: 23 Nov 2006, 19:05
by Lippy
Nice work! :-) :-) Will be very useful!

Posted: 23 Nov 2006, 19:13
by PauloMorfeo
Won't that allows us to "cheat" by allowing us to distinguish the enemy commander from the decoys?

Posted: 23 Nov 2006, 19:59
by trepan
Thanks for the reminder.
(... after having been so careful about it when doing the techLevel stuff)

It's been adjusted so that if an icon is being set for a unitDef that has
isCommand set, or TEDClass = COMMANDER, then ALL unitDefs
that match that description will have their icons set to the specified icon.

P.S. At least XTA and AA use "COMMANDER" as the TEDClass for
their decoy commanders.

Posted: 23 Nov 2006, 21:37
by FoeOfTheBee
Will this be based on the iconType fbi tag?

I think I'd prefer that the icon used be determined by UnitName, with the ability to specify icon groups, like this:

Code: Select all

icons.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<icons>

<icon1 img='lvl1air.png'>
<unit>ARMACA</unit>
<unit>ARMBRAWL</unit>
<unit>ARMPNIX</unit>
<unit>ARMLANCE</unit>
<unit>ARMHAWK</unit>
<unit>ARMSEAP</unit>
<unit>ARMAWAC</unit>
<unit>ARMSEHAK</unit>
<unit>ARMCSA</unit>
</icon1>

<icon2 img='lvl1bot.png'>
<unit>ARMCK</unit>
<unit>ARMPW</unit>
<unit>ARMROCK</unit>
<unit>ARMHAM</unit>
<unit>ARMJETH</unit>
<unit>ARMFAST</unit>
</icon2>

</icons>

Posted: 23 Nov 2006, 21:48
by trepan
I think I prefer my way.

1. The same config can be used with multiple mods with no adjustments.
(and you wont have to categorize 300+ units for some mods)

2. It's much shorter to write out, and much more flexible. My way can even
be setup to look like your way (have the LUA parse an XML file that follows
your format).

Posted: 23 Nov 2006, 21:51
by AF
Won't that allows us to "cheat" by allowing us to distinguish the enemy commander from the decoys?
Mouse over a true commander and itll say [tech level 0], but mouse over a decoy commander and it'll say [tech level 2]

Posted: 23 Nov 2006, 21:54
by trepan
AF: and under what conditions does it display the techLevel?

Posted: 23 Nov 2006, 21:57
by FoeOfTheBee
trepan wrote:I think I prefer my way.

1. The same config can be used with multiple mods with no adjustments.
(and you wont have to categorize 300+ units for some mods)

2. It's much shorter to write out, and much more flexible. My way can even
be setup to look like your way (have the LUA parse an XML file that follows
your format).
Ok, with 2 you convinced me. Now I'll have to learn LUA...

Posted: 25 Nov 2006, 15:25
by PauloMorfeo
How does techLevel works? That is not specified by the unit definitions is it?

A Description2 must be added to the unit definitions, then. I really don't fancy the idea that the engine will try to figure out the tech level of my units when i know for sure it will get it wrong (for example, the Commander is, by tradition, technology lvl 10).

Posted: 25 Nov 2006, 15:33
by trepan
The techLevel value is determined from the build tree.
The commanders are techLevel 0, the units they can
build are techLevel 1, and so on. It searches for the
shortest path to build a particular unit. Units types that
are not in the build tree are techLevel -1.

The techLevel is not used by the game directly. I initially
added it to help with the bindbuildtype sorting, but have
since been using it in the LUA UI as well. See the functions
at the end of rts/Sim/Units/UnitDefHandler.cpp.

Posted: 26 Nov 2006, 18:55
by PauloMorfeo
Well, consider the commander, as i said, which is lvl10.

Also, consider some other examples:
XTA! All factories are called lvl-1.
AA, which has the restricted style of factories. First factories are called lvl-1. It's builders and units are called lvl-2. The next factories are called lvl-3, which include the hovercraft plant, which is considered to be a intermediate between lvl-1 and lvl-2 (that is, they are called lvl-1,5 tech).

I'm sorry if you were the one who coded it, i don't want to bash on the work. It is just that i would rather have that under my control.

Posted: 26 Nov 2006, 19:11
by trepan
That's fine, you aren't bashing my work, you just want something different.
My techLevel assignments do exactly what I want them to do: they provide
access to a unit type's build level in the hierarchical build tree.

You can build all of XTA's factories initially, so having them assigned a
techLevel of 1 means that my code is working just fine.

XTA already uses the FBI "Category" tag to assign levels (LEVEL1, LEVEL2,
LEVEL3). Is that not available to you for whatever it is that you are trying
to do? It's accessible to the engine code, AIs, the keybinding code, and the
LUA UI code (and probably in more places).

Posted: 27 Nov 2006, 12:39
by Comp1337
trepan wrote:That's fine, you aren't bashing my work, you just want something different.
My techLevel assignments do exactly what I want them to do: they provide
access to a unit type's build level in the hierarchical build tree.

You can build all of XTA's factories initially, so having them assigned a
techLevel of 1 means that my code is working just fine.

XTA already uses the FBI "Category" tag to assign levels (LEVEL1, LEVEL2,
LEVEL3). Is that not available to you for whatever it is that you are trying
to do? It's accessible to the engine code, AIs, the keybinding code, and the
LUA UI code (and probably in more places).
He wants to maually override the lil nifty UI thing.

Posted: 27 Nov 2006, 15:21
by trepan
It can be done... sorta. You can tweak the tooltip
contents with the lua interface. I also have a
UnitDef Info lua widget started. It dislays all of the
vital stats for the selected unit type, with sub-panels
for its weapons and whatnot.

Image

Posted: 27 Nov 2006, 17:24
by trepan
Here's a link to some preliminary user icons:

http://trepan.bzflag.bz/spring/icons

The usericons.tdf file associates texture files to icon names.

The usericons.lua file associates icon names to unit types
(and is best viewed with an editor that supports LUA syntax highlighting)


P.S. The UserIconsUpdate() routine in usericons.lua is
called from the top level Update() call-in (every frame)