Author Topic: [patch] Clock indicating time of day  (Read 1531 times)

MirceaKitsune

  • Technician
  • ****
  • Posts: 147
    • View Profile
[patch] Clock indicating time of day
« on: 15 August 2012, 11:07:30 »
A few days ago I made my first patch for MegaGlest. It adds a feature I always wanted to see in Glest, which is a clock indicating the time of day in-game. I was originally aiming for a graphical representation (like Warcraft 3 has that sun / moon icon at the top of the screen) but since HUD graphics are faction based, I decided to simply use a text clock. It's positioned under the minimap and uses the game's time property with the needed modifications to look like a real clock (not the same as the clock in the Debug screen). My skills in programming are still bad, so please mention if I wrote something badly in the code. Also if you have a better idea for showing daytime than this clock.

Download the SVN patch from here. Text version available here, also located below. Also two screenshots of it in action... look to the upper-left under the mini-map.





Code: [Select]
Index: source/glest_game/game/game.cpp
===================================================================
--- source/glest_game/game/game.cpp (revision 3528)
+++ source/glest_game/game/game.cpp (working copy)
@@ -3735,6 +3735,11 @@
  }
  }
 
+ // clock
+ if(photoModeEnabled == false) {
+ renderer.renderClock();
+    }
+
     //resource info
  if(photoModeEnabled == false) {
  if(this->masterserverMode == false) {
Index: source/glest_game/graphics/renderer.cpp
===================================================================
--- source/glest_game/graphics/renderer.cpp (revision 3528)
+++ source/glest_game/graphics/renderer.cpp (working copy)
@@ -2213,6 +2213,36 @@
  }
 }
 
