Adventure Game Studio | Forums

AGS Support => Advanced Technical Forum => Topic started by: bx83 on 09 Nov 2017, 04:06

Title: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: bx83 on 09 Nov 2017, 04:06
Hi,

I know how to change a buttons graphic in a GUI:

Code: [Select]
button.NormalGraphic = 123;

These are for buttons which show inventory items that are there (graphic=123) or not there yet (graphic=456) - they don't need to be clicked, and have no script attached.

But what about when a GUI is invisible? Or, when it's visible, and drops down from the the top with mousover? Can I have code which 'prepares' the graphic for when the GUI is visible or partly visible? (I'm using gIconBar 'when mouse moves over the top of the screen').

Which makes it hard, since I know the code, but not where to put it :/
In rep_exec in global script??...
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: Gurok on 09 Nov 2017, 05:15
Rather than approaching this from the perspective of trying to pre-empt the GUI being displayed, I'd suggest you look at AGS' built-in events.
There are two events associated with inventory items, eEventAddInventory and eEventLoseInventory. These events fire whenever an inventory item is added or removed, respectively.

Since you're concerned only with having a different graphic when items are present, we can filter these events so that we only pay attention to those that matter: the first item added and the last item removed.
You'll need an InventoryWindow to track this, but I presume you're already using one for the aforementioned GUI.

Add or amend the on_event and on_game_start functions in your global script like so:

Code: [Select]
bool wasInventoryEmpty;

function game_start()
{
  wasInventoryEmpty = invMyWindow.ItemCount == 0;
}

function on_event(EventType event, int data)
{
    if(event == eEventAddInventory)
    {
        if(wasInventoryEmpty && invMyWindow.ItemCount > 0) // First item(s) were added
        {
            button.NormalGraphic = 123;
            // Anything else you want to have shown when there are items present
            wasInventoryEmpty = false;
        }
    }
    else
    {
        if(event == eEventLoseInventory)
        {
            if(!wasInventoryEmpty && invMyWindow.ItemCount == 0) // Last item was removed
            {
                button.NormalGraphic = 456;
                // Anything else you want to have shown when there are no items present
                wasInventoryEmpty = true;
            }
        }
    }
}

where invMyWindow is your InventoryWindow.
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: bx83 on 09 Nov 2017, 07:24
Code: [Select]
function game_start() {
...
wasInventoryEmpty = gInventory.ItemCount == 0;
...
}

...

