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
Conversation
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); |
There was a problem hiding this comment.
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.
It's ready, but I keep it as draft because it depends on OpenTTD/eints#142 |
There was a problem hiding this 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.
@@ -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)); |
There was a problem hiding this comment.
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.
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.