Make ImGui-based AF Editor build (and work, mostly)

A problem with the ImGui-based ingame editors is that when clicking
into the game window the cursor is grabbed by the game again (because
then the ImGui window doesn't have focus anymore) and it's hard to get
it back.
I feel like the ingame editor integration could overall be better, maybe
with a command to launch a menu that allows launching and editor; that
command could also free the mousecursor?
This commit is contained in:
Daniel Gibson 2025-02-01 01:17:33 +01:00
parent 680775d84c
commit 92d57119bb
13 changed files with 97 additions and 92 deletions

View file

@ -834,6 +834,16 @@ set(src_imgui ${src_imgui}
tools/imgui/ImGuiTools.cpp
tools/imgui/util/ImGui_IdWidgets.h
tools/imgui/util/ImGui_IdWidgets.cpp
tools/imgui/afeditor/AfEditor.h
tools/imgui/afeditor/AfEditor.cpp
tools/imgui/afeditor/AfBodyEditor.h
tools/imgui/afeditor/AfBodyEditor.cpp
tools/imgui/afeditor/AfConstraintEditor.h
tools/imgui/afeditor/AfConstraintEditor.cpp
tools/imgui/afeditor/AfPropertyEditor.h
tools/imgui/afeditor/AfPropertyEditor.cpp
tools/imgui/lighteditor/LightEditor.h
tools/imgui/lighteditor/LightEditor.cpp
tools/imgui/pdaeditor/PDAEditor.h

View file

@ -1260,6 +1260,22 @@ static void Com_EditLights_f( const idCmdArgs &args ) {
#endif
}
/*
==================
Com_EditAFs_f
==================
*/
static void Com_EditAFs_f( const idCmdArgs &args ) {
// TODO: cvarSystem->SetCVarInteger( "g_editEntityMode", 3 ); ?
#ifndef IMGUI_DISABLE
ImGuiTools::AfEditorInit();
#elif defined(ID_ALLOW_TOOLS)
AFEditorInit( NULL );
#else
common->Warning( "Editors not available because dhewm3 was built without ImGui or MFC Tools" );
#endif
}
#ifdef ID_ALLOW_TOOLS
/*
==================
@ -1280,15 +1296,6 @@ static void Com_EditDecls_f( const idCmdArgs &args ) {
DeclBrowserInit( NULL );
}
/*
==================
Com_EditAFs_f
==================
*/
static void Com_EditAFs_f( const idCmdArgs &args ) {
AFEditorInit( NULL );
}
/*
==================
Com_EditParticles_f
@ -2355,11 +2362,11 @@ void idCommonLocal::InitCommands( void ) {
// editors
cmdSystem->AddCommand( "editLights", Com_EditLights_f, CMD_FL_TOOL, "launches the in-game Light Editor" );
cmdSystem->AddCommand( "editAFs", Com_EditAFs_f, CMD_FL_TOOL, "launches the in-game Articulated Figure Editor" );
#ifdef ID_ALLOW_TOOLS
cmdSystem->AddCommand( "editor", Com_Editor_f, CMD_FL_TOOL, "launches the level editor Radiant" );
cmdSystem->AddCommand( "editSounds", Com_EditSounds_f, CMD_FL_TOOL, "launches the in-game Sound Editor" );
cmdSystem->AddCommand( "editDecls", Com_EditDecls_f, CMD_FL_TOOL, "launches the in-game Declaration Editor" );
cmdSystem->AddCommand( "editAFs", Com_EditAFs_f, CMD_FL_TOOL, "launches the in-game Articulated Figure Editor" );
cmdSystem->AddCommand( "editParticles", Com_EditParticles_f, CMD_FL_TOOL, "launches the in-game Particle Editor" );
cmdSystem->AddCommand( "editScripts", Com_EditScripts_f, CMD_FL_TOOL, "launches the in-game Script Editor" );
cmdSystem->AddCommand( "editGUIs", Com_EditGUIs_f, CMD_FL_TOOL, "launches the GUI Editor" );

View file

@ -29,6 +29,7 @@ If you have questions concerning this license or the applicable additional terms
#ifndef __STR_H__
#define __STR_H__
#include "sys/platform.h" // ID_INLINE
#include "idlib/CmdArgs.h"
/*

View file

@ -37,7 +37,7 @@ If you have questions concerning this license or the applicable additional terms
#include "sys/sys_imgui.h"
// TODO #include "afeditor/AfEditor.h"
#include "afeditor/AfEditor.h"
#include "lighteditor/LightEditor.h"
#include "pdaeditor/PDAEditor.h"
@ -130,11 +130,10 @@ void DrawToolWindows()
{
LightEditor::Instance().Draw();
}
/* TODO
else if( AfEditor::Instance().IsShown() )
{
AfEditor::Instance().Draw();
}*/
}
else if ( PDAEditor::Instance().IsShown() )
{
PDAEditor::Instance().Draw();
@ -167,11 +166,9 @@ void LightEditorInit( const idDict* dict )
void AfEditorInit() // TODO: why no passed spawnargs?
{
/* TODO
D3::ImGuiHooks::OpenWindow( D3::ImGuiHooks::D3_ImGuiWin_AfEditor );
AfEditor::Instance().ShowIt( true );
impl::SetReleaseToolMouse( true );
*/
}
void PDAEditorInit(const idDict* dict)

View file

@ -27,12 +27,13 @@ If you have questions concerning this license or the applicable additional terms
===========================================================================
*/
#include "precompiled.h"
#pragma hdrstop
#include "AfBodyEditor.h"
#include "../imgui/BFGimgui.h"
#include "framework/Game.h"
#include "idlib/geometry/TraceModel.h"
#include "renderer/Model.h"
#define ARRAY_COUNT IM_ARRAYSIZE
static const char* bodyTypeNames[] =
{
@ -91,7 +92,7 @@ bool AfBodyEditor::Do()
bool changed = false;
ImGui::InputText( "##rename", &renameBody );
ImGui::InputTextStr( "##rename", &renameBody );
ImGui::SameLine();
if( ImGui::Button( "Rename" ) )
{
@ -136,7 +137,7 @@ bool AfBodyEditor::Do()
changed = true;
}
changed = ImGui::Combo( "Modify", ( int* )&body->jointMod, modifyJointsNames, ARRAY_COUNT( modifyJointsNames ) ) || changed;
changed = ImGui::InputText( "Contained Joints", &body->containedJoints ) || changed;
changed = ImGui::InputTextStr( "Contained Joints", &body->containedJoints ) || changed;
}
ImGui::PopID();
@ -353,4 +354,4 @@ static bool ModelTypeItemGetter( void* data, int index, const char** out )
*out = bodyTypeNames[index];
return true;
}
}

