Game Development Community

Gui interact with the engine

by Mak Andrew · in RTS Starter Kit · 12/15/2004 (7:58 pm) · 7 replies

When the "attack" and the "move" button is being press, which part of the script does it immediate call upon...

In the "move" button, i realise (like all the other games too) that even if you did not press it, by default, the unit will be in the move mode. so in which part of the script indicted the "by default", or maybe even which part of the engine

#1
12/15/2004 (8:15 pm)
Short Answer: Look at inputHandler.cs in your client directory.

Long Answer:

The RTS-SK "stock" environment works on two major principles:

1) All orders given by icons are most probably intended to be used by the group of units that are currently highlighted (and displayed in the Selection Display), otherwise known as the "selection".

2) There is only one primary "command state" for a given selection, although some of the mouse/keyboard inputs are handled in a "smart" manner to over-ride this basic command state. This command state is either "none", or some value set by whichever command icon was clicked the most recently.

inputHandler.cs is the primary script interface to most (if not all) of the mouse inputs that can be given by the player. These include:

--"left mouse button click"-- can be a click on terrain, click on an RTSUnit (friendly or enemy), or a click on a GUI Control.
--"right mouse button click" -- see above.
--"left mouse button drag (held down)" -- see above.

The stock RTS-SK uses a combination of "smart" input handling, and "normal" input handling. For example, no matter what you have selected (units, buildings, or nothing), a click on a GUI button will interact with that button. This is "normal" input handling.

"smart" input handling (or state based input) can change the effect of a mouse input based on certain states. For example, if you have nothing in your selection (nothing showing in the Selection Display) and you right click on the terrain somewhere, nothing (obvious to the player) will happen. However, if you have one or more units selected, those units will be given a "move" command to the location you clicked on, if it was terrain, or they will be given an attack order if you clicked on an enemy unit. If you have clicked on one of the command buttons, this "smart" input handling is further modified based on which button you most recently clicked. In summary, the specific command that is issued based on a single user input event is dependent on the current game state, and specifics of the user input event.

This makes things a bit complicated, because you cannot say specifically "any time the player does this, that will happen". It depends on the current client game state, as well as being modified by the event itself. As I said in the "Short Answer", most of this is driven by the script file inputHandler.cs.

There are other "states" as well that are handled by the underlying code--a perfect example is when you have clicked on the "build" button (stock RTS-SK). This places you in a special client state, "placing building", and user inputs from the mouse are again modified via "smart" user input handling to be specific to the requirements of placing your building. In this special state, for example, clicking on the build icon puts you in the "startBuildingPlacement" state, and the underling code now interacts with your mouse input specifically to handle the state--moving the mouse moves the building attached to your mouse, and left clicking on the terrain tells the server you want to place the building where you clicked. This specific state is handled in the engine code itself (in RTSTSCtrl.cc if you are interested).
#2
12/16/2004 (3:10 am)
Thank Zepp, i did run through the inputHandler.cs but i realise that playGui.cs is also doing a similar jobs so kind of wonder which is being call first.

Next i realise that in the game the "move" button is attach to the CommandMenu::OnMoveClick() so wonder too if there's a OnMoveClick Function?
#3
12/16/2004 (5:42 am)
Good point, I had forgotten about the stuff in playGui.gui/cs. IIRC, stock RTS-SK has those function in either playGui.cs or playGui.gui.
#4
12/17/2004 (4:51 am)
Anyway do anyone know where the CommandMenu::OnMoveClick can be found
#5
12/17/2004 (5:48 am)
Quote:IIRC, stock RTS-SK has those function in either playGui.cs or playGui.gui.
#6
12/17/2004 (3:34 pm)
Sorry Zepp cause i never expect that *.gui will be used to keep function(thought that is only use to keep gui data), Sorry once again
#7
12/17/2004 (5:44 pm)
Yes, it surprised me as well! It's a fair decision they made though--it really is more of an input "redirector", since it ties pressing a particular screen area to more than one script call based on the state of other parts of the gui.