Changeset - r28745:a32e480a195f
[Not reviewed]
master
0 1 0
Peter Nelson - 10 months ago 2024-02-12 00:50:58
peter1138@openttd.org
Change: Show cargo icons on Industry View window. (#12071)
1 file changed with 22 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/industry_gui.cpp
Show inline comments
 
@@ -797,12 +797,13 @@ class IndustryViewWindow : public Window
 
		IL_NONE,              ///< No line
 
		IL_MULTIPLIER,        ///< Production multiplier
 
		IL_RATE1,             ///< Production rate of cargo 1
 
		IL_RATE2,             ///< Production rate of cargo 2
 
	};
 

	
 
	Dimension cargo_icon_size; ///< Largest cargo icon dimension.
 
	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
 
@@ -825,12 +826,13 @@ public:
 
	}
 

	
 
	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, GetCharacterHeight(FS_NORMAL));
 
		this->cargo_icon_size = GetLargestCargoIconSize();
 
	}
 

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

	
 
@@ -842,12 +844,21 @@ public:
 
			this->info_height = expected - r.top + 1;
 
			this->ReInit();
 
			return;
 
		}
 
	}
 

	
 
	void DrawCargoIcon(const Rect &r, CargoID cid) const
 
	{
 
		bool rtl = _current_text_dir == TD_RTL;
 
		SpriteID icon = CargoSpec::Get(cid)->GetCargoIcon();
 
		Dimension d = GetSpriteSize(icon);
 
		Rect ir = r.WithWidth(this->cargo_icon_size.width, rtl).WithHeight(GetCharacterHeight(FS_NORMAL));
 
		DrawSprite(icon, PAL_NONE, CenterBounds(ir.left, ir.right, d.width), CenterBounds(ir.top, ir.bottom, this->cargo_icon_size.height));
 
	}
 

	
 
	/**
 
	 * 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)
 
@@ -861,23 +872,26 @@ public:
 

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

	
 
		const int label_indent = WidgetDimensions::scaled.hsep_normal + this->cargo_icon_size.width;
 
		bool stockpiling = HasBit(ind->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(ind->callback_mask, CBM_IND_PRODUCTION_256_TICKS);
 

	
 
		for (const auto &a : i->accepted) {
 
			if (!IsValidCargoID(a.cargo)) continue;
 
			has_accept = true;
 
			if (first) {
 
				DrawString(ir, STR_INDUSTRY_VIEW_REQUIRES);
 
				ir.top += GetCharacterHeight(FS_NORMAL);
 
				first = false;
 
			}
 

	
 
			DrawCargoIcon(ir, a.cargo);
 

	
 
			CargoSuffix suffix;
 
			GetCargoSuffix(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, a.cargo, &a - i->accepted.data(), suffix);
 

	
 
			SetDParam(0, CargoSpec::Get(a.cargo)->name);
 
			SetDParam(1, a.cargo);
 
			SetDParam(2, a.waiting);
 
@@ -898,13 +912,13 @@ public:
 
					str = STR_INDUSTRY_VIEW_ACCEPT_CARGO;
 
					break;
 

	
 
				default:
 
					NOT_REACHED();
 
			}
 
			DrawString(ir.Indent(WidgetDimensions::scaled.hsep_indent, rtl), str);
 
			DrawString(ir.Indent(label_indent, rtl), str);
 
			ir.top += GetCharacterHeight(FS_NORMAL);
 
		}
 

	
 
		int line_height = this->editable == EA_RATE ? this->cheat_line_height : GetCharacterHeight(FS_NORMAL);
 
		int text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
 
		int button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
 
@@ -916,23 +930,25 @@ public:
 
				DrawString(ir, TimerGameEconomy::UsingWallclockUnits() ? STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE : STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE);
 
				ir.top += GetCharacterHeight(FS_NORMAL);
 
				if (this->editable == EA_RATE) this->production_offset_y = ir.top;
 
				first = false;
 
			}
 

	
 
			DrawCargoIcon(ir, p.cargo);
 

	
 
			CargoSuffix suffix;
 
			GetCargoSuffix(CARGOSUFFIX_OUT, CST_VIEW, i, i->type, ind, p.cargo, &p - i->produced.data(), suffix);
 

	
 
			SetDParam(0, p.cargo);
 
			SetDParam(1, p.history[LAST_MONTH].production);
 
			SetDParamStr(2, suffix.text);
 
			SetDParam(3, ToPercent8(p.history[LAST_MONTH].PctTransported()));
 
			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);
 
			DrawString(ir.Indent(label_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.Indent(WidgetDimensions::scaled.hsep_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + (&p - i->produced.data())) ? this->clicked_button : 0,
 
				DrawArrowButtons(ir.Indent(label_indent, rtl).WithWidth(SETTING_BUTTON_WIDTH, rtl).left, ir.top + button_y_offset, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + (&p - i->produced.data())) ? this->clicked_button : 0,
 
						p.rate > 0, p.rate < 255);
 
			}
 
			ir.top += line_height;
 
		}
 

	
 
		/* Display production multiplier if editable */
 
@@ -940,14 +956,14 @@ public:
 
			line_height = this->cheat_line_height;
 
			text_y_offset = (line_height - GetCharacterHeight(FS_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(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,
 
			DrawString(ir.Indent(label_indent + SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_normal, rtl).Translate(0, text_y_offset), STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
 
			DrawArrowButtons(ir.Indent(label_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 += line_height;
 
		}
 

	
 
		/* Get the extra message for the GUI */
 
		if (HasBit(ind->callback_mask, CBM_IND_WINDOW_MORE_TEXT)) {
 
@@ -1019,13 +1035,13 @@ public:
 
						}
 
						break;
 
				}
 
				if (line == IL_NONE) return;
 

	
 
				bool rtl = _current_text_dir == TD_RTL;
 
				Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect).Indent(WidgetDimensions::scaled.hsep_indent, rtl);
 
				Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect).Indent(this->cargo_icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl);
 

	
 
				if (r.WithWidth(SETTING_BUTTON_WIDTH, rtl).Contains(pt)) {
 
					/* Clicked buttons, decrease or increase production */
 
					bool decrease = r.WithWidth(SETTING_BUTTON_WIDTH / 2, rtl).Contains(pt);
 
					switch (this->editable) {
 
						case EA_MULTIPLIER:
0 comments (0 inline, 0 general)