Can you turn off a GUI's Object?

Started by Eddie Chewbacca, Mon 22/03/2004 05:20:11

Previous topic - Next topic

Eddie Chewbacca

Hello,

   I haven't spent to much time learning about GUI's as yet, as I' hoping just to use the Standard GUI's for my first game.  However I want to be able to do a couple of things with them and I have spent the last hour reading and searching for the answers with no luck.  

 My situation is I have a room where a character can walk around in normally, but when he interacts with something, I want to be able to turn off the "Walk" GUI Object, but I can't find the right function to use, I can only find GUIOn and GUIOff, which is not want I want as that turns off the whole GUI and not just that Object.  Is there a simple way to do this?  

 My second question is a little more complicated, and I probably need to fiddle around a little more searching and learning how to do this.  I want to add an extra button to the standard "Inventory" GUI, which is like a Turn on (Or Interact) command, which will allow the player to simply click on the item (Say a torch) in the inventory gui to turn it on.  I was just wondering if there is any example code out there on how I need to code this action, and info on what else is required.  If someone could do this, that would be great, but for now my first question is my main priority.  

Thanks, Eddie.

Dorcan

1. To hide a button, you could use the SetButtonPic function and change your button graphic into a transparent sprite.

2. Creating your own inventory

Eddie Chewbacca

I'll try that first part out, probably tomorrow.  I did visit the site listed for my second question, but unfortunately for me it is in a language I don't understand, but I'll check out the pictures and a few key words and see if I can make something out, a real challenge.  :)

Darth Mandarb

Same tutorial, in English

Where I learned it from!  It's a great tutorial!

~ d

Eddie Chewbacca

Hello,

   Thanks for the notes so far, that Tutorial will be great.  Tonight however I have only been concentrating on the first question and I am still stuck.  I run the command mentioned as soon as the player enters the room, which changes the picture of the button, but the walk cursor still appears.  I am not sure if I need to modify the script for this button.  I have been experimenting with "SetCursorMode(5)", (Mode=PickUp, displays a cross which does not do anything if I click on it), but I don't know how to set the cursor to this mode when I click on the old WALK button.  

I have tried testing the below out, but for some reason my message does not display when I click on WALK, but it does if I click on INVENTORY, what am I missing, I can't see where it checks the button number before this function.   Am I on the right track here, or am I over looking a simpler soloution?  Below is some of the global script where I was trying to learn how the GUI works a little more and place in my messages.  Unfortunately I have not had much time over the last couple of days to follow this up further, but hopefully over the next couple of days I'll dive into learning about GUI's a lot more, but this is a great start.

// main global script file

function show_inventory_window () {
 // This demonstrates both types of inventory window - the first part is how to
 // show the built-in inventory window, the second part uses the custom one.
 // Un-comment one section or the other below.
 
 // ** DEFAULT INVENTORY WINDOW
 InventoryScreen();
/*  
 // ** CUSTOM INVENTORY WINDOW
 GUIOn (INVENTORY);  
 // switch to the Use cursor (to select items with)
 SetCursorMode (MODE_USE);
 // But, override the appearance to look like the arrow
 SetMouseCursor (6);
*/
}

