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
105
106 |
#include "gfCParkOfficeTapComponent.h"
#include <fsCore/fsSColour.h>
#include <fsCore/fsPoint.h>
#include <fsAppCore/fsIInputManager.h>
#include <fsAppCore/src/fsCAppCoreMain.h>
#include <fsAppCore/src/fsCEntity.h>
#include <fsAppCore/fsIScene.h>
#include <fsRenderer/src/components/fsISpriteComponent.h>
#include "gfCParkLevelComponent.h"
const fsCUniqueId gfCParkOfficeTapComponent::mTypeId("gfCParkOfficeTapComponent");
namespace
{
gfCParkLevelComponent* parkLevelGet()
{
fsCEntity* const levelEnt =
fsCAppCoreMain::instanceGet()->sceneGet()->firstEntityWithComponentsOfFamilyType<gfCParkLevelComponent>();
return levelEnt ? levelEnt->firstComponentOfFamilyType<gfCParkLevelComponent>() : nullptr;
}
}
fsBool gfCParkOfficeTapComponent::hitTest(const fsPoint& pPointerPos) const
{
if (fsISpriteComponent* const sprComp = parentGet()->spriteComponentGet())
{
// Rect test, same reasoning as gfCParkSlotStaffComponent - the office art
// is drawn scaled, so a hit map would sample the wrong pixels.
return sprComp->hitTest(pPointerPos, false);
}
return false;
}
void gfCParkOfficeTapComponent::armToggle()<--- Either there is a missing 'override', or the member function 'gfCParkOfficeTapComponent::armToggle' can be static.
{
if (gfCParkLevelComponent* const parkLevel = parkLevelGet())
{
parkLevel->repairArmedSet(!parkLevel->repairArmedGet());
}
}
void gfCParkOfficeTapComponent::updateDo(fsS32 pDeltaMs)
{
fsISpriteComponent* const sprComp = parentGet()->spriteComponentGet();
if (!sprComp)
{
return;
}
const gfCParkLevelComponent* const parkLevel = parkLevelGet();
const fsS32 state = (parkLevel && parkLevel->repairArmedGet()) ? 1 : 0;
if (state == mTintState)
{
return;
}
mTintState = state;
// Amber while armed ("waiting for you to pick a building"), normal otherwise.
sprComp->colourSet(state == 1 ? fsSColour4B(255, 200, 90, 255) : fsSColour4B::fsWHITE());
}
void gfCParkOfficeTapComponent::listenersRegisterDo()
{
fsIMessageListener::listenersRegisterDo();
fsIInputManager::instanceGet()->listenerRegister(fsIInputManager::mPointerDownMsg, this);
}
void gfCParkOfficeTapComponent::listenersDeregisterDo()
{
fsIMessageListener::listenersDeregisterDo();
fsIInputManager::instanceGet()->listenerDeregister(fsIInputManager::mPointerDownMsg, this);
}
fsBool gfCParkOfficeTapComponent::messageProcessDo(const fsCUniqueId& pMessageType,
const fsIMessageDispatcher::sMessageParameters& pParam)
{
if (fsIInputManager::mPointerDownMsg == pMessageType)
{
const auto& params = static_cast<const fsIInputManager::sPointerMsgParam&>(pParam);
if (0 == params.mIdx && hitTest(params.mPos))
{
armToggle();
return true;
}
}
return false;
}
fsIComponent* const gfCParkOfficeTapComponent::create(fsCEntity* const pParent)
{
return new gfCParkOfficeTapComponent(pParent);
}
gfCParkOfficeTapComponent::gfCParkOfficeTapComponent(fsCEntity* const pParent):
fsIMessageListenerComponent(pParent),
mTintState(-1)
{
}
gfCParkOfficeTapComponent::~gfCParkOfficeTapComponent()
{
}
|