2004-07-20 21:30:35 +02:00
|
|
|
// Interact.h
|
|
|
|
//
|
|
|
|
// Manages main-screen interaction (screen->worldspace mapping, unit selection, ordering, etc.)
|
2004-07-21 18:34:07 +02:00
|
|
|
// and the hotkey message processor.
|
2004-07-20 21:30:35 +02:00
|
|
|
// Does this belong in GUI?
|
|
|
|
|
|
|
|
// Mark Thompson (mot20@cam.ac.uk / mark@wildfiregames.com)
|
|
|
|
|
|
|
|
#include <vector>
|
2005-01-27 16:31:06 +01:00
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
#include "Singleton.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "EntityMessage.h"
|
2005-09-06 10:25:41 +02:00
|
|
|
#include "Collision.h"
|
2004-07-20 21:30:35 +02:00
|
|
|
#include "Scheduler.h"
|
|
|
|
#include "Camera.h"
|
2005-01-27 16:31:06 +01:00
|
|
|
#include "lib/input.h"
|
2004-07-20 21:30:35 +02:00
|
|
|
|
2004-08-03 01:14:54 +02:00
|
|
|
#define MAX_BOOKMARKS 10
|
|
|
|
#define MAX_GROUPS 20
|
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
// CSelectedEntities: the singleton containing entities currently selected on the local machine.
|
|
|
|
// (including group allocations on the local machine)
|
|
|
|
|
|
|
|
struct CSelectedEntities : public Singleton<CSelectedEntities>
|
|
|
|
{
|
2004-11-11 08:09:32 +01:00
|
|
|
CSelectedEntities()
|
|
|
|
{
|
|
|
|
clearSelection();
|
|
|
|
m_group = -1;
|
|
|
|
m_group_highlight = -1;
|
2005-05-18 07:32:09 +02:00
|
|
|
m_defaultCommand = -1;
|
2004-11-11 08:09:32 +01:00
|
|
|
m_selectionChanged = true;
|
|
|
|
}
|
2004-10-07 21:23:35 +02:00
|
|
|
std::vector<HEntity> m_selected;
|
|
|
|
std::vector<HEntity> m_groups[MAX_GROUPS];
|
2004-08-03 01:14:54 +02:00
|
|
|
i8 m_group, m_group_highlight;
|
2004-11-11 08:09:32 +01:00
|
|
|
bool m_selectionChanged;
|
2005-05-18 07:32:09 +02:00
|
|
|
int m_defaultCommand;
|
2004-07-20 21:30:35 +02:00
|
|
|
|
2004-10-07 21:23:35 +02:00
|
|
|
void addSelection( HEntity entity );
|
|
|
|
void removeSelection( HEntity entity );
|
|
|
|
void setSelection( HEntity entity );
|
2004-07-20 21:30:35 +02:00
|
|
|
void clearSelection();
|
2004-10-07 21:23:35 +02:00
|
|
|
void removeAll( HEntity entity );
|
|
|
|
bool isSelected( HEntity entity );
|
2004-07-20 21:30:35 +02:00
|
|
|
CVector3D getSelectionPosition();
|
|
|
|
|
2004-10-07 21:23:35 +02:00
|
|
|
void addToGroup( i8 groupid, HEntity entity );
|
2004-08-03 01:14:54 +02:00
|
|
|
void saveGroup( i8 groupid );
|
|
|
|
void loadGroup( i8 groupid );
|
|
|
|
void addGroup( i8 groupid );
|
2004-10-07 21:23:35 +02:00
|
|
|
void changeGroup( HEntity entity, i8 groupid );
|
2004-08-03 01:14:54 +02:00
|
|
|
void highlightGroup( i8 groupid );
|
2004-07-20 21:30:35 +02:00
|
|
|
void highlightNone();
|
2004-08-03 01:14:54 +02:00
|
|
|
int getGroupCount( i8 groupid );
|
|
|
|
CVector3D getGroupPosition( i8 groupid );
|
2004-07-20 21:30:35 +02:00
|
|
|
|
2004-07-21 18:34:07 +02:00
|
|
|
void update();
|
2004-07-20 21:30:35 +02:00
|
|
|
|
|
|
|
void renderSelectionOutlines();
|
|
|
|
void renderOverlays();
|
2005-09-06 21:30:41 +02:00
|
|
|
void renderHealthBars();
|
2004-07-20 21:30:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// CMouseoverEntities: the singleton containing entities the mouse is currently hovering over or bandboxing
|
|
|
|
// ( for mouseover selection outlines )
|
|
|
|
|
|
|
|
struct SMouseoverFader
|
|
|
|
{
|
2004-10-07 21:23:35 +02:00
|
|
|
HEntity entity;
|
2004-07-20 21:30:35 +02:00
|
|
|
float fade;
|
|
|
|
bool isActive;
|
2004-10-07 21:23:35 +02:00
|
|
|
SMouseoverFader( HEntity _entity, float _fade = 0.0f, bool _active = true ) : entity( _entity ), fade( _fade ), isActive( _active ) {}
|
2004-07-20 21:30:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CMouseoverEntities : public Singleton<CMouseoverEntities>
|
|
|
|
{
|
|
|
|
float m_fadeinrate;
|
|
|
|
float m_fadeoutrate;
|
|
|
|
float m_fademaximum;
|
2004-08-03 01:14:54 +02:00
|
|
|
CVector2D m_worldposition;
|
2004-10-07 21:23:35 +02:00
|
|
|
HEntity m_target;
|
2004-11-11 08:09:32 +01:00
|
|
|
HEntity m_lastTarget;
|
|
|
|
bool m_targetChanged;
|
2004-07-20 21:30:35 +02:00
|
|
|
|
|
|
|
bool m_bandbox, m_viewall;
|
|
|
|
u16 m_x1, m_y1, m_x2, m_y2;
|
|
|
|
|
|
|
|
CMouseoverEntities()
|
|
|
|
{
|
|
|
|
m_bandbox = false;
|
|
|
|
m_viewall = false;
|
|
|
|
m_fadeinrate = 1.0f;
|
|
|
|
m_fadeoutrate = 2.0f;
|
|
|
|
m_fademaximum = 0.5f;
|
2004-08-03 01:14:54 +02:00
|
|
|
m_mouseover.clear();
|
2004-11-11 08:09:32 +01:00
|
|
|
m_targetChanged = true;
|
2004-07-20 21:30:35 +02:00
|
|
|
}
|
|
|
|
std::vector<SMouseoverFader> m_mouseover;
|
|
|
|
void update( float timestep );
|
|
|
|
|
|
|
|
void addSelection();
|
|
|
|
void removeSelection();
|
|
|
|
void setSelection();
|
|
|
|
|
|
|
|
void expandAcrossScreen();
|
|
|
|
void expandAcrossWorld();
|
|
|
|
|
|
|
|
void renderSelectionOutlines();
|
|
|
|
void renderOverlays();
|
2005-09-06 21:30:41 +02:00
|
|
|
void renderHealthBars();
|
2005-09-05 23:45:26 +02:00
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
bool isBandbox() { return( m_bandbox ); }
|
|
|
|
void startBandbox( u16 x, u16 y );
|
|
|
|
void stopBandbox();
|
|
|
|
};
|
|
|
|
|
2005-09-05 21:48:28 +02:00
|
|
|
struct CBuildingPlacer : public Singleton<CBuildingPlacer>
|
|
|
|
{
|
|
|
|
CBuildingPlacer()
|
|
|
|
{
|
|
|
|
m_active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CStrW m_templateName;
|
|
|
|
bool m_active;
|
|
|
|
bool m_clicked;
|
|
|
|
bool m_dragged;
|
|
|
|
float m_angle;
|
2005-09-06 10:25:41 +02:00
|
|
|
bool m_valid;
|
2005-09-05 21:48:28 +02:00
|
|
|
float m_timeSinceClick;
|
2005-09-06 10:25:41 +02:00
|
|
|
float m_totalTime;
|
2005-09-05 21:48:28 +02:00
|
|
|
CVector3D clickPos;
|
2005-09-06 10:25:41 +02:00
|
|
|
CUnit* m_actor;
|
|
|
|
CBoundingObject* m_bounds;
|
2005-09-05 21:48:28 +02:00
|
|
|
|
|
|
|
bool activate( CStrW& templateName );
|
2005-09-06 01:44:21 +02:00
|
|
|
void deactivate();
|
2005-09-05 21:48:28 +02:00
|
|
|
void mousePressed();
|
|
|
|
void mouseReleased();
|
|
|
|
void update( float timeStep );
|
|
|
|
void render();
|
|
|
|
};
|
|
|
|
|
2005-03-30 18:14:19 +02:00
|
|
|
bool isMouseoverType( CEntity* ev, void* userdata );
|
|
|
|
bool isOnScreen( CEntity* ev, void* userdata );
|
2004-07-20 21:30:35 +02:00
|
|
|
|
2005-05-18 07:32:09 +02:00
|
|
|
void StartCustomSelection();
|
|
|
|
void ResetInteraction();
|
|
|
|
|
2004-07-21 18:34:07 +02:00
|
|
|
int interactInputHandler( const SDL_Event* ev );
|
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
#define g_Selection CSelectedEntities::GetSingleton()
|
|
|
|
#define g_Mouseover CMouseoverEntities::GetSingleton()
|
2005-09-05 21:48:28 +02:00
|
|
|
#define g_BuildingPlacer CBuildingPlacer::GetSingleton()
|
2004-07-20 21:30:35 +02:00
|
|
|
|