function interface_click(int interface, int button) {
 Display("Button Clicked.");
 if (interface == ICONBAR) {

// **************** This is the start of th code I have added, but it never executes, except the first message if I click on INVENTORY instead of WALK ************

   Display("IconBar Button Clicked.");
   if (button == 1)
   {
   if (GetGlobalInt(10)==1)
      {
      Display("Change Cursor Mode To Number 5");
      SetCursorMode(5);
      Wait(160);
      }
   else
      {
      Display("Change Cursor Mode To Number 0");
      SetCursorMode(0);
      Wait(160);
      }
   }
   else if (button == 4) {  // show inventory

// ********* This is the end of the new/modified code ***************

     show_inventory_window();
   }
   else if (button == 5) {   // use selected inventory
     if (character[ GetPlayerCharacter() ].activeinv >= 0)
       SetCursorMode(4);
   }
   else if (button == 6)    // save game
     SaveGameDialog();
   else if (button == 7)   // load game
     RestoreGameDialog();
   else if (button == 8)   // quit
     QuitGame(1);
   else if (button == 9)    // about
     Display("Adventure Game Studio v2 run-time engine[[Copyright (c) 1999-2003 Chris Jones");
 }  // end if interface ICONBAR


I will check this again, but are there any other tutorials around besides the one on the links page.  They are great, but only to get you going, and some are for the old DOS version which has talkes about things that no longer exist.  If not when I've spent some time learning this program a lot more and am becoming a lot more skilled maybe I'll write some to handle similar questions to what I had, which I thought were handy topics.  If they already exist, great, where can I find some?

Hopefully I'm not too much of a pain and thanks again for everything.  (This is my largest post ever!)

SSH

The problem is that GUI buttons can be set to do one of three things: nothing, run script (ie go to interface_click) and set a cursor mode. The walk button sets cursor mode withou trunning the script. You'll need to go to the GUI editor and change the walk button to run the script instead.

Also, don't forget that right-click cycles the cursor mode, so you'll need to change that code somehow. It might be easier to put something in repeatedly_execute like:

if ((GetCursorMode()==MODE_WALK) && (GetGlobalInt(10)==1)) {
SetCursorMode(5);
}
12

Eddie Chewbacca

Thanks for that SSH.  

    I changed the WALK button to run a script instead of use cursor mode WALK. (Out of interest can you modify the code behind this cursor mode, or can you create your own?  If so are there any Tuturials on this.)  I also tried your code for the right clicking issue, however once you right clicked until WALK (When the cursor changed accordingly), when attempting to right click again, it does not change, as it must always be switching the cursor mode back to the new Cursor Mode.   :P

    So in the end I modified the function "on_mouse_click", inparticular where the value of BUTTON was for the right button.  I used the below code which seemed to do the job fine.  I am curious to know though if the function "repeatedly_execute" could still be used to do this action if there is a way.  Maybe adding a pause in between the loop may allow the right click to be recognised, if you can pause the loop but still allow interactions.  Does using this function put a high load on the CPU or reduce performance of the game, just out of interest.  

   Any way thanks for your help, that sorted things out so I now have a fair knowledge on GUI's and how they work, now to dive into the second part to learn more.

function on_mouse_click(int button) {
 // called when a mouse button is clicked. button is either LEFT or RIGHT
 if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
 }
 else if (button==LEFT) {
   ProcessClick(mouse.x, mouse.y, GetCursorMode() );
 }
 else
   {   // right-click, so cycle cursor
   if (GetGlobalInt(10)==1)
      {
      // Replace CursorMode 0 with CursorMode 5
      if (GetCursorMode() == 5)
         {
         SetCursorMode(1);
         }
      else if (GetCursorMode() == 3)
         {
         // Check to see if an inventory item has been selected or not, to determine the next Cursor Mode
         if (character[ GetPlayerCharacter() ].activeinv == -1)
            {
            SetCursorMode(5);
            }
         else
            {
            SetCursorMode(4);
            }
         }
      else if (GetCursorMode() == 4)
         {
         SetCursorMode(5);
         }
      else
         {
         SetNextCursorMode();
         }
      }
   else
      {
      SetNextCursorMode();
      }
   }
}

Thanks again everyone , it means a lot to me.   :D

Dorcan

#7
Maybe there is a simpler way to disable the walk cursor :

DisableCursorMode(MODE_WALK);

and to re-enable it, just use the opposite function :

EnableCursorMode(MODE_WALK);


Also, if you want to replace the walk cursor mode with another one, I think you could do something like:

DisableCursorMod(MODE_WALK);
EnableCursorMode(5);

Eddie Chewbacca

I'll give it a shot.  Also thanks for those great Tutes, everything seems to make sense now, and the Adobe Photoshop Tutes are good too that I've reviewed so far. 8)

Scummbuddy

With the most recent update (beta), you can turn off objects on a Gui, I do believe...
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Eddie Chewbacca

