2011-12-19 21:03:17 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file goal_gui.cpp GUI for goals. */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "industry.h"
|
|
|
|
#include "town.h"
|
|
|
|
#include "window_gui.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "date_func.h"
|
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "goal_base.h"
|
|
|
|
#include "core/geometry_func.hpp"
|
2011-12-23 23:34:19 +00:00
|
|
|
#include "company_func.h"
|
2013-06-09 13:23:03 +00:00
|
|
|
#include "company_base.h"
|
2020-03-22 14:05:10 +00:00
|
|
|
#include "company_gui.h"
|
2013-11-16 17:41:57 +00:00
|
|
|
#include "story_base.h"
|
2012-01-03 16:36:24 +00:00
|
|
|
#include "command_func.h"
|
2014-04-25 15:40:32 +00:00
|
|
|
#include "string_func.h"
|
2011-12-19 21:03:17 +00:00
|
|
|
|
|
|
|
#include "widgets/goal_widget.h"
|
|
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2013-07-21 15:59:07 +00:00
|
|
|
/** Goal list columns. */
|
|
|
|
enum GoalColumn {
|
|
|
|
GC_GOAL = 0, ///< Goal text column.
|
|
|
|
GC_PROGRESS, ///< Goal progress column.
|
|
|
|
};
|
|
|
|
|
2013-07-21 15:52:52 +00:00
|
|
|
/** Window for displaying goals. */
|
|
|
|
struct GoalListWindow : public Window {
|
|
|
|
Scrollbar *vscroll; ///< Reference to the scrollbar widget.
|
2011-12-19 21:03:17 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
GoalListWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
|
2011-12-19 21:03:17 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->CreateNestedTree();
|
2013-06-09 13:17:20 +00:00
|
|
|
this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
|
2013-05-26 19:23:42 +00:00
|
|
|
this->FinishInitNested(window_number);
|
2013-09-12 14:35:52 +00:00
|
|
|
this->owner = (Owner)this->window_number;
|
2021-02-20 23:32:45 +00:00
|
|
|
NWidgetStacked *wi = this->GetWidget<NWidgetStacked>(WID_GOAL_SELECT_BUTTONS);
|
|
|
|
wi->SetDisplayedPlane(window_number == INVALID_COMPANY ? 1 : 0);
|
2011-12-19 21:03:17 +00:00
|
|
|
this->OnInvalidateData(0);
|
|
|
|
}
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
void SetStringParameters(int widget) const override
|
2013-06-09 13:23:03 +00:00
|
|
|
{
|
|
|
|
if (widget != WID_GOAL_CAPTION) return;
|
|
|
|
|
|
|
|
if (this->window_number == INVALID_COMPANY) {
|
|
|
|
SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
|
|
|
|
} else {
|
|
|
|
SetDParam(0, STR_GOALS_CAPTION);
|
|
|
|
SetDParam(1, this->window_number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
void OnClick(Point pt, int widget, int click_count) override
|
2011-12-19 21:03:17 +00:00
|
|
|
{
|
2021-02-20 23:32:45 +00:00
|
|
|
switch (widget) {
|
|
|
|
case WID_GOAL_GLOBAL_BUTTON:
|
|
|
|
ShowGoalsList(INVALID_COMPANY);
|
|
|
|
break;
|
2011-12-19 21:03:17 +00:00
|
|
|
|
2021-02-20 23:32:45 +00:00
|
|
|
case WID_GOAL_COMPANY_BUTTON:
|
|
|
|
ShowGoalsList(_local_company);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_GOAL_LIST: {
|
2022-09-23 08:36:22 +00:00
|
|
|
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WidgetDimensions::scaled.framerect.top);
|
2021-02-20 23:32:45 +00:00
|
|
|
for (const Goal *s : Goal::Iterate()) {
|
|
|
|
if (s->company == this->window_number) {
|
|
|
|
if (y == 0) {
|
|
|
|
this->HandleClick(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
y--;
|
|
|
|
}
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
2021-02-20 23:32:45 +00:00
|
|
|
break;
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
2021-02-20 23:32:45 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-21 15:52:52 +00:00
|
|
|
/**
|
|
|
|
* Handle clicking at a goal.
|
2018-10-28 02:17:36 +00:00
|
|
|
* @param s #Goal clicked at.
|
2013-07-21 15:52:52 +00:00
|
|
|
*/
|
2011-12-19 21:03:17 +00:00
|
|
|
void HandleClick(const Goal *s)
|
|
|
|
{
|
2013-07-21 15:52:52 +00:00
|
|
|
/* Determine dst coordinate for goal and try to scroll to it. */
|
2011-12-19 21:03:17 +00:00
|
|
|
TileIndex xy;
|
|
|
|
switch (s->type) {
|
|
|
|
case GT_NONE: return;
|
2020-03-22 14:05:10 +00:00
|
|
|
|
|
|
|
case GT_COMPANY:
|
|
|
|
/* s->dst here is not a tile, but a CompanyID.
|
|
|
|
* Show the window with the overview of the company instead. */
|
|
|
|
ShowCompany((CompanyID)s->dst);
|
|
|
|
return;
|
2011-12-19 21:03:17 +00:00
|
|
|
|
|
|
|
case GT_TILE:
|
|
|
|
if (!IsValidTile(s->dst)) return;
|
|
|
|
xy = s->dst;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GT_INDUSTRY:
|
|
|
|
if (!Industry::IsValidID(s->dst)) return;
|
|
|
|
xy = Industry::Get(s->dst)->location.tile;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GT_TOWN:
|
|
|
|
if (!Town::IsValidID(s->dst)) return;
|
|
|
|
xy = Town::Get(s->dst)->xy;
|
|
|
|
break;
|
|
|
|
|
2013-11-16 17:41:57 +00:00
|
|
|
case GT_STORY_PAGE: {
|
|
|
|
if (!StoryPage::IsValidID(s->dst)) return;
|
|
|
|
|
|
|
|
/* Verify that:
|
|
|
|
* - if global goal: story page must be global.
|
|
|
|
* - if company goal: story page must be global or of the same company.
|
|
|
|
*/
|
|
|
|
CompanyID goal_company = s->company;
|
|
|
|
CompanyID story_company = StoryPage::Get(s->dst)->company;
|
|
|
|
if (goal_company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return;
|
|
|
|
|
|
|
|
ShowStoryBook((CompanyID)this->window_number, s->dst);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:03:17 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_ctrl_pressed) {
|
2020-06-29 01:38:29 +00:00
|
|
|
ShowExtraViewportWindow(xy);
|
2011-12-19 21:03:17 +00:00
|
|
|
} else {
|
|
|
|
ScrollMainWindowToTile(xy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Count the number of lines in this window.
|
2013-07-21 15:52:52 +00:00
|
|
|
* @return the number of lines.
|
2011-12-19 21:03:17 +00:00
|
|
|
*/
|
|
|
|
uint CountLines()
|
|
|
|
{
|
2013-07-21 15:52:52 +00:00
|
|
|
/* Count number of (non) awarded goals. */
|
2021-02-20 22:00:11 +00:00
|
|
|
uint num = 0;
|
2019-12-16 16:53:40 +00:00
|
|
|
for (const Goal *s : Goal::Iterate()) {
|
2021-02-20 22:00:11 +00:00
|
|
|
if (s->company == this->window_number) num++;
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
|
|
|
|
2013-07-21 15:52:52 +00:00
|
|
|
/* Count the 'none' lines. */
|
2021-02-20 22:00:11 +00:00
|
|
|
if (num == 0) num = 1;
|
2011-12-19 21:03:17 +00:00
|
|
|
|
2021-02-20 22:00:11 +00:00
|
|
|
return num;
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
2011-12-19 21:03:17 +00:00
|
|
|
{
|
2013-07-21 15:59:07 +00:00
|
|
|
if (widget != WID_GOAL_LIST) return;
|
2021-02-20 22:00:11 +00:00
|
|
|
Dimension d = GetStringBoundingBox(STR_GOALS_NONE);
|
2011-12-19 21:03:17 +00:00
|
|
|
|
2022-09-23 08:36:22 +00:00
|
|
|
resize->width = 1;
|
2011-12-19 21:03:17 +00:00
|
|
|
resize->height = d.height;
|
|
|
|
|
|
|
|
d.height *= 5;
|
2022-09-23 08:36:22 +00:00
|
|
|
d.width += WidgetDimensions::scaled.framerect.Horizontal();
|
|
|
|
d.height += WidgetDimensions::scaled.framerect.Vertical();
|
2011-12-19 21:03:17 +00:00
|
|
|
*size = maxdim(*size, d);
|
|
|
|
}
|
|
|
|
|
2012-12-20 18:35:13 +00:00
|
|
|
/**
|
2021-02-20 22:00:11 +00:00
|
|
|
* Draws a given column of the goal list.
|
2013-07-21 15:59:07 +00:00
|
|
|
* @param column Which column to draw.
|
2021-02-20 22:00:11 +00:00
|
|
|
* @param wid Pointer to the goal list widget.
|
|
|
|
* @param progress_col_width Width of the progress column.
|
|
|
|
* @return max width of drawn text
|
2012-12-20 18:35:13 +00:00
|
|
|
*/
|
2021-02-20 22:00:11 +00:00
|
|
|
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
|
2011-12-19 21:03:17 +00:00
|
|
|
{
|
2021-02-20 22:00:11 +00:00
|
|
|
/* Get column draw area. */
|
2022-09-23 08:36:22 +00:00
|
|
|
Rect r = wid->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
|
2013-07-21 15:59:07 +00:00
|
|
|
bool rtl = _current_text_dir == TD_RTL;
|
|
|
|
|
2021-02-20 22:00:11 +00:00
|
|
|
int pos = -this->vscroll->GetPosition();
|
|
|
|
const int cap = this->vscroll->GetCapacity();
|
|
|
|
|
2011-12-19 21:03:17 +00:00
|
|
|
uint num = 0;
|
2019-12-16 16:53:40 +00:00
|
|
|
for (const Goal *s : Goal::Iterate()) {
|
2021-02-20 22:00:11 +00:00
|
|
|
if (s->company == this->window_number) {
|
2011-12-19 21:03:17 +00:00
|
|
|
if (IsInsideMM(pos, 0, cap)) {
|
2013-07-21 15:59:07 +00:00
|
|
|
switch (column) {
|
|
|
|
case GC_GOAL: {
|
2013-05-26 19:54:43 +00:00
|
|
|
/* Display the goal. */
|
|
|
|
SetDParamStr(0, s->text);
|
2022-09-23 08:36:22 +00:00
|
|
|
uint width_reduction = progress_col_width > 0 ? progress_col_width + WidgetDimensions::scaled.framerect.Horizontal() : 0;
|
2022-10-15 15:55:47 +00:00
|
|
|
DrawString(r.Indent(width_reduction, !rtl), STR_GOALS_TEXT);
|
2013-05-26 19:54:43 +00:00
|
|
|
break;
|
2013-07-21 15:59:07 +00:00
|
|
|
}
|
2013-05-26 19:54:43 +00:00
|
|
|
|
2013-07-21 15:59:07 +00:00
|
|
|
case GC_PROGRESS:
|
2023-04-27 17:03:03 +00:00
|
|
|
if (!s->progress.empty()) {
|
2013-05-26 19:54:43 +00:00
|
|
|
SetDParamStr(0, s->progress);
|
2013-07-21 15:52:52 +00:00
|
|
|
StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
|
2022-10-15 15:55:47 +00:00
|
|
|
DrawString(r.WithWidth(progress_col_width, !rtl), str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
|
2013-05-26 19:54:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-10-15 15:55:47 +00:00
|
|
|
r.top += FONT_HEIGHT_NORMAL;
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 10:41:57 +00:00
|
|
|
if (num == 0) {
|
|
|
|
if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
|
2022-10-15 15:55:47 +00:00
|
|
|
DrawString(r, STR_GOALS_NONE);
|
2013-07-21 15:52:52 +00:00
|
|
|
}
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
2012-12-20 18:35:13 +00:00
|
|
|
}
|
2011-12-19 21:03:17 +00:00
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
void OnPaint() override
|
2013-07-21 15:59:07 +00:00
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
|
|
|
|
2014-03-23 12:49:22 +00:00
|
|
|
if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
|
|
|
|
|
2013-07-21 15:59:07 +00:00
|
|
|
/* Calculate progress column width. */
|
|
|
|
uint max_width = 0;
|
2019-12-16 16:53:40 +00:00
|
|
|
for (const Goal *s : Goal::Iterate()) {
|
2023-04-27 17:03:03 +00:00
|
|
|
if (!s->progress.empty()) {
|
2013-07-21 15:59:07 +00:00
|
|
|
SetDParamStr(0, s->progress);
|
|
|
|
StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
|
|
|
|
uint str_width = GetStringBoundingBox(str).width;
|
|
|
|
if (str_width > max_width) max_width = str_width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GOAL_LIST);
|
2021-01-08 10:16:18 +00:00
|
|
|
uint progress_col_width = std::min(max_width, wid->current_x);
|
2013-07-21 15:59:07 +00:00
|
|
|
|
|
|
|
/* Draw goal list. */
|
|
|
|
this->DrawListColumn(GC_PROGRESS, wid, progress_col_width);
|
|
|
|
this->DrawListColumn(GC_GOAL, wid, progress_col_width);
|
|
|
|
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
void OnResize() override
|
2011-12-19 21:03:17 +00:00
|
|
|
{
|
2022-09-23 08:36:22 +00:00
|
|
|
this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST, WidgetDimensions::scaled.framerect.Vertical());
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @param data Information about the changed data.
|
|
|
|
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
|
|
|
*/
|
2019-03-03 22:25:13 +00:00
|
|
|
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
2011-12-19 21:03:17 +00:00
|
|
|
{
|
|
|
|
if (!gui_scope) return;
|
|
|
|
this->vscroll->SetCount(this->CountLines());
|
2021-02-20 23:32:45 +00:00
|
|
|
this->SetWidgetDisabledState(WID_GOAL_COMPANY_BUTTON, _local_company == COMPANY_SPECTATOR);
|
|
|
|
this->SetWidgetDirty(WID_GOAL_COMPANY_BUTTON);
|
2013-07-21 15:59:07 +00:00
|
|
|
this->SetWidgetDirty(WID_GOAL_LIST);
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-21 15:52:52 +00:00
|
|
|
/** Widgets of the #GoalListWindow. */
|
2011-12-19 21:03:17 +00:00
|
|
|
static const NWidgetPart _nested_goals_list_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
|
2023-06-13 18:00:26 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION), SetDataTip(STR_JUST_STRING1, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2021-02-20 23:32:45 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GOAL_SELECT_BUTTONS),
|
2022-09-23 08:36:22 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_GLOBAL_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WidgetDimensions::unscaled.captiontext.Vertical()), SetDataTip(STR_GOALS_GLOBAL_BUTTON, STR_GOALS_GLOBAL_BUTTON_HELPTEXT),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_COMPANY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WidgetDimensions::unscaled.captiontext.Vertical()), SetDataTip(STR_GOALS_COMPANY_BUTTON, STR_GOALS_COMPANY_BUTTON_HELPTEXT),
|
2021-02-20 23:32:45 +00:00
|
|
|
EndContainer(),
|
2011-12-19 21:03:17 +00:00
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
|
2013-05-26 19:30:07 +00:00
|
|
|
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
|
2011-12-19 21:03:17 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
|
|
|
|
EndContainer(),
|
2013-07-21 15:59:07 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2022-10-15 15:55:47 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_BROWN, WID_GOAL_LIST), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR), SetResize(1, 1), SetMinimalTextLines(2, 0),
|
2013-05-26 19:54:43 +00:00
|
|
|
EndContainer(),
|
2011-12-19 21:03:17 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
2013-06-09 13:17:20 +00:00
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GOAL_SCROLLBAR),
|
2011-12-19 21:03:17 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _goals_list_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_AUTO, "list_goals", 500, 127,
|
2011-12-19 21:03:17 +00:00
|
|
|
WC_GOALS_LIST, WC_NONE,
|
|
|
|
0,
|
|
|
|
_nested_goals_list_widgets, lengthof(_nested_goals_list_widgets)
|
|
|
|
);
|
|
|
|
|
2013-07-21 15:52:52 +00:00
|
|
|
/**
|
|
|
|
* Open a goal list window.
|
|
|
|
* @param company %Company to display the goals for, use #INVALID_COMPANY to display global goals.
|
|
|
|
*/
|
2013-06-09 13:23:03 +00:00
|
|
|
void ShowGoalsList(CompanyID company)
|
2011-12-19 21:03:17 +00:00
|
|
|
{
|
2013-06-09 13:23:03 +00:00
|
|
|
if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
|
|
|
|
|
|
|
|
AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, company);
|
2011-12-19 21:03:17 +00:00
|
|
|
}
|
2012-01-03 16:36:24 +00:00
|
|
|
|
2013-07-21 15:52:52 +00:00
|
|
|
/** Ask a question about a goal. */
|
|
|
|
struct GoalQuestionWindow : public Window {
|
2023-04-27 17:03:03 +00:00
|
|
|
std::string question; ///< Question to ask (private copy).
|
|
|
|
int buttons; ///< Number of valid buttons in #button.
|
|
|
|
int button[3]; ///< Buttons to display.
|
|
|
|
TextColour colour; ///< Colour of the question text.
|
2012-01-03 16:36:24 +00:00
|
|
|
|
2023-04-27 17:03:03 +00:00
|
|
|
GoalQuestionWindow(WindowDesc *desc, WindowNumber window_number, TextColour colour, uint32 button_mask, const std::string &question) : Window(desc), colour(colour)
|
2012-01-03 16:36:24 +00:00
|
|
|
{
|
2023-04-27 17:03:03 +00:00
|
|
|
this->question = question;
|
2012-01-03 16:36:24 +00:00
|
|
|
|
2013-07-21 15:52:52 +00:00
|
|
|
/* Figure out which buttons we have to enable. */
|
2012-01-03 16:36:24 +00:00
|
|
|
int n = 0;
|
2021-06-13 02:18:21 +00:00
|
|
|
for (uint bit : SetBitIterator(button_mask)) {
|
2012-01-03 16:36:24 +00:00
|
|
|
if (bit >= GOAL_QUESTION_BUTTON_COUNT) break;
|
|
|
|
this->button[n++] = bit;
|
|
|
|
if (n == 3) break;
|
|
|
|
}
|
|
|
|
this->buttons = n;
|
2021-02-02 16:14:26 +00:00
|
|
|
assert(this->buttons < 4);
|
2012-01-03 16:36:24 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
this->CreateNestedTree();
|
2021-02-02 16:14:26 +00:00
|
|
|
if (this->buttons == 0) {
|
|
|
|
this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(SZSP_HORIZONTAL);
|
|
|
|
this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(SZSP_HORIZONTAL);
|
|
|
|
} else {
|
|
|
|
this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
|
|
|
|
this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(0);
|
|
|
|
}
|
2013-05-26 19:23:42 +00:00
|
|
|
this->FinishInitNested(window_number);
|
2012-01-03 16:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
void SetStringParameters(int widget) const override
|
2012-01-03 16:36:24 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case WID_GQ_BUTTON_1:
|
|
|
|
SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_GQ_BUTTON_2:
|
|
|
|
SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_GQ_BUTTON_3:
|
|
|
|
SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
void OnClick(Point pt, int widget, int click_count) override
|
2012-01-03 16:36:24 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case WID_GQ_BUTTON_1:
|
|
|
|
DoCommandP(0, this->window_number, this->button[0], CMD_GOAL_QUESTION_ANSWER);
|
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_GQ_BUTTON_2:
|
|
|
|
DoCommandP(0, this->window_number, this->button[1], CMD_GOAL_QUESTION_ANSWER);
|
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_GQ_BUTTON_3:
|
|
|
|
DoCommandP(0, this->window_number, this->button[2], CMD_GOAL_QUESTION_ANSWER);
|
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
2012-01-03 16:36:24 +00:00
|
|
|
{
|
|
|
|
if (widget != WID_GQ_QUESTION) return;
|
|
|
|
|
|
|
|
SetDParamStr(0, this->question);
|
2022-09-23 08:36:22 +00:00
|
|
|
size->height = GetStringHeight(STR_JUST_RAW_STRING, size->width) + WidgetDimensions::scaled.vsep_wide;
|
2012-01-03 16:36:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
void DrawWidget(const Rect &r, int widget) const override
|
2012-01-03 16:36:24 +00:00
|
|
|
{
|
|
|
|
if (widget != WID_GQ_QUESTION) return;
|
|
|
|
|
|
|
|
SetDParamStr(0, this->question);
|
2022-10-15 15:55:47 +00:00
|
|
|
DrawStringMultiLine(r, STR_JUST_RAW_STRING, this->colour, SA_TOP | SA_HOR_CENTER);
|
2012-01-03 16:36:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-21 15:52:52 +00:00
|
|
|
/** Widgets of the goal question window. */
|
2020-12-23 18:26:56 +00:00
|
|
|
static const NWidgetPart _nested_goal_question_widgets_question[] = {
|
2012-01-03 16:36:24 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
|
2020-12-23 18:26:56 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_QUESTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2012-01-03 16:36:24 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
|
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2012-01-03 16:36:24 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2012-01-03 16:36:24 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2012-01-03 16:36:24 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2021-02-02 16:14:26 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 8),
|
|
|
|
EndContainer(),
|
2012-01-03 16:36:24 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2020-12-23 18:26:56 +00:00
|
|
|
static const NWidgetPart _nested_goal_question_widgets_info[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_INFORMATION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
|
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2021-02-02 16:14:26 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 8),
|
|
|
|
EndContainer(),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const NWidgetPart _nested_goal_question_widgets_warning[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_YELLOW),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_YELLOW, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_WARNING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_YELLOW),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
|
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2021-02-02 16:14:26 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 8),
|
|
|
|
EndContainer(),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const NWidgetPart _nested_goal_question_widgets_error[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_RED),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_RED, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_ERROR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_RED),
|
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
|
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(85, 10, 85),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(65, 10, 65),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(25, 10, 25),
|
2023-04-25 09:03:48 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2021-02-02 16:14:26 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 8),
|
|
|
|
EndContainer(),
|
2020-12-23 18:26:56 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static WindowDesc _goal_question_list_desc[] = {
|
|
|
|
{
|
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
|
|
|
WC_GOAL_QUESTION, WC_NONE,
|
|
|
|
WDF_CONSTRUCTION,
|
|
|
|
_nested_goal_question_widgets_question, lengthof(_nested_goal_question_widgets_question),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
|
|
|
WC_GOAL_QUESTION, WC_NONE,
|
|
|
|
WDF_CONSTRUCTION,
|
|
|
|
_nested_goal_question_widgets_info, lengthof(_nested_goal_question_widgets_info),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
|
|
|
WC_GOAL_QUESTION, WC_NONE,
|
|
|
|
WDF_CONSTRUCTION,
|
|
|
|
_nested_goal_question_widgets_warning, lengthof(_nested_goal_question_widgets_warning),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
|
|
|
WC_GOAL_QUESTION, WC_NONE,
|
|
|
|
WDF_CONSTRUCTION,
|
|
|
|
_nested_goal_question_widgets_error, lengthof(_nested_goal_question_widgets_error),
|
|
|
|
},
|
|
|
|
};
|
2012-01-03 16:36:24 +00:00
|
|
|
|
2013-07-21 15:52:52 +00:00
|
|
|
/**
|
|
|
|
* Display a goal question.
|
|
|
|
* @param id Window number to use.
|
|
|
|
* @param type Type of question.
|
|
|
|
* @param button_mask Buttons to display.
|
|
|
|
* @param question Question to ask.
|
|
|
|
*/
|
2023-04-27 17:03:03 +00:00
|
|
|
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const std::string &question)
|
2012-01-03 16:36:24 +00:00
|
|
|
{
|
2021-02-02 16:14:26 +00:00
|
|
|
assert(type < GQT_END);
|
2020-12-23 18:26:56 +00:00
|
|
|
new GoalQuestionWindow(&_goal_question_list_desc[type], id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);
|
2012-01-03 16:36:24 +00:00
|
|
|
}
|