Can you turn off a GUI's Object?

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

Previous topic - Next topic

Scorpiorus

#20
Quote from: Eddie Chewbacca on Thu 20/05/2004 23:34:32I 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
You can do that but since they are read-only it's not recommended. But you even don't need to. Just stretch the inventory window, thus more items will fit into its area. Resizing is equivalent to adjusting these variables, only in a more official fashion. :)
There is another command that you may find useful - SetInvDimensions (int width, int height). It sets the width and height of the inventory item slot (default is 40x22).

For example, if you inventory window size is 120x120 and you want to have 9 items (3 items per line) the SetInvDimensions() would look like:

function game_start() {

SetInvDimensions(120/3, 120/3); // 3 x 3


}



Eddie Chewbacca

Okay well I got the 9 inventory items on the screen working fine now, and I can right click and make the cursor change, however when I right click on one of the items in the Inventory Window, it still runs the "LOOK" code before changing the cursor.Ã,  I am posting my Global Script again from the very top down to where I think no more is required.Ã,  This is so I can enure everything is in the right order.Ã,  There is some extra code in the On_Mouse_click function, but this works fine, for where I need it.Ã, 

To help debug this, I have placed "Display" commands to see what executes before the "LOOK code is displayed.Ã,  I have highlighted these with theÃ,  8) smiley face, and it they execute in the order from top down when run.Ã,  I have placed theÃ,  ??? Smiley face where the "LOOK" code seems to execute, which I can't determine how, when no line seems to be executed to do this.Ã,  So in summary, the line "On_Event - Mouse Down End" is displayed, then the relevant "LOOK" code is executed, before the line "On_Event - Mouse Up Start" is executed.  If you need any other code let me know.

// main global script file
int TButton;

function game_start() {
Ã,  // called when the game starts, before the first room is loaded
Ã,  SetInvDimensions (64,64);
}

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

function on_key_press(int keycode) {
Ã,  // called when a key is pressed. keycode holds the key's ASCII code
Ã,  if (IsGamePaused() == 1) keycode=0;Ã,  // game paused, so don't react to keypresses
Ã,  if (keycode==17)Ã,  QuitGame(1);Ã,  Ã, // Ctrl-Q
Ã,  if (keycode==363) SaveGameDialog();Ã,  Ã, // F5
Ã,  if (keycode==365) RestoreGameDialog();Ã,  // F7
Ã,  if (keycode==367) RestartGame();Ã,  // F9
Ã,  if (keycode==434) SaveScreenShot("scrnshot.bmp");Ã,  // F12
Ã,  if (keycode==9)Ã,  Ã, GUIOn(1);
      Ã,  Ã,  SetCursorMode(2);

Ã,  if (keycode==19)Ã,  Debug(0,0);Ã,  // Ctrl-S, give all inventory
Ã,  if (keycode==22)Ã,  Debug(1,0);Ã,  // Ctrl-V, version
Ã,  if (keycode==1)Ã,  Ã, Debug(2,0);Ã,  // Ctrl-A, show walkable areas
Ã,  if (keycode==24)Ã,  Debug(3,0);Ã,  // Ctrl-X, teleport to room
}

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)
      {
      if (GetCursorMode() == 10)
         {
         SetCursorMode(1);
         }
      else if (GetCursorMode() == 3)
         {
         if (character[ GetPlayerCharacter() ].activeinv == -1)
            {
            SetCursorMode(10);
            }
         else
            {
            SetCursorMode(4);
            }
         }
      else if (GetCursorMode() == 4)
         {
         SetCursorMode(10);
         }
      else
         {
         SetNextCursorMode();
         }
      }
   else if (GetGlobalInt(8 ) == 1)
      {
      SetCursorMode (MODE_USE);
      SetMouseCursor (2);
      }
   else
      {
      SetNextCursorMode();
      }
   }
}

function Interface_Click(int interface, int button)
{
if (interface == ICONBAR)
   {
   if (button == 0)
      {
      if (GetGlobalInt(10)==1)
         {
         SetCursorMode(10);
         }
      else
         {
         SetCursorMode(0);
         }
      }
   if (button == 4)
      {
      // show inventory
      GUIOn(1);
      SetCursorMode(2);
      }
   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   
else if (interface == INVENTORY)
   {
   ifÃ,  (TButton==2)Ã,  // They clicked the right button on the Inventory GUI
      {
      if (GetCursorMode() == 1)
         {
         SetCursorMode(3);
         SetMouseCursor(2);
         }
      else if (GetCursorMode() == 3)
         {
         SetCursorMode(2);
         SetMouseCursor(6);
         }
      else if (GetCursorMode() == 2)
         {
         SetCursorMode(1);
         SetMouseCursor(1);
         }
      }
   elseÃ,  // They clicked the left button on the Inventory GUI
      {
      if (button == 0)
         {
         // USE Button
         SetCursorMode(1);
         SetMouseCursor(1);
         }
      if (button == 1)
         {
         // USE Button
         SetCursorMode(3);
         SetMouseCursor(2);
         }
      if (button == 2)
         {
         // TAKE Button
         SetCursorMode(2);
         SetMouseCursor(6);
         }
      if (button == 3)
         {
         // CLOSE Button
         GUIOff(1);
         SetDefaultCursor();
         }
      if (button == 4)
      {
         // UP Button
         if (game.top_inv_item > 0)
            {
            game.top_inv_item = game.top_inv_item - game.items_per_line;
            }
         }
      if (button == 5)
         {
         // DOWN Button
         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;
            }
         }
      }
   }Ã,  // end if interface INVENTORY
}

