Inside3D!
     

[Tutorial] CSQC Progress Bar

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
GiffE



Joined: 08 Oct 2006
Posts: 141
Location: USA, CT

PostPosted: Sun Mar 02, 2008 3:00 pm    Post subject: [Tutorial] CSQC Progress Bar Reply with quote

People requested CSQC Tutorials, I was working on this and figured I'd make a tutorial out of it since CSQC Tutorials are hard to come accross.

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:
float vid_conwidth, vid_conheight;
float progress;


progress is a boolean variable whether or not to draw, and the others are used to center the drawing on your screen.

Now we have to setup our cvar and showprogress command.

Open Main.QC
Find the function:
Code:
void CSQC_Init(void)

Inside this function add the lines:
Code:
   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


That registers the command and progress bar cvar.
Now to implement our new command ("showprogress")


Scroll down until you find the function:
Code:
float CSQC_ConsoleCommand(string strMessage)


Inside there is a switch statement which determines what to do with client commands.

Add this case statement to that switch
Code:
      case "showprogress": // This command turns on and off the progress bar
         if(progress == TRUE)
            progress = FALSE;
         else
            progress = TRUE;
         break;


Now we have to start drawing our progress bar.

Open View.QC
Find the function:
Code:
void CSQC_UpdateView(void)

Directly above R_AddEntities Paste this code:
Code:
   // 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:
// 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'
}


When Drawing you must call the draw functions below
R_RenderScene(); to work.

So back inside the CSQC_UpdateView function:
Below R_RenderScene add:

Code:

   if(progress == TRUE)
      DrawProgress();


Hope that helps anyone who is completely lost in CSQC.
Back to top
View user's profile Send private message Visit poster's website
RenegadeC



Joined: 15 Oct 2004
Posts: 370
Location: The freezing hell; Canada

PostPosted: Mon Mar 03, 2008 2:25 am    Post subject: Reply with quote

Very awesome, this could come in handy. Thanks!
Back to top
View user's profile Send private message AIM Address MSN Messenger
CocoT



Joined: 14 Dec 2004
Posts: 599
Location: Belly-Gum

PostPosted: Mon Mar 03, 2008 4:58 am    Post subject: Reply with quote

Yeah, really, really neat, GiffE!
I'm sure lots of people would love to see more CSQC tutorials like this!
_________________
http://www.planetcocot.net/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
GiffE



Joined: 08 Oct 2006
Posts: 141
Location: USA, CT

PostPosted: Tue Mar 04, 2008 12:13 am    Post subject: Reply with quote

Thanks!
It is something v. simple but that could be useful I suppose Very Happy
CSQC is really no different than standard qc just needs a little thinking to figure out how it works. Word just needs to get out about it.

Sorry about not using the "Submit Tutorial" I didn't really notice that or have it all typed outside of the post. Its also embarrassingly badly formatted and figured its not up to par with the tutorials page.

I'll do some more CSQC tut's if anyone has any suggestions. If not I'm gonna work on a scripted HUD system.
Back to top
View user's profile Send private message Visit poster's website
Stealth Kill



Joined: 29 Dec 2006
Posts: 83

PostPosted: Wed Mar 05, 2008 7:39 pm    Post subject: Reply with quote

Can I use this with QC?

i donīt know what CSQC is Embarassed
Back to top
View user's profile Send private message
leileilol



Joined: 15 Oct 2004
Posts: 1321

PostPosted: Wed Mar 05, 2008 7:40 pm    Post subject: Reply with quote

CSQC stands for Counter-Strike QuakeC as you can clearly see this is the bomb defusing bar
_________________
Back to top
View user's profile Send private message
RenegadeC



Joined: 15 Oct 2004
Posts: 370
Location: The freezing hell; Canada

PostPosted: Wed Mar 05, 2008 9:10 pm    Post subject: Reply with quote

leileilol wrote:
CSQC stands for Counter-Strike QuakeC as you can clearly see this is the bomb defusing bar


Laughing
Back to top
View user's profile Send private message AIM Address MSN Messenger
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Thu Mar 06, 2008 7:56 am    Post subject: Reply with quote

Funny Smile
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
ceriux



Joined: 06 Sep 2008
Posts: 969
Location: Florida, USA

PostPosted: Tue Mar 17, 2009 4:53 am    Post subject: Reply with quote

i think posts like this should be stickyed.
_________________
QuakeDB - Quake ModDB Group
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group