Thanks for that Scummbuddy, I'll keep that in mind.  I currently have version 2.6 SP1, and can't seem to find the beta version, unless it's not available for download.  I checked the download site and news sites of AGS, but no luck.  Where can I get a copy of this, or do we need to wait for 2.6 SP2 or so?

Scummbuddy

#11
In the tech forum, its usually the first sticky thread, but it is a high one none the less.

http://www.agsforums.com/yabb/index.php?board=2;action=display;threadid=12051

Remember to back up your game before using this.  *Make a copy of your game files*
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Eddie Chewbacca

Thanks for that, I'll download it now.   8)

Eddie Chewbacca

Hi guys and gals, 

       It's been a while since I posted this, but I've spent a bit of time away from AGS but I'm finally back.  My question is kind of continuing along the lines of DORCAN's tutorial on creating your own GUI.  I have since created my own GUI, but it really bugs me when I want to cycle through the cursor modes (By right clicking) to the one I want, but it always just runs the "Loook" Script, no matter what current cursor mode is.  I started trying to work it out, and learnt that I can turn "Handle InventoryClicks In Script" on, and maybe use the value RIGHTINV through the on_mouse_click function, but not sure how to put it all together.  Can some one please provide an example of how the code should look for this to work.  I have attached my current code. 


function on_mouse_click(int button)
  {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1)
    {
    // Game is paused, so do nothing (ie. don't allow mouse click)
    }
  else if (button==LEFT)
    {
    ProcessClick(mouse.x, mouse.y, GetCursorMode() );
    }
  //else if (button==RIGHTINV)
    //{
    //SetNextCursorMode();
    //}
  else
    {
    // right-click, so cycle cursor
    SetNextCursorMode();
    }   
  }



function interface_click(int interface, int button)
  {
  if (interface == 2)
    {
    // They clicked a button on the Inventory GUI
   
    if (button == 1)
      {
      // They pressed SELECT, so switch to the Get cursor
      SetCursorMode (3);
      SetMouseCursor (2);
      }

    if (button == 2)
      {
      // They pressed TAKE, so switch to that mode
      SetCursorMode(2);
      SetMouseCursor (6);
      }

    if (button == 3)
      {
      // They pressed the CLOSE button, close the GUI
      GUIOff (2);
      SetDefaultCursor();
      SetButtonPic(0,5,1,2049);
      }

    if  (button == 4)
      {
      //"Up" arrow
      if  (game.top_inv_item > 0)
        game.top_inv_item = game.top_inv_item - game.items_per_line;
      }

    if  (button == 5)
      {
      //"Down" arrow
      if  (game.top_inv_item < game.num_inv_items - game.num_inv_displayed)
        game.top_inv_item = game.top_inv_item + game.items_per_line;
      }
  }
}

Thanks in advance, Eddie.

Scorpiorus

Could you post the content of the repeatedly_execute()?

Eddie Chewbacca

There is nothing in the repeatedly execute function.

function repeatedly_execute() {
  // put anything you want to happen every game cycle here
}

Thanks.

Scorpiorus

So you have troubles with changing cursor mode when it's over a GUI? In that case you should check another tutorial by Dorcan about right/left mouse clicks on GUI: http://www.digitalmindstudio.ch/script.php?id=1

There is also a tip at the end of the tutorial concerning of how to cycle cursor modes when mouse is over a GUI.

In addition, check out the Visible property of the inventory GUI. Making it Normal instead of Popup Modal will also make it possible to change the cursor mode when the inventory GUI is turned on but a mouse cursor is outside of its area.

Eddie Chewbacca


Eddie Chewbacca

Actually why I'm at it, just thought I'd ask my only other question.  I know in the manual says that these values are read only, but I would still like to know if I can set the below values to what I want them to be 

game.items_per_line            (I would like this to be 3, not 2)
game.num_inv_displayed     (I would like this to be 9, not 4)

This should then cover all my questions with GUI's.

Thanks.

Snake

#19
SetGUIObjectEnabled(GUI, int obj, int enabled);
0=disabled
1=enabled

I just asked this question not too long ago ;)


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

SMF spam blocked by CleanTalk