Changeset - r28752:a27b176a812f
[Not reviewed]
master
0 1 0
Peter Nelson - 3 months ago 2024-02-13 07:41:24
peter1138@openttd.org
Add: Show cargo icons on subsidy list window. (#12079)
1 file changed with 20 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/subsidy_gui.cpp
Show inline comments
 
@@ -24,21 +24,27 @@
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 

	
 
struct SubsidyListWindow : Window {
 
	Scrollbar *vscroll;
 
	Dimension cargo_icon_size;
 

	
 
	SubsidyListWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
 
	{
 
		this->CreateNestedTree();
 
		this->vscroll = this->GetScrollbar(WID_SUL_SCROLLBAR);
 
		this->FinishInitNested(window_number);
 
		this->OnInvalidateData(0);
 
	}
 

	
 
	void OnInit() override
 
	{
 
		this->cargo_icon_size = GetLargestCargoIconSize();
 
	}
 

	
 
	void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
 
	{
 
		if (widget != WID_SUL_PANEL) return;
 

	
 
		int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SUL_PANEL, WidgetDimensions::scaled.framerect.top);
 
		int num = 0;
 
@@ -135,19 +141,29 @@ struct SubsidyListWindow : Window {
 
		d.height *= 5;
 
		d.width += WidgetDimensions::scaled.framerect.Horizontal();
 
		d.height += WidgetDimensions::scaled.framerect.Vertical();
 
		*size = maxdim(*size, d);
 
	}
 

	
 
	void DrawCargoIcon(const Rect &r, int y_offset, 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) + y_offset);
 
	}
 

	
 
	void DrawWidget(const Rect &r, WidgetID widget) const override
 
	{
 
		if (widget != WID_SUL_PANEL) return;
 

	
 
		TimerGameEconomy::YearMonthDay ymd = TimerGameEconomy::ConvertDateToYMD(TimerGameEconomy::date);
 

	
 
		Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
 
		Rect sr = tr.Indent(this->cargo_icon_size.width + WidgetDimensions::scaled.hsep_normal, _current_text_dir == TD_RTL);
 

	
 
		int pos = -this->vscroll->GetPosition();
 
		const int cap = this->vscroll->GetCapacity();
 

	
 
		/* Section for drawing the offered subsidies */
 
		if (IsInsideMM(pos, 0, cap)) DrawString(tr.left, tr.right, tr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_OFFERED_TITLE);
 
@@ -165,13 +181,14 @@ struct SubsidyListWindow : Window {
 
						SetDParam(8, s->remaining + 1); // We get the rest of the current economy month for free, since the expiration is checked on each new month.
 
					} else {
 
						SetDParam(7, STR_SUBSIDIES_OFFERED_EXPIRY_DATE);
 
						SetDParam(8, TimerGameEconomy::date - ymd.day + s->remaining * 32);
 
					}
 

	
 
					DrawString(tr.left, tr.right, tr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_OFFERED_FROM_TO);
 
					DrawCargoIcon(tr, pos * GetCharacterHeight(FS_NORMAL), s->cargo_type);
 
					DrawString(sr.left, sr.right, sr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_OFFERED_FROM_TO);
 
				}
 
				pos++;
 
				num++;
 
			}
 
		}
 

	
 
@@ -199,13 +216,14 @@ struct SubsidyListWindow : Window {
 
					else {
 
						SetDParam(8, STR_SUBSIDIES_SUBSIDISED_EXPIRY_DATE);
 
						SetDParam(9, TimerGameEconomy::date - ymd.day + s->remaining * 32);
 
					}
 

	
 
					/* Displays the two connected stations */
 
					DrawString(tr.left, tr.right, tr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_SUBSIDISED_FROM_TO);
 
					DrawCargoIcon(tr, pos * GetCharacterHeight(FS_NORMAL), s->cargo_type);
 
					DrawString(sr.left, sr.right, sr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_SUBSIDISED_FROM_TO);
 
				}
 
				pos++;
 
				num++;
 
			}
 
		}
 

	
0 comments (0 inline, 0 general)