User Interface
Commands - By Ad0
Well,
howdy there! I have looked at the UI code, and I found it
funny and interesting! So in this tutorial, I will try to
explain an easy example of UI coding, and I will introduce you
into UI communication. Yes, I mean you,
buster!
OK, let's
start with looking in the In-game menu, where you can add
bots, and so on: The ui_ingame.c file....
The
concept is pretty easy of adding menu items. Simply follow an
menu item, e.g. the "Restart Arena" menu function. This is a
nice example of sending commands to both Game and Cgame! It's
as easy as it gets: This function sends a command:
EXEC_APPEND command that is the same thing as you would typed
it in the console yourself, and there's another function for
popping you back to the game after pushing the button:
UI_PopMenu();
OK, let me
show you how I would add a menu item called: "Be
LAME!". Just make another definition in that file (on the
top that is), named, for example, #define ID_BE_LAME 20 , because 19
was the last flag number (if you have a clean UI
source). Now, add the be_lame to the struct under the
definitions (you should know how it's done, just use your
eyes, and LOOK at it).
After you
have added that, you move a bit downwards...
Now you
have to add a function for that menu. The function is usually
a send command function. Just copy and paste the entire The
whole InGame_RestartAction function and paste it above or
under. You shall of course rename this to your own Be_Lame
function! Just leave the line : "trap_Cmd_ExecuteText(
EXEC_APPEND, "map_restart 0\n" );" and replace the
"map_restart" with your own command, e.g. "say I am a
coder!\n".
After you
have done that, you scroll downwards, and look some more till
you find the InGame_Event function. This is the function for
the events in the in-game menu (of course! It speaks for
itself!). This is very interesting!: If you look at this code,
you will copy, paste and change inside the code (not from this
tutorial!), you will discover that this event calls our
function!:
case ID_SERVERINFO:
UI_ServerInfoMenu(); break;
The
UI_ServerInfoMenu(); function is called. You just have to
copy, paste and modify this code to:
case
ID_BE_LAME: Be_Lame(); break;
Do like this, and you
will call your function (if it is defined "ID_LAME" and the
function is named "Be_Lame".
Else, you can just
erase your function and do like this:
case ID_LAME:
trap_Cmd_ExecuteText( EXEC_APPEND, "cmd say I am a coder!\n"
); UI_PopMenu(); //this exits the menu after
execing! break;
Then you don't have
to have a function, then this is just a direct command
sending. Look at UI_PopMenu();. It exits the menu when added.
Remove if you want to stay in the menu. Otherwhis, you can
just add it in your function that you hopeully create.
Now, search for
"RESUME GAME", and copy and paste the whole block of code.
This code CREATES the menu item. Just modify this to your
own. Example: s_ingame.resume.generic.x should be
s_ingame.be_lame.generic.x if your struct is
be_lame.
The very last thing
to do, is to ADD the menu item. This can be done by adding
another line, just like the other, exept it is your own
function. When you see it, you should understand it!
I hope you understood
this, really! Just send questions to my mail address above.
For my music, go here!
Cheers! |