Use same Instance pattern of AF editor for light editor

This commit is contained in:
Robert Beckebans 2023-09-29 20:26:08 +02:00
parent c6ae88310f
commit d337111fbe
3 changed files with 59 additions and 70 deletions

View file

@ -74,25 +74,14 @@ bool ReleaseMouseForTools()
void DrawToolWindows()
{
#if 0
ImGui::Begin( "Show Ingame Editors", &showToolWindows, 0 );
ImGui::Checkbox( "Light", &LightEditor::showIt );
ImGui::SameLine();
ImGui::Checkbox( "Particle", &showParticlesEditor );
#endif // 0
if( LightEditor::showIt )
if( LightEditor::Instance().IsShown() )
{
LightEditor::Draw();
LightEditor::Instance().Draw();
}
if( AfEditor::Instance().IsShown() )
else if( AfEditor::Instance().IsShown() )
{
AfEditor::Instance().Draw();
}
// TODO: other editor windows..
//ImGui::End();
}
void LightEditorInit( const idDict* dict, idEntity* ent )
@ -108,7 +97,7 @@ void LightEditorInit( const idDict* dict, idEntity* ent )
&& "LightEditorInit() must only be called with light entities or NULL!" );
LightEditor::showIt = true;
LightEditor::Instance().ShowIt( true );
impl::SetReleaseToolMouse( true );
LightEditor::ReInit( dict, ent );

View file

@ -4,7 +4,7 @@
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
Copyright (C) 2015 Daniel Gibson
Copyright (C) 2020-2021 Robert Beckebans
Copyright (C) 2020-2023 Robert Beckebans
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
@ -290,23 +290,18 @@ LightInfo::LightInfo()
// ########### LightEditor #############
// static
LightEditor LightEditor::TheLightEditor;
LightEditor& LightEditor::Instance()
{
static LightEditor instance;
return instance;
}
// static
bool LightEditor::showIt = false;
// static
void LightEditor::ReInit( const idDict* dict, idEntity* light )
{
// TODO: if the lighteditor is currently shown, show a warning first about saving current changes to the last light?
TheLightEditor.Init( dict, light );
}
// static
void LightEditor::Draw()
{
TheLightEditor.DrawWindow();
Instance().Init( dict, light );
}
void LightEditor::Init( const idDict* dict, idEntity* light )
@ -588,10 +583,10 @@ static float* vecToArr( idVec3& v )
return &v.x;
}
void LightEditor::DrawWindow()
void LightEditor::Draw()
{
bool showWindow = showIt;
if( ImGui::Begin( title, &showWindow ) ) //, ImGuiWindowFlags_ShowBorders ) )
bool showTool = isShown;
if( ImGui::Begin( title, &showTool ) ) //, ImGuiWindowFlags_ShowBorders ) )
{
bool changes = false;
@ -766,12 +761,12 @@ void LightEditor::DrawWindow()
if( ImGui::Button( "Save to .map" ) )
{
SaveChanges();
showWindow = false;
showTool = false;
}
else if( ImGui::SameLine(), ImGui::Button( "Cancel" ) )
{
CancelChanges();
showWindow = false;
showTool = false;
}
else if( changes )
{
@ -780,10 +775,10 @@ void LightEditor::DrawWindow()
}
ImGui::End();
if( showIt && !showWindow )
if( isShown && !showTool )
{
// TODO: do the same as when pressing cancel?
showIt = showWindow;
isShown = showTool;
impl::SetReleaseToolMouse( false );
}
}

View file

@ -4,6 +4,7 @@
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
Copyright (C) 2015 Daniel Gibson
Copyright (C) 2016-2023 Robert Beckebans
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
@ -57,12 +58,6 @@ public:
idVec3 color;
idVec3 origin;
#if 0 // FIXME: unused, delete?
bool fog;
idVec4 fogDensity;
#endif // 0
idVec3 lightRadius;
bool castShadows;
bool castSpecular;
@ -82,55 +77,65 @@ public:
class LightEditor
{
private:
idStr title;
idStr entityName;
idVec3 entityPos;
bool isShown;
LightInfo original;
LightInfo cur; // current status of the light
idStr title;
idStr entityName;
idVec3 entityPos;
idEntity* lightEntity;
LightInfo original;
LightInfo cur; // current status of the light
idList<idStr> textureNames;
int currentTextureIndex;
idImage* currentTexture;
const idMaterial* currentTextureMaterial;
idEntity* lightEntity;
idList<idStr> textureNames;
int currentTextureIndex;
idImage* currentTexture;
const idMaterial* currentTextureMaterial;
// RB: light style support
idList<idStr> styleNames;
int currentStyleIndex;
idList<idStr> styleNames;
int currentStyleIndex;
void LoadLightStyles();
static bool StyleItemsGetter( void* data, int idx, const char** out_text );
void LoadLightStyles();
static bool StyleItemsGetter( void* data, int idx, const char** out_text );
void Init( const idDict* dict, idEntity* light );
void Reset();
void Init( const idDict* dict, idEntity* light );
void Reset();
void LoadLightTextures();
static bool TextureItemsGetter( void* data, int idx, const char** out_text );
void LoadCurrentTexture();
void LoadLightTextures();
static bool TextureItemsGetter( void* data, int idx, const char** out_text );
void LoadCurrentTexture();
void DrawWindow();
void TempApplyChanges();
void SaveChanges();
void CancelChanges();
void TempApplyChanges();
void SaveChanges();
void CancelChanges();
LightEditor()
{
isShown = false;
Reset();
}
static LightEditor TheLightEditor; // FIXME: maybe at some point we could allow more than one..
public:
static void ReInit( const idDict* dict, idEntity* light );
static void Draw();
static LightEditor& Instance();
static void ReInit( const idDict* dict, idEntity* light );
static bool showIt;
inline void ShowIt( bool show )
{
isShown = show;
}
inline bool IsShown() const
{
return isShown;
}
void Draw();
};
} //namespace ImGuiTools
#endif /* NEO_TOOLS_EDITORS_LIGHTEDITOR_H_ */
#endif