View file

@ -31,6 +31,9 @@ If you have questions concerning this license or the applicable additional terms
#include "../util/ImGui_IdWidgets.h"
#include "idlib/containers/StrList.h"
#include "framework/DeclAF.h"
namespace ImGuiTools
{
@ -69,4 +72,4 @@ private:
idStrList joints;
};
}
}

View file

@ -27,12 +27,12 @@ If you have questions concerning this license or the applicable additional terms
===========================================================================
*/
#include "precompiled.h"
#pragma hdrstop
#include "AfConstraintEditor.h"
#include "../imgui/BFGimgui.h"
#include "framework/Game.h"
#include "renderer/Model.h"
#define ARRAY_COUNT IM_ARRAYSIZE
static const char* constraintTypeNames[] =
{
@ -104,7 +104,7 @@ bool AfConstraintEditor::Do()
bool changed = false;
ImGui::InputText( "##rename", &renameConstraint );
ImGui::InputTextStr( "##rename", &renameConstraint );
ImGui::SameLine();

View file

@ -29,7 +29,10 @@ If you have questions concerning this license or the applicable additional terms
#pragma once
#include "../util/Imgui_IdWidgets.h"
#include "../util/ImGui_IdWidgets.h"
#include "framework/DeclAF.h"
#include "idlib/containers/StrList.h"
namespace ImGuiTools
{

View file

@ -27,40 +27,13 @@ If you have questions concerning this license or the applicable additional terms
===========================================================================
*/
#include "precompiled.h"
#pragma hdrstop
#include "AfEditor.h"
#include "../imgui/BFGimgui.h"
#include "../framework/DeclAF.h"
#include "../util/ImGui_IdWidgets.h"
#include "../util/Imgui_IdWidgets.h"
#include "framework/FileSystem.h"
#include "framework/Game.h"
extern idCVar af_useLinearTime;
extern idCVar af_useImpulseFriction;
extern idCVar af_useJointImpulseFriction;
extern idCVar af_useSymmetry;
extern idCVar af_skipSelfCollision;
extern idCVar af_skipLimits;
extern idCVar af_skipFriction;
extern idCVar af_forceFriction;
extern idCVar af_maxLinearVelocity;
extern idCVar af_showTimings;
extern idCVar af_showConstraints;
extern idCVar af_showConstraintNames;
extern idCVar af_showConstrainedBodies;
extern idCVar af_showPrimaryOnly;
extern idCVar af_showTrees;
extern idCVar af_showLimits;
extern idCVar af_showBodies;
extern idCVar af_showBodyNames;
extern idCVar af_showMass;
extern idCVar af_showTotalMass;
extern idCVar af_showInertia;
extern idCVar af_showVelocity;
extern idCVar af_showActive;
extern idCVar af_testSolid;
namespace
{
@ -72,7 +45,7 @@ static idDeclAF_Constraint emptyConstraint;
static int linearTolerance = 10;
static int angularTolerance = 10;
static idStrStatic<256> currentBody;
static idStr currentBody; // was idStrStatic<256>
static int bodyLength = 8;
static int bodyWidth = 16;
static int bodyHeight = 20;
@ -159,7 +132,7 @@ namespace ImGuiTools
static bool BodyItemGetter( void* data, int index, const char** items );
static bool ConstraintItemGetter( void* data, int index, const char** items );
static bool CVarCheckBox( const char* label, idCVar* cvar );
static bool CVarCheckBox( const char* label, const char* cvarname );
AfEditor::AfEditor()
: isShown( false )
@ -181,8 +154,8 @@ AfEditor::~AfEditor()
{
delete propertyEditor;
}
bodyEditors.DeleteContents();
constraintEditors.DeleteContents();
bodyEditors.DeleteContents( true );
constraintEditors.DeleteContents( true );
}
void AfEditor::Init()
@ -192,7 +165,7 @@ void AfEditor::Init()
void AfEditor::Draw()
{
bool showTool = isShown;
static char buff[256];
//static char buff[256];
if( ImGui::Begin( "AF Editor", &showTool, ImGuiWindowFlags_MenuBar ) )
{
@ -266,7 +239,7 @@ void AfEditor::Draw()
ImGui::SameLine();
ImGui::SmallButton( "New File" );
ImGui::InputText( "AF Name", &fileName );
ImGui::InputTextStr( "AF Name", &fileName );
if( ImGui::Button( "Create" ) )
{
idStr afName = fileName;
@ -343,14 +316,16 @@ void AfEditor::Draw()
{
if( ImGui::BeginTabItem( "View" ) )
{
CVarCheckBox( "Show Bodies", &af_showBodies );
CVarCheckBox( "Show Body Names", &af_showBodyNames );
CVarCheckBox( "Show Constraints", &af_showConstraints );
CVarCheckBox( "Show Constraint Names", &af_showConstraintNames );
CVarCheckBox( "Show Limits", &af_showLimits );
CVarCheckBox( "Show Active ", &af_showActive );
CVarCheckBox( "Show Trees", &af_showTrees );
CVarCheckBox( "Show Mass", &af_showMass );
// the CVars must be fetched by name because they're from the Game DLL
// TODO: alternatively, the cvars could be fetched in Init() and kept around
CVarCheckBox( "Show Bodies", "af_showBodies" );
CVarCheckBox( "Show Body Names", "af_showBodyNames" );
CVarCheckBox( "Show Constraints", "af_showConstraints" );
CVarCheckBox( "Show Constraint Names", "af_showConstraintNames" );
CVarCheckBox( "Show Limits", "af_showLimits" );
CVarCheckBox( "Show Active ", "af_showActive" );
CVarCheckBox( "Show Trees", "af_showTrees" );
CVarCheckBox( "Show Mass", "af_showMass" );
ImGui::EndTabItem();
}
@ -561,7 +536,7 @@ void AfEditor::Draw()
}
catch( idException& exception )
{
common->DWarning( "AfEditor exception %s", exception.GetError() );
common->DWarning( "AfEditor exception %s", exception.error );
}
}
}
@ -572,6 +547,7 @@ void AfEditor::Draw()
// TODO: do the same as when pressing cancel?
isShown = showTool;
impl::SetReleaseToolMouse( false );
D3::ImGuiHooks::CloseWindow( D3::ImGuiHooks::D3_ImGuiWin_AfEditor );
}
}
@ -582,8 +558,8 @@ void AfEditor::OnNewDecl( idDeclAF* newDecl )
{
delete propertyEditor;
}
bodyEditors.DeleteContents();
constraintEditors.DeleteContents();
bodyEditors.DeleteContents( true );
constraintEditors.DeleteContents( true );
propertyEditor = new AfPropertyEditor( newDecl );
@ -665,15 +641,19 @@ bool ConstraintItemGetter( void* data, int index, const char** items )
return true;
}
static bool CVarCheckBox( const char* label, idCVar* cvar )
static bool CVarCheckBox( const char* label, const char* cvarName )
{
bool value = cvar->GetBool();
if( ImGui::Checkbox( label, &value ) )
idCVar* cvar = cvarSystem->Find( cvarName );
if( cvar != NULL )
{
cvar->SetBool( value );
return true;
bool value = cvar->GetBool();
if( ImGui::Checkbox( label, &value ) )
{
cvar->SetBool( value );
return true;
}
}
return false;
}
}
}

