Hacked up ScEd a bit, to disable its actor editor and to let users place entities (rather than actors) on the map.

This was SVN commit r2039.
This commit is contained in:
Ykkrosh 2005-03-22 23:31:30 +00:00
parent f19d8dafee
commit 020645d583
16 changed files with 324 additions and 251 deletions

View File

@ -7,6 +7,7 @@
#include "timer.h"
#include "VFSUtil.h"
#include "ObjectBase.h"
#include "ObjectEntry.h"
#define LOG_CATEGORY "graphics"
@ -20,7 +21,7 @@ bool operator< (const CObjectManager::ObjectKey& a, const CObjectManager::Object
return a.ActorVariation < b.ActorVariation;
}
CObjectManager::CObjectManager() : m_SelectedObject(0)
CObjectManager::CObjectManager() : m_SelectedEntity(NULL)
{
m_ObjectTypes.reserve(32);
}
@ -29,8 +30,6 @@ template<typename T, typename S> void delete_pair_2nd(std::pair<T,S> v) { delete
CObjectManager::~CObjectManager()
{
m_SelectedObject = NULL;
for (size_t i = 0; i < m_ObjectTypes.size(); i++) {
std::for_each(
m_ObjectTypes[i].m_Objects.begin(),

View File

@ -2,8 +2,14 @@
#define _OBJECTMANAGER_H
#include <vector>
#include <map>
#include "Singleton.h"
#include "ObjectEntry.h"
#include "CStr.h"
#include "ObjectBase.h"
class CObjectBase;
class CObjectEntry;
class CBaseEntity;
// access to sole CObjectManager object
#define g_ObjMan CObjectManager::GetSingleton()
@ -53,15 +59,12 @@ public:
void AddObjectBase(CObjectBase* base);
void DeleteObjectBase(CObjectBase* base);
CObjectEntry* GetSelectedObject() const { return m_SelectedObject; }
void SetSelectedObject(CObjectEntry* obj) { m_SelectedObject=obj; }
CBaseEntity* m_SelectedEntity;
std::vector<SObjectType> m_ObjectTypes;
private:
void LoadObjectsIn(CStr& pathname);
CObjectEntry* m_SelectedObject;
};

View File

@ -14,6 +14,7 @@
#include "Unit.h"
#include "CConsole.h"
#include "ObjectManager.h"
#include "ObjectEntry.h"
extern CConsole* g_Console;

View File

@ -973,12 +973,15 @@ static int ProgressiveLoad()
break;
}
#ifndef NO_GUI
// display progress / description in loading screen
CStrW i18n_description = translate(description);
JSString* js_desc = StringConvert::wstring_to_jsstring(g_ScriptingHost.getContext(), i18n_description);
g_ScriptingHost.SetGlobal("g_Progress", INT_TO_JSVAL(progress_percent));
g_ScriptingHost.SetGlobal("g_LoadDescription", STRING_TO_JSVAL(js_desc));
g_GUI.SendEventToAll("progress");
#endif
return 0;
}

View File

@ -61,10 +61,12 @@ PSRETURN CGame::RegisterInit(CGameAttributes* pAttribs)
PSRETURN CGame::ReallyStartGame()
{
#ifndef NO_GUI
jsval rval;
JSBool ok = JS_CallFunctionName(g_ScriptingHost.getContext(),
g_GUI.GetScriptObject(), "reallyStartGame", 0, NULL, &rval);
assert(ok);
#endif
debug_out("GAME STARTED, ALL INIT COMPLETE\n");
m_GameStarted=true;

View File

@ -128,6 +128,19 @@ CBaseEntity* CBaseEntityCollection::getTemplateByActor( CStrW actorName )
return( NULL );
}
void CBaseEntityCollection::getTemplateNames( std::vector<CStrW>& names )
{
for( u16 t = 0; t < m_templates.size(); t++ )
names.push_back( m_templates[t]->m_Tag );
}
#ifdef SCED
CBaseEntity* CBaseEntityCollection::getTemplateByID( int n )
{
return m_templates[n];
}
#endif
CBaseEntityCollection::~CBaseEntityCollection()
{
for( u16 t = 0; t < m_templates.size(); t++ )

View File

@ -11,7 +11,7 @@
// Find an entity class by the actor it uses: g_EntityTemplateCollection.getTemplateByActor()
// Note that this is included solely for loading ScnEd 4,5 and 6 format map files. Don't rely on this
// working all the time.
// Find an entity class by it's name: g_EntityTemplateCollection.getTemplate()
// Find an entity class by its name: g_EntityTemplateCollection.getTemplate()
// g_EntityManager will also use this class to lookup entity templates when you instantiate an entity with
// a class name string.
@ -36,6 +36,15 @@ public:
void LoadDirectory( Handle directory, CStr pathname );
void addTemplate( CBaseEntity* temp );
CBaseEntity* getTemplateByActor( CStrW actorName );
// Create a list of the names of all templates, for display in ScEd's
// entity-selection box. (This isn't really very good, since it includes
// 'abstract' entity classes that should never be created, and it doesn't
// split them into useful categories or give them readable names.)
void getTemplateNames( std::vector<CStrW>& names );
#ifdef SCED // a slightly unpleasant hack, since ScEd can only remember numbers:
CBaseEntity* getTemplateByID( int n );
#endif
};
#endif

View File

@ -52,10 +52,10 @@ void CAlterLightEnvCommand::ApplyData(const CLightEnv& env)
unit->GetModel()->SetDirty(RENDERDATA_UPDATE_VERTICES);
}
CObjectEntry* selobject=g_ObjMan.GetSelectedObject();
if (selobject && selobject->m_Model) {
selobject->m_Model->SetDirty(RENDERDATA_UPDATE_VERTICES);
}
// CObjectEntry* selobject=g_ObjMan.GetSelectedObject();
// if (selobject && selobject->m_Model) {
// selobject->m_Model->SetDirty(RENDERDATA_UPDATE_VERTICES);
// }
}

