Duplicating lights with Ctrl+D works now

This commit is contained in:
Robert Beckebans 2023-12-10 17:00:07 +01:00
parent 563f1be37d
commit 08be7a35f9
4 changed files with 64 additions and 7 deletions

View file

@ -644,6 +644,22 @@ void idDict::Delete( const char* key )
#endif
}
// RB
void idDict::DeleteEmptyKeys()
{
idList<idKeyValue> orig = args;
for( int i = 0; i < orig.Num(); i++ )
{
const idKeyValue& kv = orig[ i ];
if( kv.GetValue().Length() == 0 )
{
Delete( kv.GetKey() );
}
}
}
/*
================
idDict::MatchPrefix

View file

@ -104,20 +104,28 @@ public:
// set the granularity for the index
void SetGranularity( int granularity );
// set hash size
void SetHashSize( int hashSize );
// clear existing key/value pairs and copy all key/value pairs from other
idDict& operator=( const idDict& other );
// copy from other while leaving existing key/value pairs in place
void Copy( const idDict& other );
// clear existing key/value pairs and transfer key/value pairs from other
void TransferKeyValues( idDict& other );
// parse dict from parser
bool Parse( idParser& parser );
// copy key/value pairs from other dict not present in this dict
void SetDefaults( const idDict* dict );
// clear dict freeing up memory
void Clear();
// print the dict
void Print() const;
@ -167,17 +175,25 @@ public:
int GetNumKeyVals() const;
const idKeyValue* GetKeyVal( int index ) const;
// returns the key/value pair with the given key
// returns NULL if the key/value pair does not exist
const idKeyValue* FindKey( const char* key ) const;
// returns the index to the key/value pair with the given key
// returns -1 if the key/value pair does not exist
int FindKeyIndex( const char* key ) const;
// delete the key/value pair with the given key
void Delete( const char* key );
// RB: delete all keys with a "" value
void DeleteEmptyKeys();
// finds the next key/value pair with the given key prefix.
// lastMatch can be used to do additional searches past the first match.
const idKeyValue* MatchPrefix( const char* prefix, const idKeyValue* lastMatch = NULL ) const;
// randomly chooses one of the key/value pairs with the given key prefix and returns it's value
const char* RandomPrefix( const char* prefix, idRandom& random ) const;

View file

@ -459,6 +459,9 @@ void LightEditor::Reset()
//boundsSnap[] = { 0.1f, 0.1f, 0.1f };
boundSizing = false;
boundSizingSnap = false;
shortcutSaveMapEnabled = true;
shortcutDuplicateLightEnabled = true;
}
namespace
@ -642,6 +645,8 @@ void LightEditor::SaveChanges( bool saveMap )
gameEdit->MapCopyDictToEntityAtOrigin( entityPos, &d );
}
original = cur;
if( saveMap )
{
gameEdit->MapSave();
@ -670,6 +675,7 @@ void LightEditor::DuplicateLight()
// spawn the new light
idDict d;
cur.ToDict( &d );
d.DeleteEmptyKeys();
entityName = gameEdit->GetUniqueEntityName( "light" );
d.Set( "name", entityName );
@ -681,6 +687,9 @@ void LightEditor::DuplicateLight()
if( light )
{
gameEdit->MapAddEntity( &d );
gameEdit->ClearEntitySelection();
gameEdit->AddSelectedEntity( light );
Init( &d, light );
}
}
@ -715,13 +724,15 @@ void LightEditor::Draw()
// TODO use view direction like just global values
if( io.KeyCtrl )
{
if( io.KeysDown[K_S] )
if( io.KeysDown[K_S] && shortcutSaveMapEnabled )
{
SaveChanges( true );
shortcutSaveMapEnabled = false;
}
else if( io.KeysDown[K_D] )
else if( io.KeysDown[K_D] && shortcutDuplicateLightEnabled )
{
DuplicateLight();
shortcutDuplicateLightEnabled = false;
}
}
else if( io.KeyAlt )
@ -764,6 +775,17 @@ void LightEditor::Draw()
changes = true;
}
// reenable commands if keys were released
if( ( !io.KeyCtrl || !io.KeysDown[K_S] ) && !shortcutSaveMapEnabled )
{
shortcutSaveMapEnabled = true;
}
if( ( !io.KeyCtrl || !io.KeysDown[K_D] ) && !shortcutDuplicateLightEnabled )
{
shortcutDuplicateLightEnabled = true;
}
if( !entityName.IsEmpty() )
{
ImGui::SeparatorText( entityName.c_str() );
@ -1067,11 +1089,11 @@ void LightEditor::Draw()
DuplicateLight();
}
if( ImGui::MenuItem( "Delete", "Backspace" ) )
{
// TODO
goto exitLightEditor;
}
//if( ImGui::MenuItem( "Delete", "Backspace" ) )
//{
// TODO
// goto exitLightEditor;
//}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();

View file

@ -123,6 +123,9 @@ private:
bool boundSizing = false;
bool boundSizingSnap = false;
bool shortcutSaveMapEnabled;
bool shortcutDuplicateLightEnabled;
void LoadLightStyles();
static bool StyleItemsGetter( void* data, int idx, const char** out_text );