Primitive entity player-selection in ScEd

This was SVN commit r1727.
This commit is contained in:
Ykkrosh 2005-01-16 23:09:41 +00:00
parent 2e58a8fd21
commit 1c044ac229
14 changed files with 117 additions and 11 deletions

View File

@ -2,9 +2,10 @@
<!ELEMENT Entities (Entity*)>
<!ELEMENT Entity (Template,Position,Orientation)>
<!ELEMENT Entity (Template,Player,Position,Orientation)>
<!ELEMENT Template (#PCDATA)>
<!ELEMENT Player (#PCDATA)>
<!ELEMENT Position EMPTY>
<!ATTLIST Position

View File

@ -214,6 +214,7 @@ void CMapReader::ReadXML(const char* filename)
EL(entities);
EL(entity);
EL(template);
EL(player);
EL(position);
EL(orientation);
AT(x);
@ -245,6 +246,7 @@ void CMapReader::ReadXML(const char* filename)
// <entity>
CStrW TemplateName;
int PlayerID;
CVector3D Position;
float Orientation;
@ -259,6 +261,11 @@ void CMapReader::ReadXML(const char* filename)
// <template>
TemplateName = child.getText();
}
else if (element_name == el_player)
{
// <player>
PlayerID = CStr(child.getText()).ToInt();
}
else if (element_name == el_position)
{
// <position>
@ -279,7 +286,8 @@ void CMapReader::ReadXML(const char* filename)
debug_warn("Invalid XML data - DTD shouldn't allow this");
}
g_EntityManager.create(g_EntityTemplateCollection.getTemplate(TemplateName), Position, Orientation);
HEntity ent = g_EntityManager.create(g_EntityTemplateCollection.getTemplate(TemplateName), Position, Orientation);
ent->m_player = PlayerID;
}
}
else

View File

@ -279,6 +279,8 @@ void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan)
XML_Setting("Template", entity->m_base->m_Tag);
XML_Setting("Player", entity->m_player);
{
CVector3D position = entity->m_position;

View File

@ -19,6 +19,9 @@
#include "scripting/JSInterface_Vector3D.h"
// TODO: don't hardcode player-colours
static const float PlayerColours[8][3] = { {1,1,1}, {1,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,0.5,0} };
CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
{
m_position = position;
@ -66,6 +69,8 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
m_selected = false;
m_grouped = -1;
m_player = 1;
}
CEntity::~CEntity()
@ -495,12 +500,22 @@ void CEntity::render()
void CEntity::renderSelectionOutline( float alpha )
{
#ifdef SCED
extern CTerrain g_Terrain;
CTerrain *pTerrain = &g_Terrain;
#else
CTerrain *pTerrain = g_Game->GetWorld()->GetTerrain();
#endif
if( !m_bounds ) return;
glColor4f( 1.0f, 1.0f, 1.0f, alpha );
if( getCollisionObject( this ) ) glColor4f( 1.0f, 0.5f, 0.5f, alpha );
if( getCollisionObject( this ) )
glColor4f( 1.0f, 0.5f, 0.5f, alpha );
else
{
int player = min(max(1, m_player), 8) - 1;
glColor4f( PlayerColours[player][0], PlayerColours[player][1], PlayerColours[player][2], alpha);
}
glBegin( GL_LINE_LOOP );

View File

@ -68,6 +68,9 @@ public:
bool m_selected;
i32 m_grouped;
// The player that owns this entity. TODO: do this properly (if this way is wrong)
int m_player;
// If this unit has been removed from the gameworld but has still
// has references.
bool m_destroyed;
@ -165,7 +168,7 @@ public:
void teleport(); // Fixes things if the position is changed by something externally.
void checkSelection(); // In case anyone tries to select/deselect this through JavaScript.
void checkGroup(); // Groups
void checkExtant(); // Existance
void checkExtant(); // Existence
// Returns the default action of the entity upon the target (or -1 if none apply)
int CEntity::defaultOrder( CEntity* orderTarget );

View File

@ -38,7 +38,7 @@ void CCommandManager::Append(CCommand* cmd)
}
// update history position to point at last command executed
m_HistoryPos=m_CommandHistory.size()-1;
m_HistoryPos=(i32)m_CommandHistory.size()-1;
}
}

View File

@ -347,7 +347,7 @@ void CEditorData::OnScreenShot(const char* filename)
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// SubmitModelRecursive: recurse down given model, submitting it and all it's descendents to the
// SubmitModelRecursive: recurse down given model, submitting it and all its descendants to the
// renderer
void SubmitModelRecursive(CModel* model)
{
@ -407,7 +407,7 @@ void CEditorData::RenderWorld()
// render all the units
RenderModels();
// flush prior to rendering overlays etc
// flush prior to rendering overlays etc
g_Renderer.FlushFrame();
}
@ -495,6 +495,12 @@ void CEditorData::OnDraw()
// .. and here's the overlays
g_MiniMap.Render();
m_InfoBox.Render();
const std::vector<CUnit*>& units=g_UnitMan.GetUnits();
for (size_t i=0;i<units.size();++i)
if (units[i]->GetEntity())
units[i]->GetEntity()->renderSelectionOutline();
} else {
g_Renderer.SetClearColor(0x00453015);
g_Renderer.BeginFrame();

View File

@ -41,7 +41,8 @@ void CPaintObjectCommand::Finalize()
CVector3D orient = m_Unit->GetModel()->GetTransform().GetIn();
CVector3D position = m_Unit->GetModel()->GetTransform().GetTranslation();
g_UnitMan.RemoveUnit(m_Unit);
g_EntityManager.create( templateObject, position, atan2( -orient.X, -orient.Z ) );
HEntity ent = g_EntityManager.create( templateObject, position, atan2( -orient.X, -orient.Z ) );
ent->m_player = 1;
}
}