View File

@ -20,6 +20,7 @@
#include "EntityManager.h"
#include "ConfigDB.h"
#include "Scheduler.h"
#include "Loader.h"
#include "XML.h"
@ -175,6 +176,16 @@ bool CEditorData::Init()
return false;
}
int progress_percent;
wchar_t description[100];
int ret2;
do
{
ret2 = LDR_ProgressiveLoad(100.f, description, ARRAY_SIZE(description), &progress_percent);
assert(ret2 == 0 || ret2 == 1 || ret2 == ERR_TIMED_OUT);
}
while (ret2 != 0);
// create the scene - terrain, camera, light environment etc
if (!InitScene()) return false;
@ -483,31 +494,31 @@ void CEditorData::OnDraw()
g_Renderer.SetClearColor(0x00453015);
g_Renderer.BeginFrame();
CObjectEntry* selobject=g_ObjMan.GetSelectedObject();
if (selobject && selobject->m_Model) {
// setup camera such that object is in the centre of the viewport
m_ModelMatrix.SetIdentity();
selobject->m_Model->SetTransform(m_ModelMatrix);
const CBound& bound=selobject->m_Model->GetBounds();
CVector3D pt((bound[0].X+bound[1].X)*0.5f,(bound[0].Y+bound[1].Y)*0.5f,bound[0].Z);
float hfov=tan(DEGTORAD(45));
float vfov=hfov/g_Renderer.GetAspect();
float zx=(bound[1].X-bound[0].X)*0.5f/hfov;
float zy=(bound[1].Y-bound[0].Y)*0.5f/vfov;
float z=zx>zy ? zx : zy;
z=(z+1)*2;
m_ObjectCamera.m_Orientation.SetIdentity();
m_ObjectCamera.m_Orientation.Translate(pt.X,pt.Y,-z);
g_Renderer.SetCamera(m_ObjectCamera);
RenderObEdGrid();
g_Renderer.Submit(selobject->m_Model);
}
// CObjectEntry* selobject=g_ObjMan.GetSelectedObject();
// if (selobject && selobject->m_Model) {
// // setup camera such that object is in the centre of the viewport
// m_ModelMatrix.SetIdentity();
// selobject->m_Model->SetTransform(m_ModelMatrix);
//
// const CBound& bound=selobject->m_Model->GetBounds();
// CVector3D pt((bound[0].X+bound[1].X)*0.5f,(bound[0].Y+bound[1].Y)*0.5f,bound[0].Z);
//
// float hfov=tan(DEGTORAD(45));
// float vfov=hfov/g_Renderer.GetAspect();
// float zx=(bound[1].X-bound[0].X)*0.5f/hfov;
// float zy=(bound[1].Y-bound[0].Y)*0.5f/vfov;
// float z=zx>zy ? zx : zy;
// z=(z+1)*2;
//
// m_ObjectCamera.m_Orientation.SetIdentity();
// m_ObjectCamera.m_Orientation.Translate(pt.X,pt.Y,-z);
//
// g_Renderer.SetCamera(m_ObjectCamera);
//
// RenderObEdGrid();
//
// g_Renderer.Submit(selobject->m_Model);
// }
// flush prior to rendering overlays ..
g_Renderer.FlushFrame();
@ -604,10 +615,10 @@ void CEditorData::UpdateWorld(float time)
g_EntityManager.updateAll( time );
}
} else {
CObjectEntry* selobject=g_ObjMan.GetSelectedObject();
if (selobject && selobject->m_Model) {
selobject->m_Model->Update(time);
}
// CObjectEntry* selobject=g_ObjMan.GetSelectedObject();
// if (selobject && selobject->m_Model) {
// selobject->m_Model->Update(time);
// }
}
}