function on_event(EventType event, int data)
{
    if(event == eEventAddInventory)
    {
        if(wasInventoryEmpty && gInventory.ItemCount > 0) // First item(s) were added
        {
if (cJulius.HasInventory(iCarKeys)) {
            Button1.NormalGraphic = 2231;
} else {
Button1.NormalGraphic = 2244;
}
else if (cJulius.HasInventory(iFlowInductor)) {
Button2.NormalGraphic = 2243;
} else {
Button2.NormalGraphic = 2243;
}
else if (cJulius.HasInventory(iBackingPlate)) {
Button3.NormalGraphic = 2233;
} else {
Button3.NormalGraphic = 2246;
}
else if (cJulius.HasInventory(iCog)) {
Button4.NormalGraphic = 2234;
} else {
Button4.NormalGraphic = 2247;
}
else if (cJulius.HasInventory(iCarCoolant)) {
Button5.NormalGraphic = 2235;
} else {
Button5.NormalGraphic = 2248;
}
else if (cJulius.HasInventory(iOilContainer)) {
Button6.NormalGraphic = 2239;
} else {
Button6.NormalGraphic = 2252;
}
else if (cJulius.HasInventory(iCarPetrol)) {
Button7.NormalGraphic = 2240;
} else {
Button7.NormalGraphic = 2253;
}
else if (cJulius.HasInventory(iDialFace1)) {
Button8.NormalGraphic = 2236;
} else {
Button8.NormalGraphic = 2249;
}
else if (cJulius.HasInventory(iKeyboardKeys)) {
Button9.NormalGraphic = 2238;
} else {
Button9.NormalGraphic = 2251;
}
else if (cJulius.HasInventory(iFuzzyDice)) {
Button10.NormalGraphic = 2237;
} else {
Button10.NormalGraphic = 2250;
}
else if (cJulius.HasInventory(iElectricWireSilver)) {
Button11.NormalGraphic = 2241;
} else {
Button11.NormalGraphic = 2254;
}
else if (cJulius.HasInventory(iBobbleHead)) {
Button12.NormalGraphic = 2240;
} else {
Button12.NormalGraphic = 2255;
}
else if (cJulius.HasInventory(iGum)) {
Button13.NormalGraphic = 2232;
} else {
Button13.NormalGraphic = 2245;
}

wasInventoryEmpty = false;

        }
    }
    else
    {
        if(event == eEventLoseInventory)
        {
            if(!wasInventoryEmpty && gInventory.ItemCount == 0) // Last item was removed
            {
if (cJulius.HasInventory(iCarKeys)) {
Button1.NormalGraphic = 2231;
} else {
Button1.NormalGraphic = 2244;
}
else if (cJulius.HasInventory(iFlowInductor)) {
Button2.NormalGraphic = 2243;
} else {
Button2.NormalGraphic = 2243;
}
else if (cJulius.HasInventory(iBackingPlate)) {
Button3.NormalGraphic = 2233;
} else {
Button3.NormalGraphic = 2246;
}
else if (cJulius.HasInventory(iCog)) {
Button4.NormalGraphic = 2234;
} else {
Button4.NormalGraphic = 2247;
}
else if (cJulius.HasInventory(iCarCoolant)) {
Button5.NormalGraphic = 2235;
} else {
Button5.NormalGraphic = 2248;
}
else if (cJulius.HasInventory(iOilContainer)) {
Button6.NormalGraphic = 2239;
} else {
Button6.NormalGraphic = 2252;
}
else if (cJulius.HasInventory(iCarPetrol)) {
Button7.NormalGraphic = 2240;
} else {
Button7.NormalGraphic = 2253;
}
else if (cJulius.HasInventory(iDialFace1)) {
Button8.NormalGraphic = 2236;
} else {
Button8.NormalGraphic = 2249;
}
else if (cJulius.HasInventory(iKeyboardKeys)) {
Button9.NormalGraphic = 2238;
} else {
Button9.NormalGraphic = 2251;
}
else if (cJulius.HasInventory(iFuzzyDice)) {
Button10.NormalGraphic = 2237;
} else {
Button10.NormalGraphic = 2250;
}
else if (cJulius.HasInventory(iElectricWireSilver)) {
Button11.NormalGraphic = 2241;
} else {
Button11.NormalGraphic = 2254;
}
else if (cJulius.HasInventory(iBobbleHead)) {
Button12.NormalGraphic = 2240;
} else {
Button12.NormalGraphic = 2255;
}
else if (cJulius.HasInventory(iGum)) {
Button13.NormalGraphic = 2232;
} else {
Button13.NormalGraphic = 2245;
}

                wasInventoryEmpty = true;
            }
        }
    }
}

"ERROR: .ItemCount is not a public member of GUI."
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: Gurok on 09 Nov 2017, 08:09
Okay, you do not need that wasInventory empty stuff. I perhaps misunderstood your initial statement. Here's a revised on_event:

Spoiler: ShowHide

