summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordP <dp@dpointer.org>2021-02-21 02:32:45 +0300
committerCharles Pigott <charlespigott@googlemail.com>2021-03-08 18:18:47 +0000
commit56911a86ea2fad84383729ece63c837dc012f14d (patch)
treef8c6ca8d939beea64cdae4ef86a321c2e2b75a8d
parent818bee3961d41dc830803792ab3cbe064c8b1f65 (diff)
downloadopenttd-56911a86ea2fad84383729ece63c837dc012f14d.tar.xz
Add: Buttons to open global goals from company goals and vice versa
-rw-r--r--src/company_cmd.cpp1
-rw-r--r--src/goal_gui.cpp38
-rw-r--r--src/lang/english.txt4
-rw-r--r--src/widgets/goal_widget.h9
4 files changed, 41 insertions, 11 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 946ff0d57..ab9e7e12e 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -120,6 +120,7 @@ void SetLocalCompany(CompanyID new_company)
/* ... and redraw the whole screen. */
MarkWholeScreenDirty();
InvalidateWindowClassesData(WC_SIGN_LIST, -1);
+ InvalidateWindowClassesData(WC_GOALS_LIST);
}
/**
diff --git a/src/goal_gui.cpp b/src/goal_gui.cpp
index bf200050b..9fdca309b 100644
--- a/src/goal_gui.cpp
+++ b/src/goal_gui.cpp
@@ -46,6 +46,8 @@ struct GoalListWindow : public Window {
this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
this->FinishInitNested(window_number);
this->owner = (Owner)this->window_number;
+ NWidgetStacked *wi = this->GetWidget<NWidgetStacked>(WID_GOAL_SELECT_BUTTONS);
+ wi->SetDisplayedPlane(window_number == INVALID_COMPANY ? 1 : 0);
this->OnInvalidateData(0);
}
@@ -63,17 +65,31 @@ struct GoalListWindow : public Window {
void OnClick(Point pt, int widget, int click_count) override
{
- if (widget != WID_GOAL_LIST) return;
+ switch (widget) {
+ case WID_GOAL_GLOBAL_BUTTON:
+ ShowGoalsList(INVALID_COMPANY);
+ break;
- int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
- for (const Goal *s : Goal::Iterate()) {
- if (s->company == this->window_number) {
- if (y == 0) {
- this->HandleClick(s);
- return;
+ case WID_GOAL_COMPANY_BUTTON:
+ ShowGoalsList(_local_company);
+ break;
+
+ case WID_GOAL_LIST: {
+ int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
+ for (const Goal *s : Goal::Iterate()) {
+ if (s->company == this->window_number) {
+ if (y == 0) {
+ this->HandleClick(s);
+ return;
+ }
+ y--;
+ }
}
- y--;
+ break;
}
+
+ default:
+ break;
}
}
@@ -260,6 +276,8 @@ struct GoalListWindow : public Window {
{
if (!gui_scope) return;
this->vscroll->SetCount(this->CountLines());
+ this->SetWidgetDisabledState(WID_GOAL_COMPANY_BUTTON, _local_company == COMPANY_SPECTATOR);
+ this->SetWidgetDirty(WID_GOAL_COMPANY_BUTTON);
this->SetWidgetDirty(WID_GOAL_LIST);
}
};
@@ -269,6 +287,10 @@ static const NWidgetPart _nested_goals_list_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
+ NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GOAL_SELECT_BUTTONS),
+ NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_GLOBAL_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GOALS_GLOBAL_BUTTON, STR_GOALS_GLOBAL_BUTTON_HELPTEXT),
+ NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_COMPANY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_GOALS_COMPANY_BUTTON, STR_GOALS_COMPANY_BUTTON_HELPTEXT),
+ EndContainer(),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 29ffa5855..6e803a37c 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -3197,6 +3197,10 @@ STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE :{YELLOW}Bribe t
STR_GOALS_CAPTION :{WHITE}{COMPANY} Goals
STR_GOALS_SPECTATOR_CAPTION :{WHITE}Global Goals
STR_GOALS_SPECTATOR :Global Goals
+STR_GOALS_GLOBAL_BUTTON :{BLACK}Global
+STR_GOALS_GLOBAL_BUTTON_HELPTEXT :{BLACK}Show global goals
+STR_GOALS_COMPANY_BUTTON :{BLACK}Company
+STR_GOALS_COMPANY_BUTTON_HELPTEXT :{BLACK}Show company goals
STR_GOALS_TEXT :{ORANGE}{RAW_STRING}
STR_GOALS_NONE :{ORANGE}- None -
STR_GOALS_PROGRESS :{ORANGE}{RAW_STRING}
diff --git a/src/widgets/goal_widget.h b/src/widgets/goal_widget.h
index ad530210b..27c5cf722 100644
--- a/src/widgets/goal_widget.h
+++ b/src/widgets/goal_widget.h
@@ -13,9 +13,12 @@
/** Widgets of the #GoalListWindow class. */
enum GoalListWidgets {
- WID_GOAL_CAPTION, ///< Caption of the window.
- WID_GOAL_LIST, ///< Goal list.
- WID_GOAL_SCROLLBAR, ///< Scrollbar of the goal list.
+ WID_GOAL_CAPTION, ///< Caption of the window.
+ WID_GOAL_SELECT_BUTTONS, ///< Selection widget for the title bar button.
+ WID_GOAL_GLOBAL_BUTTON, ///< Button to show global goals.
+ WID_GOAL_COMPANY_BUTTON, ///< Button to show company goals.
+ WID_GOAL_LIST, ///< Goal list.
+ WID_GOAL_SCROLLBAR, ///< Scrollbar of the goal list.
};
/** Widgets of the #GoalQuestionWindow class. */