Tuesday, 1 May 2012

More Panel Icons

With all the group icons visible at once, there has to be a way to tell which group the objects belong to.

Highlighting the current group works in a similar way as highlighting menu items, but as there is no way to know in advance which colours will be used for icons, it's safer to modify it's transparency

As with the menu, these use a set of constants to define the alpha levels both normal and highlighted icons.
#constant PGROUP_ALPHA   127
#constant PGROUP_ALPHAHI 255
The initial colours should use a yellow tint for highlighted icons and a darker grey colour for others.

Following on from the last code in the group portion of the SetPanelIcons() function, goes the code to set the colour.
// Change Icon Colour
if thisObject = PanelGroup()
   setSpriteColorAlpha( thisSprite , PGROUP_ALPHAHI )
else
   setSpriteColorAlpha( thisSprite , PGROUP_ALPHA )
endif
This checks to see if the code for the object currently being processed matches the code for the currently selected group and uses the appropriate alpha value.
This is all that is needed for the group icons.

The object icons are done in the same way as the group icons, so a lot of the code can be reused.
This.
   // Process Objects
   if PanelGroup() > 0
      thisString$ = ObjectDetail( PanelGroup() )
      thisMembers = len(thisString$) / 2.0
      nextIcon = 1
      for i=0 to thisMembers - 1
         thisCode$ = mid( thisString$ , i * 2 + 1 , 2 )
         thisObject = Base96Decode( thisCode$ )
//         if ObjectIsKnown( thisObject ) > 0
            thisFrame = ObjectIcon( thisObject )
            thisSprite = panelIconSprite[ nextIcon ]
            setSpriteImage( thisSprite , IconImage() )
            setSpriteAnimation( thisSprite , 64 , 64 , 252 )
            setSpriteFrame( thisSprite , thisFrame )
            setSpriteColorAlpha( thisSprite , PGROUP_ALPHAHI )
            inc nextIcon , 1
            if nextIcon >= firstGroupIcon then exit
//         endif
      next i
      // Reset Remainder
This routine works from a member list, so if there is no active group, then there must be no member list and this routine cannot run. This is the purpose of the first check.

The list is copied to a local variable and its length used to find the number of members.

Now not every object is known about, so as we go through the list, any unknowns are ignored.  Only known objects will be displayed.

Because of this, we can't use the loop counter to get the panel position - as was done with the groups - and so a local variable nextIcon is defined to indicate this.

Now it loops through the list members as before, getting the coded ID and decoding it.

Here, there is a commented out line which checks if an object is known.  As this is an if command, the corresponding endif is also commented out later.

This will be how the unknown objects will be ignored later.  Since we have not yet set which objects are known, for now, this is commented out so all objects will be shown.

There are changes to increment and check the nextIcon variable, and the remainder of the code sets the sprite as was done for the groups.

At the end of this routine, nextIcon points to the first panel position not used by objects and firstGroupIcon points to the position after the last panel position available for objects.

All that remains is to reset the sprites in the gap.
      // Reset Remainder
      for i = nextIcon to firstGroupIcon - 1
         thisSprite = panelIconSprite[ i ]
         setSpriteImage( thisSprite , 0 )
         clearSpriteAnimationFrames( thisSprite )
         setSpriteColorAlpha( thisSprite , PGROUP_ALPHA )
      next i
   endif
endfunction
Now the panel shows an object icon for the axe which corresponding to the highlighted tool group.

No comments:

Post a Comment