Patch: Rating in Town Label [v13-r18684]

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Patch: Rating in Town Label [v13-r18684]

Post by Terkhen » 30 Mar 2009 21:53

The idea around this patch is based on Progman's Town rating indicator patch, taking users and devs comments into account. Without knowing it, the patch does this in a similar way than Vikthor's Local authority rating in town label patch. I have adopted some fixes and improvements from the Russian OpenTTD Community patchpack.

Essentialy, the patch uses a colour code in the population part of the town label to show the current rating. If the window is zoomed out, the complete town label will have a changed colour. When the rating at a town changes, the colour is updated accordingly.

Currently the colour scheme is:

Red: Appalling and Very poor ratings.
Orange: Poor and mediocre ratings.
Yellow: Good rating.
White: Very Good rating (standard).
Green: Excellent and outstanding ratings.

Here's a screenshot showing all ratings:
colour.png
colour.png (81.46 KiB) Viewed 16577 times
Version history
  • v13-r17745: Update to current trunk. Version format changed to fit the used at the rest of my patches. Some code cleanup and simplifications.
  • v12-r17558: Update to current trunk. Fixed an incorrect string.
  • v11: Patch renamed, and almost completely remade. The patch uses only standard colours, and because of that now the code is way more simple. Added comments and fixed a situation in which the correct ratings weren't shown.
  • v10: Update to current trunk. Critical parts of the patch have been remade to be both faster and easier to read. This version is the last one with a colour for each rating. You can download this version here.
  • v09: Update to current trunk. Coding style corrected, including trailing whitespaces (I hope they are out now). Statements to check current rating changed to a better solution that is already used in other parts of OpenTTD code. TownRatingColour implemented as a member of the Town class. Unified some duplicated code. Thanks, Hirundo!
  • v08: (Minor) update to trunk.
  • v07: Update to trunk. Added version for stable 0.7.0 (which is essentially identical to v0.6).
  • v06: Symbol version removed: you still can find the v0.5 version here. Now only the population is coloured. Setting option merged with "show population". Fixed a bug where the colour won't update after town growth. Made sure that the patch can be applied to 0.7.
  • v05: I finally found why _current_company != _local_company. Because of this bug, when the game just commenced the town names were white. A more exact colour scheme is introduced. The code have been almost completely remade to be more efficient (no longer it needs to calculate the colour each time the sign is drawn, only when the rating changes).
  • v04: Colour scheme changed again. Ratings are now shown with 4x and 8x zoom-out. Symbol-only version released.
  • v03: Colour scheme changed for better readability. Code changed to work only with colours instead of completely different string IDs. Use always the white colour while playing as spectator. Fixed some indentation errors.
  • v02: Added patch option to activate / deactivate this option. Now everytime that a town rating is changed, that town's sign is updated.
  • v01: Initial release
Attachments
rating_town_label_r18684.diff
(7.31 KiB) Downloaded 573 times
rating_town_label_v13-r18762.rar
(3.02 MiB) Downloaded 495 times
Last edited by Terkhen on 09 Jan 2010 13:07, edited 35 times in total.

Timmaexx
Transport Coordinator
Transport Coordinator
Posts: 301
Joined: 03 Jan 2009 17:55

Re: Patch: Town sign color shows ratings

Post by Timmaexx » 30 Mar 2009 22:45

Very nice idea Terkhen!
This will be my favourite patch ;)
Oh and I bet, in 6 hours the first demands for the KGATPP are coming in :D
Last edited by Timmaexx on 19 Apr 2009 18:07, edited 1 time in total.

Eddi
Tycoon
Tycoon
Posts: 7414
Joined: 17 Jan 2007 00:14

Re: Patch: Town sign color shows ratings

Post by Eddi » 31 Mar 2009 00:45

what's a must-of?
You might not exactly be interested in Ferion, but if you are, have fun :)

Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Town sign color shows ratings

Post by Terkhen » 31 Mar 2009 21:47

New version posted: see first post for details.

@Eddi: I suppose he means a "must-have". Thank you Timmaexx!

2007Alain2007
Chief Executive
Chief Executive
Posts: 658
Joined: 11 Nov 2007 12:06

Re: Patch: Town sign color shows ratings

Post by 2007Alain2007 » 31 Mar 2009 23:52

I had a look at this patch and it looks nice but not all the coulours work all the time it be nice to see what the rateings for each palyer not just one get a setting to show yours and everones who run in that town
For Community Integrated Version http://code.google.com/p/civopenttd/

Vikthor
Engineer
Engineer
Posts: 69
Joined: 13 Jun 2004 16:57
Location: Prague, Czech republic

Re: Patch: Town sign color shows ratings

Post by Vikthor » 01 Apr 2009 09:15

It's interesting how some ideas emerge again and again. I made similar patch over a year ago. I wish you luck and I hope you will be more successful in getting it commited.

Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Town sign color shows ratings

Post by Terkhen » 01 Apr 2009 09:34

@2007Alain2007: I'm not sure I understood what you meant, but the aim of this patch is to provide info about ratings while building near a city. That way, you don't have to open the ratings window and have it occupying screen space. If you need to check ratings for other companies, the best solution is just to look at the ratings window.

@Vikthor: It's incredible: I hadn't seen your patch but after reading it, I see that we reached almost the same solution. I added a link to your work in the first post. Thanks for your support!.

User avatar
FooBar
Tycoon
Tycoon
Posts: 6559
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Patch: Town sign color shows ratings

Post by FooBar » 01 Apr 2009 09:47

Maybe instead of colours (which make the sign quite unreadable sometimes), you could do something with plusses and minusses.

For instance, add a double plus (++) at the end of the town label in case of Excellent or Outstanding rating, and along those lines outher ratings could be indicated as follows:

