@@ -1212,68 +1212,70 @@ struct ScriptDebugWindow : public Window
Hotkey('5', "company_5", WID_SCRD_COMPANY_BUTTON_START + 4),
Hotkey('6', "company_6", WID_SCRD_COMPANY_BUTTON_START + 5),
Hotkey('7', "company_7", WID_SCRD_COMPANY_BUTTON_START + 6),
Hotkey('8', "company_8", WID_SCRD_COMPANY_BUTTON_START + 7),
Hotkey('9', "company_9", WID_SCRD_COMPANY_BUTTON_START + 8),
Hotkey(0, "company_10", WID_SCRD_COMPANY_BUTTON_START + 9),
Hotkey(0, "company_11", WID_SCRD_COMPANY_BUTTON_START + 10),
Hotkey(0, "company_12", WID_SCRD_COMPANY_BUTTON_START + 11),
Hotkey(0, "company_13", WID_SCRD_COMPANY_BUTTON_START + 12),
Hotkey(0, "company_14", WID_SCRD_COMPANY_BUTTON_START + 13),
Hotkey(0, "company_15", WID_SCRD_COMPANY_BUTTON_START + 14),
Hotkey('S', "settings", WID_SCRD_SETTINGS),
Hotkey('0', "game_script", WID_SCRD_SCRIPT_GAME),
Hotkey(0, "reload", WID_SCRD_RELOAD_TOGGLE),
Hotkey('B', "break_toggle", WID_SCRD_BREAK_STR_ON_OFF_BTN),
Hotkey('F', "break_string", WID_SCRD_BREAK_STR_EDIT_BOX),
Hotkey('C', "match_case", WID_SCRD_MATCH_CASE_BTN),
Hotkey(WKC_RETURN, "continue", WID_SCRD_CONTINUE_BTN),
}, ScriptDebugGlobalHotkeys};
};
/** Make a number of rows with buttons for each company for the Script debug window. */
std::unique_ptr<NWidgetBase> MakeCompanyButtonRowsScriptDebug()
{
return MakeCompanyButtonRows(WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END, COLOUR_GREY, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP);
return MakeCompanyButtonRows(WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END, COLOUR_GREY, 5, STR_AI_DEBUG_SELECT_AI_TOOLTIP, false);
}
/** Widgets for the Script debug window. */
static const NWidgetPart _nested_script_debug_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_GREY),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
NWidget(WWT_STICKYBOX, COLOUR_GREY),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY, WID_SCRD_VIEW),
NWidgetFunction(MakeCompanyButtonRowsScriptDebug), SetPadding(0, 2, 1, 2),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_SCRIPT_GAME), SetMinimalSize(100, 20), SetResize(1, 0), SetDataTip(STR_AI_GAME_SCRIPT, STR_AI_GAME_SCRIPT_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_NAME_TEXT), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING2, STR_AI_DEBUG_NAME_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_SETTINGS), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_SCRIPT_GAME), SetMinimalSize(100, 20), SetDataTip(STR_AI_GAME_SCRIPT, STR_AI_GAME_SCRIPT_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_NAME_TEXT), SetResize(1, 0), SetDataTip(STR_JUST_STRING2, STR_AI_DEBUG_NAME_TOOLTIP),
NWidget(NWID_VERTICAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_SETTINGS), SetMinimalSize(100, 20), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
/* Log panel */
NWidget(WWT_PANEL, COLOUR_GREY, WID_SCRD_LOG_PANEL), SetMinimalSize(287, 180), SetResize(1, 1), SetScrollbar(WID_SCRD_VSCROLLBAR),
/* Break string widgets */
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCRD_BREAK_STRING_WIDGETS),
NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_SCRD_BREAK_STR_ON_OFF_BTN), SetFill(0, 1), SetDataTip(SPR_FLAG_VEH_STOPPED, STR_AI_DEBUG_BREAK_STR_ON_OFF_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_LABEL, COLOUR_GREY), SetPadding(2, 2, 2, 4), SetDataTip(STR_AI_DEBUG_BREAK_ON_LABEL, 0x0),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SCRD_BREAK_STR_EDIT_BOX), SetFill(1, 1), SetResize(1, 0), SetPadding(2, 2, 2, 2), SetDataTip(STR_AI_DEBUG_BREAK_STR_OSKTITLE, STR_AI_DEBUG_BREAK_STR_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_MATCH_CASE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_MATCH_CASE, STR_AI_DEBUG_MATCH_CASE_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_CONTINUE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_CONTINUE, STR_AI_DEBUG_CONTINUE_TOOLTIP),
NWidget(NWID_HSCROLLBAR, COLOUR_GREY, WID_SCRD_HSCROLLBAR),
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SCRD_VSCROLLBAR),
@@ -3308,70 +3308,71 @@ std::unique_ptr<NWidgetBase> MakeWindowN
root->Add(std::move(nwid));
if (nwid_begin == nwid_end) return root; // There is no body at all.
if (hor_cont != nullptr && hor_cont->GetWidgetOfType(WWT_CAPTION) != nullptr && hor_cont->GetWidgetOfType(WWT_SHADEBOX) != nullptr) {
/* If the first widget has a title bar and a shade box, silently add a shade selection widget in the tree. */
auto shade_stack = std::make_unique<NWidgetStacked>(-1);
*shade_select = shade_stack.get();
/* Load the remaining parts into the shade stack. */
shade_stack->Add(MakeNWidgets(nwid_begin, nwid_end, std::make_unique<NWidgetVertical>()));
root->Add(std::move(shade_stack));
return root;
/* Load the remaining parts into 'root'. */
return MakeNWidgets(nwid_begin, nwid_end, std::move(root));
/**
* Make a number of rows with button-like graphics, for enabling/disabling each company.
* @param widget_first The first widget index to use.
* @param widget_last The last widget index to use.
* @param colour The colour in which to draw the button.
* @param max_length Maximal number of company buttons in one row.
* @param button_tooltip The tooltip-string of every button.
* @param resizable Whether the rows are resizable.
* @return Panel with rows of company buttons.
*/
std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip)
std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable)
assert(max_length >= 1);
std::unique_ptr<NWidgetVertical> vert = nullptr; // Storage for all rows.
std::unique_ptr<NWidgetHorizontal> hor = nullptr; // Storage for buttons in one row.
int hor_length = 0;
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON, nullptr, ZOOM_LVL_OUT_4X);
sprite_size.width += WidgetDimensions::unscaled.matrix.Horizontal();
sprite_size.height += WidgetDimensions::unscaled.matrix.Vertical() + 1; // 1 for the 'offset' of being pressed
for (WidgetID widnum = widget_first; widnum <= widget_last; widnum++) {
/* Ensure there is room in 'hor' for another button. */
if (hor_length == max_length) {
if (vert == nullptr) vert = std::make_unique<NWidgetVertical>();
vert->Add(std::move(hor));
hor = nullptr;
hor_length = 0;
if (hor == nullptr) {
hor = std::make_unique<NWidgetHorizontal>();
auto panel = std::make_unique<NWidgetBackground>(WWT_PANEL, button_colour, widnum);
panel->SetMinimalSize(sprite_size.width, sprite_size.height);
panel->SetFill(1, 1);
panel->SetResize(1, 0);
if (resizable) panel->SetResize(1, 0);
panel->SetDataTip(0x0, button_tooltip);
hor->Add(std::move(panel));
hor_length++;
if (vert == nullptr) return hor; // All buttons fit in a single row.
if (hor_length > 0 && hor_length < max_length) {
/* Last row is partial, add a spacer at the end to force all buttons to the left. */
auto spc = std::make_unique<NWidgetSpacer>(sprite_size.width, sprite_size.height);
spc->SetFill(1, 1);
spc->SetResize(1, 0);
if (resizable) spc->SetResize(1, 0);
hor->Add(std::move(spc));
if (hor != nullptr) vert->Add(std::move(hor));
return vert;
@@ -1335,29 +1335,29 @@ inline NWidgetPart NWidget(WidgetType tp
part.u.cont_flags = cont_flags;
return part;
* Obtain a nested widget (sub)tree from an external source.
* @param func_ptr Pointer to function that returns the tree.
* @ingroup NestedWidgetParts
inline NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
NWidgetPart part;
part.type = WPT_FUNCTION;
part.u.func_ptr = func_ptr;
bool IsContainerWidgetType(WidgetType tp);
std::unique_ptr<NWidgetBase> MakeNWidgets(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr<NWidgetBase> &&container);
std::unique_ptr<NWidgetBase> MakeWindowNWidgetTree(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, NWidgetStacked **shade_select);
std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip);
std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable = true);
void SetupWidgetDimensions();
#endif /* WIDGET_TYPE_H */
Status change: