[nogo] Goal gui improvements

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

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

[nogo] Goal gui improvements

Post by Zuu »

From creating and playing with NoCarGoal I have got some ideas on how the GUI facilities for Game Scripts could be improved. In this first patch I have added a progress counter (from 0 to 100 %) to the in-memory goals. Using a new API function GSGoal::Update it is now possible to update the text and progress information of a goal. The progress is shown in a separate column in the Goal GUI.

Further on I will probably try to add a company selector to the goal window with a first tab for viewing global goals. The goal list for each scope could then possible have sort by completion percentage rather than by goal ID.

API additions:
  • GSGoal::Update(goal_id, text, progress)
  • GSGoal::IsCompleted(goal_id) // Returns true if progress is 100, otherwise false

Thoughts about the patch/work
I'm thinking that if you haven't set any progress yet, it shouldn't show any value at all. Or that you can turn of progress display by setting progress to 255. As for NoCarGoal, showing percentage for global goals doesn't really make sense.

This patch includes changes to the savegame format and as I haven't done any such changes before, it is probably not complete in that matter. I have for example not changed the savegame format number yet.


Screenshots
(mind that I haven't updated the Goal strings in NoCarGoal to regard the fact that the goals are left visible after they have been completed)
Clueless, 18th Apr 1950.png
Clueless, 18th Apr 1950.png (93.59 KiB) Viewed 4654 times
Clueless, 6th Jun 1950.png
Clueless, 6th Jun 1950.png (36.34 KiB) Viewed 4654 times
Attachments
goal-gui-r24512.patch
(10.56 KiB) Downloaded 136 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4763
Joined: 09 Sep 2007 05:03
Location: home

Re: [nogo] Goal gui improvements

Post by Alberth »

Perhaps display the percentage at the left?
Then I can make the window much smaller, once I know the goal to reach.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: [nogo] Goal gui improvements

Post by frosch »

Maybe instead of a percentage, just allow to set a separate text for the progress.
I don't think a percentage is always the best choice for a progress. "2/7" feels a lot better than "29%". A percentage is useful if the progress can change in very small steps ("28%" is better than "15717/56134"), but it is not suitable for stuff like "2/7".

In the case of Silicon Valley I would use the "x/y" form for the number of industries goals, and the "xxx%" form for the cargo amount.

Using a general text for progress would allow a lot of different progress indicators:
  • "" (no progress indication)
  • "xxx %"
  • "x/y"
  • "1st", "2nd", "3rd", ...
  • "5 months left"
  • ...
Using a general text would not offer a IsComplete thingie. That would need a separate parameter.

Wrt. global goals: The progress should be set per company.

In total I propose these functions:
  • GSGoal::SetText(goal_id, text)
  • GSGoal::SetProgess(goal_id, company_id, text)
  • GSGoal::SetComplete(goal_id, company_id, bool)
  • GSGoal::GetComplete(goal_id, company_id)
The company_id is meant for global goals. Using COMPANY_INVALID would affect the company the goal belongs to, or all companies in case of global goals (for goals which are really shared between companies).

Edit:
Wrt. the window design. Progress on right looks more intuitive for me. But the resizing should clip the goal text and keep the progress text.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [nogo] Goal gui improvements

Post by Zuu »

frosch wrote:Wrt. global goals: The progress should be set per company.
So for the GUI design, global goals should still show up at the company tab of each company instead of having a separate tab for global goals? (as otherwise you can't see the progress of global goals for other companies)

Alberth wrote:Perhaps display the percentage at the left?
Then I can make the window much smaller, once I know the goal to reach.
In the current implementation it use 40 pixels at the right side for progress information. So you can resize the window and it will cut down on the goal text rather than on the progress text.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: [nogo] Goal gui improvements

Post by frosch »

I thought about a separate button in the main toolbar, next to subsidies, not "under subsidies".
It would behave like most of those buttons, and offer a dropdown to select the "goal view" of another company.
Also that button might be hidden if no GS is present to not confuse users. (Similar to how the "build object" button is hidden when no objects are present)

I don't think tabs as in the script debug window or company score is the way to go. Those do not fit the GUI style of the rest imo :)
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [nogo] Goal gui improvements

Post by Zuu »

frosch wrote:I thought about a separate button in the main toolbar, next to subsidies, not "under subsidies".
It would behave like most of those buttons, and offer a dropdown to select the "goal view" of another company.
Also that button might be hidden if no GS is present to not confuse users. (Similar to how the "build object" button is hidden when no objects are present)

I don't think tabs as in the script debug window or company score is the way to go. Those do not fit the GUI style of the rest imo :)
Isn't the main toolbar width limited to the current size? Eg. do I need to first remove something in order to get room for a new button there? Or can I just add a button there?

Also, even if we add a goal button to the main toolbar, if that is used to show a menu of all companies at top level, it will not allow more goal related windows to appear there. The only way for further windows is to add buttons in the goal window to show them from there.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13233
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Re: [nogo] Goal gui improvements

Post by Hyronymus »

Percentages are clear cut and easy to rea, no need to worry about writing out 222 of 1.000 tonnes or 222 out of 1.000 passengers.

Allow me to say that I truly admire the entire Goal framework you and others have created, Zuu :bow: .
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: [nogo] Goal gui improvements

Post by frosch »

Hyronymus:
Take a look at this:
http://www.tt-forums.net/download/file.php?id=163924

A percentage works nice for the third goal. It works somewhat for the first two, but 0/3 would be better. For the last one a percentage does not work at all.

Zuu:
More goal buttons? Ok, but maybe we should then move everything to the company league menu.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Honza_
Engineer
Engineer
Posts: 122
Joined: 29 Aug 2010 10:29

Re: [nogo] Goal gui improvements

Post by Honza_ »

It is nice, but why to code this. one can easily compute percentages in goal script already, and align hem to the left.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [nogo] Goal gui improvements

Post by Zuu »

Honza_ wrote:It is nice, but why to code this. one can easily compute percentages in goal script already, and align hem to the left.
  • I was unaware that there is a posibility to create two columns with current OpenTTD. Please show me.
  • With the original percentage-only implementation, adding AI friendly APIs is possible. With the newer complete-text implementation, that is not really true anymore
  • The IsCompleted state can be read by AIs
  • In future we can add APIs to allow town growth depend on an arbitrary goal by allowing it to depend on the completeness of a goal. (this is however not very AI friendly so that is a drawback with this path)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Honza_
Engineer
Engineer
Posts: 122
Joined: 29 Aug 2010 10:29

Re: [nogo] Goal gui improvements

Post by Honza_ »

Zuu wrote: I was unaware that there is a posibility to create two columns with current OpenTTD. Please show me.
You do very well know, there is not.
I think it is nice, but computing percentages is simple (current goal / goal * 100%), and aling it left is pure [number percent]...few spaces..."some text"

Much better would be extended gui in town window.

But sure, this your patch is indeed a gui improvement :)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [nogo] Goal gui improvements

Post by Zuu »

I've updated the patch:

- Added a codechange patch that reduce code duplication before the actual changes
- Fixed resizeing of window.
- Changed the progress column to be aligned to the right. I think this makes more sense both with "k %" and "k out of n" type of progress displays. In both cases k will align up better for comparing small/large numbers if progress is aligned to the right.


If any user of a RTL language reads this, what is the preferred aliment for RTL languages? As far as I can see OpenTTD outputs numbers so that the most significant digit is still to the left. Thus perhaps also RTL languages should have the progress text aligned to the right so that digits of the same significance appear above each other just as what I was aiming to do for non-RTL languages.
Attachments
05-goal-gui-refactor.patch
(2.87 KiB) Downloaded 75 times
10-goal-gui-completed-column.patch
(21.07 KiB) Downloaded 72 times
goal-progress.png
goal-progress.png (9.15 KiB) Viewed 3475 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [nogo] Goal gui improvements

Post by Zuu »

Screenshot with RTL language
Attachments
goal-rtl.png
goal-rtl.png (15.04 KiB) Viewed 3474 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [nogo] Goal gui improvements

Post by Zuu »

Updated patch (now that the code change patch is in trunk):
Attachments
10-goal-gui-completed-column.patch
(21.04 KiB) Downloaded 75 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [nogo] Goal gui improvements

Post by Zuu »

My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [nogo] Goal gui improvements

Post by Zuu »

r25296 changes
r25296 wrote:-Feature: Goals can now have a progress text and/or be marked as completed.
You can now use these methods to update goals:
  • GSGoal.SetProgress
  • GSGoal.SetCompleted
  • GSGoal.SetText
There is also a method to check if a given goal is marked as completed or not:
  • GSGoal.IsCompleted
Note however, that until FS#5561 is fixed, you need to create all goals after world gen has completed in order to get the goal ID. To force world gen to finish you can make sure GSController.Sleep(1) is called at least once in the game before you create any goal.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 36 guests