Changeset - r26602:1e2755a41424
[Not reviewed]
master
0 2 0
PeterN - 23 months ago 2022-11-19 21:18:53
peter1138@openttd.org
Fix: Indent production in industry window and resolve button issues. (#10184)

Industry production used to be indented, although a different amount than
the industry accepts list. This is now added back, with the standard indent
width.

Additionally the cheat-mode production modifier buttons now support RTL and
the list height now takes account of the button height.
2 files changed with 45 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/core/geometry_type.hpp
Show inline comments
 
@@ -205,12 +205,23 @@ struct Rect {
 
	[[nodiscard]] inline Rect WithHeight(int height, bool end = false) const
 
	{
 
		return end
 
			? Rect {this->left, this->bottom - height + 1, this->right, this->bottom}
 
			: Rect {this->left, this->top,                 this->right, this->top + height - 1};
 
	}
 

	
 
	/**
 
	 * Test if a point falls inside this Rect.
 
	 * @param pt the point to test.
 
	 * @return true iif the point falls inside the Rect.
 
	 */
 
	inline bool Contains(const Point &pt) const
 
	{
 
		/* This is a local version of IsInsideMM, to avoid including math_func everywhere. */
 
		return (uint)(pt.x - this->left) < (uint)(this->right - this->left) && (uint)(pt.y - this->top) < (uint)(this->bottom - this->top);
 
	}
 
};
 

	
 
/**
 
 * Specification of a rectangle with an absolute top-left coordinate and a
 
 * (relative) width/height
 
 */
src/industry_gui.cpp
Show inline comments
 
@@ -810,12 +810,13 @@ class IndustryViewWindow : public Window
 
	Editability editable;     ///< Mode for changing production
 
	InfoLine editbox_line;    ///< The line clicked to open the edit box
 
	InfoLine clicked_line;    ///< The line of the button that has been clicked
 
	byte clicked_button;      ///< The button that has been clicked (to raise)
 
	int production_offset_y;  ///< The offset of the production texts/buttons
 
	int info_height;          ///< Height needed for the #WID_IV_INFO panel
 
	int cheat_line_height;    ///< Height of each line for the #WID_IV_INFO panel
 

	
 
public:
 
	IndustryViewWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
 
	{
 
		this->flags |= WF_DISABLE_VP_SCROLL;
 
		this->editbox_line = IL_NONE;
 
@@ -827,21 +828,27 @@ public:
 
		NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_IV_VIEWPORT);
 
		nvp->InitializeViewport(this, Industry::Get(window_number)->location.GetCenterTile(), ScaleZoomGUI(ZOOM_LVL_INDUSTRY));
 

	
 
		this->InvalidateData();
 
	}
 

	
 
	void OnInit() override
 
	{
 
		/* This only used when the cheat to alter industry production is enabled */
 
		this->cheat_line_height = std::max(SETTING_BUTTON_HEIGHT + WidgetDimensions::scaled.vsep_normal, FONT_HEIGHT_NORMAL);
 
	}
 

	
 
	void OnPaint() override
 
	{
 
		this->DrawWidgets();
 

	
 
		if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
 

	
 
		const Rect r = this->GetWidget<NWidgetBase>(WID_IV_INFO)->GetCurrentRect();
 
		int expected = this->DrawInfo(r);
 
		if (expected > r.bottom) {
 
		if (expected != r.bottom) {
 
			this->info_height = expected - r.top + 1;
 
			this->ReInit();
 
			return;
 
		}
 
	}
 

	
 
@@ -849,21 +856,22 @@ public:
 
	 * Draw the text in the #WID_IV_INFO panel.
 
	 * @param r Rectangle of the panel.
 
	 * @return Expected position of the bottom edge of the panel.
 
	 */
 
	int DrawInfo(const Rect &r)
 
	{
 
		bool rtl = _current_text_dir == TD_RTL;
 
		Industry *i = Industry::Get(this->window_number);
 
		const IndustrySpec *ind = GetIndustrySpec(i->type);
 
		Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
 
		bool first = true;
 
		bool has_accept = false;
 

	
 
		if (i->prod_level == PRODLEVEL_CLOSURE) {
 
			DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
 
			ir.top += 2 * FONT_HEIGHT_NORMAL;
 
			ir.top += FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.vsep_wide;
 
		}
 

	
 
		CargoSuffix cargo_suffix[lengthof(i->accepts_cargo)];
 
		GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, i->accepts_cargo, cargo_suffix);
 
		bool stockpiling = HasBit(ind->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_mask, CBM_IND_PRODUCTION_256_TICKS);
 

	
 
@@ -895,17 +903,20 @@ public:
 
					str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
 
					break;
 

	
 
				default:
 
					NOT_REACHED();
 
			}
 
			DrawString(ir.Indent(WidgetDimensions::scaled.hsep_indent, _current_text_dir == TD_RTL), str);
 
			DrawString(ir.Indent(WidgetDimensions::scaled.hsep_indent, rtl), str);
 
			ir.top += FONT_HEIGHT_NORMAL;
 
		}
 

	
 
		GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_VIEW, i, i->type, ind, i->produced_cargo, cargo_suffix);
 
		int line_height = this->editable == EA_RATE ? this->cheat_line_height : FONT_HEIGHT_NORMAL;
 
		int text_y_offset = (line_height - FONT_HEIGHT_NORMAL) / 2;
 
		int button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
 
		first = true;
 
		for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
 
			if (i->produced_cargo[j] == CT_INVALID) continue;
 
			if (first) {
 
				if (has_accept) ir.top += WidgetDimensions::scaled.vsep_wide;
 
				DrawString(ir, STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE);
 
@@ -915,30 +926,33 @@ public:
 
			}
 

	
 
			SetDParam(0, i->produced_cargo[j]);
 
			SetDParam(1, i->last_month_production[j]);
 
			SetDParamStr(2, cargo_suffix[j].text);
 
			SetDParam(3, ToPercent8(i->last_month_pct_transported[j]));
 
			DrawString(ir.Indent(this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_indent : 0, false), STR_INDUSTRY_VIEW_TRANSPORTED);
 
			DrawString(ir.Indent(WidgetDimensions::scaled.hsep_indent + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal : 0), rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_TRANSPORTED);
 
			/* Let's put out those buttons.. */
 
			if (this->editable == EA_RATE) {
 
				DrawArrowButtons(ir.left, ir.top, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + j) ? this->clicked_button : 0,
 
				DrawArrowButtons(ir.Indent(WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + j) ? this->clicked_button : 0,
 
						i->production_rate[j] > 0, i->production_rate[j] < 255);
 
			}
 
			ir.top += FONT_HEIGHT_NORMAL;
 
			ir.top += line_height;
 
		}
 

	
 
		/* Display production multiplier if editable */
 
		if (this->editable == EA_MULTIPLIER) {
 
			line_height = this->cheat_line_height;
 
			text_y_offset = (line_height - FONT_HEIGHT_NORMAL) / 2;
 
			button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
 
			ir.top += WidgetDimensions::scaled.vsep_wide;
 
			this->production_offset_y = ir.top;
 
			SetDParam(0, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT));
 
			DrawString(ir.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_indent, false), STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
 
			DrawArrowButtons(ir.left, ir.top, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
 
			DrawString(ir.Indent(WidgetDimensions::scaled.hsep_indent + SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal, rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
 
			DrawArrowButtons(ir.Indent(WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
 
					i->prod_level > PRODLEVEL_MINIMUM, i->prod_level < PRODLEVEL_MAXIMUM);
 
			ir.top += FONT_HEIGHT_NORMAL;
 
			ir.top += line_height;
 
		}
 

	
 
		/* Get the extra message for the GUI */
 
		if (HasBit(ind->callback_mask, CBM_IND_WINDOW_MORE_TEXT)) {
 
			uint16 callback_res = GetIndustryCallback(CBID_INDUSTRY_WINDOW_MORE_TEXT, 0, 0, i, i->type, i->location.tile);
 
			if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
 
@@ -988,18 +1002,18 @@ public:
 
				InfoLine line = IL_NONE;
 

	
 
				switch (this->editable) {
 
					case EA_NONE: break;
 

	
 
					case EA_MULTIPLIER:
 
						if (IsInsideBS(pt.y, this->production_offset_y, FONT_HEIGHT_NORMAL)) line = IL_MULTIPLIER;
 
						if (IsInsideBS(pt.y, this->production_offset_y, this->cheat_line_height)) line = IL_MULTIPLIER;
 
						break;
 

	
 
					case EA_RATE:
 
						if (pt.y >= this->production_offset_y) {
 
							int row = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL;
 
							int row = (pt.y - this->production_offset_y) / this->cheat_line_height;
 
							for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
 
								if (i->produced_cargo[j] == CT_INVALID) continue;
 
								row--;
 
								if (row < 0) {
 
									line = (InfoLine)(IL_RATE1 + j);
 
									break;
 
@@ -1007,31 +1021,31 @@ public:
 
							}
 
						}
 
						break;
 
				}
 
				if (line == IL_NONE) return;
 

	
 
				NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
 
				int left = nwi->pos_x + WidgetDimensions::scaled.framerect.left;
 
				int right = nwi->pos_x + nwi->current_x - 1 - WidgetDimensions::scaled.framerect.right;
 
				if (IsInsideMM(pt.x, left, left + SETTING_BUTTON_WIDTH)) {
 
				bool rtl = _current_text_dir == TD_RTL;
 
				Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect).Indent(WidgetDimensions::scaled.hsep_indent, rtl);
 

	
 
				if (r.WithWidth(SETTING_BUTTON_WIDTH, rtl).Contains(pt)) {
 
					/* Clicked buttons, decrease or increase production */
 
					byte button = (pt.x < left + SETTING_BUTTON_WIDTH / 2) ? 1 : 2;
 
					bool decrease = r.WithWidth(SETTING_BUTTON_WIDTH / 2, rtl).Contains(pt);
 
					switch (this->editable) {
 
						case EA_MULTIPLIER:
 
							if (button == 1) {
 
							if (decrease) {
 
								if (i->prod_level <= PRODLEVEL_MINIMUM) return;
 
								i->prod_level = std::max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM);
 
							} else {
 
								if (i->prod_level >= PRODLEVEL_MAXIMUM) return;
 
								i->prod_level = std::min<uint>(i->prod_level * 2, PRODLEVEL_MAXIMUM);
 
							}
 
							break;
 

	
 
						case EA_RATE:
 
							if (button == 1) {
 
							if (decrease) {
 
								if (i->production_rate[line - IL_RATE1] <= 0) return;
 
								i->production_rate[line - IL_RATE1] = std::max(i->production_rate[line - IL_RATE1] / 2, 0);
 
							} else {
 
								if (i->production_rate[line - IL_RATE1] >= 255) return;
 
								/* a zero production industry is unlikely to give anything but zero, so push it a little bit */
 
								int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2;
 
@@ -1043,14 +1057,14 @@ public:
 
					}
 

	
 
					UpdateIndustryProduction(i);
 
					this->SetDirty();
 
					this->SetTimeout();
 
					this->clicked_line = line;
 
					this->clicked_button = button;
 
				} else if (IsInsideMM(pt.x, left + SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_indent, right)) {
 
					this->clicked_button = (decrease ^ rtl) ? 1 : 2;
 
				} else if (r.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal, rtl).Contains(pt)) {
 
					/* clicked the text */
 
					this->editbox_line = line;
 
					switch (this->editable) {
 
						case EA_MULTIPLIER:
 
							SetDParam(0, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT));
 
							ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION_LEVEL, 10, this, CS_ALPHANUMERAL, QSF_NONE);
0 comments (0 inline, 0 general)