int GUIButton;

function on_eventÃ,  (int event, int data)
{
   ifÃ,  (event==GUI_MDOWN)
      {
8)      Display("On_Event - Mouse Down Start");
      Ã, 
      RefreshMouse();
      if (IsButtonDown (RIGHT) ==1)
         {
         TButton=2;
         }
      else if (IsButtonDown (LEFT) ==1)
         {
         TButton=1;
         GUIButton=GetGUIObjectAt(mouse.x,mouse.y);
         }
8)      Display("On_Event - Mouse Down End");
      }
???
   ifÃ,  (event==GUI_MUP)
      {
8)      Display("On_Event - Mouse Up Start");
      Interface_Click (data,GUIButton);
8)      Display("On_Event - Mouse Up End");
      }
}

Scorpiorus

Ah, I forgot that if the handle inventory clicks in script option is disabled then AGS engine handles inventory clicks itself. That is why there is no relevant code in the global script that is responsible for the clicking on the inventory items. (the on_mouse_click() function is not even called!)

By default, AGS runs the look at interaction on right click and runs other interactions on left click unless the current mode is MODE_USE. In that case AGS selects the inventory item, so it becomes the active one.

The following example shows how to simulate AGS behaviour on clicking on the inventory item:

Enable handle inventory clicks in script option so that AGS doesn't process inventory clicks but call on_mouse_click() function instead with passing the RIGHTINV or LEFTINV value, so we could check it and decide what to do.

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==LEFTINV) // left click on inventory item:
   {
      if (GetCursorMode()==MODE_USE)
      {   // select inventory on MODE_USE:
         SetActiveInventory(game.inv_activated);
      }
      else
      {   // run other interaction if the cursor mode isn't MODE_USE:
         RunInventoryInteraction(game.inv_activated, GetCursorMode());
      }
   }
   else if (button==RIGHTINV) // right click on inventory item:
   {   // always run look interaction on MODE_LOOK:
      RunInventoryInteraction(game.inv_activated, MODE_LOOK);
   }

   else if (button==LEFT)
   {
      ProcessClick(mouse.x, mouse.y, GetCursorMode() );
   }
   else
   {Ã,  Ã, // right-click, so cycle cursor
      if (GetGlobalInt(10)==1)
      {
         if (GetCursorMode() == 10)
         {
            SetCursorMode(1);
         }
         else if (GetCursorMode() == 3)
         {
            if (character[ GetPlayerCharacter() ].activeinv == -1)
            {
               SetCursorMode(10);
            }
            else
            {
               SetCursorMode(4);
            }
         }
         else if (GetCursorMode() == 4)
         {
            SetCursorMode(10);
         }
         else
         {
            SetNextCursorMode();
         }
      }
      else if (GetGlobalInt(8 ) == 1)
      {
         SetCursorMode (MODE_USE);
         SetMouseCursor (2);
      }
      else
      {
         SetNextCursorMode();
      }
   }[/color]
}

So, the above script simulates how AGS handles inventory clicks. If you don't want the right click to trigger the "look at" interaction just comment out the "RunInventoryInteraction(game.inv_activated, MODE_LOOK);" line:
...
else if (button==RIGHTINV) // right click on inventory item:
{   // always run look interaction on MODE_LOOK:
   //RunInventoryInteraction(game.inv_activated, MODE_LOOK);
}
...

By the way, the game.inv_activated variable holds an inventory item number the player last clicked on. It's very handy to use when you control inventory item clicks manually.

Hope it helps :)

Eddie Chewbacca

You're an absolute marvell.Ã,  That did the trick, thanks for that.Ã,  I'm annoyed with myself because I read about that setting and the RIGHTINV option, but I just didn't know how to get them working when I tried them out earlier, then I forgot all about them.Ã,  Any way thanks for all your help over the weeks, that should be the last time I bug any one for a while now, I hope.Ã,  :D

Scorpiorus

You are welcome :)

Yeah, LEFTINV/RIGHTINV are in the manual but I know that it could be difficult to figure out how exactly they are supposed to be used without an example provided.

SMF spam blocked by CleanTalk