2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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?
|
|
|
|
|
2010-02-18 00:21:49 +01:00
|
|
|
#ifndef INCLUDED_INTERACT
|
|
|
|
#define INCLUDED_INTERACT
|
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
#include <vector>
|
2006-09-30 17:46:40 +02:00
|
|
|
#include <map>
|
2005-01-27 16:31:06 +01:00
|
|
|
|
2006-11-12 05:02:36 +01:00
|
|
|
#include "CStr.h"
|
2004-07-20 21:30:35 +02:00
|
|
|
#include "Singleton.h"
|
2006-06-09 20:32:00 +02:00
|
|
|
#include "simulation/EntityHandles.h"
|
|
|
|
#include "ps/Vector2D.h"
|
2005-01-27 16:31:06 +01:00
|
|
|
#include "lib/input.h"
|
2006-06-09 18:44:16 +02:00
|
|
|
#include "lib/res/handle.h"
|
2004-07-20 21:30:35 +02:00
|
|
|
|
2006-06-09 20:32:00 +02:00
|
|
|
class CVector3D;
|
|
|
|
class CUnit;
|
2006-07-13 05:29:33 +02:00
|
|
|
class CEntityTemplate;
|
2006-06-09 20:32:00 +02:00
|
|
|
class CBoundingObject;
|
|
|
|
|
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()
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
ClearSelection();
|
2004-11-11 08:09:32 +01:00
|
|
|
m_group = -1;
|
|
|
|
m_group_highlight = -1;
|
2005-05-18 07:32:09 +02:00
|
|
|
m_defaultCommand = -1;
|
2005-12-29 09:42:44 +01:00
|
|
|
m_defaultAction = -1;
|
2006-01-16 11:56:12 +01:00
|
|
|
m_secondaryCommand = -1;
|
|
|
|
m_secondaryAction = -1;
|
2004-11-11 08:09:32 +01:00
|
|
|
m_selectionChanged = true;
|
2006-01-21 12:04:09 +01:00
|
|
|
m_mouseOverMM = false;
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
LoadUnitUiTextures();
|
2006-03-31 05:30:34 +02:00
|
|
|
}
|
|
|
|
~CSelectedEntities()
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
DestroyUnitUiTextures();
|
2004-11-11 08:09:32 +01:00
|
|
|
}
|
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;
|
2006-01-21 12:04:09 +01:00
|
|
|
bool m_mouseOverMM;
|
2005-05-18 07:32:09 +02:00
|
|
|
int m_defaultCommand;
|
2005-12-29 09:42:44 +01:00
|
|
|
int m_defaultAction;
|
2006-01-16 11:56:12 +01:00
|
|
|
int m_secondaryCommand;
|
|
|
|
int m_secondaryAction;
|
2004-07-20 21:30:35 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
void AddSelection( HEntity entity );
|
|
|
|
void RemoveSelection( HEntity entity );
|
|
|
|
void SetSelection( HEntity entity );
|
|
|
|
void ClearSelection();
|
|
|
|
void RemoveAll( HEntity entity );
|
|
|
|
bool IsSelected( HEntity entity );
|
|
|
|
CVector3D GetSelectionPosition();
|
|
|
|
|
|
|
|
void AddToGroup( i8 groupid, HEntity entity );
|
|
|
|
void SaveGroup( i8 groupid );
|
|
|
|
void LoadGroup( i8 groupid );
|
|
|
|
void AddGroup( i8 groupid );
|
|
|
|
void ChangeGroup( HEntity entity, i8 groupid );
|
|
|
|
void HighlightGroup( i8 groupid );
|
|
|
|
void HighlightNone();
|
|
|
|
int GetGroupCount( i8 groupid );
|
|
|
|
CVector3D GetGroupPosition( i8 groupid );
|
|
|
|
|
|
|
|
void Update();
|
|
|
|
|
|
|
|
void RenderSelectionOutlines();
|
|
|
|
void RenderOverlays();
|
|
|
|
void RenderAuras();
|
|
|
|
void RenderRallyPoints();
|
|
|
|
void RenderBars();
|
|
|
|
void RenderHealthBars();
|
|
|
|
void RenderStaminaBars();
|
|
|
|
void RenderRanks();
|
|
|
|
void RenderBarBorders();
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
void DestroyUnitUiTextures();
|
|
|
|
int LoadUnitUiTextures();
|
2009-11-03 22:46:35 +01:00
|
|
|
typedef std::map<CStrW, Handle> MapFilenameToHandle;
|
|
|
|
MapFilenameToHandle m_unitUITextures;
|
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;
|
2007-05-02 14:07:08 +02:00
|
|
|
void Update( float timestep );
|
|
|
|
|
|
|
|
void AddSelection();
|
|
|
|
void RemoveSelection();
|
|
|
|
void SetSelection();
|
|
|
|
|
|
|
|
void ExpandAcrossScreen();
|
|
|
|
void ExpandAcrossWorld();
|
|
|
|
|
|
|
|
void RenderSelectionOutlines();
|
|
|
|
void RenderOverlays();
|
|
|
|
void RenderRallyPoints();
|
|
|
|
void RenderAuras();
|
|
|
|
void RenderBars();
|
|
|
|
void RenderHealthBars();
|
|
|
|
void RenderStaminaBars();
|
|
|
|
void RenderRanks();
|
|
|
|
void RenderBarBorders();
|
|
|
|
|
|
|
|
bool IsBandbox() { return( m_bandbox ); }
|
|
|
|
void StartBandbox( u16 x, u16 y );
|
|
|
|
void StopBandbox();
|
|
|
|
|
|
|
|
void Clear() { m_mouseover.clear(); }
|
2004-07-20 21:30:35 +02:00
|
|
|
};
|
|
|
|
|
2005-09-05 21:48:28 +02:00
|
|
|
struct CBuildingPlacer : public Singleton<CBuildingPlacer>
|
|
|
|
{
|
|
|
|
CBuildingPlacer()
|
|
|
|
{
|
|
|
|
m_active = false;
|
2005-10-30 00:50:54 +02:00
|
|
|
m_actor = 0;
|
|
|
|
m_bounds = 0;
|
2005-09-05 21:48:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CStrW m_templateName;
|
2006-07-13 05:29:33 +02:00
|
|
|
CEntityTemplate* m_template;
|
2005-09-05 21:48:28 +02:00
|
|
|
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
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
bool Activate( CStrW& templateName );
|
|
|
|
void Deactivate();
|
|
|
|
void MousePressed();
|
|
|
|
void MouseReleased();
|
|
|
|
void Update( float timeStep );
|
2007-07-14 08:15:19 +02:00
|
|
|
void CheckValidLocation( CVector3D pos, bool onSocket );
|
|
|
|
bool IsWithinLimit( CVector3D pos );
|
2005-09-05 21:48:28 +02:00
|
|
|
};
|
|
|
|
|
2007-05-02 14:07:08 +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();
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
InReaction InteractInputHandler( const SDL_Event_* ev );
|
2004-07-21 18:34:07 +02:00
|
|
|
|
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
|
|
|
|
2010-02-18 00:21:49 +01:00
|
|
|
#endif // INCLUDED_INTERACT
|