Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codechange: Simplify drawing of timetables #10687

Merged
merged 2 commits into from Jun 20, 2023
Merged

Codechange: Simplify drawing of timetables #10687

merged 2 commits into from Jun 20, 2023

Conversation

glx22
Copy link
Contributor

@glx22 glx22 commented Apr 21, 2023

Motivation / Problem

Each timetable departure/arrival time is drawn using 2 strings, the abbreviation and the time.

Description

Introduce {COLOUR} control code and use it to merge abbreviation and time into a single string.

Limitations

EINTS needs to be updated.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

src/strings.cpp Outdated
@@ -1618,6 +1618,12 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
break;
}

case SCC_COLOUR: { // {COLOUR}
StringControlCode scc = (StringControlCode)(SCC_BLUE + args->GetInt32(SCC_COLOUR));
if (IsInsideMM(scc, SCC_BLUE, SCC_COLOUR) && (buff + Utf8CharLen(scc) < last)) buff += Utf8Encode(buff, scc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This relies on SCC_COLOUR being placed after SCC_BLACK. May be better as SCC_BLACK + 1? Though this does all rely on the colours being in specific order in the first place, so may not matter.

@glx22
Copy link
Contributor Author

glx22 commented Apr 23, 2023

It's ready, but I keep it as draft because it depends on OpenTTD/eints#142

@glx22 glx22 marked this pull request as ready for review June 14, 2023 22:45
Copy link
Member

@2TallTyler 2TallTyler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you've tested this thoroughly. Code looks good to me.

I wonder, idly of course since it's out of scope here, if there are other places that could use this simplified drawing method.

@glx22 glx22 merged commit 6c7f977 into OpenTTD:master Jun 20, 2023
19 checks passed
@glx22 glx22 deleted the colour branch June 20, 2023 17:05
@@ -1627,6 +1627,12 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
break;
}

case SCC_COLOUR: { // {COLOUR}
StringControlCode scc = (StringControlCode)(SCC_BLUE + args.GetInt32(SCC_COLOUR));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a compile error on this line after the merge.

C:\Users\nielsm\Dev\OpenTTD\src\strings.cpp(1628): error C2660: 'StringParameters::GetInt32': function does not take 1 arguments
  C:\Users\nielsm\Dev\OpenTTD\src\strings_internal.h(91): note: see declaration of 'StringParameters::GetInt32'
  C:\Users\nielsm\Dev\OpenTTD\src\strings.cpp(1628): note: while trying to match the argument list '(StringControlCode)'

As far as I can tell, StringParameters::GetInt32() has never existed in a version that takes a parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants