Navigation

 UI Coding Tutorial #2 Feature Type: Coding Tutorials     Added: 30/04  
  Author: IoN_PuLse 

This one is called: Main Menu Button Position Manipulation

Main Menu Button Position Manipulation

Buttons positions are determined with x and y coordinates. You may remember these annoying buggers from high school math, and they haunt many of us to this day, sometimes even with their buddy the z axis. But not to worry, he doesn’t show up in the main menu of Quake3. Here is the code for the positioning of the SinglePlayer button. I will detail with a commented line what each line does:

// gives y’s definition, you don’t need this , specify y yourself.
y = 134;
// tells what MTYPE the button is. It can also be MTYPE_BITMAP


s_main.singleplayer.generic.type = MTYPE_PTEXT;

// flags to tell how it acts and stuff
s_main.singleplayer.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
// it’s position on the x plane. (up and down)(goes from 480 to 0)

s_main.singleplayer.generic.x = 320;

// it’s position on the y plane. (left and right)(goes from 640 to 0)
s_main.singleplayer.generic.y = y;
// the ID for it (makes reference to the CASE ID_whatever above
s_main.singleplayer.generic.id = ID_SINGLEPLAYER;
// what menu it’s making the command under
s_main.singleplayer.generic.callback = Main_MenuEvent;
// what text shows up
s_main.singleplayer.string = "SINGLE PLAYER";
// The color of the text, can be color_black; color_white; color_yellow; color_blue; color_orange;

s_main.singleplayer.color = color_red;

// the style of the text, and the value they give is “style”, which is defined above (top of this function)
s_main.singleplayer.style = style;

Now with this you can do many wonderful things. First of all, to demonstrate something you could do, let’s move the SinglePlayer button somewhere else on the screen, and call it “Bot Play” in the color blue. To do this, you’ll need to change the following:
(note: you will need to change the original code to this or paste this after the original and comment out the original in order for it to work)

s_main.singleplayer.generic.type = MTYPE_PTEXT;
s_main.singleplayer.generic.flags = QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;

// everything above we keep the same, but notice the following differences
// x coordinate is same (middle of screen left and right)

s_main.singleplayer.generic.x = 320;

// no more y for the y coordinate! now the y coordinate is 20, higher up on the screen

s_main.singleplayer.generic.y = 20;

// still acts the same when clicked


s_main.singleplayer.generic.id = ID_SINGLEPLAYER;

// same menu called

s_main.singleplayer.generic.callback = Main_MenuEvent;

// we’ve changed the text to BOT MODE, which will show up in the menu instead of singleplayer


s_main.singleplayer.string = "BOT MODE";

// here we changed the text color to orange

s_main.singleplayer.color = color_orange;

// style is the same, no need to change it

s_main.singleplayer.style = style;

I hope you understand the main menu of Quake3 even better, and I look forward to seeing some interesting menus later on! I will deal with images for buttons and more in later tutorials!
-IoN_PuLse

Comments »



  Page 1

  Comments ( 0 )


  Features Index

  Home

Copyright © 2001 MGON International AB - Privacy statement