Game Development Community

Onrightmousedown for dynamic buttons.. How?

by Flybynight Studios · in Torque Game Engine · 07/29/2008 (10:42 pm) · 3 replies

Take an inventory type of window with a bunch of buttons in them. In the case of my inventory, the containers are very dynamic and the buttons are generated when the character is loaded based on the size of containers he is carrying.

What I am trying to achieve is allow the players to "activate" an inventory item with a right click rather than having to focus on the item with a left click and then click another button on the item popup window to activate it.

Perhaps a clearer way to describe what I am doing is in a game like World of warcraft when you click on an item in a corpse loot window it picks it up.. when you right click the item it dumps it right to your first available slot..

now with GUIs I can dynamically generate buttons and arrays and so forth till I am blue in the face but how do I dynamicalyl generate an onrightmousedown command based on whats under the mouse?

Today the player may have a dagger in container 3 slot 2 but 5 minutes form now he may move that and put a rock there. how would one go about changing the rightmousedown stuff for that button? all I can find is something like: containter3slot2::onrightmousedown(docoolstuff) but that is a function and must be parsed at run time. it cant be created on the fly.. so when a player moves inventory around Im screwed. It sounds like what I need to do is add another item to the GUIcontrol to allow for a rightclickcommand=... I am definitely not good enough to do that on my own. anyone else have any suggestions is there something I am missing here? I bet there is :)

Peace.

#1
07/29/2008 (11:26 pm)
Well, I'm sure this isn't what you want to hear, but, I don't know how to do that in script off the top of my head...

BUT, if you DID want to start modifying controls in C++ or making your own...

I'm pretty sure GuiControl already has a onRightMouseDown method in C++, it would just be adding Con::executef( this, "onRightMouseDown" ); to it, just like Buttons do for onLeftMouseDown executing onClick.

You might need something more complex than just a "onRightMouseDown" callback though...

Buttons have a "command" which is eval-ed when you click, perhaps adding a second, altCommand which is eval-ed on a right click would accomplish what you want...

Note: a field called altCommand might actually already exist for some controls, that is just an example name I threw out there.

For example, you create a guiControl (of some type) representing a dagger. You set the altCommand to... "Player.addToInventory(InventoryItem_Dagger::create());" or something like that...

Alternatively, if this is YOUR control, it might just have fields for the "item" and know to do the equivalent of that onRightClick without needing to do an eval at all.
#2
07/30/2008 (12:11 am)
First, make sure your guiControl that has the icon of your item has a onRightMouseUp callback in C++. Some other controls already have this, so do a search for onRightMouseUp in the source.

When you create the control, assign your identifying item data to it. Here is an example, you would replace the variables with whatever you are using to identify that inventory item.

%foo = new guiInventoryControl(myInventorySlot);

%foo.itemId = %itemId
%foo.itemType = %itemType;

etc..

Then in your onRightMouseUp callback, you can reference which item they clicked on:

function guiInventoryControl::onRightMouseUp(%this)
{
    echo("I clicked on item ID" SPC %this.itemId SPC "of type" SPC %this.itemType);
}
#3
07/30/2008 (10:38 am)
Damn guys great feedback thank you. I am just on my way out the door right now and cant think it through but Peter that looks like it's going to do it. Going to have to think it through. Thanks both of you. Awesome