Date and Time in Save Games

Started by TheJBurger, Fri 20/01/2006 23:39:58

Previous topic - Next topic

TheJBurger

I'm having some trouble trying to implement date and time into my save game GUI.
Basically, I want the date and time of the save game displayed on a label in my save GUI.

I know about the date and time functions, but I still haven't been able to figure it out.


Pumaman

The easiest way is to modify the save game description that the user inputs, and include the date and time in it. Then, when they call up the Restore Game GUI, it will show the save slot name including the date.

TheJBurger

Thank you for your reply, I managed to put the date into the save game name.

However, I was wondering about something else.

Code: ags

Ã,  Ã,  GetTextBoxText(6,0,text);Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, // Get the typed text
Ã,  Ã,  string buffer;
Ã,  Ã,  DateTime *dt = DateTime.Now;
Ã,  Ã,  StrFormat (buffer, "%s %02d/%02d/%04d %02d:%02d", text, dt.DayOfMonth, dt.Month, dt.Year, dt.Hour, dt.Minute);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 


From my code, the date and time will always be one space after the "text" they typed. Is there any way to align the date and time to always be at 20 spaces or so? Because right now it looks kind of messy having the date and time constantly shifted. For instance, one save game is only four letters long, and the next is ten letters, and then the time is shifted all over.

Ashen

The easiest way would probably be:
Code: ags

while (StrLen(text) < 20) StrCat(text, " ");


Put that after you've got the inputted name, to pad it out to 20 characters (obviously, it won't do anything if the player already gave it a name with more than 20 characters), then add the date and time as you normally would.
I know what you're thinking ... Don't think that.

TheJBurger

It works, except that certain characters (such as 1 and 3) take up different amounts of space. So if I name my savegame "1"  the date will be placed differently than "3." But other than that it works great.

DoorKnobHandle

To workaround that issue you will need to import a fixed-font (such as Courier New), those fonts will use exactly the same width for any character.


SMF spam blocked by CleanTalk