Forum

Add Date and Time to Menu

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

Add Date and Time to Menu

Postby Rikku2000 » Sun Dec 25, 2011 12:32 pm

Just create 2 files called time.c and time.h

Image

time.h:
Code: Select all
#ifndef __TIME_H__
#define __TIME_H__

int Time_Draw ();

#endif

time.c:
Code: Select all
#include <fcntl.h>
#include <unistd.h>
#include <time.h>

#include "quakedef.h"

int Time_Draw () {
   time_t current_time;

   struct tm *tm_ptr;
   static int current_min = 0;

   current_time = time(0);
   localtime(&current_time);
   tm_ptr = gmtime(&current_time);

   char *result[24];

   int hour = tm_ptr->tm_hour;
   int ampm = 0;

   current_min = tm_ptr->tm_min;

   if(hour == 0)
      hour = 12;
   else if(hour >= 12)  {
      ampm = 1;

      if(hour >= 13)
         hour -= 12;
   }

   if(ampm == 0)
      snprintf (result, 20, "%02d/%02d AM %02d:%02d", tm_ptr->tm_mon+1, tm_ptr->tm_mday, hour, tm_ptr->tm_min);
   else
      snprintf (result, 20, "%02d/%02d PM %02d:%02d", tm_ptr->tm_mon+1, tm_ptr->tm_mday, hour, tm_ptr->tm_min);

   M_Print (200 + ((vid.width - 320)>>1), 8, result);

   return 0;
}


Open the menu.c now and search for:
Code: Select all
void M_DrawColorBar (int x, int y, int highlight) {
...
}

after that you add this:
Code: Select all
#include "time.h"


now looking in "void M_Main_Draw (void)" for that:
Code: Select all
M_DrawTransPic (54, 32 + m_main_cursor * 20,Draw_CachePic( va("gfx/menudot%i.lmp", f+1 ) ) );
and add this here:
Code: Select all
Time_Draw ();
I am sorry for my English...
User avatar
Rikku2000
 
Posts: 49
Joined: Wed Oct 20, 2010 6:33 pm
Location: Germany

Re: Add Date and Time to Menu

Postby toneddu2000 » Sun Dec 25, 2011 7:11 pm

Thanks! And happy Xmas! :)
Meadow Fun!! - my first commercial game, made with FTEQW game engine
toneddu2000
 
Posts: 1352
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest