[patch] Refactor planet meters

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
Vegavis
Space Squid
Posts: 71
Joined: Sun Jan 12, 2014 7:04 am

[patch] Refactor planet meters

#1 Post by Vegavis »

Planet meters currently use three classes (PopulationPanel, ResourcePanel, and MilitaryPanel) that are almost identical. Here's a patch that refactors them into one class that supports arbitrary meters. This saves ~500 lines and makes it much easier to modify these panels.

This is pure refactoring: it should not change behavior. (Tiny exception: it changes the sort order of Infrastructure and Trade when they're equal. I think this doesn't matter, since no one looks at those meters, let alone cares about their ordering.) It does, however, make it much easier to change the planet meters. In particular, it's now trivial to remove unused meters (happiness, construction, trade) and rearrange the others so they're all visible at once.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [patch] Refactor planet meters

#2 Post by Geoff the Medio »

I'm not seeing sorting of any of the icons by the meter value in the resources panel... It's not just the trade / construction meters that are affected by this, and not only when equal.

Which is not to say that that's really a problem... the utility of such sorting is debatable.

Anyway, it builds and runs OK for me. Alternative OS testing would be good though, due to use of unusual assignment boost stuff.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: [patch] Refactor planet meters

#3 Post by Dilvish »

It appears to build and run fine for me in Linux; I see sorting in the minimized panel view but not in the maximized panel view, which I seem to recall has been (or was at some point) the behavior for a long time. I guess that different treatment has been motivated by the need to be able to drop some icons for the minimized view, but I think I would be in favor of both having a fixed ordering though still dropping the lowest valued meters from the minimized view.

Since the top bar empire summary icons/numbers always has Production to the left of Research, perhaps these panels should always use that same ordering (and the window toggle buttons in the upper right of the top bar as well) .
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [patch] Refactor planet meters

#4 Post by Geoff the Medio »

Vegavis, could you tweak the patch to make the meter ordering consistent... (probaby not changing with meter values, to be simpler) ?

Vegavis
Space Squid
Posts: 71
Joined: Sun Jan 12, 2014 7:04 am

Re: [patch] Refactor planet meters

#5 Post by Vegavis »

OK. (I agree that the sorting is confusing and the meters should stay in the same order.)

Here's an updated patch that (in addition to the refactoring):
  1. Removes the sorting.
  2. Removes the unused meters (happiness, infrastructure, trade) and rearranges the others so there are three per row, so they're all visible all the time. (This is very easy, which was the point of the refactoring.)
I suggest committing the refactoring first and the visible changes as a separate patch (or two), so it's easy to distinguish them.

While we're reordering meters, should planet defenses go before shields, for consistency with weapons going before armor?
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: [patch] Refactor planet meters

#6 Post by MatGB »

Infrastructure isn't unused, it's still got a fairly strong effect on defences recovery.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: [patch] Refactor planet meters

#7 Post by Dilvish »

I can still recall the happiness meter/icon being added. I think it's presence acts as a bit of a reminder and perhaps subtle inspiration to be thinking about the happiness system to be implemented. I see no significant reason to remove the icons/meters that are currently expected to play a role (so long as a wikipedia entry exists explaining that they are an early step towards future development with no current function).

As Matt noted, the infrastructure icon should certainly not be removed at this time (even though it might possibly be heading in that direction).
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13603
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [patch] Refactor planet meters

#8 Post by Geoff the Medio »

Reordering is fine, but happiness and infrastructure should stay.

Vegavis
Space Squid
Posts: 71
Joined: Sun Jan 12, 2014 7:04 am

Re: [patch] Refactor planet meters

#9 Post by Vegavis »

Oh, I thought those were obsolete features on their way out, not new features not finished yet. (But isn't it better to hide Happiness until it's used, to avoid confusing newbies?) OK, ignore that part of the patch (or do whatever rearrangements you like; it's trivial so you don't need a patch from me).

Here's the patch to remove sorting, isolated from the rest.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


Post Reply