It makes a Counter-strike style Progress bar which is controllable via client cvar and command.
NOTE: I based my coded off of the csqc scratch files in this forum and it works with DP (not tested in FTE)
By the end of this tutorial you should be able to:
-Draw and Fill shapes onto the screen
-Register and use CVARs and CMDs for use in CSQC
Lets get started:
First thing we need to do is a few declare a few things.
Open up Defs.QC
Paste these at the very bottom:
Code: Select all
float vid_conwidth, vid_conheight;
float progress;
Now we have to setup our cvar and showprogress command.
Open Main.QC
Find the function:
Code: Select all
void CSQC_Init(void)
Code: Select all
progress = FALSE; // By default we want our progress bar to not be on
registercmd("showprogress"); // This command turns on and off the progress bar
registercvar("c_progressbar","0"); // This cvar is the percent of the progress bar you would like to be filled
Now to implement our new command ("showprogress")
Scroll down until you find the function:
Code: Select all
float CSQC_ConsoleCommand(string strMessage)
Add this case statement to that switch
Code: Select all
case "showprogress": // This command turns on and off the progress bar
if(progress == TRUE)
progress = FALSE;
else
progress = TRUE;
break;
Open View.QC
Find the function:
Code: Select all
void CSQC_UpdateView(void)
Code: Select all
// Set the console size vars
vid_conwidth = cvar("vid_conwidth");
vid_conheight = cvar("vid_conheight");
Its time to add our draw functions now, I commented this so you should be able to understand whats going on.
First it draws an empty box (using 4 lines)
Then It takes the value from the cvar and makes a fill proportional to our progress bar and draws it in.
Now at the very top of the file (view.qc)
Add this code:
Code: Select all
// Just put this function together to make drawing the empty box easier, you could use drawline and go around the points but
// I found having the
void drawline_center(vector center_ofs, vector linesize, vector do_rgb, float do_alpha, float do_flags)
{
local vector barpos;
barpos_x = vid_conwidth;
barpos_y = vid_conheight;
barpos = barpos*0.5 + center_ofs;
drawfill(barpos, linesize, do_rgb, do_alpha, do_flags);
}
// This function draws an empty
void DrawProgressEmpty(void)
{
drawline_center(' -200 -2 0 ', '400 1 0', '1 0.91 0.51', 0.7, 0); // Top
drawline_center(' -200 -2 0 ', '1 9.5 0', '1 0.91 0.51', 0.7, 0); // Left
drawline_center(' -200 7 0 ', '400 0.5 0', '1 0.91 0.51', 0.7, 0); // Bottom
drawline_center(' 200 -2 0 ', '1 9.5 0', '1 0.91 0.51', 0.7, 0); // Right
}
// This Draws the progress bar
void DrawProgress(void)
{
local vector barpos, fillsize;
local float progrs;
progrs = cvar("c_progressbar"); // Get the progress
DrawProgressEmpty(); // Draw an empty box
fillsize_x = (progrs*396) / 100; // This finds the correct % of our fill
fillsize_y = 6; // Give it a hieght of 6
barpos_x = vid_conwidth;
barpos_y = vid_conheight;
barpos = barpos*0.5 - '198 0.25 0'; // center the progress bar on the screen
//Draw the bar
drawfill(barpos, fillsize, '1 0.91 0.51', 0.7, 0); // The Fill //'396 6 0'
}
R_RenderScene(); to work.
So back inside the CSQC_UpdateView function:
Below R_RenderScene add:
Code: Select all
if(progress == TRUE)
DrawProgress();