-
-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathBuildLastOfTab.cpp
More file actions
104 lines (88 loc) · 2.6 KB
/
Copy pathBuildLastOfTab.cpp
File metadata and controls
104 lines (88 loc) · 2.6 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "BuildLastOfTab.h"
#include <Utilities/GeneralUtils.h>
#include <Ext/House/Body.h>
#include <HouseClass.h>
#include <EventClass.h>
#include <SidebarClass.h>
static constexpr const char* BuildLastTabNames[4] =
{
"RebuildStructure",
"RebuildDefense",
"RebuildInfantry",
"RebuildVehicle",
};
static constexpr const char* BuildLastTabDescKeys[4] =
{
"RebuildStructure_Desc",
"RebuildDefense_Desc",
"RebuildInfantry_Desc",
"RebuildVehicle_Desc",
};
static constexpr const wchar_t* BuildLastTabUINames[4] =
{
L"Rebuild Structure",
L"Rebuild Defense",
L"Rebuild Infantry",
L"Rebuild Vehicle",
};
static constexpr const wchar_t* BuildLastTabUIDescs[4] =
{
L"Re-queue the last produced Power/Resources building.",
L"Re-queue the last produced Defense/Combat building.",
L"Re-queue the last produced Infantry unit.",
L"Re-queue the last produced Vehicle or Aircraft.",
};
template<int TabIndex>
const char* BuildLastOfTabCommandClass<TabIndex>::GetName() const
{
return BuildLastTabNames[TabIndex];
}
template<int TabIndex>
const wchar_t* BuildLastOfTabCommandClass<TabIndex>::GetUIName() const
{
return GeneralUtils::LoadStringUnlessMissing(BuildLastTabNames[TabIndex], BuildLastTabUINames[TabIndex]);
}
template<int TabIndex>
const wchar_t* BuildLastOfTabCommandClass<TabIndex>::GetUICategory() const
{
return CATEGORY_INTERFACE;
}
template<int TabIndex>
const wchar_t* BuildLastOfTabCommandClass<TabIndex>::GetUIDescription() const
{
static_assert(TabIndex >= 0 && TabIndex < 4, "TabIndex out of range");
return GeneralUtils::LoadStringUnlessMissing(BuildLastTabDescKeys[TabIndex], BuildLastTabUIDescs[TabIndex]);
}
template<int TabIndex>
void BuildLastOfTabCommandClass<TabIndex>::Execute(WWKey eInput) const
{
auto const pPlayer = HouseClass::CurrentPlayer;
if (!pPlayer)
return;
auto const pExt = HouseExt::ExtMap.Find(pPlayer);
if (!pExt)
return;
auto const typeIndex = pExt->LastBuiltPerTab[TabIndex];
if (typeIndex < 0)
return;
// Focus the sidebar to the corresponding tab.
if (SidebarClass::Instance.IsSidebarActive)
{
SidebarClass::Instance.ActiveTabIndex = TabIndex;
SidebarClass::Instance.SidebarNeedsRepaint();
}
auto const rtti = pExt->LastBuiltRTTIPerTab[TabIndex];
auto const isNaval = pExt->LastBuiltIsNavalPerTab[TabIndex];
EventClass::OutList.Add(EventClass(
pPlayer->ArrayIndex,
EventType::Produce,
static_cast<int>(rtti),
typeIndex,
isNaval ? TRUE : FALSE
));
}
// Explicit instantiations
template class BuildLastOfTabCommandClass<0>;
template class BuildLastOfTabCommandClass<1>;
template class BuildLastOfTabCommandClass<2>;
template class BuildLastOfTabCommandClass<3>;