1
0
Fork 0

Add: Show house information in house placer.

pull/13141/head
Peter Nelson 2024-05-15 11:39:03 +01:00 committed by Peter Nelson
parent 041b9181f9
commit 9e182871c7
3 changed files with 96 additions and 1 deletions

View File

@ -2832,6 +2832,14 @@ STR_PICKER_HOUSE_CLASS_TOOLTIP :Select a town z
STR_PICKER_HOUSE_TYPE_TOOLTIP :Select a house type to build. Ctrl+Click to add or remove in saved items
STR_HOUSE_PICKER_CAPTION :House Selection
STR_HOUSE_PICKER_NAME :{BLACK}Name: {ORANGE}{STRING}
STR_HOUSE_PICKER_POPULATION :{BLACK}Population: {ORANGE}{NUM}
STR_HOUSE_PICKER_YEARS :{BLACK}Years: {ORANGE}{NUM}-{NUM}
STR_HOUSE_PICKER_YEARS_ANY :{BLACK}Years: {ORANGE}Any
STR_HOUSE_PICKER_YEARS_FROM :{BLACK}Years: {ORANGE}From {NUM}
STR_HOUSE_PICKER_YEARS_UNTIL :{BLACK}Years: {ORANGE}Until {NUM}
STR_HOUSE_PICKER_SIZE :{BLACK}Size: {ORANGE}{NUM}x{NUM} tiles
STR_HOUSE_PICKER_CARGO_ACCEPTED :{BLACK}Cargo accepted: {ORANGE}
STR_HOUSE_PICKER_CLASS_ZONE1 :Edge
STR_HOUSE_PICKER_CLASS_ZONE2 :Outskirts

View File

@ -13,6 +13,7 @@
#include "error.h"
#include "gui.h"
#include "house.h"
#include "newgrf_cargo.h"
#include "newgrf_house.h"
#include "newgrf_text.h"
#include "picker_gui.h"
@ -49,6 +50,8 @@
#include "table/strings.h"
#include <sstream>
#include "safeguards.h"
TownKdtree _town_local_authority_kdtree{};
@ -1603,6 +1606,8 @@ public:
/* static */ HousePickerCallbacks HousePickerCallbacks::instance;
struct BuildHouseWindow : public PickerWindow {
std::string house_info;
BuildHouseWindow(WindowDesc &desc, Window *parent) : PickerWindow(desc, parent, 0, HousePickerCallbacks::instance)
{
HousePickerCallbacks::instance.SetClimateMask();
@ -1629,6 +1634,75 @@ struct BuildHouseWindow : public PickerWindow {
}
}
/**
* Get a date range string for house availability year.
* @param min_year Earliest year house can be built.
* @param max_year Latest year house can be built.
* @return Formatted string with the date range formatted appropriately.
*/
static std::string GetHouseYear(TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year)
{
if (min_year == CalendarTime::MIN_YEAR) {
if (max_year == CalendarTime::MAX_YEAR) {
return GetString(STR_HOUSE_PICKER_YEARS_ANY);
}
SetDParam(0, max_year);
return GetString(STR_HOUSE_PICKER_YEARS_UNTIL);
}
if (max_year == CalendarTime::MAX_YEAR) {
SetDParam(0, min_year);
return GetString(STR_HOUSE_PICKER_YEARS_FROM);
}
SetDParam(0, min_year);
SetDParam(1, max_year);
return GetString(STR_HOUSE_PICKER_YEARS);
}
/**
* Get information string for a house.
* @param hs HosueSpec to get information string for.
* @return Formatted string with information for house.
*/
static std::string GetHouseInformation(const HouseSpec *hs)
{
std::stringstream line;
SetDParam(0, GetHouseName(hs));
line << GetString(STR_HOUSE_PICKER_NAME);
line << "\n";
SetDParam(0, hs->population);
line << GetString(STR_HOUSE_PICKER_POPULATION);
line << "\n";
line << GetHouseYear(hs->min_year, hs->max_year);
line << "\n";
uint8_t size = 0;
if ((hs->building_flags & TILE_SIZE_1x1) != 0) size = 0x11;
if ((hs->building_flags & TILE_SIZE_2x1) != 0) size = 0x21;
if ((hs->building_flags & TILE_SIZE_1x2) != 0) size = 0x12;
if ((hs->building_flags & TILE_SIZE_2x2) != 0) size = 0x22;
SetDParam(0, GB(size, 0, 4));
SetDParam(1, GB(size, 4, 4));
line << GetString(STR_HOUSE_PICKER_SIZE);
line << "\n";
auto cargo_string = BuildCargoAcceptanceString(GetAcceptedCargoOfHouse(hs), STR_HOUSE_PICKER_CARGO_ACCEPTED);
if (cargo_string.has_value()) line << *cargo_string;
return line.str();
}
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget == WID_BH_INFO) {
if (!this->house_info.empty()) DrawStringMultiLine(r, this->house_info);
} else {
this->PickerWindow::DrawWidget(r, widget);
}
}
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
this->PickerWindow::OnInvalidateData(data, gui_scope);
@ -1637,6 +1711,7 @@ struct BuildHouseWindow : public PickerWindow {
if ((data & PickerWindow::PFI_POSITION) != 0) {
const HouseSpec *spec = HouseSpec::Get(HousePickerCallbacks::sel_type);
UpdateSelectSize(spec);
this->house_info = GetHouseInformation(spec);
}
}
@ -1668,7 +1743,14 @@ static constexpr NWidgetPart _nested_build_house_widgets[] = {
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidgetFunction(MakePickerClassWidgets),
NWidget(NWID_VERTICAL),
NWidgetFunction(MakePickerClassWidgets),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_picker, 0), SetPadding(WidgetDimensions::unscaled.picker),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BH_INFO), SetFill(1, 1), SetMinimalTextLines(10, 0),
EndContainer(),
EndContainer(),
EndContainer(),
NWidgetFunction(MakePickerTypeWidgets),
EndContainer(),
};

View File

@ -66,4 +66,9 @@ enum TownFoundingWidgets : WidgetID {
WID_TF_LAYOUT_RANDOM, ///< Selection for a randomly chosen town layout.
};
/** Widgets of the #BuildHouseWindow class. */
enum BuildHouseWidgets : WidgetID {
WID_BH_INFO, ///< Information panel of selected house.
};
#endif /* WIDGETS_TOWN_WIDGET_H */