-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTileInspector.cpp
90 lines (64 loc) · 2 KB
/
TileInspector.cpp
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
87
88
89
#include "TileInspector.h"
#include "TextRender.h"
#include "../OreDepositYieldString.h"
#include "../Constants/Strings.h"
#include "../Constants/UiConstants.h"
#include "../MapObjects/OreDeposit.h"
#include <libOPHD/EnumTerrainType.h>
#include <NAS2D/StringFrom.h>
#include <map>
#include <sstream>
using namespace NAS2D;
namespace
{
const auto lineSpacing = 12;
const auto sectionSpacing = constants::Margin;
const std::map<TerrainType, std::string> terrainTypeStringTable =
{
{TerrainType::Dozed, constants::TileBulldozed},
{TerrainType::Clear, constants::TileClear},
{TerrainType::Rough, constants::TileRough},
{TerrainType::Difficult, constants::TileDifficult},
{TerrainType::Impassable, constants::TileImpassable},
};
}
TileInspector::TileInspector() :
Window{constants::WindowTileInspector},
btnClose{"Close", {this, &TileInspector::onClose}}
{
size({200, sWindowTitleBarHeight + lineSpacing * 5 + sectionSpacing + constants::Margin * 2});
btnClose.size({50, 20});
add(btnClose, size() - btnClose.size() - Vector{constants::Margin, constants::Margin});
}
void TileInspector::update()
{
if (!visible())
return;
if (!mTile)
return;
if(!mTile->excavated())
{
visible(false);
return;
}
Window::update();
auto position = mRect.position + NAS2D::Vector{5, 25};
const auto tilePosition = mTile->xy();
drawLabelAndValue(position, "Location: ", NAS2D::stringFrom(tilePosition));
position.y += lineSpacing;
drawLabelAndValue(position, "Terrain: ", terrainTypeStringTable.at(mTile->index()));
const auto* oreDeposit = mTile->oreDeposit();
position.y += lineSpacing + sectionSpacing;
drawLabelAndValue(position, "Has Ore Deposit: ", (oreDeposit ? "Yes" : "No"));
if (oreDeposit)
{
position.y += lineSpacing;
drawLabelAndValue(position, "Active: ", (oreDeposit->active() ? "Yes" : "No"));
position.y += lineSpacing;
drawLabelAndValue(position, "Yield: ", oreDepositYieldEnumToString(mTile->oreDeposit()->yield()));
}
}
void TileInspector::onClose()
{
visible(false);
}