mirror of https://github.com/OpenTTD/OpenTTD
(svn r25623) -Fix [FS#5611] (r25296): Progress column width in goal window was not updated when a string changed while the window is open
parent
7a805b621e
commit
4f6d19465b
115
src/goal_gui.cpp
115
src/goal_gui.cpp
|
@ -27,6 +27,12 @@
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
/** Goal list columns. */
|
||||||
|
enum GoalColumn {
|
||||||
|
GC_GOAL = 0, ///< Goal text column.
|
||||||
|
GC_PROGRESS, ///< Goal progress column.
|
||||||
|
};
|
||||||
|
|
||||||
/** Window for displaying goals. */
|
/** Window for displaying goals. */
|
||||||
struct GoalListWindow : public Window {
|
struct GoalListWindow : public Window {
|
||||||
Scrollbar *vscroll; ///< Reference to the scrollbar widget.
|
Scrollbar *vscroll; ///< Reference to the scrollbar widget.
|
||||||
|
@ -53,9 +59,9 @@ struct GoalListWindow : public Window {
|
||||||
|
|
||||||
/* virtual */ void OnClick(Point pt, int widget, int click_count)
|
/* virtual */ void OnClick(Point pt, int widget, int click_count)
|
||||||
{
|
{
|
||||||
if (widget != WID_GOAL_GOAL && widget != WID_GOAL_PROGRESS) return;
|
if (widget != WID_GOAL_LIST) return;
|
||||||
|
|
||||||
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_GOAL, WD_FRAMERECT_TOP);
|
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
|
||||||
int num = 0;
|
int num = 0;
|
||||||
const Goal *s;
|
const Goal *s;
|
||||||
FOR_ALL_GOALS(s) {
|
FOR_ALL_GOALS(s) {
|
||||||
|
@ -153,25 +159,9 @@ struct GoalListWindow : public Window {
|
||||||
|
|
||||||
/* virtual */ void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
/* virtual */ void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
||||||
{
|
{
|
||||||
if (widget != WID_GOAL_GOAL && widget != WID_GOAL_PROGRESS) return;
|
if (widget != WID_GOAL_LIST) return;
|
||||||
Dimension d = maxdim(GetStringBoundingBox(STR_GOALS_GLOBAL_TITLE), GetStringBoundingBox(STR_GOALS_COMPANY_TITLE));
|
Dimension d = maxdim(GetStringBoundingBox(STR_GOALS_GLOBAL_TITLE), GetStringBoundingBox(STR_GOALS_COMPANY_TITLE));
|
||||||
|
|
||||||
if (widget == WID_GOAL_PROGRESS) {
|
|
||||||
/* Get max progress width. */
|
|
||||||
d.width = 0;
|
|
||||||
Goal *s;
|
|
||||||
FOR_ALL_GOALS(s) {
|
|
||||||
if (s->progress != NULL) {
|
|
||||||
SetDParamStr(0, s->progress);
|
|
||||||
Dimension goal_d = GetStringBoundingBox(STR_GOALS_PROGRESS);
|
|
||||||
|
|
||||||
if (goal_d.width > d.width) {
|
|
||||||
d.width = goal_d.width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resize->height = d.height;
|
resize->height = d.height;
|
||||||
|
|
||||||
d.height *= 5;
|
d.height *= 5;
|
||||||
|
@ -189,29 +179,36 @@ struct GoalListWindow : public Window {
|
||||||
* @param y Vertical position of the top edge of the window.
|
* @param y Vertical position of the top edge of the window.
|
||||||
* @param right Right edge of the text line to draw.
|
* @param right Right edge of the text line to draw.
|
||||||
* @param global_section Whether the global goals are printed.
|
* @param global_section Whether the global goals are printed.
|
||||||
|
* @param column Which column to draw.
|
||||||
*/
|
*/
|
||||||
void DrawPartialGoalList(int widget, int &pos, const int cap, int x, int y, int right, bool global_section) const
|
void DrawPartialGoalList(int &pos, const int cap, int x, int y, int right, uint progress_col_width, bool global_section, GoalColumn column) const
|
||||||
{
|
{
|
||||||
if (widget == WID_GOAL_GOAL && IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, global_section ? STR_GOALS_GLOBAL_TITLE : STR_GOALS_COMPANY_TITLE);
|
if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, global_section ? STR_GOALS_GLOBAL_TITLE : STR_GOALS_COMPANY_TITLE);
|
||||||
pos++;
|
pos++;
|
||||||
|
|
||||||
|
bool rtl = _current_text_dir == TD_RTL;
|
||||||
|
|
||||||
uint num = 0;
|
uint num = 0;
|
||||||
const Goal *s;
|
const Goal *s;
|
||||||
FOR_ALL_GOALS(s) {
|
FOR_ALL_GOALS(s) {
|
||||||
if (global_section ? s->company == INVALID_COMPANY : s->company == this->window_number && s->company != INVALID_COMPANY) {
|
if (global_section ? s->company == INVALID_COMPANY : (s->company == this->window_number && s->company != INVALID_COMPANY)) {
|
||||||
if (IsInsideMM(pos, 0, cap)) {
|
if (IsInsideMM(pos, 0, cap)) {
|
||||||
switch (widget) {
|
switch (column) {
|
||||||
case WID_GOAL_GOAL:
|
case GC_GOAL: {
|
||||||
/* Display the goal. */
|
/* Display the goal. */
|
||||||
SetDParamStr(0, s->text);
|
SetDParamStr(0, s->text);
|
||||||
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
|
uint width_reduction = progress_col_width > 0 ? progress_col_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT : 0;
|
||||||
|
DrawString(x + (rtl ? width_reduction : 0), right - (rtl ? 0 : width_reduction), y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WID_GOAL_PROGRESS:
|
case GC_PROGRESS:
|
||||||
if (s->progress != NULL) {
|
if (s->progress != NULL) {
|
||||||
SetDParamStr(0, s->progress);
|
SetDParamStr(0, s->progress);
|
||||||
StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
|
StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
|
||||||
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
|
int progress_x = x;
|
||||||
|
int progress_right = rtl ? x + progress_col_width : right;
|
||||||
|
DrawString(progress_x, progress_right, y + pos * FONT_HEIGHT_NORMAL, str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -221,7 +218,7 @@ struct GoalListWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget == WID_GOAL_GOAL && num == 0) {
|
if (column == GC_GOAL && num == 0) {
|
||||||
if (IsInsideMM(pos, 0, cap)) {
|
if (IsInsideMM(pos, 0, cap)) {
|
||||||
StringID str = !global_section && this->window_number == INVALID_COMPANY ? STR_GOALS_SPECTATOR_NONE : STR_GOALS_NONE;
|
StringID str = !global_section && this->window_number == INVALID_COMPANY ? STR_GOALS_SPECTATOR_NONE : STR_GOALS_NONE;
|
||||||
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, str);
|
DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, str);
|
||||||
|
@ -230,28 +227,60 @@ struct GoalListWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ void DrawWidget(const Rect &r, int widget) const
|
/**
|
||||||
|
* Draws a given column of the goal list.
|
||||||
|
* @param column Which column to draw.
|
||||||
|
* @wid Pointer to the goal list widget.
|
||||||
|
* @progress_col_width Width of the progress column.
|
||||||
|
* @return max width of drawn text
|
||||||
|
*/
|
||||||
|
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
|
||||||
{
|
{
|
||||||
if (widget != WID_GOAL_GOAL && widget != WID_GOAL_PROGRESS) return;
|
/* Get column draw area. */
|
||||||
|
bool rtl = _current_text_dir == TD_RTL;
|
||||||
int right = r.right - WD_FRAMERECT_RIGHT;
|
int y = wid->pos_y + WD_FRAMERECT_TOP;
|
||||||
int y = r.top + WD_FRAMERECT_TOP;
|
int x = wid->pos_x + WD_FRAMERECT_LEFT;
|
||||||
int x = r.left + WD_FRAMERECT_LEFT;
|
int right = x + wid->current_x - WD_FRAMERECT_RIGHT;
|
||||||
|
|
||||||
int pos = -this->vscroll->GetPosition();
|
int pos = -this->vscroll->GetPosition();
|
||||||
const int cap = this->vscroll->GetCapacity();
|
const int cap = this->vscroll->GetCapacity();
|
||||||
|
|
||||||
/* Draw partial list with global goals. */
|
/* Draw partial list with global goals. */
|
||||||
DrawPartialGoalList(widget, pos, cap, x, y, right, true);
|
DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, true, column);
|
||||||
|
|
||||||
/* Draw partial list with company goals. */
|
/* Draw partial list with company goals. */
|
||||||
pos++;
|
pos++;
|
||||||
DrawPartialGoalList(widget, pos, cap, x, y, right, false);
|
DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, false, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* virtual */ void OnPaint()
|
||||||
|
{
|
||||||
|
this->DrawWidgets();
|
||||||
|
|
||||||
|
/* Calculate progress column width. */
|
||||||
|
uint max_width = 0;
|
||||||
|
Goal *s;
|
||||||
|
FOR_ALL_GOALS(s) {
|
||||||
|
if (s->progress != NULL) {
|
||||||
|
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);
|
||||||
|
uint progress_col_width = min(max_width, wid->current_x);
|
||||||
|
|
||||||
|
/* Draw goal list. */
|
||||||
|
this->DrawListColumn(GC_PROGRESS, wid, progress_col_width);
|
||||||
|
this->DrawListColumn(GC_GOAL, wid, progress_col_width);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ void OnResize()
|
/* virtual */ void OnResize()
|
||||||
{
|
{
|
||||||
this->vscroll->SetCapacityFromWidget(this, WID_GOAL_GOAL);
|
this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -263,6 +292,7 @@ struct GoalListWindow : public Window {
|
||||||
{
|
{
|
||||||
if (!gui_scope) return;
|
if (!gui_scope) return;
|
||||||
this->vscroll->SetCount(this->CountLines());
|
this->vscroll->SetCount(this->CountLines());
|
||||||
|
this->SetWidgetDirty(WID_GOAL_LIST);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -275,14 +305,9 @@ static const NWidgetPart _nested_goals_list_widgets[] = {
|
||||||
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
|
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
|
||||||
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
|
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
NWidget(NWID_HORIZONTAL), SetFill(1, 1),
|
NWidget(NWID_HORIZONTAL),
|
||||||
NWidget(WWT_PANEL, COLOUR_BROWN), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetResize(1, 1), SetFill(1, 0), SetScrollbar(WID_GOAL_SCROLLBAR),
|
NWidget(WWT_PANEL, COLOUR_BROWN), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR),
|
||||||
NWidget(NWID_VERTICAL), SetPIP(WD_FRAMERECT_TOP, 4, WD_FRAMETEXT_BOTTOM),
|
NWidget(WWT_EMPTY, COLOUR_GREY, WID_GOAL_LIST), SetResize(1, 1), SetMinimalTextLines(2, 0), SetFill(1, 1), SetPadding(WD_FRAMERECT_TOP, 2, WD_FRAMETEXT_BOTTOM, 2),
|
||||||
NWidget(NWID_HORIZONTAL), SetPIP(2, 4, 2),
|
|
||||||
NWidget(WWT_EMPTY, COLOUR_GREY, WID_GOAL_GOAL), SetResize(1, 1), SetMinimalTextLines(2, 0), SetFill(1, 0),
|
|
||||||
NWidget(WWT_EMPTY, COLOUR_GREY, WID_GOAL_PROGRESS), SetResize(0, 1), SetMinimalTextLines(2, 0), SetFill(0, 1),
|
|
||||||
EndContainer(),
|
|
||||||
EndContainer(),
|
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
NWidget(NWID_VERTICAL),
|
NWidget(NWID_VERTICAL),
|
||||||
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GOAL_SCROLLBAR),
|
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GOAL_SCROLLBAR),
|
||||||
|
|
|
@ -496,8 +496,7 @@ void SQGSWindow_Register(Squirrel *engine)
|
||||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GP_PROGRESS_TEXT, "WID_GP_PROGRESS_TEXT");
|
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GP_PROGRESS_TEXT, "WID_GP_PROGRESS_TEXT");
|
||||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GP_ABORT, "WID_GP_ABORT");
|
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GP_ABORT, "WID_GP_ABORT");
|
||||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GOAL_CAPTION, "WID_GOAL_CAPTION");
|
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GOAL_CAPTION, "WID_GOAL_CAPTION");
|
||||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GOAL_GOAL, "WID_GOAL_GOAL");
|
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GOAL_LIST, "WID_GOAL_LIST");
|
||||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GOAL_PROGRESS, "WID_GOAL_PROGRESS");
|
|
||||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GOAL_SCROLLBAR, "WID_GOAL_SCROLLBAR");
|
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GOAL_SCROLLBAR, "WID_GOAL_SCROLLBAR");
|
||||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GQ_CAPTION, "WID_GQ_CAPTION");
|
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GQ_CAPTION, "WID_GQ_CAPTION");
|
||||||
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GQ_QUESTION, "WID_GQ_QUESTION");
|
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GQ_QUESTION, "WID_GQ_QUESTION");
|
||||||
|
|
|
@ -1340,8 +1340,7 @@ public:
|
||||||
/** Widgets of the #GoalListWindow class. */
|
/** Widgets of the #GoalListWindow class. */
|
||||||
enum GoalListWidgets {
|
enum GoalListWidgets {
|
||||||
WID_GOAL_CAPTION = ::WID_GOAL_CAPTION, ///< Caption of the window.
|
WID_GOAL_CAPTION = ::WID_GOAL_CAPTION, ///< Caption of the window.
|
||||||
WID_GOAL_GOAL = ::WID_GOAL_GOAL, ///< Goal text column of the goal list.
|
WID_GOAL_LIST = ::WID_GOAL_LIST, ///< Goal list.
|
||||||
WID_GOAL_PROGRESS = ::WID_GOAL_PROGRESS, ///< Goal progress column of the goal list.
|
|
||||||
WID_GOAL_SCROLLBAR = ::WID_GOAL_SCROLLBAR, ///< Scrollbar of the goal list.
|
WID_GOAL_SCROLLBAR = ::WID_GOAL_SCROLLBAR, ///< Scrollbar of the goal list.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
/** Widgets of the #GoalListWindow class. */
|
/** Widgets of the #GoalListWindow class. */
|
||||||
enum GoalListWidgets {
|
enum GoalListWidgets {
|
||||||
WID_GOAL_CAPTION, ///< Caption of the window.
|
WID_GOAL_CAPTION, ///< Caption of the window.
|
||||||
WID_GOAL_GOAL, ///< Goal text column of the goal list.
|
WID_GOAL_LIST, ///< Goal list.
|
||||||
WID_GOAL_PROGRESS, ///< Goal progress column of the goal list.
|
|
||||||
WID_GOAL_SCROLLBAR, ///< Scrollbar of the goal list.
|
WID_GOAL_SCROLLBAR, ///< Scrollbar of the goal list.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue