From c6252fe3fce6b3054e6b80275bea0dc74e19bbd4 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Mon, 8 Feb 2010 16:40:20 +0100 Subject: [PATCH] add a feature shift-k to assign killtarget, not target like ctrl-k --- include/ientity.h | 2 +- plugins/entity/entity.cpp | 60 +++++++++++++++++++++++++++------------ radiant/entity.cpp | 21 +++++++++++++- 3 files changed, 63 insertions(+), 20 deletions(-) diff --git a/include/ientity.h b/include/ientity.h index 444e377..c74ed7c 100644 --- a/include/ientity.h +++ b/include/ientity.h @@ -124,7 +124,7 @@ public: virtual void setCounter(Counter* counter) = 0; - virtual void connectEntities(const scene::Path& e1, const scene::Path& e2) = 0; + virtual void connectEntities(const scene::Path& e1, const scene::Path& e2, int index) = 0; virtual void setLightRadii(bool lightRadii) = 0; virtual bool getLightRadii() = 0; diff --git a/plugins/entity/entity.cpp b/plugins/entity/entity.cpp index 441481d..16dd774 100644 --- a/plugins/entity/entity.cpp +++ b/plugins/entity/entity.cpp @@ -132,12 +132,23 @@ class ConnectEntities public: Entity* m_e1; Entity* m_e2; - ConnectEntities(Entity* e1, Entity* e2) : m_e1(e1), m_e2(e2) + int m_index; + ConnectEntities(Entity* e1, Entity* e2, int index) : m_e1(e1), m_e2(e2), m_index(index) { } + const char *keyname() + { + StringOutputStream key(16); + if(m_index <= 0) + return "target"; + if(m_index == 1) + return "killtarget"; + key << "target" << m_index; + return key.c_str(); + } void connect(const char* name) { - m_e1->setKeyValue("target", name); + m_e1->setKeyValue(keyname(), name); m_e2->setKeyValue("targetname", name); } typedef MemberCaller1 ConnectCaller; @@ -168,7 +179,7 @@ public: { EntityKeyValues::setCounter(counter); } - void connectEntities(const scene::Path& path, const scene::Path& targetPath) + void connectEntities(const scene::Path& path, const scene::Path& targetPath, int index) { Entity* e1 = ScenePath_getEntity(path); Entity* e2 = ScenePath_getEntity(targetPath); @@ -191,29 +202,42 @@ public: if(g_gameType == eGameTypeDoom3) { StringOutputStream key(16); - for(unsigned int i = 0; ; ++i) + if(index >= 0) { - key << "target"; - if(i != 0) - { - key << i; - } - const char* value = e1->getKeyValue(key.c_str()); - if(string_empty(value)) - { - e1->setKeyValue(key.c_str(), e2->getKeyValue("name")); - break; - } - key.clear(); + key << "target"; + if(index != 0) + { + key << index; + } + e1->setKeyValue(key.c_str(), e2->getKeyValue("name")); + key.clear(); + } + else + { + for(unsigned int i = 0; ; ++i) + { + key << "target"; + if(i != 0) + { + key << i; + } + const char* value = e1->getKeyValue(key.c_str()); + if(string_empty(value)) + { + e1->setKeyValue(key.c_str(), e2->getKeyValue("name")); + break; + } + key.clear(); + } } } else { - ConnectEntities connector(e1, e2); + ConnectEntities connector(e1, e2, index); const char* value = e2->getKeyValue("targetname"); if(string_empty(value)) { - value = e1->getKeyValue("target"); + value = e1->getKeyValue(connector.keyname()); } if(!string_empty(value)) { diff --git a/radiant/entity.cpp b/radiant/entity.cpp index 52be82f..a572539 100644 --- a/radiant/entity.cpp +++ b/radiant/entity.cpp @@ -258,7 +258,8 @@ void Entity_connectSelected() { GlobalEntityCreator().connectEntities( GlobalSelectionSystem().penultimateSelected().path(), - GlobalSelectionSystem().ultimateSelected().path() + GlobalSelectionSystem().ultimateSelected().path(), + 0 ); } else @@ -267,6 +268,22 @@ void Entity_connectSelected() } } +void Entity_killconnectSelected() +{ + if(GlobalSelectionSystem().countSelected() == 2) + { + GlobalEntityCreator().connectEntities( + GlobalSelectionSystem().penultimateSelected().path(), + GlobalSelectionSystem().ultimateSelected().path(), + 1 + ); + } + else + { + globalErrorStream() << "entityKillConnectSelected: exactly two instances must be selected\n"; + } +} + AABB Doom3Light_getBounds(const AABB& workzone) { AABB aabb(workzone); @@ -618,6 +635,7 @@ void Entity_constructMenu(GtkMenu* menu) create_menu_item_with_mnemonic(menu, "_Regroup", "GroupSelection"); create_menu_item_with_mnemonic(menu, "_Ungroup", "UngroupSelection"); create_menu_item_with_mnemonic(menu, "_Connect", "ConnectSelection"); + create_menu_item_with_mnemonic(menu, "_KillConnect", "KillConnectSelection"); create_menu_item_with_mnemonic(menu, "_Select Color...", "EntityColor"); create_menu_item_with_mnemonic(menu, "_Normalize Color...", "NormalizeColor"); } @@ -632,6 +650,7 @@ void Entity_Construct() GlobalCommands_insert("EntityColor", FreeCaller(), Accelerator('K')); GlobalCommands_insert("NormalizeColor", FreeCaller()); GlobalCommands_insert("ConnectSelection", FreeCaller(), Accelerator('K', (GdkModifierType)GDK_CONTROL_MASK)); + GlobalCommands_insert("KillConnectSelection", FreeCaller(), Accelerator('K', (GdkModifierType)(GDK_SHIFT_MASK))); GlobalCommands_insert("GroupSelection", FreeCaller()); GlobalCommands_insert("UngroupSelection", FreeCaller()); -- 2.39.2