mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Add weather 'forecast' as preview
This commit is contained in:
@@ -3802,3 +3802,4 @@ STR_6740 :{WINDOW_COLOUR_2}Cash: {BLACK}{CURRENCY2DP}
|
||||
STR_6741 :{WINDOW_COLOUR_2}Num. rides: {BLACK}{UINT16}
|
||||
STR_6742 :{WINDOW_COLOUR_2}Num. guests: {BLACK}{UINT16}
|
||||
STR_6743 :Climate
|
||||
STR_6744 :{WINDOW_COLOUR_2}{UINT16}%
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include <openrct2/drawing/Text.h>
|
||||
#include <openrct2/localisation/Formatter.h>
|
||||
#include <openrct2/object/ClimateObject.h>
|
||||
#include <openrct2/object/MusicObject.h>
|
||||
#include <openrct2/object/ObjectList.h>
|
||||
#include <openrct2/object/ObjectManager.h>
|
||||
@@ -1268,6 +1269,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
screenPos.y += DrawTextWrapped(dpi, screenPos, descriptionWidth, STR_WINDOW_COLOUR_2_STRINGID, ft);
|
||||
screenPos.y += kListRowHeight;
|
||||
}
|
||||
|
||||
if (GetSelectedObjectType() == ObjectType::ride)
|
||||
{
|
||||
auto* rideObject = reinterpret_cast<RideObject*>(_loadedObject.get());
|
||||
|
||||
@@ -1725,6 +1725,7 @@ enum : StringId
|
||||
STR_DIVE_LOOP_RIGHT = 6728,
|
||||
|
||||
STR_OBJECT_SELECTION_CLIMATE = 6743,
|
||||
STR_CLIMATE_WEATHER_PERCENT = 6744,
|
||||
|
||||
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
|
||||
/* MAX_STR_COUNT = 32768 */ // MAX_STR_COUNT - upper limit for number of strings, not the current count strings
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include "../core/Guard.hpp"
|
||||
#include "../core/IStream.hpp"
|
||||
#include "../core/Json.hpp"
|
||||
#include "../localisation/Formatter.h"
|
||||
#include "../localisation/StringIds.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
@@ -48,6 +52,26 @@ void ClimateObject::Unload()
|
||||
static RawClimate readWeatherTable(json_t& weather);
|
||||
static Climate convertRawClimate(const RawClimate& rawClimate);
|
||||
|
||||
void ClimateObject::DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const
|
||||
{
|
||||
const auto dist = getYearlyDistribution();
|
||||
const auto totalSize = kNumClimateMonths * kWeatherDistSize;
|
||||
|
||||
for (auto i = 0u; i < EnumValue(WeatherType::Count); i++)
|
||||
{
|
||||
auto type = WeatherType(i);
|
||||
auto imageId = ImageId(ClimateGetWeatherSpriteId(type));
|
||||
auto coords = ScreenCoordsXY(8 + (i % 3) * 35, 3 + (i / 3) * 37);
|
||||
GfxDrawSprite(dpi, imageId, coords);
|
||||
|
||||
auto ft = Formatter();
|
||||
ft.Add<uint16_t>(dist[i] * 100 / totalSize);
|
||||
DrawTextEllipsised(
|
||||
dpi, coords + ScreenCoordsXY{ 12, 22 }, 35, STR_CLIMATE_WEATHER_PERCENT, ft,
|
||||
{ FontStyle::Small, TextAlignment::CENTRE });
|
||||
}
|
||||
}
|
||||
|
||||
void ClimateObject::ReadJson(IReadObjectContext* context, json_t& root)
|
||||
{
|
||||
Guard::Assert(root.is_object(), "ClimateObject::ReadJson expects parameter root to be an object");
|
||||
@@ -58,11 +82,34 @@ void ClimateObject::ReadJson(IReadObjectContext* context, json_t& root)
|
||||
_climate = convertRawClimate(rawClimate);
|
||||
}
|
||||
|
||||
const WeatherPattern& ClimateObject::getPatternForMonth(uint8_t month)
|
||||
const WeatherPattern& ClimateObject::getPatternForMonth(uint8_t month) const
|
||||
{
|
||||
return _climate[month];
|
||||
}
|
||||
|
||||
YearlyDistribution ClimateObject::getYearlyDistribution() const
|
||||
{
|
||||
auto weatherTypeCount = [](const WeatherPattern& pattern, const WeatherType target) {
|
||||
auto count = 0u;
|
||||
for (auto type : pattern.distribution)
|
||||
{
|
||||
if (type == target)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
};
|
||||
|
||||
YearlyDistribution dist{};
|
||||
for (auto m = 0; m < kNumClimateMonths; m++)
|
||||
{
|
||||
auto& pattern = getPatternForMonth(m);
|
||||
for (auto i = 0u; i < EnumValue(WeatherType::Count); i++)
|
||||
dist[i] += weatherTypeCount(pattern, WeatherType(i));
|
||||
}
|
||||
|
||||
return dist;
|
||||
}
|
||||
|
||||
static Climate convertRawClimate(const RawClimate& rawClimate)
|
||||
{
|
||||
Climate climate{};
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
struct IReadObjectContext;
|
||||
|
||||
using YearlyDistribution = std::array<uint8_t, EnumValue(WeatherType::Count)>;
|
||||
|
||||
class ClimateObject final : public Object
|
||||
{
|
||||
private:
|
||||
@@ -26,5 +28,8 @@ public:
|
||||
void Load() override;
|
||||
void Unload() override;
|
||||
|
||||
const WeatherPattern& getPatternForMonth(uint8_t month);
|
||||
void DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const override;
|
||||
|
||||
const WeatherPattern& getPatternForMonth(uint8_t month) const;
|
||||
YearlyDistribution getYearlyDistribution() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user