+void Renderer::renderClock() {
+ if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
+ return;
+ }
+
+ const Metrics &metrics = Metrics::getInstance();
+ const World *world = game->getWorld();
+ const Vec4f fontColor = game->getGui()->getDisplay()->getColor();
+
+ int hours = world->getTimeFlow()->getTime();
+ int minutes = (world->getTimeFlow()->getTime() - hours) * 100 * 0.6; // scale 100 to 60
+
+ string str = hours < 10 ? "0" + intToStr(hours) : intToStr(hours); // change 1 to 01 etc
+ str += ":";
+ str += minutes < 10 ? "0" + intToStr(minutes) : intToStr(minutes); // change 1 to 01 etc
+
+ if(renderText3DEnabled == true) {
+ renderTextShadow3D(
+ str, CoreData::getInstance().getDisplayFontSmall3D(),
+ fontColor,
+ 10, metrics.getVirtualH()-160, false);
+ }
+ else {
+ renderTextShadow(
+ str, CoreData::getInstance().getDisplayFontSmall(),
+ fontColor,
+ 10, metrics.getVirtualH()-160, false);
+ }
+}
+
 void Renderer::renderResourceStatus() {
  if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
  return;
Index: source/glest_game/graphics/renderer.h
===================================================================
--- source/glest_game/graphics/renderer.h (revision 3528)
+++ source/glest_game/graphics/renderer.h (working copy)
@@ -477,6 +477,7 @@
  void renderConsoleLine(int lineIndex, int xPosition, int yPosition, int lineHeight, Font2D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo);
 
  void renderChatManager(const ChatManager *chatManager);
+ void renderClock();
  void renderResourceStatus();
  void renderSelectionQuad();
  void renderText(const string &text, Font2D *font, float alpha, int x, int y, bool centered= false);

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: [patch] Clock indicating time of day
« Reply #1 on: 15 August 2012, 14:38:01 »
Patch added in svn.

MirceaKitsune

  • Technician
  • ****
  • Posts: 147
    • View Profile
Re: [patch] Clock indicating time of day
« Reply #2 on: 15 August 2012, 18:52:53 »
Thanks! Glad people find it useful... hope I'll get around to coding even more useful features in time.

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: [patch] Clock indicating time of day
« Reply #3 on: 16 August 2012, 02:51:46 »
I'd like to see this feature expanded in a few ways. First of all, I'd like to see an option in the INI to enable or disable the clock. Secondly, I'd like to be able to change the clock to display the real world time (localized for the user). Why? Because when playing full screen games, it's very easy to lose track of the time. Lately, I've found myself enabling mods in games, where available, to display a clock ingame (for example, a Civ V mod added a clock to the top window, and a Skyrim mod added the time to loading screens). Frankly, I love it. I actually notice that it's getting late before I have one of those "holy crap, it's four AM" moments. Could this clock function be adapted to this functionality too?
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: [patch] Clock indicating time of day
« Reply #4 on: 16 August 2012, 06:32:11 »
Done, svn shows the following format:

Code: [Select]
Game: 07:32 Local: 23:13
To turn off the clock set this in the ini:

Code: [Select]
InGameClock=false

MirceaKitsune

  • Technician
  • ****
  • Posts: 147
    • View Profile
Re: [patch] Clock indicating time of day
« Reply #5 on: 16 August 2012, 09:25:18 »
Fair enough. I'd rather the ini setting could decide between seeing realtime clock, game clock, or both. Since I'd kinda avoid the realtime one, or do that one separately. But it's ok like this too.

Coldfusionstorm

  • Golem
  • ******
  • Posts: 868
    • View Profile
Re: [patch] Clock indicating time of day
« Reply #6 on: 16 August 2012, 15:14:40 »
This is a really nice feature, but could we exstend it to have a "game time elapsed" too?.

This would be really nice!

No matter what, AWESOME PATCH!
WiP Game developer.
I do danish translations.
"i break stuff"

MirceaKitsune

  • Technician
  • ****
  • Posts: 147
    • View Profile
Re: [patch] Clock indicating time of day
« Reply #7 on: 16 August 2012, 15:39:17 »
Maybe... but if anything else is added, instead of an in-game clock this is turning into a list of things. If even more is going to be added to it, I'd rather suggest something else: For each entry (game clock, computer clock, elapsed time, etc) use a new line, so it's like a list. Also allow the config to specify what to show exactly, so any of those entries can be enabled or disabled.

The debug screen is already such a list, but that's a debug screen so different purpose. Something like that but with smaller text (and 3-4 lines at most) under the minimap could do it.

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: [patch] Clock indicating time of day
« Reply #8 on: 16 August 2012, 21:15:49 »
ok two ini options control the clock, the default is both enabled:

Code: [Select]
InGameClock=true
InGameLocalClock=true

MirceaKitsune

  • Technician
  • ****
  • Posts: 147
    • View Profile
Re: [patch] Clock indicating time of day
« Reply #9 on: 17 August 2012, 00:11:41 »
Looks great, I agree with that (I assume each clock is a different line, so both clocks enabled would mean two lines... since one text after another would probably look weird and long).

tomreyn

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 2,764
    • View Profile
    • MegaGlest - the free and open source cross platform 3D real-time strategy game
Re: [patch] Clock indicating time of day
« Reply #10 on: 17 August 2012, 00:19:43 »
Personally I think either none or just the game clock should be enabled by default. I bet that's what Titi will say, too. But we can wait for him to return before we finalize this.
atibox: Ryzen 1800X (8 cores @3.6GHz), 32 GB RAM, MSI Radeon RX 580 Gaming X 8G, PCI subsystem ID [1462:3417], (Radeon RX 580 chipset, POLARIS10) @3440x1440; latest stable Ubuntu release, (open source) radeon (amdgpu) / mesa video driver
atibox (old): Core2Quad Q9400 (4 cores @2.66GHz), 8 GB RAM, XFX HD-467X-DDF2, PCI subsystem ID [1682:2931], (Radeon HD 4670, RV730 XT) @1680x1050; latest stable Ubuntu release, (open source) radeon / mesa video driver
notebook: HP envy13d020ng
internet access: VDSL2+

· · · How YOU can contribute to MG · Latest development snapshot · How to build yourself · Megapack techtree · Currently hosted MG games · · ·

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: [patch] Clock indicating time of day
« Reply #11 on: 10 September 2012, 11:40:10 »
Well, I am indeed with tomreyn opinion here. As Day/Nighttime doesn't affect the gameplay ( yet? ) its just somthing thats displayed for "interest". So by default I would remove it.
Maybe we add this to the (ingame)options and have it default off  ?
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

 

anything