Code: [Select]
function on_event(EventType event, int data)
{
if(event == eEventAddInventory)
{
if (cJulius.HasInventory(iCarKeys)) {
Button1.NormalGraphic = 2231;
} else {
Button1.NormalGraphic = 2244;
}
if (cJulius.HasInventory(iFlowInductor)) {
Button2.NormalGraphic = 2243;
} else {
Button2.NormalGraphic = 2243;
}
if (cJulius.HasInventory(iBackingPlate)) {
Button3.NormalGraphic = 2233;
} else {
Button3.NormalGraphic = 2246;
}
if (cJulius.HasInventory(iCog)) {
Button4.NormalGraphic = 2234;
} else {
Button4.NormalGraphic = 2247;
}
if (cJulius.HasInventory(iCarCoolant)) {
Button5.NormalGraphic = 2235;
} else {
Button5.NormalGraphic = 2248;
}
if (cJulius.HasInventory(iOilContainer)) {
Button6.NormalGraphic = 2239;
} else {
Button6.NormalGraphic = 2252;
}
if (cJulius.HasInventory(iCarPetrol)) {
Button7.NormalGraphic = 2240;
} else {
Button7.NormalGraphic = 2253;
}
if (cJulius.HasInventory(iDialFace1)) {
Button8.NormalGraphic = 2236;
} else {
Button8.NormalGraphic = 2249;
}
if (cJulius.HasInventory(iKeyboardKeys)) {
Button9.NormalGraphic = 2238;
} else {
Button9.NormalGraphic = 2251;
}
if (cJulius.HasInventory(iFuzzyDice)) {
Button10.NormalGraphic = 2237;
} else {
Button10.NormalGraphic = 2250;
}
if (cJulius.HasInventory(iElectricWireSilver)) {
Button11.NormalGraphic = 2241;
} else {
Button11.NormalGraphic = 2254;
}
if (cJulius.HasInventory(iBobbleHead)) {
Button12.NormalGraphic = 2240;
} else {
Button12.NormalGraphic = 2255;
}
if (cJulius.HasInventory(iGum)) {
Button13.NormalGraphic = 2232;
} else {
Button13.NormalGraphic = 2245;
}
}
else
{
if(event == eEventLoseInventory)
{
if (cJulius.HasInventory(iCarKeys)) {
Button1.NormalGraphic = 2231;
} else {
Button1.NormalGraphic = 2244;
}
if (cJulius.HasInventory(iFlowInductor)) {
Button2.NormalGraphic = 2243;
} else {
Button2.NormalGraphic = 2243;
}
if (cJulius.HasInventory(iBackingPlate)) {
Button3.NormalGraphic = 2233;
} else {
Button3.NormalGraphic = 2246;
}
if (cJulius.HasInventory(iCog)) {
Button4.NormalGraphic = 2234;
} else {
Button4.NormalGraphic = 2247;
}
if (cJulius.HasInventory(iCarCoolant)) {
Button5.NormalGraphic = 2235;
} else {
Button5.NormalGraphic = 2248;
}
if (cJulius.HasInventory(iOilContainer)) {
Button6.NormalGraphic = 2239;
} else {
Button6.NormalGraphic = 2252;
}
if (cJulius.HasInventory(iCarPetrol)) {
Button7.NormalGraphic = 2240;
} else {
Button7.NormalGraphic = 2253;
}
if (cJulius.HasInventory(iDialFace1)) {
Button8.NormalGraphic = 2236;
} else {
Button8.NormalGraphic = 2249;
}
if (cJulius.HasInventory(iKeyboardKeys)) {
Button9.NormalGraphic = 2238;
} else {
Button9.NormalGraphic = 2251;
}
if (cJulius.HasInventory(iFuzzyDice)) {
Button10.NormalGraphic = 2237;
} else {
Button10.NormalGraphic = 2250;
}
if (cJulius.HasInventory(iElectricWireSilver)) {
Button11.NormalGraphic = 2241;
} else {
Button11.NormalGraphic = 2254;
}
if (cJulius.HasInventory(iBobbleHead)) {
Button12.NormalGraphic = 2240;
} else {
Button12.NormalGraphic = 2255;
}
if (cJulius.HasInventory(iGum)) {
Button13.NormalGraphic = 2232;
} else {
Button13.NormalGraphic = 2245;
}
}
}
}


