[solved] new left/right click infterface

Started by digitalray, Tue 12/04/2011 18:09:59

Previous topic - Next topic

Khris

Hm, works for me.

Check if the GUI is set to being clickable.

Also, to check if a function is called at all, put a Display("Clicked."); in there (outside the if) and see if it appears.

digitalray

#21
i found out why it's not working..

it only works on the GUI, but not in the InventoryWindow, when no other items are in there to right click on.

seems that the InventoryWindow Area is an extra area and not the same as the GUI.


i would need a function to check if a mousebutton event was done while the mouse(x,y) are on the InventoryWindow area, as this area is not the same as the gui.



or does it work for you directly in the item area (not to the right where the arrows are) ?

i cleared all buttons and made the inventorywindow as big as the gui itself, i just left about 4 pixels on each side.
in this small area it works, but not in the InventoryWindow itself.


i am referring to the invCustomInv (InventoryWindow; ID0) (the control that is not clickable) from the dropdown box in ags inventory gui, not the gInventory (NormalGUI2) (that is set to clickable=true)

Khris

Ah, I see. And inventory windows don't have an OnClick event either.

This worked for me:

Code: ags
void on_event(EventType event, int data) {
  if (event == eEventGUIMouseUp) {
    if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == invCustomInv && player.ActiveInventory != null) player.ActiveInventory = null;
  }
}

digitalray

#23
i put this void in the main script, it works now. you are getting close to a god now khris...  :o
i tried to use GUIControl with invCustomInv before that, but this alone didn't do the job.


what is the eEventGUIMouseUp used for ? is this the same as mouseclick (i read it's the event if the mouse button is released..)?


the last of the 3 lines seems logic to me, but can you explain to me what is going on in the first 2 lines ?


so this void runs every cycle then and checks if a mouse button was released and if the mouse was over the gui control and if the player activeinventory is NOT empty ?

i miss the right mouse button somewhere in this.. and yes.. as i thought, it works with the left mouse button, too, but it shouldn't.

i see there is no way to use these 3 lines with the ags eMouseRight somehow because there is no clickable event in this area, therefore you had to use an own void and the guimouseup isn't even documented in the ags wiki.

so i guess there is no way to make the event only happen on a right click or a guimouseupright ?


i found IsKeyPressed(13) instead of an on click event in an older post, could this be of value to this somehow ?

Khris

You're right, unfortunately it doesn't seem possible to limit this to the right button.

eEventGUIMouseUp is called whenever the player released a mouse button over a (clickable?) GUI.
You can check out the other events here:
http://www.adventuregamestudio.co.uk/manual/TextScriptEvents.htm

Basically AGS calls
Code: ags
 on_event(eEventGUIMouseUp, GUIUnderMouse.ID);

so if I define the function in GlobalScript.asc, I can react to the event.

It doesn't run every cycle, only once after the event was detected. This makes it easy to add code globally to actions like losing inventory items or entering a room.

I guess the only way to handle this is to get creative:

Code: ags
// above repeatedly_execute_always
MouseButton last_button;

// add this inside rep_ex_always:

  int i = eMouseLeft;
  while (i <= eMouseMiddle) {
    if (mouse.IsButtonDown(i)) {
      last_button = i;
    }
    i++;
  }


(This works because enums are actually ints.)

Now we can always check for the button that was last pressed:

Code: ags
void on_event(EventType event, int data) {
  if (event == eEventGUIMouseUp && last_button == eMouseRight) {
    if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == invCustomInv && player.ActiveInventory != null) player.ActiveInventory = null;
  }
}


I tested it and it seems to work fine. It's still possible to break this by holding down both buttons etc.

digitalray

#25
i am still at the first lines, still trying to understand what you did before.

so you created a void instead of a function, because you don't need any return values from the on_event function ? i didn't see the on_event function beeing called somewhere. i just pasted the void in the main script.

so how does this work ?

are all functions that are in the main script called automatically every cycle ? and if so, all others would be called, too..

i don't really get this step, still..


edit: oh, i got  it... "the function is called when a particular event happens. "

simple as that. :/
;)


so it would work, too, if we did it like this and set the number of the inventory gui as int data ?

function on_event(EventType eEventGUIMouseUP, int data) {
   if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == invCustomInv && player.ActiveInventory != null) player.ActiveInventory = null;
}

or is this the reason why you used it as a void, because we don't want to use the inventory gui ?


------------


