2
* Component for robot selection
4
* @author Adrian Friebel
8
#include <srCore/simulationRobotSelectionComponent.h>
9
#include <srCore/simulationArenaComponent.h>
10
#include <srCore/robot/robotActorBase.h>
11
#include <srCore/simulationEvents.h>
13
using namespace srCore;
15
////////////////////////////////////////////////////////////////////
16
SimulationRobotSelectionComponent::SimulationRobotSelectionComponent(const std::string &name, int robFoc)
17
: dtGame::GMComponent(name)
19
mFocusChanged = new dtDAL::GameEvent( ROBOT_SELECTION_CHANGED );
20
dtDAL::GameEventManager::GetInstance().AddEvent(*mFocusChanged);
26
void SimulationRobotSelectionComponent::init()
28
std::vector< dtGame::GameActorProxy* > allGameActors;
29
GetGameManager()->GetAllGameActors(allGameActors);
31
for(int i=0; i<(int)allGameActors.size(); i++)
33
RobotActorBase &actor = static_cast<RobotActorBase&>(allGameActors[i]->GetGameActor());
35
if(robotFocus == actor.getID())
38
actor.setSelectionState(true);
39
actor.renderCollisionGeometry(true);
46
//////////////////////////////////////////////////////////////////////////
47
void SimulationRobotSelectionComponent::sendMessageToAll(dtDAL::GameEvent &event)
49
dtCore::RefPtr<dtGame::GameEventMessage> eventMsg;
50
GetGameManager()->GetMessageFactory().CreateMessage(dtGame::MessageType::INFO_GAME_EVENT, eventMsg);
52
eventMsg->SetGameEvent(event);
53
GetGameManager()->SendMessage(*eventMsg);
57
//////////////////////////////////////////////////////////////////////////
58
void SimulationRobotSelectionComponent::ProcessMessage(const dtGame::Message& message)
60
if (message.GetMessageType() == dtGame::MessageType::INFO_GAME_EVENT)
62
const dtGame::GameEventMessage &eventMsg = static_cast<const dtGame::GameEventMessage&>(message);
63
// printf("Robot Selection Component: %s\n", eventMsg.GetGameEvent()->GetName().c_str());
65
if(eventMsg.GetGameEvent() != NULL)
67
if(eventMsg.GetGameEvent()->GetName() == CHANGE_ROBOT_SELECTION )
70
SimulationArenaComponent *comp = static_cast<SimulationArenaComponent*>(GetGameManager()->GetComponentByName("SimulationArenaComponent"));
72
if(comp->getNumRobots()>0)
74
std::vector< dtGame::GameActorProxy* > allGameActors;
75
GetGameManager()->GetAllGameActors(allGameActors);
77
RobotActorBase &actor = static_cast<RobotActorBase&>(allGameActors[robotFocusIndex]->GetGameActor());
78
actor.setSelectionState(false);
79
actor.renderCollisionGeometry(false);
81
std::string number = eventMsg.GetGameEvent()->GetDescription();
84
robotFocusIndex = (robotFocusIndex+1) % comp->getNumRobots();
85
RobotActorBase &actor = static_cast<RobotActorBase&>(allGameActors[robotFocusIndex]->GetGameActor());
86
robotFocus = actor.getID();
87
actor.setSelectionState(true);
88
actor.renderCollisionGeometry(true);
92
robotFocus = atoi(number.c_str());
94
for(int i=0; i<comp->getNumRobots(); i++)
96
RobotActorBase &actor = static_cast<RobotActorBase&>(allGameActors[i]->GetGameActor());
98
if(robotFocus == actor.getID())
101
actor.setSelectionState(true);
102
actor.renderCollisionGeometry(true);
107
sendMessageToAll(*mFocusChanged);
110
if(eventMsg.GetGameEvent()->GetName() == DESTROY_ACTOR )
112
SimulationArenaComponent *comp = static_cast<SimulationArenaComponent*>(GetGameManager()->GetComponentByName("SimulationArenaComponent"));
114
if(comp->getNumRobots()>0)
116
robotFocusIndex = (robotFocusIndex+1) % comp->getNumRobots();
117
std::vector< dtGame::GameActorProxy* > allGameActors;
118
GetGameManager()->GetAllGameActors(allGameActors);
120
RobotActorBase &actor = static_cast<RobotActorBase&>(allGameActors[robotFocusIndex]->GetGameActor());
121
robotFocus = actor.getID();
122
actor.setSelectionState(true);
123
actor.renderCollisionGeometry(true);
127
robotFocusIndex = -1;
130
sendMessageToAll(*mFocusChanged);