Appalling and Very Poor: --
Poor: -
Mediocre: (no indication)
Good and Very Good ratings: +
Excellent and Outstanding: ++

Otherwise I think it's a very nice addition to the game. Keeps me from opening two windows in every town.

Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: Patch: Town sign color shows ratings

Post by Hirundo » 01 Apr 2009 15:30

Some random comments on the code:

_current_company != _local_company.
Also, both current and local company may not be a valid company. e.g. t->ratings[COMPANY_SPECTATOR] will overflow badly.

Isn't it possible to specify a colour when drawing a string? I think this would be preferable to using many different strings in english.txt.

In some places the code isn't aligned properly w.r.t. tabs/indentation. Read the .diff thoroughly to see what I mean.
Create your own NewGRF? Check out this tutorial!

Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Town sign color shows ratings

Post by Terkhen » 01 Apr 2009 15:56

I like Foobar's idea: is more readable than using colors. What do other people think?

Swallow: Thanks for your comments. I'll look into the company problem and the indentation errors tonight. I don't know how to use strings that aren't defined at english.txt, but I'll give it a try.

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Patch: Town sign color shows ratings

Post by Zuu » 01 Apr 2009 17:07

About choosing what color to draw with. The sign list window uses the following code to draw sign names in yellow. Notice the last argument to DrawString is the colour.

Code: Select all

			SetDParam(0, si->index);
			DrawString(this->widget[SLW_LIST].left + 22, this->widget[SLW_LIST].right, y, STR_SIGN_NAME, TC_YELLOW);
I've checked your patch and see that the town names are drawn using another function "AddStringToDraw", but looking up that function it has two optional parameters. The first optional parameter is named colour. If it works the same as the colour parameter to DrawString, it will override the colour information in the string with the supplied colour.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Town sign color shows ratings

Post by Terkhen » 04 Apr 2009 15:19

I have posted a new version of the patch in the first post. See the changelog for details.

What is your opinion about the new colors?

Zuu: Thanks for your help: I think the code is cleaner now that it works just with colors.

Swallow: I think I fixed everything, except the _current_company and _local_company issue. All functions related to the town sign drawing used _current_company, so I wasn't sure if I had to change it or not.

User avatar
FooBar
Tycoon
Tycoon
Posts: 6559
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Patch: Town sign color shows ratings

Post by FooBar » 04 Apr 2009 17:50

Terkhen wrote:What is your opinion about the new colors?
Much better. That blue was just terribly unreadable.

Maybe change the red for orange? That red is a bit 'screamish' compared to the other colours.

Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Town sign color shows ratings

Post by Terkhen » 04 Apr 2009 18:17

This screenshot shows how it looks after changing red with orange:
orange.png
orange.png (92.22 KiB) Viewed 18929 times
I prefer orange too. It's not as striking as red, but still shows a bad rating nicely.

User avatar
ChillCore
Tycoon
Tycoon
Posts: 2658
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Patch: Town sign color shows ratings

Post by ChillCore » 11 Apr 2009 09:28

I like this patch.
I is much easier to see which towns needs that little extra attention.
Also it prevents me bulldozing and terraforming then to find out i am not allowed to build whatever i was preparing the terrain for.

The only thing that confuses me a little bit is the townname colourchange.

Would it be possible to leave the townname white and only have the townpopulation change colour?
That way we still see the townratings and I am no longer searching for the townname between my station/busstop signs (and other player/ai stations/busstops).

Anyway nice patch.
I hope it hits trunk.
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.

Auge
Transport Coordinator
Transport Coordinator
Posts: 383
Joined: 23 Oct 2006 02:07
Location: Berlin

Re: Patch: Town sign color shows ratings

Post by Auge » 11 Apr 2009 12:17

Hello
ChillCore wrote: The only thing that confuses me a little bit is the townname colourchange.

Would it be possible to leave the townname white and only have the townpopulation change colour?
That could cause a problem. You can disable the displaying of the townpopulation. Wich element want you to be coloured in this case?
ChillCore wrote: I hope it hits trunk.
Me too. :-)

Tschö, Auge

User avatar
ChillCore
Tycoon
Tycoon
Posts: 2658
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Patch: Town sign color shows ratings

Post by ChillCore » 11 Apr 2009 12:25

That could cause a problem. You can disable the displaying of the townpopulation. Wich element want you to be coloured in this case?
None?

I have the grass on tracks in my patchpack and if i disable all details the grass is gone and so is my extra system load.(hint)
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.

Auge
Transport Coordinator
Transport Coordinator
Posts: 383
Joined: 23 Oct 2006 02:07
Location: Berlin

Re: Patch: Town sign color shows ratings

Post by Auge » 11 Apr 2009 13:56

ChillCore wrote:
That could cause a problem. You can disable the displaying of the townpopulation. Wich element want you to be coloured in this case?
None?
Oh, sorry. I thought, the patch make it into trunk and should be available for everyone (including those, who disabled the displaying of town population).

Tschö, Auge

User avatar
ChillCore
Tycoon
Tycoon
Posts: 2658
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Patch: Town sign color shows ratings

Post by ChillCore » 11 Apr 2009 15:43

Maybe like FooBar suggested adding :

++ + N - --

to/before the townstring.

Its just an idea.
The way it is now it is fine too.
I just have to search a bit longer after the townname sometimes,
because in some of my games i dont let towns build roads so the towname is not always in the center. No biggy
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.

Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Patch: Town sign color shows ratings

Post by Terkhen » 11 Apr 2009 21:33

Both approachs (different color only in town population and adding something at the end of the string) would need a new string in english.txt for each color / symbol to be added. Since that makes the patch more messy, I'd prefer not to add more strings. I think there's a way to pass a string parameter to a string, I'll give it a look soon.

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 3 guests