Add Date and Time to Menu

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
Rikku2000
Posts: 49
Joined: Wed Oct 20, 2010 6:33 pm
Location: Germany
Contact:

Add Date and Time to Menu

Post by Rikku2000 »

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...
toneddu2000
Posts: 1395
Joined: Tue Feb 24, 2009 4:39 pm
Location: Italy

Re: Add Date and Time to Menu

Post by toneddu2000 »

Thanks! And happy Xmas! :)
Meadow Fun!! - my first commercial game, made with FTEQW game engine
Post Reply