-
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathFlyingStrings.cpp
More file actions
86 lines (69 loc) · 2.58 KB
/
Copy pathFlyingStrings.cpp
File metadata and controls
86 lines (69 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "FlyingStrings.h"
#include <Phobos.h>
#include <MapClass.h>
#include <Phobos.CRT.h>
#include <TacticalClass.h>
#include <BitFont.h>
#include <Utilities/EnumFunctions.h>
std::vector<FlyingStrings::Item> FlyingStrings::Data;
bool FlyingStrings::DrawAllowed(const CoordStruct& nCoords)
{
if (auto const pCell = MapClass::Instance.TryGetCellAt(nCoords))
return !(pCell->IsFogged() || pCell->IsShrouded());
return false;
}
void FlyingStrings::Add(const wchar_t* text, const CoordStruct& coords, ColorStruct color, Point2D pixelOffset)
{
Item item {};
item.Location = coords;
item.PixelOffset = pixelOffset;
item.CreationFrame = Unsorted::CurrentFrame;
item.Color = Drawing::RGB_To_Int(color);
PhobosCRT::wstrCopy(item.Text, text, 0x20);
Data.emplace_back(item);
}
void FlyingStrings::AddMoneyString(int amount, ObjectClass* pSource, HouseClass* pOwner,
AffectedHouse displayToHouses, const CoordStruct& coords, Point2D pixelOffset)
{
if (amount == 0 || !FlyingStrings::DrawAllowed(coords))
return;
if (displayToHouses != AffectedHouse::All && !EnumFunctions::CanTargetHouse(displayToHouses, pOwner, HouseClass::CurrentPlayer))
return;
if (pSource && pSource->VisualCharacter(false, nullptr) == VisualType::Hidden)
return;
const bool isPositive = amount > 0;
const ColorStruct color = isPositive ? ColorStruct { 0, 255, 0 } : ColorStruct { 255, 0, 0 };
wchar_t moneyStr[0x20];
swprintf_s(moneyStr, L"%ls%ls%d", isPositive ? L"+" : L"-", Phobos::UI::CostLabel, std::abs(amount));
int width = 0, height = 0;
BitFont::Instance->GetTextDimension(moneyStr, &width, &height, 120);
pixelOffset.X -= (width / 2);
FlyingStrings::Add(moneyStr, coords, color, pixelOffset);
}
void FlyingStrings::UpdateAll()
{
if (Data.empty())
return;
for (int i = Data.size() - 1; i >= 0; --i)
{
auto& dataItem = Data[i];
auto [point, visible] = TacticalClass::Instance->CoordsToClient(dataItem.Location);
point += dataItem.PixelOffset;
if (FlyingStrings::DrawAllowed(dataItem.Location))
{
RectangleStruct bound = DSurface::Temp->GetRect();
bound.Height -= 32;
if (Unsorted::CurrentFrame > dataItem.CreationFrame + Duration - 70)
{
point.Y -= (Unsorted::CurrentFrame - dataItem.CreationFrame);
DSurface::Temp->DrawText(dataItem.Text, &bound, &point, dataItem.Color, 0, TextPrintType::NoShadow);
}
else
{
DSurface::Temp->DrawText(dataItem.Text, &bound, &point, dataItem.Color, 0, TextPrintType::NoShadow);
}
}
if (Unsorted::CurrentFrame > dataItem.CreationFrame + Duration || Unsorted::CurrentFrame < dataItem.CreationFrame)
Data.erase(Data.begin() + i);
}
}