-
-
Notifications
You must be signed in to change notification settings - Fork 843
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: use vector with struct for string parameter backups #11052
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2c95110
Codechange: introduce new type and functions for StringParameter backups
rubidium42 de30e29
Codechange: move tooltip and query window over to the new StringParam…
rubidium42 f332772
Codechange: move news over to the new StringParameterBackup type
rubidium42 d0b12c3
Codechange: move errors over to the new StringParameterBackup type
rubidium42 06b0857
Cleanup: remove old backup/restore of string parameters
rubidium42 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -662,17 +662,14 @@ static WindowDesc _tool_tips_desc( | |
struct TooltipsWindow : public Window | ||
{ | ||
StringID string_id; ///< String to display as tooltip. | ||
byte paramcount; ///< Number of string parameters in #string_id. | ||
uint64 params[8]; ///< The string parameters. | ||
std::vector<StringParameterBackup> params; ///< The string parameters. | ||
TooltipCloseCondition close_cond; ///< Condition for closing the window. | ||
|
||
TooltipsWindow(Window *parent, StringID str, uint paramcount, TooltipCloseCondition close_tooltip) : Window(&_tool_tips_desc) | ||
{ | ||
this->parent = parent; | ||
this->string_id = str; | ||
assert(paramcount <= lengthof(this->params)); | ||
this->paramcount = paramcount; | ||
if (paramcount > 0) CopyOutDParam(this->params, this->paramcount); | ||
CopyOutDParam(this->params, paramcount); | ||
this->close_cond = close_tooltip; | ||
|
||
this->InitNested(); | ||
|
@@ -703,7 +700,7 @@ struct TooltipsWindow : public Window | |
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override | ||
{ | ||
/* There is only one widget. */ | ||
for (uint i = 0; i != this->paramcount; i++) SetDParam(i, this->params[i]); | ||
CopyInDParam(this->params); | ||
|
||
size->width = std::min<uint>(GetStringBoundingBox(this->string_id).width, ScaleGUITrad(194)); | ||
size->height = GetStringHeight(this->string_id, size->width); | ||
|
@@ -719,9 +716,7 @@ struct TooltipsWindow : public Window | |
GfxFillRect(r, PC_BLACK); | ||
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_LIGHT_YELLOW); | ||
|
||
for (uint arg = 0; arg < this->paramcount; arg++) { | ||
SetDParam(arg, this->params[arg]); | ||
} | ||
CopyInDParam(this->params); | ||
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect).Shrink(WidgetDimensions::scaled.fullbevel), this->string_id, TC_BLACK, SA_CENTER); | ||
} | ||
|
||
|
@@ -1098,14 +1093,14 @@ void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *paren | |
*/ | ||
struct QueryWindow : public Window { | ||
QueryCallbackProc *proc; ///< callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' clicked, false otherwise | ||
uint64 params[10]; ///< local copy of #_global_string_params | ||
std::vector<StringParameterBackup> params; ///< local copy of #_global_string_params | ||
StringID message; ///< message shown for query window | ||
|
||
QueryWindow(WindowDesc *desc, StringID caption, StringID message, Window *parent, QueryCallbackProc *callback) : Window(desc) | ||
{ | ||
/* Create a backup of the variadic arguments to strings because it will be | ||
* overridden pretty often. We will copy these back for drawing */ | ||
CopyOutDParam(this->params, lengthof(this->params)); | ||
CopyOutDParam(this->params, 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Magic 10, as above I suppose. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, misc_gui.cpp:1101 to be precise. |
||
this->message = message; | ||
this->proc = callback; | ||
this->parent = parent; | ||
|
@@ -1134,7 +1129,7 @@ struct QueryWindow : public Window { | |
switch (widget) { | ||
case WID_Q_CAPTION: | ||
case WID_Q_TEXT: | ||
CopyInDParam(this->params, lengthof(this->params)); | ||
CopyInDParam(this->params); | ||
break; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Magic 20, presumably that's just some limit that was set elsewhere before.
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.
Yes, error.h:34/35 to be precise. In the end only the needed amount of parameters should be copied, but that's for later.