View File

@ -112,3 +112,12 @@ void CSelectObjectTool::RenderUnitBounds(CUnit* unit)
glPopMatrix();
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// GetFirstEntity: return the entity of the first selected object
CEntity* CSelectObjectTool::GetFirstEntity()
{
if (m_SelectedUnits.size() == 0)
return NULL;
return m_SelectedUnits[0]->GetEntity();
}

View File

@ -10,6 +10,7 @@
#include "Model.h"
class CUnit;
class CEntity;
class CSelectObjectTool : public CBrushTool
{
@ -21,6 +22,10 @@ public:
// tool triggered via left mouse button; paint current selection
void OnLButtonDown(unsigned int flags,int px,int py) { SelectObject(flags,px,py); }
// return the entity of the first selected object, or null if it can't
// (TODO: less hackiness, for the whole player-selection system)
CEntity* GetFirstEntity();
// get the default select object instance
static CSelectObjectTool* GetTool() { return &m_SelectObjectTool; }

View File

@ -43,6 +43,9 @@
#include "RaiseElevationTool.h"
#include "BrushShapeEditorTool.h"
#include "SelectObjectTool.h"
#include "simulation/Entity.h"
extern CTerrain g_Terrain;
extern CLightEnv g_LightEnv;
@ -90,6 +93,14 @@ BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_COMMAND(IDR_UNIT_TOOLS, OnUnitTools)
ON_COMMAND(ID_RANDOM_MAP, OnRandomMap)
//}}AFX_MSG_MAP
ON_COMMAND(ID_PLAYER_PLAYER1, OnEntityPlayer1)
ON_COMMAND(ID_PLAYER_PLAYER2, OnEntityPlayer2)
ON_COMMAND(ID_PLAYER_PLAYER3, OnEntityPlayer3)
ON_COMMAND(ID_PLAYER_PLAYER4, OnEntityPlayer4)
ON_COMMAND(ID_PLAYER_PLAYER5, OnEntityPlayer5)
ON_COMMAND(ID_PLAYER_PLAYER6, OnEntityPlayer6)
ON_COMMAND(ID_PLAYER_PLAYER7, OnEntityPlayer7)
ON_COMMAND(ID_PLAYER_PLAYER8, OnEntityPlayer8)
END_MESSAGE_MAP()
static UINT indicators[] =
@ -852,3 +863,14 @@ void CMainFrame::OnRandomMap()
g_MiniMap.Rebuild();
*/
}
#define P(n) void CMainFrame::OnEntityPlayer##n() { return OnEntityPlayerX(n); }
P(1) P(2) P(3) P(4) P(5) P(6) P(7) P(8)
#undef P
void CMainFrame::OnEntityPlayerX(int x)
{
CEntity* entity = CSelectObjectTool::GetTool()->GetFirstEntity();
if (entity)
entity->m_player = x;
}

View File

@ -108,6 +108,17 @@ protected:
afx_msg void OnRandomMap();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnEntityPlayer1();
afx_msg void OnEntityPlayer2();
afx_msg void OnEntityPlayer3();
afx_msg void OnEntityPlayer4();
afx_msg void OnEntityPlayer5();
afx_msg void OnEntityPlayer6();
afx_msg void OnEntityPlayer7();
afx_msg void OnEntityPlayer8();
afx_msg void OnEntityPlayerX(int x);
};
/////////////////////////////////////////////////////////////////////////////

View File

@ -165,6 +165,20 @@ BEGIN
MENUITEM SEPARATOR
MENUITEM "Ra&ndom Map", ID_RANDOM_MAP
END
POPUP "E&ntity"
BEGIN
POPUP "&Player"
BEGIN
MENUITEM "Player &1", ID_PLAYER_PLAYER1
MENUITEM "Player &2", ID_PLAYER_PLAYER2
MENUITEM "Player &3", ID_PLAYER_PLAYER3
MENUITEM "Player &4", ID_PLAYER_PLAYER4
MENUITEM "Player &5", ID_PLAYER_PLAYER5
MENUITEM "Player &6", ID_PLAYER_PLAYER6
MENUITEM "Player &7", ID_PLAYER_PLAYER7
MENUITEM "Player &8", ID_PLAYER_PLAYER8
END
END
POPUP "&Tools"
BEGIN
MENUITEM "&Options", ID_TOOLS_OPTIONS

View File

@ -1,5 +1,5 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Microsoft Visual C++ generated include file.
// Used by ScEd.rc
//
#define IDD_ABOUTBOX 100
@ -100,6 +100,15 @@
#define ID_TEST_STOP 32797
#define ID_TEST_GO 32798
#define ID_RANDOM_MAP 32799
#define ID_ENTITY_PLAYER 32800
#define ID_PLAYER_PLAYER1 32801
#define ID_PLAYER_PLAYER2 32802
#define ID_PLAYER_PLAYER3 32803
#define ID_PLAYER_PLAYER4 32804
#define ID_PLAYER_PLAYER5 32805
#define ID_PLAYER_PLAYER6 32806
#define ID_PLAYER_PLAYER7 32807
#define ID_PLAYER_PLAYER8 32808
// Next default values for new objects
//
@ -107,7 +116,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 156
#define _APS_NEXT_COMMAND_VALUE 32800
#define _APS_NEXT_COMMAND_VALUE 32809
#define _APS_NEXT_CONTROL_VALUE 1044
#define _APS_NEXT_SYMED_VALUE 101
#endif