Skip to content

Commit

Permalink
#6302: Add "Show definition" button for the "inherit" spawnarg
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 13, 2024
1 parent 8bf85d7 commit 5d0d366
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 1 deletion.
1 change: 1 addition & 0 deletions install/games/darkmod.game
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<entityInspector>
<property match="origin" category="Basic" type="vector3">The origin of this object in 3D space</property>
<property match="classname" category="Basic" type="classname">The classname of this entity. This must be a recognised class defined in one of the DEF files, and governs the overall behaviour of the entity</property>
<property match="inherit" category="Basic" type="inherit"></property>
<property match="name" category="Basic" type="text">The displayed name of this entity. This can be arbitrary, but must be unique across the entire map</property>
<property match="rotation" category="Basic" type="text" />
<property match="_color" category="Basic" type="colour" />
Expand Down
1 change: 1 addition & 0 deletions radiant/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ add_executable(darkradiant
ui/einspector/EntityPropertyEditor.cpp
ui/einspector/FloatPropertyEditor.cpp
ui/einspector/FxPropertyEditor.cpp
ui/einspector/InheritPropertyEditor.cpp
ui/einspector/ModelPropertyEditor.cpp
ui/einspector/PropertyEditor.cpp
ui/einspector/PropertyEditorFactory.cpp
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/einspector/ClassnamePropertyEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ui
{

/**
* PropertyEditor displaying a single browse button to allow the selection of
* PropertyEditor displaying a browse button to allow the selection of
* an EntityClass using the EntityClassChooser dialog.
*/
class ClassnamePropertyEditor :
Expand Down
51 changes: 51 additions & 0 deletions radiant/ui/einspector/InheritPropertyEditor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "InheritPropertyEditor.h"
#include "PropertyEditorFactory.h"

#include "i18n.h"
#include "ientity.h"
#include "ieclass.h"

#include <wx/panel.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include "wxutil/sourceview/DeclarationSourceView.h"

#include "wxutil/Bitmap.h"

namespace ui
{

// Main constructor
InheritPropertyEditor::InheritPropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key)
: PropertyEditor(entities),
_key(key)
{
auto mainVBox = new wxPanel(parent, wxID_ANY);
mainVBox->SetSizer(new wxBoxSizer(wxHORIZONTAL));

// Register the main widget in the base class
setMainWidget(mainVBox);

auto showDefinition = new wxButton(mainVBox, wxID_ANY, _("Show Definition..."));
showDefinition->SetBitmap(wxutil::GetLocalBitmap("decl.png"));
showDefinition->Bind(wxEVT_BUTTON, &InheritPropertyEditor::_onShowDefinition, this);

mainVBox->GetSizer()->Add(showDefinition, 0, wxALIGN_CENTER_VERTICAL | wxALL, 6);
}

void InheritPropertyEditor::_onShowDefinition(wxCommandEvent& ev)
{
auto parentClass = _entities.getSharedKeyValue(_key->getFullKey(), true);
auto eclass = GlobalEntityClassManager().findClass(parentClass);

if (eclass)
{
auto view = new wxutil::DeclarationSourceView(getWidget());
view->setDeclaration(eclass);

view->ShowModal();
view->Destroy();
}
}

} // namespace ui
34 changes: 34 additions & 0 deletions radiant/ui/einspector/InheritPropertyEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "PropertyEditor.h"

#include <wx/event.h>
#include <string>

namespace ui
{

/**
* PropertyEditor displaying a single "Show Definition".
*/
class InheritPropertyEditor :
public PropertyEditor
{
private:
// Keyvalue to set
ITargetKey::Ptr _key;

private:

void _onShowDefinition(wxCommandEvent& ev);

public:
InheritPropertyEditor(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key);

static Ptr CreateNew(wxWindow* parent, IEntitySelection& entities, const ITargetKey::Ptr& key)
{
return std::make_shared<InheritPropertyEditor>(parent, entities, key);
}
};

}
2 changes: 2 additions & 0 deletions radiant/ui/einspector/PropertyEditorFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ClassnamePropertyEditor.h"
#include "AnglePropertyEditor.h"
#include "FxPropertyEditor.h"
#include "InheritPropertyEditor.h"

#include <regex>

Expand Down Expand Up @@ -47,6 +48,7 @@ void PropertyEditorFactory::registerBuiltinTypes()
_peMap["float"] = FloatPropertyEditor::CreateNew;
_peMap["model"] = ModelPropertyEditor::CreateNew;
_peMap["classname"] = ClassnamePropertyEditor::CreateNew;
_peMap["inherit"] = InheritPropertyEditor::CreateNew;
_peMap["angle"] = AnglePropertyEditor::CreateNew;
_peMap["fx"] = FxPropertyEditor::CreateNew;

Expand Down
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
<ClCompile Include="..\..\radiant\ui\eclasstree\EClassTreeBuilder.cpp" />
<ClCompile Include="..\..\radiant\ui\einspector\EntityInspectorModule.cpp" />
<ClCompile Include="..\..\radiant\ui\einspector\FxPropertyEditor.cpp" />
<ClCompile Include="..\..\radiant\ui\einspector\InheritPropertyEditor.cpp" />
<ClCompile Include="..\..\radiant\ui\entitylist\EntityList.cpp" />
<ClCompile Include="..\..\radiant\ui\entitylist\GraphTreeModel.cpp" />
<ClCompile Include="..\..\radiant\ui\favourites\FavouritesBrowser.cpp" />
Expand Down Expand Up @@ -441,6 +442,7 @@
<ClInclude Include="..\..\radiant\ui\eclasstree\EClassTreeBuilder.h" />
<ClInclude Include="..\..\radiant\ui\einspector\EntityInspectorModule.h" />
<ClInclude Include="..\..\radiant\ui\einspector\FxPropertyEditor.h" />
<ClInclude Include="..\..\radiant\ui\einspector\InheritPropertyEditor.h" />
<ClInclude Include="..\..\radiant\ui\einspector\TargetKey.h" />
<ClInclude Include="..\..\radiant\ui\entitylist\EntityList.h" />
<ClInclude Include="..\..\radiant\ui\entitylist\EntityListControl.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,9 @@
<ClCompile Include="..\..\radiant\xyview\OrthoView.cpp">
<Filter>src\xyview</Filter>
</ClCompile>
<ClCompile Include="..\..\radiant\ui\einspector\InheritPropertyEditor.cpp">
<Filter>src\ui\einspector</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\camera\CameraSettings.h">
Expand Down Expand Up @@ -1443,6 +1446,9 @@
<ClInclude Include="..\..\radiant\xyview\OrthoView.h">
<Filter>src\xyview</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\einspector\InheritPropertyEditor.h">
<Filter>src\ui\einspector</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit 5d0d366

Please sign in to comment.