A couple of things:
The else if structure you posted would not work. You can't have an else if for an else block. You do not need the else before your ifs. The if is enough.
By InventoryWindow, I did not mean the GUI you're using, but a type of object called an InventoryWindow. Are you trying to emulate that using buttons? Using an inventory window would be much simpler, in my opinion:
(https://i.imgur.com/QgYIUMa.png)

Edit: I restructured the whole thing. "data" for the eEventAddInventory and eEventLoseInventory events is the ID of the added or removed inventory item. You can use this to eliminate a lot of unnecessary ifs.

Code: [Select]
function on_event(EventType event, int data)
{
switch(event)
{
case eEventAddInventory:
switch(data)
{
case iCarKeys.ID:
Button1.NormalGraphic = 2231;
break;
// This graphic stays the same
/*
case iFlowInductor.ID:
Button2.NormalGraphic = 2243;
break;
*/
case iBackingPlate.ID:
Button3.NormalGraphic = 2234;
break;
case iCog.ID:
Button4.NormalGraphic = 2235;
break;
case iCarCoolant.ID:
Button5.NormalGraphic = 2239;
break;
case iOilContainer.ID:
Button6.NormalGraphic = 2240;
break;
case iCarPetrol.ID:
Button7.NormalGraphic = 2231;
break;
case iDialFace1.ID:
Button8.NormalGraphic = 2236;
break;
case iKeyboardKeys.ID:
Button9.NormalGraphic = 2238;
break;
case iFuzzyDice.ID:
Button10.NormalGraphic = 2237;
break;
case iElectricWireSilver.ID:
Button11.NormalGraphic = 2241;
break;
case iBobbleHead.ID:
Button12.NormalGraphic = 2240;
break;
case iGum.ID:
Button13.NormalGraphic = 2232;
break;
}
break;
case eEventLoseInventory:
switch(data)
{
case iCarKeys.ID:
Button1.NormalGraphic = 2244;
break;
// This graphic stays the same
/*
case iFlowInductor.ID:
Button2.NormalGraphic = 2243;
break;
*/
case iBackingPlate.ID:
Button3.NormalGraphic = 2246;
break;
case iCog.ID:
Button4.NormalGraphic = 2247;
break;
case iCarCoolant.ID:
Button5.NormalGraphic = 2248;
break;
case iOilContainer.ID:
Button6.NormalGraphic = 2252;
break;
case iCarPetrol.ID:
Button7.NormalGraphic = 2253;
break;
case iDialFace1.ID:
Button8.NormalGraphic = 2249;
break;
case iKeyboardKeys.ID:
Button9.NormalGraphic = 2251;
break;
case iFuzzyDice.ID:
Button10.NormalGraphic = 2250;
break;
case iElectricWireSilver.ID:
Button11.NormalGraphic = 2254;
break;
case iBobbleHead.ID:
Button12.NormalGraphic = 2255;
break;
case iGum.ID:
Button13.NormalGraphic = 2245;
break;
}
break;
}
}
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: bx83 on 09 Nov 2017, 09:07
I'm trying to use the gIconbar window, which is a panel at the top of the screen, autohiding, that has the inventory items, inventory, option menu and the load/save games button on it.

(http://redrom.ltd/img/giconbar.png)
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: bx83 on 09 Nov 2017, 09:48
Ah, InvWindow code deleted :)

Now I only have the on_event function.

One final bug:
When I add all items, they all show colour-filled (ie. non-transparent) (correct)
When I add some items, some show colour filled, some show translucent (correct)
When I have *no* items, they all show colour-filled (should be all translucent)

What is wrong?
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: Gurok on 09 Nov 2017, 10:16
If you don't add any items, all of the buttons will show in the state you see in the editor.
Try using the translucent version as your graphic for each button in the editor.

You can add an InventoryWindow to any GUI, including the one you're using.
Though, I understand that it may not be exactly what you want -- you won't get the translucency effect.
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: Khris on 09 Nov 2017, 10:36
I'm trying to understand what's happening, because only adding some items works, but adding items only changes the buttons for those items. It should leave not added items' buttons untouched. So how on earth do those buttons all change to color-filled with only on_event in play? Doesn't make any sense.

bx83, did you remove all code you had tried earlier from rep_exec?
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: Gurok on 09 Nov 2017, 10:41
Khris, I had guessed that he was using the intermediate version of the code (above, in the hide tag).
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: bx83 on 09 Nov 2017, 21:18
Take a look at this image so far:
(http://redrom.ltd/img/objects.png)

As you can see, the two images ('none' and 'all') are exactly the same - I want 'none' to be like the middle image ('some'). In other words, I want all to be saturated, none to be unsaturated, and some to be objects in the inventory saturated only.

Here's the code so far:

Code: [Select]
function on_event(EventType event, int data)
{
if(event == eEventAddInventory)
{
if (cJulius.HasInventory(iCarKeys)) {
Button1.NormalGraphic = 2231;
} else {
Button1.NormalGraphic = 2244;
}
if (cJulius.HasInventory(iFlowInductor)) {
Button2.NormalGraphic = 2243;
} else {
Button2.NormalGraphic = 2256;
}
if (cJulius.HasInventory(iBackingPlate)) {
Button3.NormalGraphic = 2233;
} else {
Button3.NormalGraphic = 2246;
}
if (cJulius.HasInventory(iCog)) {
Button4.NormalGraphic = 2234;
} else {
Button4.NormalGraphic = 2247;
}
if (cJulius.HasInventory(iCarCoolant)) {
Button5.NormalGraphic = 2235;
} else {
Button5.NormalGraphic = 2248;
}
if (cJulius.HasInventory(iOilContainer)) {
Button6.NormalGraphic = 2239;
} else {
Button6.NormalGraphic = 2252;
}
if (cJulius.HasInventory(iCarPetrol)) {
Button7.NormalGraphic = 2240;
} else {
Button7.NormalGraphic = 2253;
}
if (cJulius.HasInventory(iDialFace1)) {
Button8.NormalGraphic = 2236;
} else {
Button8.NormalGraphic = 2249;
}
if (cJulius.HasInventory(iKeyboardKeys)) {
Button9.NormalGraphic = 2238;
} else {
Button9.NormalGraphic = 2251;
}
if (cJulius.HasInventory(iFuzzyDice)) {
Button10.NormalGraphic = 2237;
} else {
Button10.NormalGraphic = 2250;
}
if (cJulius.HasInventory(iElectricWireSilver)) {
Button11.NormalGraphic = 2241;
} else {
Button11.NormalGraphic = 2254;
}
if (cJulius.HasInventory(iBobbleHead)) {
Button12.NormalGraphic = 2242;
} else {
Button12.NormalGraphic = 2255;
}
if (cJulius.HasInventory(iGum)) {
Button13.NormalGraphic = 2232;
} else {
Button13.NormalGraphic = 2245;
}

} else {

if (event == eEventLoseInventory)
{
if (cJulius.HasInventory(iCarKeys)) {
Button1.NormalGraphic = 2231;
} else {
Button1.NormalGraphic = 2244;
}
if (cJulius.HasInventory(iFlowInductor)) {
Button2.NormalGraphic = 2243;
} else {
Button2.NormalGraphic = 2256;
}
if (cJulius.HasInventory(iBackingPlate)) {
Button3.NormalGraphic = 2233;
} else {
Button3.NormalGraphic = 2246;
}
if (cJulius.HasInventory(iCog)) {
Button4.NormalGraphic = 2234;
} else {
Button4.NormalGraphic = 2247;
}
if (cJulius.HasInventory(iCarCoolant)) {
Button5.NormalGraphic = 2235;
} else {
Button5.NormalGraphic = 2248;
}
if (cJulius.HasInventory(iOilContainer)) {
Button6.NormalGraphic = 2239;
} else {
Button6.NormalGraphic = 2252;
}
if (cJulius.HasInventory(iCarPetrol)) {
Button7.NormalGraphic = 2240;
} else {
Button7.NormalGraphic = 2253;
}
if (cJulius.HasInventory(iDialFace1)) {
Button8.NormalGraphic = 2236;
} else {
Button8.NormalGraphic = 2249;
}
if (cJulius.HasInventory(iKeyboardKeys)) {
Button9.NormalGraphic = 2238;
} else {
Button9.NormalGraphic = 2251;
}
if (cJulius.HasInventory(iFuzzyDice)) {
Button10.NormalGraphic = 2237;
} else {
Button10.NormalGraphic = 2250;
}
if (cJulius.HasInventory(iElectricWireSilver)) {
Button11.NormalGraphic = 2241;
} else {
Button11.NormalGraphic = 2254;
}
if (cJulius.HasInventory(iBobbleHead)) {
Button12.NormalGraphic = 2242;
} else {
Button12.NormalGraphic = 2255;
}
if (cJulius.HasInventory(iGum)) {
Button13.NormalGraphic = 2232;
} else {
Button13.NormalGraphic = 2245;
}
}
}
}
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: bx83 on 09 Nov 2017, 21:30
SOLVED :)
Here's the code:

Code: [Select]
function on_event(EventType event, int data)
{
if (
!cJulius.HasInventory(iCarKeys) &&
!cJulius.HasInventory(iFlowInductor) &&
!cJulius.HasInventory(iBackingPlate) &&
!cJulius.HasInventory(iCog) &&
!cJulius.HasInventory(iCarCoolant) &&
!cJulius.HasInventory(iOilContainer) &&
!cJulius.HasInventory(iCarPetrol) &&
!cJulius.HasInventory(iDialFace1) &&
!cJulius.HasInventory(iKeyboardKeys) &&
!cJulius.HasInventory(iFuzzyDice) &&
!cJulius.HasInventory(iElectricWireSilver) &&
!cJulius.HasInventory(iBobbleHead) &&
!cJulius.HasInventory(iGum)
)
{
Button1.NormalGraphic = 2244;
Button2.NormalGraphic = 2256;
Button3.NormalGraphic = 2246;
Button4.NormalGraphic = 2247;
Button5.NormalGraphic = 2248;
Button6.NormalGraphic = 2252;
Button7.NormalGraphic = 2253;
Button8.NormalGraphic = 2249;
Button9.NormalGraphic = 2251;
Button10.NormalGraphic = 2250;
Button11.NormalGraphic = 2254;
Button12.NormalGraphic = 2255;
Button13.NormalGraphic = 2245;
}

if (event == eEventAddInventory || event == eEventLoseInventory)
{
if (cJulius.HasInventory(iCarKeys)) {
Button1.NormalGraphic = 2231;
} else {
Button1.NormalGraphic = 2244;
}
if (cJulius.HasInventory(iFlowInductor)) {
Button2.NormalGraphic = 2243;
} else {
Button2.NormalGraphic = 2256;
}
if (cJulius.HasInventory(iBackingPlate)) {
Button3.NormalGraphic = 2233;
} else {
Button3.NormalGraphic = 2246;
}
if (cJulius.HasInventory(iCog)) {
Button4.NormalGraphic = 2234;
} else {
Button4.NormalGraphic = 2247;
}
if (cJulius.HasInventory(iCarCoolant)) {
Button5.NormalGraphic = 2235;
} else {
Button5.NormalGraphic = 2248;
}
if (cJulius.HasInventory(iOilContainer)) {
Button6.NormalGraphic = 2239;
} else {
Button6.NormalGraphic = 2252;
}
if (cJulius.HasInventory(iCarPetrol)) {
Button7.NormalGraphic = 2240;
} else {
Button7.NormalGraphic = 2253;
}
if (cJulius.HasInventory(iDialFace1)) {
Button8.NormalGraphic = 2236;
} else {
Button8.NormalGraphic = 2249;
}
if (cJulius.HasInventory(iKeyboardKeys)) {
Button9.NormalGraphic = 2238;
} else {
Button9.NormalGraphic = 2251;
}
if (cJulius.HasInventory(iFuzzyDice)) {
Button10.NormalGraphic = 2237;
} else {
Button10.NormalGraphic = 2250;
}
if (cJulius.HasInventory(iElectricWireSilver)) {
Button11.NormalGraphic = 2241;
} else {
Button11.NormalGraphic = 2254;
}
if (cJulius.HasInventory(iBobbleHead)) {
Button12.NormalGraphic = 2242;
} else {
Button12.NormalGraphic = 2255;
}
if (cJulius.HasInventory(iGum)) {
Button13.NormalGraphic = 2232;
} else {
Button13.NormalGraphic = 2245;
}
}
}
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: Gurok on 09 Nov 2017, 22:09
It's important to understand why something works. That first block of code is being called on EVERY event (enters room after fade in, among others). You could make things more efficient by putting the inner part of the if-block in game_start or as I suggested earlier, just making your buttons reflect the initial state of the inventory (all items translucent) in the editor.
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: bx83 on 10 Nov 2017, 03:23
How would game_start call the code on events, or is it just once? This doesn't seem like a good idea to me.
How do I make the buttons reflect their state? In their own script? (RunScript)
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: Gurok on 10 Nov 2017, 03:47
The code to set the initial state of the buttons would be called just once -- when the game starts.
You could break it up like this:

Code: [Select]
    function game_start()
    {
        // Set the initial state of all icon bar buttons
        Button1.NormalGraphic = 2244;
        Button2.NormalGraphic = 2256;
        Button3.NormalGraphic = 2246;
        Button4.NormalGraphic = 2247;
        Button5.NormalGraphic = 2248;
        Button6.NormalGraphic = 2252;
        Button7.NormalGraphic = 2253;
        Button8.NormalGraphic = 2249;
        Button9.NormalGraphic = 2251;
        Button10.NormalGraphic = 2250;
        Button11.NormalGraphic = 2254;
        Button12.NormalGraphic = 2255;
        Button13.NormalGraphic = 2245;
    }

    function on_event(EventType event, int data)
    {
           
            if (event == eEventAddInventory || event == eEventLoseInventory)
            {
                    if (cJulius.HasInventory(iCarKeys)) {
                            Button1.NormalGraphic = 2231;
                    } else {
                            Button1.NormalGraphic = 2244;
                    }
                    if (cJulius.HasInventory(iFlowInductor)) {
                            Button2.NormalGraphic = 2243;
                    } else {
                            Button2.NormalGraphic = 2256;
                    }
                    if (cJulius.HasInventory(iBackingPlate)) {
                            Button3.NormalGraphic = 2233;
                    } else {
                            Button3.NormalGraphic = 2246;
                    }
                    if (cJulius.HasInventory(iCog)) {
                            Button4.NormalGraphic = 2234;
                    } else {
                            Button4.NormalGraphic = 2247;
                    }
                    if (cJulius.HasInventory(iCarCoolant)) {
                            Button5.NormalGraphic = 2235;
                    } else {
                            Button5.NormalGraphic = 2248;
                    }
                    if (cJulius.HasInventory(iOilContainer)) {
                            Button6.NormalGraphic = 2239;
                    } else {
                            Button6.NormalGraphic = 2252;
                    }
                    if (cJulius.HasInventory(iCarPetrol)) {
                            Button7.NormalGraphic = 2240;
                    } else {
                            Button7.NormalGraphic = 2253;
                    }
                    if (cJulius.HasInventory(iDialFace1)) {
                            Button8.NormalGraphic = 2236;
                    } else {
                            Button8.NormalGraphic = 2249;
                    }
                    if (cJulius.HasInventory(iKeyboardKeys)) {
                            Button9.NormalGraphic = 2238;
                    } else {
                            Button9.NormalGraphic = 2251;
                    }
                    if (cJulius.HasInventory(iFuzzyDice)) {
                            Button10.NormalGraphic = 2237;
                    } else {
                            Button10.NormalGraphic = 2250;
                    }
                    if (cJulius.HasInventory(iElectricWireSilver)) {
                            Button11.NormalGraphic = 2241;
                    } else {
                            Button11.NormalGraphic = 2254;
                    }
                    if (cJulius.HasInventory(iBobbleHead)) {
                            Button12.NormalGraphic = 2242;
                    } else {
                            Button12.NormalGraphic = 2255;
                    }
                    if (cJulius.HasInventory(iGum)) {
                            Button13.NormalGraphic = 2232;
                    } else {
                            Button13.NormalGraphic = 2245;
                    }
            }
    }

That said, it would be EVEN SIMPLER to just follow my suggestion and use the translucent graphics for your buttons in the editor, thereby eliminating the block of code in game_start above.
Title: Re: How to change graphic for buttons in GUI - when it loads with mouseover
Post by: bx83 on 10 Nov 2017, 03:59
Ah yes I see - slow smarts day :P