Refactor townwnd draw function (#432)
* Refactor townwnd draw function * Rename unk_8
This commit is contained in:
parent
69b8a6749d
commit
c4bf1e1f5d
|
@ -1,5 +1,6 @@
|
|||
#include "town.h"
|
||||
#include "interop/interop.hpp"
|
||||
#include "localisation/string_ids.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace openloco::interop;
|
||||
|
@ -30,4 +31,21 @@ namespace openloco
|
|||
min_company_rating,
|
||||
max_company_rating);
|
||||
}
|
||||
|
||||
string_id town::getTownSizeString() const
|
||||
{
|
||||
static string_id townSizeNames[5] = {
|
||||
string_ids::town_size_hamlet,
|
||||
string_ids::town_size_village,
|
||||
string_ids::town_size_town,
|
||||
string_ids::town_size_city,
|
||||
string_ids::town_size_metropolis
|
||||
};
|
||||
|
||||
if (static_cast<uint8_t>(size) < std::size(townSizeNames))
|
||||
{
|
||||
return townSizeNames[static_cast<uint8_t>(size)];
|
||||
}
|
||||
return string_ids::town_size_hamlet;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ namespace openloco
|
|||
bool empty() const;
|
||||
void update();
|
||||
void adjust_company_rating(company_id_t cid, int amount);
|
||||
string_id getTownSizeString() const;
|
||||
};
|
||||
static_assert(sizeof(town) == 0x270);
|
||||
#pragma pack(pop)
|
||||
|
|
|
@ -10,17 +10,17 @@ using namespace openloco::interop;
|
|||
|
||||
namespace openloco::ui
|
||||
{
|
||||
int16_t widget_t::mid_x()
|
||||
int16_t widget_t::mid_x() const
|
||||
{
|
||||
return (this->left + this->right) / 2;
|
||||
}
|
||||
|
||||
uint16_t widget_t::width()
|
||||
uint16_t widget_t::width() const
|
||||
{
|
||||
return (this->right - this->left) + 1;
|
||||
}
|
||||
|
||||
uint16_t widget_t::height()
|
||||
uint16_t widget_t::height() const
|
||||
{
|
||||
return (this->bottom - this->top) + 1;
|
||||
}
|
||||
|
|
|
@ -38,9 +38,9 @@ namespace openloco::ui
|
|||
};
|
||||
string_id tooltip; // 0x0E
|
||||
|
||||
int16_t mid_x();
|
||||
uint16_t width();
|
||||
uint16_t height();
|
||||
int16_t mid_x() const;
|
||||
uint16_t width() const;
|
||||
uint16_t height() const;
|
||||
};
|
||||
|
||||
enum class widget_type : uint8_t
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "../graphics/image_ids.h"
|
||||
#include "../input.h"
|
||||
#include "../interop/interop.hpp"
|
||||
#include "../localisation/FormatArguments.hpp"
|
||||
#include "../localisation/string_ids.h"
|
||||
#include "../map/tile.h"
|
||||
#include "../objects/interface_skin_object.h"
|
||||
|
@ -67,7 +68,7 @@ namespace openloco::ui::windows::town
|
|||
enum widx
|
||||
{
|
||||
viewport = 7,
|
||||
unk_8,
|
||||
status_bar,
|
||||
centre_on_viewport,
|
||||
expand_town,
|
||||
demolish_town,
|
||||
|
@ -95,9 +96,9 @@ namespace openloco::ui::windows::town
|
|||
self->widgets[widx::viewport].right = self->width - 26;
|
||||
self->widgets[widx::viewport].bottom = self->height - 14;
|
||||
|
||||
self->widgets[widx::unk_8].top = self->height - 12;
|
||||
self->widgets[widx::unk_8].bottom = self->height - 3;
|
||||
self->widgets[widx::unk_8].right = self->width - 14;
|
||||
self->widgets[widx::status_bar].top = self->height - 12;
|
||||
self->widgets[widx::status_bar].bottom = self->height - 3;
|
||||
self->widgets[widx::status_bar].right = self->width - 14;
|
||||
|
||||
self->widgets[widx::expand_town].right = self->width - 2;
|
||||
self->widgets[widx::expand_town].left = self->width - 25;
|
||||
|
@ -131,24 +132,19 @@ namespace openloco::ui::windows::town
|
|||
self->draw(dpi);
|
||||
common::drawTabs(self, dpi);
|
||||
self->drawViewports(dpi);
|
||||
widget::drawViewportCentreButton(dpi, self, (widget_index)widx::centre_on_viewport);
|
||||
|
||||
static string_id townSizeLabelIds[] = {
|
||||
string_ids::town_size_hamlet,
|
||||
string_ids::town_size_village,
|
||||
string_ids::town_size_town,
|
||||
string_ids::town_size_city,
|
||||
string_ids::town_size_metropolis,
|
||||
};
|
||||
widget::drawViewportCentreButton(dpi, self, widx::centre_on_viewport);
|
||||
|
||||
auto town = townmgr::get(self->number);
|
||||
commonFormatArgs[0] = townSizeLabelIds[(uint8_t)town->size];
|
||||
*(int32_t*)&commonFormatArgs[1] = town->population;
|
||||
|
||||
const uint16_t xPos = self->x + self->widgets[widx::unk_8].left - 1;
|
||||
const uint16_t yPos = self->y + self->widgets[widx::unk_8].top - 1;
|
||||
const uint16_t width = self->widgets[widx::unk_8].width() - 1;
|
||||
gfx::draw_string_494BBF(*dpi, xPos, yPos, width, colour::black, string_ids::status_town_population, &*commonFormatArgs);
|
||||
auto args = FormatArguments();
|
||||
args.push(town->getTownSizeString());
|
||||
args.push(town->population);
|
||||
|
||||
const auto& widget = self->widgets[widx::status_bar];
|
||||
const auto x = self->x + widget.left - 1;
|
||||
const auto y = self->y + widget.top - 1;
|
||||
const auto width = widget.width() - 1;
|
||||
gfx::draw_string_494BBF(*dpi, x, y, width, colour::black, string_ids::status_town_population, &args);
|
||||
}
|
||||
|
||||
// 0x00499079
|
||||
|
|
Loading…
Reference in New Issue