View file

@ -36,6 +36,8 @@ If you have questions concerning this license or the applicable additional terms
#include "AfConstraintEditor.h"
#include "AfPropertyEditor.h"
#include "framework/DeclAF.h"
namespace ImGuiTools
{
@ -119,4 +121,4 @@ inline bool AfEditor::IsShown() const
}
#endif
#endif

View file

@ -27,13 +27,8 @@ If you have questions concerning this license or the applicable additional terms
===========================================================================
*/
#include "precompiled.h"
#pragma hdrstop
#include "AfPropertyEditor.h"
#include "../imgui/BFGimgui.h"
namespace ImGuiTools
{
AfPropertyEditor::AfPropertyEditor( idDeclAF* newDecl )
@ -65,7 +60,7 @@ bool AfPropertyEditor::Do()
decl->model = modelDefs[currentModel];
changed = true;
}
ImGui::InputText( "Skin", &decl->skin, ImGuiInputTextFlags_CharsNoBlank );
ImGui::InputTextStr( "Skin", &decl->skin, ImGuiInputTextFlags_CharsNoBlank );
}
if( ImGui::CollapsingHeader( "Default Collision Detection" ) )
@ -136,4 +131,4 @@ void AfPropertyEditor::UpdateModelDefList()
}
}
}
}

View file

@ -30,7 +30,10 @@ If you have questions concerning this license or the applicable additional terms
#ifndef EDITOR_TOOLS_AFPROPERTYEDITOR_H_
#define EDITOR_TOOLS_AFPROPERTYEDITOR_H_
#include "../util/Imgui_IdWidgets.h"
#include "../util/ImGui_IdWidgets.h"
#include "framework/DeclAF.h"
#include "idlib/containers/StrList.h"
namespace ImGuiTools
{
@ -59,4 +62,4 @@ private:
}
#endif
#endif

View file

@ -29,6 +29,9 @@ If you have questions concerning this license or the applicable additional terms
#pragma once
#include "sys/sys_imgui.h"
#include "idlib/Str.h"
// FIXME: put this in a namespace
/**