How would you make Gui to...

Started by Cyberion, Tue 24/08/2004 13:23:47

Previous topic - Next topic

Cyberion

How would you make Gui to popup and close down on right mouse click?

I've used the following code, but it doesn't work, i mean my Gui popup, but i can't close it and also my default Cursor Mode switches to Look_Mode:

// MOUSE BUTTONS

  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, MODE_USE);
  }
  else if (button == RIGHT){
if (IsGUIOn(2)==1) {
    GUIOff(2);
    }
else ProcessClick(mouse.x, mouse.y, GUIOn(2));
CentreGUI(2);
   }
}

// MOUSE BUTTONS END



any help would be greatly apreciated?

Mr Jake

ProcessClick(mouse.x, mouse.y, GUIOn(2));  ??

you could just put 'GUIOn(2);'

ok, what you need to do is put

if (IsButtonDown(LEFT) == 1) && IsGUIOn (2) == 1){
GUIOff (2)'
}

to rep_exe also change

if (IsGUIOn(2)==1) {
    GUIOff(2);
    }
else ProcessClick(mouse.x, mouse.y, GUIOn(2));
CentreGUI(2);
   }

to

if (IsGUIOn(2)==0) {
    GUIOn(2);
    }


Cyberion

#2
*fixed* lol


it tells me --> parser error at '&&'

Ehh any idea?

Now my mouse code looks like:

// MOUSE BUTTONS

  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, MODE_USE);
  }
 
else if (IsButtonDown(RIGHT) == 1) && IsGUIOn (2) == 1){
     GUIOff (2);
    }
  else GUIOn(2);
}

// MOUSE BUTTONS END



and i've put in rep_exe as you said:

if (IsGUIOn(2)==0) {
    GUIOn(2);
    }
----------------------------------------------------------------------------

[edit]: But i do not get it, why should i put anything into rep_execute?

Mr Jake

you put that the wrong way around :D the stuff you put in the on_click should be in the rep_exe and vise-versa

Cyberion


Mr Jake

ooops, also make
else if (IsButtonDown(RIGHT) == 1) && IsGUIOn (2) == 1){

into

else if (IsButtonDown(RIGHT) == 1 && IsGUIOn (2) == 1){

Cyberion

*ya i've corrected it, when i found the parser error at &&*


heheh, well, now whenever i click right button, it popups only for 1 second, while i click the button, it doesn't stay on the screen. Do i need to put the pause command or anyhting?

Mr Jake

actually yes, try a wait(1); command

Cyberion

hmm nope, the same thing, GUI goes off. I need to make it permanent on the screen til you click right buton again.

I've tried to do it through show_inventory function. Like it goes from default. So i had my inventory gui defined thre already. I mean custom inventory gui. so i used thos code in right mouse button:

if (IsGUIOn(2)==0) {
    show_inventory_window();
    }


but still Gui popups up only while i click :(

Ishmael

  else if (button == RIGHT){
    if (IsGUIOn(2)==1) {
      GUIOff(2);
    } else {
      ProcessClick(mouse.x, mouse.y, MODE_x);
    }
  }

should make it that if GUI 2 is on, it goes off on right click, otherwise it will process the click on the mode you wish, just fiddle the x...

What else is the problem now?
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Cyberion

yes, that's what i've tried for the first time. But i need to make it, so whenever i click right mouse button, my inventory popup and whenever i click right moue button while my inventory is turned on, it would turn off.

So far with the help of HotSpot i managed to make it pupup and go off on right mouse click. The problem is that it won't stay on the screen. I click right ouse button and it turns on and than immediately turns off  :-\

Mr Jake

Ish: On_mouse_click isnt called when a GUI is up

actually, you do what Ish said, and make sure you set the GUI mode to 'Normal' and put GUIOff (2); in the 'GameStart' section

Ashen

Or, you add a line before if (IsGamePaused() == 1), e.g.

Code: ags

function on_mouse_click(int button) {
Ã,  // called when a mouse button is clicked. button is either LEFT or RIGHT
Ã,  if ((button == RIGHT) && (IsGUIOn(2) ==1)) { // GUI is on so do this
Ã,  Ã,  GUIOff (2);
Ã,  Ã,  SetCursorMode (GetGlobalInt (1)); // Or whichever you used, resets cursor to what it was
Ã,  }
Ã,  else 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 == RIGHT) {
Ã,  Ã,  SetGlobalInt (1, GetCursorMode()); // Use another GlobalInt if 1 is taken
Ã,  Ã,  show_inventory_window();
Ã,  }
}


With this, right click will open the inventory, and a right click outside of the inventory will close it again. To make a right click on the inventory close it, I thick you have to play around with 'Handle inventory clicks in script'.
I know what you're thinking ... Don't think that.

Mr Jake

On_mouse_click isnt called at all if any non 'normal' mode gui is on

Ashen

#14
That code works with my inventory GUI, which is popup modal. It just doesn't work if you click while over the GUI

I thought on_mouse_click didn't usually do anything when non-normal GUIs were up as they pause the game, and this bit
Code: ags
if (IsGamePaused() == 1) {
Ã,  Ã,  // Game is paused, so do nothing (ie. don't allow mouse click)
Ã,  }

stops it processing when the game is paused. Which is why I put a line before that.

EDIT: I don't mean this post to sound narky, which it might, I'm just saying the code I posted does actually work, kind of.
I know what you're thinking ... Don't think that.

BlackMan890

Do you mind if i use your code?
Jonatan Nilsson
860 Iceland

Please go to www.simnet.is/elinnils52 and download my non ags/adventure game :)

Cyberion

Ok it worked perfectly, i've made few additions and corrections, so now when you choose the item in inventory, than right click outside it, it closes, second right click *while you are holding the item) will deselect the item. here is the code:

Important: works perfectly  for the "popup modal" value.


// MOUSE BUTTONS

function on_mouse_click(int button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if ((button == RIGHT) && (IsGUIOn(2) ==1)) { // GUI is on so do this
    GUIOff (2);
  }
  else 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 == RIGHT) {
   
    if (character[GetPlayerCharacter()].activeinv >=0){    // if you are holding inv item, right-click, so deselect item
    character[GetPlayerCharacter()].activeinv = -1;
    SetCursorMode (MODE_USE); // will turn the use  mode after you deselected the item, you may use any mode of course
   }
    else show_inventory_window(); // will turn on the inventoy window, whenever you right click
  }
}

// MOUSE BUTTONS END

SMF spam blocked by CleanTalk