forked from rosebudai/OpenRCT2-Web
Create enum for TextColour
This commit is contained in:
1 parent
c17a3fed82
commit
1a571cd4e4
19 files changed
+111
-93
No files matched your search
@@ -19,6 +19,7 @@
|
||||
#include <openrct2/actions/BannerSetNameAction.h>
|
||||
#include <openrct2/actions/BannerSetStyleAction.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/drawing/TextColour.h>
|
||||
#include <openrct2/object/BannerSceneryEntry.h>
|
||||
#include <openrct2/object/ObjectEntryManager.h>
|
||||
#include <openrct2/ui/WindowManager.h>
|
||||
@@ -47,21 +48,21 @@ namespace OpenRCT2::Ui::Windows
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
static constexpr StringId BannerColouredTextFormats[] = {
|
||||
STR_TEXT_COLOUR_BLACK,
|
||||
STR_TEXT_COLOUR_GREY,
|
||||
STR_TEXT_COLOUR_WHITE,
|
||||
STR_TEXT_COLOUR_RED,
|
||||
STR_TEXT_COLOUR_GREEN,
|
||||
STR_TEXT_COLOUR_YELLOW,
|
||||
STR_TEXT_COLOUR_TOPAZ,
|
||||
STR_TEXT_COLOUR_CELADON,
|
||||
STR_TEXT_COLOUR_BABYBLUE,
|
||||
STR_TEXT_COLOUR_PALELAVENDER,
|
||||
STR_TEXT_COLOUR_PALEGOLD,
|
||||
STR_TEXT_COLOUR_LIGHTPINK,
|
||||
STR_TEXT_COLOUR_PEARLAQUA,
|
||||
STR_TEXT_COLOUR_PALESILVER,
|
||||
static constexpr StringId kBannerColouredTextFormats[] = {
|
||||
STR_TEXT_COLOUR_BLACK, // TextColour::black
|
||||
STR_TEXT_COLOUR_GREY, // TextColour::grey
|
||||
STR_TEXT_COLOUR_WHITE, // TextColour::white
|
||||
STR_TEXT_COLOUR_RED, // TextColour::red
|
||||
STR_TEXT_COLOUR_GREEN, // TextColour::green
|
||||
STR_TEXT_COLOUR_YELLOW, // TextColour::yellow
|
||||
STR_TEXT_COLOUR_TOPAZ, // TextColour::topaz
|
||||
STR_TEXT_COLOUR_CELADON, // TextColour::celadon
|
||||
STR_TEXT_COLOUR_BABYBLUE, // TextColour::babyBlue
|
||||
STR_TEXT_COLOUR_PALELAVENDER, // TextColour::paleLavender
|
||||
STR_TEXT_COLOUR_PALEGOLD, // TextColour::paleGold
|
||||
STR_TEXT_COLOUR_LIGHTPINK, // TextColour::lightPink
|
||||
STR_TEXT_COLOUR_PEARLAQUA, // TextColour::pearlAqua
|
||||
STR_TEXT_COLOUR_PALESILVER, // TextColour::paleSilver
|
||||
};
|
||||
|
||||
static constexpr Widget window_banner_widgets[] = {
|
||||
@@ -164,10 +165,11 @@ namespace OpenRCT2::Ui::Windows
|
||||
break;
|
||||
case WIDX_TEXT_COLOUR_DROPDOWN_BUTTON:
|
||||
|
||||
for (int32_t i = 0; i < 13; ++i)
|
||||
auto numItems = std::size(kBannerColouredTextFormats) - 1;
|
||||
for (size_t i = 0; i < numItems; ++i)
|
||||
{
|
||||
gDropdownItems[i].Format = STR_DROPDOWN_MENU_LABEL;
|
||||
gDropdownItems[i].Args = BannerColouredTextFormats[i + 1];
|
||||
gDropdownItems[i].Args = kBannerColouredTextFormats[i + 1];
|
||||
}
|
||||
|
||||
// Switch to the dropdown box widget.
|
||||
@@ -175,9 +177,9 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
WindowDropdownShowTextCustomWidth(
|
||||
{ widget->left + windowPos.x, widget->top + windowPos.y }, widget->height() + 1, colours[1], 0,
|
||||
Dropdown::Flag::StayOpen, 13, widget->width() - 3);
|
||||
Dropdown::Flag::StayOpen, numItems, widget->width() - 3);
|
||||
|
||||
Dropdown::SetChecked(banner->text_colour - 1, true);
|
||||
Dropdown::SetChecked(EnumValue(banner->textColour) - 1, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -299,7 +301,7 @@ namespace OpenRCT2::Ui::Windows
|
||||
}
|
||||
colourBtn.image = GetColourButtonImage(banner->colour);
|
||||
Widget& dropDownWidget = widgets[WIDX_TEXT_COLOUR_DROPDOWN];
|
||||
dropDownWidget.text = BannerColouredTextFormats[banner->text_colour];
|
||||
dropDownWidget.text = kBannerColouredTextFormats[EnumValue(banner->textColour)];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ GameActions::Result BannerPlaceAction::Execute() const
|
||||
}
|
||||
banner->flags = 0;
|
||||
banner->text = {};
|
||||
banner->text_colour = 2;
|
||||
banner->textColour = TextColour::white;
|
||||
banner->type = _bannerType; // Banner must be deleted after this point in an early return
|
||||
banner->colour = _primaryColour;
|
||||
banner->position = TileCoordsXY(_loc);
|
||||
|
||||
@@ -151,7 +151,7 @@ GameActions::Result BannerSetStyleAction::Execute() const
|
||||
banner->colour = _parameter;
|
||||
break;
|
||||
case BannerSetStyleType::TextColour:
|
||||
banner->text_colour = _parameter;
|
||||
banner->textColour = static_cast<TextColour>(_parameter);
|
||||
break;
|
||||
case BannerSetStyleType::NoEntry:
|
||||
{
|
||||
|
||||
@@ -250,7 +250,7 @@ GameActions::Result LargeSceneryPlaceAction::Execute() const
|
||||
|
||||
banner->text = {};
|
||||
banner->colour = 2;
|
||||
banner->text_colour = 2;
|
||||
banner->textColour = TextColour::white;
|
||||
banner->flags = BANNER_FLAG_IS_LARGE_SCENERY;
|
||||
banner->type = 0;
|
||||
banner->position = TileCoordsXY(_loc);
|
||||
|
||||
@@ -361,7 +361,7 @@ GameActions::Result WallPlaceAction::Execute() const
|
||||
|
||||
banner->text = {};
|
||||
banner->colour = COLOUR_WHITE;
|
||||
banner->text_colour = COLOUR_WHITE;
|
||||
banner->textColour = TextColour::white;
|
||||
banner->flags = BANNER_FLAG_IS_WALL;
|
||||
banner->type = 0; // Banner must be deleted after this point in an early return
|
||||
banner->position = TileCoordsXY(_loc);
|
||||
|
||||
@@ -999,7 +999,7 @@ struct DataSerializerTraitsT<Banner>
|
||||
stream->WriteString(banner.text);
|
||||
stream->WriteValue(banner.colour);
|
||||
DataSerializerTraits<RideId>().encode(stream, banner.ride_index);
|
||||
stream->WriteValue(banner.text_colour);
|
||||
stream->WriteValue(banner.textColour);
|
||||
DataSerializerTraits<TileCoordsXY>().encode(stream, banner.position);
|
||||
}
|
||||
|
||||
@@ -1011,7 +1011,7 @@ struct DataSerializerTraitsT<Banner>
|
||||
banner.text = stream->ReadStdString();
|
||||
stream->Read(&banner.colour);
|
||||
DataSerializerTraits<RideId>().decode(stream, banner.ride_index);
|
||||
stream->Read(&banner.text_colour);
|
||||
stream->Read(&banner.textColour);
|
||||
DataSerializerTraits<TileCoordsXY>().decode(stream, banner.position);
|
||||
}
|
||||
|
||||
|
||||
@@ -271,13 +271,13 @@ void GfxDrawStringLeftCentred(
|
||||
/**
|
||||
* Changes the palette so that the next character changes colour
|
||||
*/
|
||||
static void ColourCharacter(uint8_t colour, const uint16_t* current_font_flags, uint8_t* palette_pointer)
|
||||
static void ColourCharacter(TextColour colour, const uint16_t* current_font_flags, uint8_t* palette_pointer)
|
||||
{
|
||||
int32_t colour32 = 0;
|
||||
const G1Element* g1 = GfxGetG1Element(SPR_TEXT_PALETTE);
|
||||
if (g1 != nullptr)
|
||||
{
|
||||
uint32_t idx = (colour & 0xFF) * 4;
|
||||
uint32_t idx = EnumValue(colour) * 4;
|
||||
std::memcpy(&colour32, &g1->offset[idx], sizeof(colour32));
|
||||
}
|
||||
|
||||
@@ -608,8 +608,8 @@ static void TTFProcessFormatCode(RenderTarget& rt, const FmtString::Token& token
|
||||
if (FormatTokenIsColour(token.kind))
|
||||
{
|
||||
uint16_t flags = info->flags;
|
||||
auto colourIndex = FormatTokenGetTextColourIndex(token.kind);
|
||||
ColourCharacter(static_cast<uint8_t>(colourIndex), &flags, info->palette);
|
||||
auto colourIndex = FormatTokenToTextColour(token.kind);
|
||||
ColourCharacter(colourIndex, &flags, info->palette);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1535,8 +1535,8 @@ static void ScrollingTextSetBitmapForSprite(
|
||||
auto g1 = GfxGetG1Element(SPR_TEXT_PALETTE);
|
||||
if (g1 != nullptr)
|
||||
{
|
||||
auto colourIndex = FormatTokenGetTextColourIndex(token.kind);
|
||||
characterColour = g1->offset[colourIndex * 4];
|
||||
auto colourIndex = FormatTokenToTextColour(token.kind);
|
||||
characterColour = g1->offset[EnumValue(colourIndex) * 4];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1569,8 +1569,8 @@ static void ScrollingTextSetBitmapForTTF(
|
||||
auto g1 = GfxGetG1Element(SPR_TEXT_PALETTE);
|
||||
if (g1 != nullptr)
|
||||
{
|
||||
auto colourIndex = FormatTokenGetTextColourIndex(token.kind);
|
||||
colour = g1->offset[colourIndex * 4];
|
||||
auto colourIndex = FormatTokenToTextColour(token.kind);
|
||||
colour = g1->offset[EnumValue(colourIndex) * 4];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "../interface/Colour.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
enum class TextColour : uint8_t
|
||||
{
|
||||
black = 0,
|
||||
grey = 1,
|
||||
white = 2,
|
||||
red = 3,
|
||||
green = 4,
|
||||
yellow = 5,
|
||||
topaz = 6,
|
||||
celadon = 7,
|
||||
babyBlue = 8,
|
||||
paleLavender = 9,
|
||||
paleGold = 10,
|
||||
lightPink = 11,
|
||||
pearlAqua = 12,
|
||||
paleSilver = 13,
|
||||
};
|
||||
constexpr size_t kNumTextColours = 14;
|
||||
} // namespace OpenRCT2
|
||||
@@ -255,6 +255,7 @@
|
||||
<ClInclude Include="drawing\ScrollingText.h" />
|
||||
<ClInclude Include="drawing\Weather.h" />
|
||||
<ClInclude Include="drawing\Text.h" />
|
||||
<ClInclude Include="drawing\TextColour.h" />
|
||||
<ClInclude Include="drawing\TTF.h" />
|
||||
<ClInclude Include="drawing\X8DrawingEngine.h" />
|
||||
<ClInclude Include="Editor.h" />
|
||||
@@ -1169,4 +1170,4 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -10,6 +10,10 @@
|
||||
#include "FormatCodes.h"
|
||||
|
||||
#include "../core/EnumMap.hpp"
|
||||
#include "../core/EnumUtils.hpp"
|
||||
#include "../drawing/TextColour.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
// clang-format off
|
||||
static const EnumMap<FormatToken> FormatTokenMap = {
|
||||
@@ -136,53 +140,33 @@ bool FormatTokenIsColour(FormatToken token)
|
||||
}
|
||||
}
|
||||
|
||||
size_t FormatTokenGetTextColourIndex(FormatToken token)
|
||||
TextColour FormatTokenToTextColour(FormatToken token)
|
||||
{
|
||||
switch (token)
|
||||
{
|
||||
case FormatToken::ColourBlack:
|
||||
return 0;
|
||||
case FormatToken::ColourGrey:
|
||||
return 1;
|
||||
case FormatToken::ColourWhite:
|
||||
return 2;
|
||||
case FormatToken::ColourRed:
|
||||
return 3;
|
||||
case FormatToken::ColourGreen:
|
||||
return 4;
|
||||
case FormatToken::ColourYellow:
|
||||
return 5;
|
||||
case FormatToken::ColourTopaz:
|
||||
return 6;
|
||||
case FormatToken::ColourCeladon:
|
||||
return 7;
|
||||
case FormatToken::ColourBabyBlue:
|
||||
return 8;
|
||||
case FormatToken::ColourPaleLavender:
|
||||
return 9;
|
||||
case FormatToken::ColourPaleGold:
|
||||
return 10;
|
||||
case FormatToken::ColourLightPink:
|
||||
return 11;
|
||||
case FormatToken::ColourPearlAqua:
|
||||
return 12;
|
||||
case FormatToken::ColourPaleSilver:
|
||||
return 13;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
uint8_t value = EnumValue(token) - EnumValue(FormatToken::ColourBlack);
|
||||
if (value >= kNumTextColours)
|
||||
return TextColour::black;
|
||||
|
||||
return static_cast<TextColour>(value);
|
||||
}
|
||||
|
||||
FormatToken FormatTokenFromTextColour(size_t textColour)
|
||||
FormatToken FormatTokenFromTextColour(TextColour textColour)
|
||||
{
|
||||
static constexpr FormatToken tokens[] = {
|
||||
FormatToken::ColourBlack, FormatToken::ColourGrey, FormatToken::ColourWhite,
|
||||
FormatToken::ColourRed, FormatToken::ColourGreen, FormatToken::ColourYellow,
|
||||
FormatToken::ColourTopaz, FormatToken::ColourCeladon, FormatToken::ColourBabyBlue,
|
||||
FormatToken::ColourPaleLavender, FormatToken::ColourPaleGold, FormatToken::ColourLightPink,
|
||||
FormatToken::ColourPearlAqua, FormatToken::ColourPaleSilver,
|
||||
FormatToken::ColourBlack, // TextColour::black
|
||||
FormatToken::ColourGrey, // TextColour::grey
|
||||
FormatToken::ColourWhite, // TextColour::white
|
||||
FormatToken::ColourRed, // TextColour::red
|
||||
FormatToken::ColourGreen, // TextColour::green
|
||||
FormatToken::ColourYellow, // TextColour::yellow
|
||||
FormatToken::ColourTopaz, // TextColour::topaz
|
||||
FormatToken::ColourCeladon, // TextColour::celadon
|
||||
FormatToken::ColourBabyBlue, // TextColour::babyBlue
|
||||
FormatToken::ColourPaleLavender, // TextColour::paleLavender
|
||||
FormatToken::ColourPaleGold, // TextColour::paleGold
|
||||
FormatToken::ColourLightPink, // TextColour::lightPink
|
||||
FormatToken::ColourPearlAqua, // TextColour::pearlAqua
|
||||
FormatToken::ColourPaleSilver, // TextColour::paleSilver
|
||||
};
|
||||
if (textColour >= std::size(tokens))
|
||||
return FormatToken::ColourBlack;
|
||||
return tokens[textColour];
|
||||
|
||||
return tokens[EnumValue(textColour)];
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../drawing/TextColour.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -82,5 +84,5 @@ std::string FormatTokenToString(FormatToken token);
|
||||
std::string FormatTokenToStringWithBraces(FormatToken token);
|
||||
bool FormatTokenTakesArgument(FormatToken token);
|
||||
bool FormatTokenIsColour(FormatToken token);
|
||||
size_t FormatTokenGetTextColourIndex(FormatToken token);
|
||||
FormatToken FormatTokenFromTextColour(size_t textColour);
|
||||
OpenRCT2::TextColour FormatTokenToTextColour(FormatToken token);
|
||||
FormatToken FormatTokenFromTextColour(OpenRCT2::TextColour textColour);
|
||||
@@ -1365,7 +1365,7 @@ namespace OpenRCT2
|
||||
cs.ReadWrite(banner.text);
|
||||
cs.ReadWrite(banner.colour);
|
||||
cs.ReadWrite(banner.ride_index);
|
||||
cs.ReadWrite(banner.text_colour);
|
||||
cs.ReadWrite(banner.textColour);
|
||||
cs.ReadWrite(banner.position.x);
|
||||
cs.ReadWrite(banner.position.y);
|
||||
}
|
||||
|
||||
@@ -2522,7 +2522,7 @@ namespace OpenRCT2::RCT1
|
||||
}
|
||||
|
||||
dst->colour = RCT1::GetColour(src->Colour);
|
||||
dst->text_colour = src->TextColour;
|
||||
dst->textColour = src->textColour;
|
||||
dst->position.x = src->x;
|
||||
dst->position.y = src->y;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ class ObjectList;
|
||||
namespace OpenRCT2
|
||||
{
|
||||
enum class TrackElemType : uint16_t;
|
||||
}
|
||||
enum class TextColour : uint8_t;
|
||||
} // namespace OpenRCT2
|
||||
namespace OpenRCT2::RCT12
|
||||
{
|
||||
enum class ClimateType : uint8_t
|
||||
@@ -1197,9 +1198,9 @@ struct RCT12Banner
|
||||
uint8_t Colour; // 0x04
|
||||
uint8_t RideIndex; // 0x04
|
||||
};
|
||||
uint8_t TextColour; // 0x05
|
||||
uint8_t x; // 0x06
|
||||
uint8_t y; // 0x07
|
||||
OpenRCT2::TextColour textColour; // 0x05
|
||||
uint8_t x; // 0x06
|
||||
uint8_t y; // 0x07
|
||||
};
|
||||
static_assert(sizeof(RCT12Banner) == 8);
|
||||
|
||||
|
||||
@@ -1141,7 +1141,7 @@ namespace OpenRCT2::RCT2
|
||||
dst->colour = src->Colour;
|
||||
}
|
||||
|
||||
dst->text_colour = src->TextColour;
|
||||
dst->textColour = src->textColour;
|
||||
dst->position.x = src->x;
|
||||
dst->position.y = src->y;
|
||||
}
|
||||
|
||||
@@ -1421,7 +1421,7 @@ namespace OpenRCT2::Scripting
|
||||
case TileElementType::Banner:
|
||||
{
|
||||
auto* el = _element->AsBanner();
|
||||
duk_push_int(ctx, el->GetBanner()->text_colour);
|
||||
duk_push_int(ctx, EnumValue(el->GetBanner()->textColour));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -1461,7 +1461,7 @@ namespace OpenRCT2::Scripting
|
||||
case TileElementType::Banner:
|
||||
{
|
||||
auto* el = _element->AsBanner();
|
||||
el->GetBanner()->text_colour = value;
|
||||
el->GetBanner()->textColour = static_cast<TextColour>(value);
|
||||
Invalidate();
|
||||
break;
|
||||
}
|
||||
@@ -2254,7 +2254,7 @@ namespace OpenRCT2::Scripting
|
||||
{
|
||||
banner->text = {};
|
||||
banner->colour = 0;
|
||||
banner->text_colour = 0;
|
||||
banner->textColour = TextColour::black;
|
||||
banner->flags = 0;
|
||||
if (_element->GetType() == TileElementType::Wall)
|
||||
banner->flags = BANNER_FLAG_IS_WALL;
|
||||
|
||||
@@ -53,7 +53,7 @@ void Banner::FormatTextTo(Formatter& ft, bool addColour) const
|
||||
{
|
||||
if (addColour)
|
||||
{
|
||||
auto formatToken = FormatTokenFromTextColour(text_colour);
|
||||
auto formatToken = FormatTokenFromTextColour(textColour);
|
||||
formattedTextBuffer = FormatTokenToStringWithBraces(formatToken);
|
||||
ft.Add<StringId>(STR_STRING_STRINGID);
|
||||
ft.Add<const char*>(formattedTextBuffer.data());
|
||||
@@ -442,7 +442,7 @@ Banner* CreateBanner()
|
||||
banner->type = 0;
|
||||
banner->text = {};
|
||||
banner->colour = COLOUR_WHITE;
|
||||
banner->text_colour = COLOUR_WHITE;
|
||||
banner->textColour = TextColour::white;
|
||||
}
|
||||
return banner;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Identifiers.h"
|
||||
#include "../drawing/TextColour.h"
|
||||
#include "../ride/RideTypes.h"
|
||||
#include "Location.hpp"
|
||||
|
||||
@@ -38,7 +39,7 @@ struct Banner
|
||||
mutable std::string formattedTextBuffer;
|
||||
uint8_t colour{};
|
||||
RideId ride_index{};
|
||||
uint8_t text_colour{};
|
||||
OpenRCT2::TextColour textColour{};
|
||||
TileCoordsXY position;
|
||||
|
||||
bool IsNull() const
|
||||
|
||||
Reference in new issue
Block a user