View File

@ -11,8 +11,8 @@
#include "BaseEntityCollection.h"
#include "EntityManager.h"
CPaintObjectCommand::CPaintObjectCommand(CObjectEntry* object,const CMatrix3D& transform)
: m_Object(object), m_Transform(transform), m_Unit(0)
CPaintObjectCommand::CPaintObjectCommand(CBaseEntity* object,const CMatrix3D& transform)
: m_BaseEntity(object), m_Transform(transform), m_Entity()
{
}
@ -23,12 +23,28 @@ CPaintObjectCommand::~CPaintObjectCommand()
void CPaintObjectCommand::Execute()
{
// create new unit
m_Unit=new CUnit(m_Object,m_Object->m_Model->Clone());
m_Unit->GetModel()->SetTransform(m_Transform);
CVector3D orient = m_Transform.GetIn();
CVector3D position = m_Transform.GetTranslation();
m_Entity = g_EntityManager.create(m_BaseEntity, position, atan2(-orient.X, -orient.Z));
m_Entity->SetPlayer(g_Game->GetPlayer(1));
}
// add this unit to list of units stored in unit manager
g_UnitMan.AddUnit(m_Unit);
void CPaintObjectCommand::UpdateTransform(CMatrix3D& transform)
{
CVector3D orient = transform.GetIn();
CVector3D position = transform.GetTranslation();
// This is quite yucky, but nothing else seems to actually work:
m_Entity->m_position =
m_Entity->m_position_previous =
m_Entity->m_graphics_position = position;
m_Entity->teleport();
m_Entity->m_orientation =
m_Entity->m_orientation_previous =
m_Entity->m_graphics_orientation = atan2(-orient.X, -orient.Z);
m_Entity->reorient();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
@ -36,26 +52,26 @@ void CPaintObjectCommand::Execute()
// unit to entity if there's a template for it
void CPaintObjectCommand::Finalize()
{
CBaseEntity* templateObject = g_EntityTemplateCollection.getTemplateByActor(m_Object);
if( templateObject )
{
CVector3D orient = m_Unit->GetModel()->GetTransform().GetIn();
CVector3D position = m_Unit->GetModel()->GetTransform().GetTranslation();
g_UnitMan.RemoveUnit(m_Unit);
HEntity ent = g_EntityManager.create( templateObject, position, atan2( -orient.X, -orient.Z ) );
ent->SetPlayer(g_Game->GetPlayer(1));
}
// CBaseEntity* templateObject = g_EntityTemplateCollection.getTemplateByActor(m_Object);
// if( templateObject )
// {
// CVector3D orient = m_Unit->GetModel()->GetTransform().GetIn();
// CVector3D position = m_Unit->GetModel()->GetTransform().GetTranslation();
// g_UnitMan.RemoveUnit(m_Unit);
// HEntity ent = g_EntityManager.create( templateObject, position, atan2( -orient.X, -orient.Z ) );
// ent->SetPlayer(g_Game->GetPlayer(1));
// }
}
void CPaintObjectCommand::Undo()
{
// remove model from unit managers list
g_UnitMan.RemoveUnit(m_Unit);
// g_UnitMan.RemoveUnit(m_Unit);
}
void CPaintObjectCommand::Redo()
{
// add the unit back to the unit manager
g_UnitMan.AddUnit(m_Unit);
// g_UnitMan.AddUnit(m_Unit);
}

View File

@ -3,15 +3,16 @@
#include "Command.h"
#include "Matrix3D.h"
#include "Entity.h"
class CUnit;
class CObjectEntry;
class CBaseEntity;
class CPaintObjectCommand : public CCommand
{
public:
// constructor, destructor
CPaintObjectCommand(CObjectEntry* object,const CMatrix3D& transform);
CPaintObjectCommand(CBaseEntity* entity, const CMatrix3D& transform);
~CPaintObjectCommand();
// return the texture name of this command
@ -31,14 +32,16 @@ public:
// unit to entity if there's a template for it
void Finalize();
void UpdateTransform(CMatrix3D& transform);
// return unit added to world
CUnit* GetUnit() { return m_Unit; }
// CUnit* GetUnit() { return m_Unit; }
private:
// unit to add to world
CUnit* m_Unit;
// object to paint
CObjectEntry* m_Object;
HEntity m_Entity;
// entity to paint
CBaseEntity* m_BaseEntity;
// model transformation
CMatrix3D m_Transform;
};

View File

@ -11,6 +11,8 @@
#include "ObjectManager.h"
#include "PaintObjectCommand.h"
#include "BaseEntity.h"
// rotate object at 180 degrees each second when applying to terrain
#define ROTATION_SPEED PI
@ -36,15 +38,15 @@ void CPaintObjectTool::PaintSelection()
double curtime=get_time();
m_Rotation+=ROTATION_SPEED*float(curtime-m_LastTriggerTime);
BuildTransform();
m_PaintCmd->GetUnit()->GetModel()->SetTransform(m_ObjectTransform);
m_PaintCmd->UpdateTransform(m_ObjectTransform);
m_LastTriggerTime=curtime;
} else {
m_Rotation=0;
m_Position=m_SelectionPoint;
m_LastTriggerTime=get_time();
CObjectEntry* obj=g_ObjMan.GetSelectedObject();
if (obj && obj->m_Model) {
CBaseEntity* obj=g_ObjMan.m_SelectedEntity;
if (obj) {
// get up to date transform
BuildTransform();
@ -73,10 +75,13 @@ void CPaintObjectTool::OnDraw()
// don't draw object if we're currently rotating it on the terrain
if (m_PaintCmd) return;
// don't draw unless we have a valid object to apply
CObjectEntry* obj=g_ObjMan.GetSelectedObject();
if (!obj || !obj->m_Model) return;
CBaseEntity* ent=g_ObjMan.m_SelectedEntity;
if (!ent) return;
// don't draw unless we have a valid object to apply
CObjectEntry* obj = g_ObjMan.FindObject((CStr)ent->m_actorName);
if (!obj || !obj->m_Model) return;
// try to get object transform, in world space
m_Position=m_SelectionPoint;
BuildTransform();

View File

@ -786,23 +786,24 @@ static float getExactGroundLevel( float x, float y )
static CObjectEntry* GetRandomActorTemplate()
{
if (g_ObjMan.m_ObjectTypes.size()==0) return 0;
CObjectEntry* found=0;
int checkloop=250;
do {
u32 type=rand()%(u32)g_ObjMan.m_ObjectTypes.size();
u32 actorsoftype=(u32)g_ObjMan.m_ObjectTypes[type].m_Objects.size();
if (actorsoftype>0) {
found=g_ObjMan.m_ObjectTypes[type].m_Objects[rand()%actorsoftype];
if (found && found->m_Model && found->m_Model->GetModelDef()->GetNumBones()>0) {
} else {
found=0;
}
}
} while (--checkloop && !found);
return found;
return NULL;
// if (g_ObjMan.m_ObjectTypes.size()==0) return 0;
//
// CObjectEntry* found=0;
// int checkloop=250;
// do {
// u32 type=rand()%(u32)g_ObjMan.m_ObjectTypes.size();
// u32 actorsoftype=(u32)g_ObjMan.m_ObjectTypes[type].m_Objects.size();
// if (actorsoftype>0) {
// found=g_ObjMan.m_ObjectTypes[type].m_Objects[rand()%actorsoftype];
// if (found && found->m_Model && found->m_Model->GetModelDef()->GetNumBones()>0) {
// } else {
// found=0;
// }
// }
// } while (--checkloop && !found);
//
// return found;
}
static CTextureEntry* GetRandomTexture()

View File

@ -145,7 +145,7 @@ int CScEdView::OnCreate(LPCREATESTRUCT lpCreateStruct)
oglInit();
// check for minimum requirements
if(!oglExtAvail("GL_ARB_multitexture") || !oglExtAvail("GL_ARB_texture_env_combine")) {
if(!oglHaveExtension("GL_ARB_multitexture") || !oglHaveExtension("GL_ARB_texture_env_combine")) {
const char* err="No graphics card support for multitexturing found; please visit the 0AD Forums for more information.";
::MessageBox(0,err,"Error",MB_OK);
exit(0);

View File

@ -106,23 +106,23 @@ void CUnitPropertiesDlgBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoH
void CUnitPropertiesDlgBar::OnButtonBack()
{
// save current object (if we've got one) before going back
if (m_Object) {
CStr filename("art/actors/");
filename+=g_ObjMan.m_ObjectTypes[m_Object->m_Type].m_Name;
filename+="/";
filename+=m_Object->m_Name;
filename+=".xml";
if (! m_Object->Save((const char*) filename))
::MessageBox(0,"Error saving actor file","Error",MB_OK|MB_TASKMODAL);
// and rebuild the model
UpdateEditorData();
}
CMainFrame* mainfrm=(CMainFrame*) AfxGetMainWnd();
mainfrm->OnUnitTools();
// // save current object (if we've got one) before going back
// if (m_Object) {
//
// CStr filename("art/actors/");
// filename+=g_ObjMan.m_ObjectTypes[m_Object->m_Type].m_Name;
// filename+="/";
// filename+=m_Object->m_Name;
// filename+=".xml";
// if (! m_Object->Save((const char*) filename))
// ::MessageBox(0,"Error saving actor file","Error",MB_OK|MB_TASKMODAL);
//
// // and rebuild the model
// UpdateEditorData();
// }
//
// CMainFrame* mainfrm=(CMainFrame*) AfxGetMainWnd();
// mainfrm->OnUnitTools();
}
void CUnitPropertiesDlgBar::OnButtonRefresh()
@ -186,90 +186,90 @@ void CUnitPropertiesDlgBar::OnButtonModelBrowse()
void CUnitPropertiesDlgBar::UpdateEditorData()
{
if (!m_Object) {
g_ObjMan.SetSelectedObject(0);
return;
}
CString str;
CWnd* name=GetDlgItem(IDC_EDIT_NAME);
name->GetWindowText(str);
m_Object->m_Name=(const char*)str;
CWnd* model=GetDlgItem(IDC_EDIT_MODEL);
model->GetWindowText(str);
m_Object->m_ModelName=(const char*)str;
CWnd* texture=GetDlgItem(IDC_EDIT_TEXTURE);
texture->GetWindowText(str);
m_Object->m_TextureName=(const char*)str;
CWnd* animation=GetDlgItem(IDC_EDIT_ANIMATION);
animation->GetWindowText(str);
if (m_Object->m_Animations.size()==0) {
m_Object->m_Animations.resize(1);
m_Object->m_Animations[0].m_AnimName="Idle";
}
m_Object->m_Animations[0].m_FileName=(const char*)str;
std::vector<CUnit*> animupdatelist;
const std::vector<CUnit*>& units=g_UnitMan.GetUnits();
for (uint i=0;i<units.size();++i) {
if (units[i]->GetModel()->GetModelDef()==m_Object->m_Model->GetModelDef()) {
animupdatelist.push_back(units[i]);
}
}
if (m_Object->BuildModel()) {
g_ObjMan.SetSelectedObject(m_Object);
CSkeletonAnim* anim=m_Object->m_Model->GetAnimation();
if (anim) {
for (uint i=0;i<animupdatelist.size();++i) {
animupdatelist[i]->GetModel()->SetAnimation(anim);
}
}
} else {
g_ObjMan.SetSelectedObject(0);
}
// if (!m_Object) {
// g_ObjMan.SetSelectedObject(0);
// return;
// }
//
// CString str;
//
// CWnd* name=GetDlgItem(IDC_EDIT_NAME);
// name->GetWindowText(str);
// m_Object->m_Name=(const char*)str;
//
// CWnd* model=GetDlgItem(IDC_EDIT_MODEL);
// model->GetWindowText(str);
// m_Object->m_ModelName=(const char*)str;
//
// CWnd* texture=GetDlgItem(IDC_EDIT_TEXTURE);
// texture->GetWindowText(str);
// m_Object->m_TextureName=(const char*)str;
//
// CWnd* animation=GetDlgItem(IDC_EDIT_ANIMATION);
// animation->GetWindowText(str);
// if (m_Object->m_Animations.size()==0) {
// m_Object->m_Animations.resize(1);
// m_Object->m_Animations[0].m_AnimName="Idle";
// }
// m_Object->m_Animations[0].m_FileName=(const char*)str;
//
// std::vector<CUnit*> animupdatelist;
// const std::vector<CUnit*>& units=g_UnitMan.GetUnits();
// for (uint i=0;i<units.size();++i) {
// if (units[i]->GetModel()->GetModelDef()==m_Object->m_Model->GetModelDef()) {
// animupdatelist.push_back(units[i]);
// }
// }
// if (m_Object->BuildModel()) {
// g_ObjMan.SetSelectedObject(m_Object);
// CSkeletonAnim* anim=m_Object->m_Model->GetAnimation();
// if (anim) {
// for (uint i=0;i<animupdatelist.size();++i) {
// animupdatelist[i]->GetModel()->SetAnimation(anim);
// }
// }
// } else {
// g_ObjMan.SetSelectedObject(0);
// }
}
void CUnitPropertiesDlgBar::UpdatePropertiesDlg()
{
if (!m_Object) return;
CWnd* name=GetDlgItem(IDC_EDIT_NAME);
if (name) {
name->SetWindowText(m_Object->m_Name);
}
CWnd* model=GetDlgItem(IDC_EDIT_MODEL);
if (model) {
model->SetWindowText(m_Object->m_ModelName);
}
CWnd* texture=GetDlgItem(IDC_EDIT_TEXTURE);
if (texture) {
texture->SetWindowText(m_Object->m_TextureName);
}
CWnd* animation=GetDlgItem(IDC_EDIT_ANIMATION);
if (animation) {
if (m_Object->m_Animations.size()>0) {
animation->SetWindowText(m_Object->m_Animations[0].m_FileName);
}
}
// if (!m_Object) return;
//
// CWnd* name=GetDlgItem(IDC_EDIT_NAME);
// if (name) {
// name->SetWindowText(m_Object->m_Name);
// }
//
// CWnd* model=GetDlgItem(IDC_EDIT_MODEL);
// if (model) {
// model->SetWindowText(m_Object->m_ModelName);
// }
//
// CWnd* texture=GetDlgItem(IDC_EDIT_TEXTURE);
// if (texture) {
// texture->SetWindowText(m_Object->m_TextureName);
// }
//
// CWnd* animation=GetDlgItem(IDC_EDIT_ANIMATION);
// if (animation) {
// if (m_Object->m_Animations.size()>0) {
// animation->SetWindowText(m_Object->m_Animations[0].m_FileName);
// }
// }
}
void CUnitPropertiesDlgBar::SetObject(CObjectEntry* obj)
{
m_Object=obj;
if (m_Object) {
if (m_Object->BuildModel()) {
g_ObjMan.SetSelectedObject(m_Object);
} else {
g_ObjMan.SetSelectedObject(0);
}
}
UpdatePropertiesDlg();
// m_Object=obj;
// if (m_Object) {
// if (m_Object->BuildModel()) {
// g_ObjMan.SetSelectedObject(m_Object);
// } else {
// g_ObjMan.SetSelectedObject(0);
// }
// }
// UpdatePropertiesDlg();
}

View File

@ -8,6 +8,8 @@
#include "SelectObjectTool.h"
#include "ToolManager.h"
#include "BaseEntityCollection.h"
BEGIN_MESSAGE_MAP(CUnitToolsDlgBar, CDialogBar)
//{{AFX_MSG_MAP(CUnitToolsDlgBar)
// NOTE - the ClassWizard will add and remove mapping macros here.
@ -79,12 +81,16 @@ BOOL CUnitToolsDlgBar::OnInitDialog()
objecttypes->SetCurSel(0);
// set initial list contents
if (types.size()) {
const std::vector<CObjectEntry*>& objects=types[0].m_Objects;
for (uint i=0;i<objects.size();++i) {
listctrl->InsertItem(i,(const char*) objects[i]->m_Name,i);
}
}
// if (types.size()) {
// const std::vector<CObjectEntry*>& objects=types[0].m_Objects;
// for (uint i=0;i<objects.size();++i) {
// listctrl->InsertItem(i,(const char*) objects[i]->m_Name,i);
// }
// }
std::vector<CStrW> names;
g_EntityTemplateCollection.getTemplateNames(names);
for (size_t i = 0; i < names.size(); ++i)
listctrl->InsertItem(i, (CStr)names[i], i);
}
CButton* addunit=(CButton*) GetDlgItem(IDC_BUTTON_ADDUNIT);
@ -106,59 +112,59 @@ void CUnitToolsDlgBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler
void CUnitToolsDlgBar::OnButtonAdd()
{
bool foundname=false;
CSimpleEdit dlg("Enter Object Name");
while (!foundname && dlg.DoModal()==IDOK) {
// get object name
CString& name=dlg.m_Text;
if (name.GetLength()==0) {
MessageBox("Bad name","Error");
} else if (g_ObjMan.FindObject(name)!=0) {
MessageBox("Object with that name already exists","Error");
} else {
// add to list ctrl
CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
int index=listctrl->GetItemCount();
listctrl->InsertItem(index,(const char*) name,index);
// deselect current selection in list ctrl, if any
POSITION pos=listctrl->GetFirstSelectedItemPosition();
if (pos) {
int oldindex=listctrl->GetNextSelectedItem(pos);
listctrl->SetItemState(oldindex, 0, LVIS_SELECTED);
}
// select new entry
listctrl->SetItemState(index, LVIS_SELECTED, LVIS_SELECTED);
// now enter edit mode
CObjectEntry* obj=new CObjectEntry(GetCurrentObjectType());
obj->m_Name=(const char*)name;
g_ObjMan.AddObject(obj,GetCurrentObjectType());
CMainFrame* mainfrm=(CMainFrame*) AfxGetMainWnd();
mainfrm->OnObjectProperties(obj);
foundname=true;
}
}
// bool foundname=false;
// CSimpleEdit dlg("Enter Object Name");
// while (!foundname && dlg.DoModal()==IDOK) {
// // get object name
// CString& name=dlg.m_Text;
// if (name.GetLength()==0) {
// MessageBox("Bad name","Error");
// } else if (g_ObjMan.FindObject(name)!=0) {
// MessageBox("Object with that name already exists","Error");
// } else {
// // add to list ctrl
// CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
// int index=listctrl->GetItemCount();
// listctrl->InsertItem(index,(const char*) name,index);
//
// // deselect current selection in list ctrl, if any
// POSITION pos=listctrl->GetFirstSelectedItemPosition();
// if (pos) {
// int oldindex=listctrl->GetNextSelectedItem(pos);
// listctrl->SetItemState(oldindex, 0, LVIS_SELECTED);
// }
//
// // select new entry
// listctrl->SetItemState(index, LVIS_SELECTED, LVIS_SELECTED);
//
// // now enter edit mode
// CObjectEntry* obj=new CObjectEntry(GetCurrentObjectType());
// obj->m_Name=(const char*)name;
// g_ObjMan.AddObject(obj,GetCurrentObjectType());
//
// CMainFrame* mainfrm=(CMainFrame*) AfxGetMainWnd();
// mainfrm->OnObjectProperties(obj);
// foundname=true;
// }
// }
}
void CUnitToolsDlgBar::OnButtonEdit()
{
// get current selection, if any
CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
POSITION pos=listctrl->GetFirstSelectedItemPosition();
if (!pos) {
// nothing selected, nothing to do
return;
}
// get object at position
const std::vector<CObjectEntry*>& objects=g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects;
CObjectEntry* obj=objects[(intptr_t)pos-1];
CMainFrame* mainfrm=(CMainFrame*) AfxGetMainWnd();
mainfrm->OnObjectProperties(obj);
// // get current selection, if any
// CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
// POSITION pos=listctrl->GetFirstSelectedItemPosition();
// if (!pos) {
// // nothing selected, nothing to do
// return;
// }
//
// // get object at position
// const std::vector<CObjectEntry*>& objects=g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects;
// CObjectEntry* obj=objects[(intptr_t)pos-1];
// CMainFrame* mainfrm=(CMainFrame*) AfxGetMainWnd();
// mainfrm->OnObjectProperties(obj);
}
@ -169,7 +175,8 @@ void CUnitToolsDlgBar::OnClickListObjectBrowser(NMHDR* pNMHDR, LRESULT* pResult)
// deselect current selection in list ctrl, if any
POSITION pos=listctrl->GetFirstSelectedItemPosition();
if (pos) {
g_ObjMan.SetSelectedObject(g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects[(intptr_t)pos-1]);
// g_ObjMan.SetSelectedObject(g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects[(intptr_t)pos-1]);
g_ObjMan.m_SelectedEntity = g_EntityTemplateCollection.getTemplateByID((intptr_t)pos-1);
}
// shift to add mode
@ -186,18 +193,18 @@ int CUnitToolsDlgBar::GetCurrentObjectType()
void CUnitToolsDlgBar::OnSelChangeObjectTypes()
{
// clear out the listctrl
CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
listctrl->DeleteAllItems();
// add new items back to listbox
std::vector<CObjectEntry*>& objects=g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects;
for (uint i=0;i<objects.size();i++) {
// add to list ctrl
listctrl->InsertItem(i,(const char*) objects[i]->m_Name,i);
}
g_ObjMan.SetSelectedObject(0);
// // clear out the listctrl
// CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
// listctrl->DeleteAllItems();
//
// // add new items back to listbox
// std::vector<CObjectEntry*>& objects=g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects;
// for (uint i=0;i<objects.size();i++) {
// // add to list ctrl
// listctrl->InsertItem(i,(const char*) objects[i]->m_Name,i);
// }
//
// g_ObjMan.SetSelectedObject(0);
}
void CUnitToolsDlgBar::OnButtonSelect()