on to the new way you described:

wouldn't it be sufficient to insert "if (mouse.IsButtonDown(eMouseRight))" into the code before with the on_event function or wouldn't this work because the on_event asks for a mousebutton relase that is AFTER the ismousebuttondown function ?


----------------

digitalray

#26
ok, it didn't work for me like this.

when i go with the mouse to the top gui (gIconBar) the program crashes as soon as i reach the top with the mouse at the line:

   if (mouse.IsButtonDown(i)) {

and explanation: IsButtonDown only works with eMouseLeft and eMouseRight


fixed this error with
 while (i < eMouseRight) {

but now right clicking doesn't deselect the item anymore in the InventoryWindow. :/

Khris

Regarding your last paragraph: you answered this yourself. AGS calls on_event after the mouse button was released, so it doesn't make sense to use mouse.IsButtonDown().

Now:
Like I said, on_event is called by AGS (specifically: its internal main loop which we can't see).

I used void because neither we nor AGS needs the return value; we couldn't store it anyway since we don't call on_event, AGS does.

Quoteso it would work, too, if we did it like this and set the number of the inventory gui as int data ?

function on_event(EventType eEventGUIMouseUP, int data) {
    if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == invCustomInv && player.ActiveInventory != null) player.ActiveInventory = null;
}

No, not at all. I'm fairly sure this wouldn't even compile (it actually would since you wrote UP, not Up, but that's beside the point).
Plus, if it were done that way I'd need a separate function for every event which is impossible since they all are supposed to be called on_event and you can't have more then one function with the same name.

In a default game, gInventory's ID is 2. Looking at the event enum order, eEventGUIMouseUp is 5.
So what happens is if I release a mouse button with the mouse over gInventory, AGS calls on_event(5, 2);

Thus I need to check the value of the parameters inside on_event to determine which event was triggered.

If I define the function like this:
Code: ags
void on_event(int blah, int bleh) { ... }

blah holds the event value and I must compare it to eEventMouseGUIUp to find out if it actually was that event that triggered the call of on_event.

I know this can be difficult at first to understand, it's a bit backwards from what we usually do when using custom functions.
The principle is the same as on_mouse_click though; with that we check button's value to find out which button was pressed.

Regarding your second post:
Always post the exact full error message.
I can't replicate the crash, btw.

digitalray

have to go over your last post again tomorrow.. didn't get all of it this evening ;))

about the crash:

IsButtonDown only works with eMouseLeft and eMouseRight

was the full error message (little yellow popup box)


there was nothing more. how can it run with eMoueMiddle in your script if i get an error telling me that i can't use eMouseMiddle with IsButtonDown ?

Khris

Which version of AGS are you using?

To quote 3.2.1's manual:
QuoteTests whether the user has the specified mouse button down. BUTTON must either be eMouseLeft, eMouseRight or eMouseMiddle.

I checked the manuals and it looks like mouse.IsButtonDown didn't support eMouseMiddle until 3.2. Either replace eMouseMiddle with eMouseRight or switch to the most recent version.

digitalray

oh, that would explain it.

thanks for looking that up.

i downloaded the only version on the main page that is available, and that is 3.1.2.82

http://www.adventuregamestudio.co.uk/acdload.htm

http://www.adventuregamestudio.co.uk/AGS-3.1.2-SP1.rar


where can i get a newer version ?


digitalray

thx matti, will try it with the new version now..

and besides.. i found the error why it didn't work yesterday, even with the 3.1 version.

i used i<mouseRight instead of i<=mouseRight..

it should work now.. i'll post it when i installed the new version.

digitalray

#33
is there a zipped version of ags.3.2.1 ?

(edit: looked through the thread, seems there is none)

i can't install .exe installers here at work. :/
can't extract from the .exe with winrar or uniextract either.. :/

will have to install it at home tonight and make a zipped archive for work for tomorrow and use 3.1.2 for today.

digitalray

#34
happiness! :)

just entered the changed code with eMouseRight for 3.1.2 and it works now.

so, until i won't have any errors with combining objects in the future, this left/right interface is DONE !


you are really cool people here.

i never really got that much help in any other forum so far with special codings, that really worked.


i hope i don't get into more trouble, soon :)

thanks a lot for your help so far!!!


will definately add khris in the credits for additional scripting.

Matti

Then just modify your first post by putting a (SOLVED) in the title and you're done  :)

digitalray


SMF spam blocked by CleanTalk