Skip to content

Commit

Permalink
#5501: Add checkbox to toggle "ai_see" to Light Inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 24, 2021
1 parent b82e439 commit 4786c15
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 18 deletions.
2 changes: 2 additions & 0 deletions install/games/darkmod.game
Expand Up @@ -233,6 +233,8 @@
<prefix>fogs</prefix>
</texture>

<!-- Whether the ai_see key is supported on light entities -->
<supportsAiSeeSpawnarg value="1" />
</light>

<!-- Information about the map format, for loading and saving -->
Expand Down
64 changes: 64 additions & 0 deletions install/ui/lightinspector.fbp
Expand Up @@ -777,6 +777,70 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Affects Lightgem and AI</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">LightInspectorAiSee</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Whether the light affects the player&apos;s light gem and AI ability to see other things</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
</object>
</object>
</object>
Expand Down
10 changes: 10 additions & 0 deletions install/ui/lightinspector.xrc
Expand Up @@ -125,6 +125,16 @@
<checked>0</checked>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxCheckBox" name="LightInspectorAiSee">
<tooltip>Whether the light affects the player&apos;s light gem and AI ability to see other things</tooltip>
<label>Affects Lightgem and AI</label>
<checked>0</checked>
</object>
</object>
</object>
</object>
</object>
Expand Down
53 changes: 35 additions & 18 deletions radiant/ui/lightinspector/LightInspector.cpp
Expand Up @@ -19,6 +19,8 @@
#include <wx/radiobut.h>

#include "ui/common/ShaderChooser.h" // for static displayLightInfo() function
#include "util/ScopedBoolLock.h"
#include "gamelib.h"

namespace ui
{
Expand Down Expand Up @@ -56,11 +58,12 @@ namespace
}

// Private constructor sets up dialog
LightInspector::LightInspector()
: wxutil::TransientWindow(_(LIGHTINSPECTOR_TITLE), GlobalMainFrame().getWxTopLevelWindow(), true),
_isProjected(false),
_texSelector(NULL),
_updateActive(false)
LightInspector::LightInspector() :
wxutil::TransientWindow(_(LIGHTINSPECTOR_TITLE), GlobalMainFrame().getWxTopLevelWindow(), true),
_isProjected(false),
_texSelector(nullptr),
_updateActive(false),
_supportsAiSee(game::current::getValue<bool>("/light/supportsAiSeeSpawnarg", false))
{
loadNamedPanel(this, "LightInspectorMainPanel");

Expand Down Expand Up @@ -142,17 +145,23 @@ void LightInspector::setupLightShapeOptions()
// Connect the options checkboxes
void LightInspector::setupOptionsPanel()
{
findNamedObject<wxColourPickerCtrl>(this, "LightInspectorColour")->Connect(
wxEVT_COLOURPICKER_CHANGED, wxColourPickerEventHandler(LightInspector::_onColourChange), NULL, this);

findNamedObject<wxCheckBox>(this, "LightInspectorParallel")->Connect(
wxEVT_CHECKBOX, wxCommandEventHandler(LightInspector::_onOptionsToggle), NULL, this);
findNamedObject<wxCheckBox>(this, "LightInspectorNoShadows")->Connect(
wxEVT_CHECKBOX, wxCommandEventHandler(LightInspector::_onOptionsToggle), NULL, this);
findNamedObject<wxCheckBox>(this, "LightInspectorSkipSpecular")->Connect(
wxEVT_CHECKBOX, wxCommandEventHandler(LightInspector::_onOptionsToggle), NULL, this);
findNamedObject<wxCheckBox>(this, "LightInspectorSkipDiffuse")->Connect(
wxEVT_CHECKBOX, wxCommandEventHandler(LightInspector::_onOptionsToggle), NULL, this);
findNamedObject<wxColourPickerCtrl>(this, "LightInspectorColour")->Bind(
wxEVT_COLOURPICKER_CHANGED, &LightInspector::_onColourChange, this);

findNamedObject<wxCheckBox>(this, "LightInspectorParallel")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
findNamedObject<wxCheckBox>(this, "LightInspectorNoShadows")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
findNamedObject<wxCheckBox>(this, "LightInspectorSkipSpecular")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
findNamedObject<wxCheckBox>(this, "LightInspectorSkipDiffuse")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);

if (_supportsAiSee)
{
findNamedObject<wxCheckBox>(this, "LightInspectorAiSee")->Show();
findNamedObject<wxCheckBox>(this, "LightInspectorAiSee")->Bind(wxEVT_CHECKBOX, &LightInspector::_onOptionsToggle, this);
}
else
{
findNamedObject<wxCheckBox>(this, "LightInspectorAiSee")->Hide();
}
}

// Create the texture widgets
Expand Down Expand Up @@ -313,7 +322,7 @@ void LightInspector::_onProjToggle(wxCommandEvent& ev)
void LightInspector::getValuesFromEntity()
{
// Disable unwanted callbacks
_updateActive = true;
util::ScopedBoolLock updateLock(_updateActive);

// Read values from the first entity in the list of lights (we have to pick
// one, so might as well use the first).
Expand Down Expand Up @@ -386,7 +395,10 @@ void LightInspector::getValuesFromEntity()
findNamedObject<wxCheckBox>(this, "LightInspectorSkipDiffuse")->SetValue(entity->getKeyValue("nodiffuse") == "1");
findNamedObject<wxCheckBox>(this, "LightInspectorNoShadows")->SetValue(entity->getKeyValue("noshadows") == "1");

_updateActive = false;
if (_supportsAiSee)
{
findNamedObject<wxCheckBox>(this, "LightInspectorAiSee")->SetValue(entity->getKeyValue("ai_see") == "1");
}
}

// Write to all entities
Expand Down Expand Up @@ -472,6 +484,11 @@ void LightInspector::setValuesOnEntity(Entity* entity)
setEntityValueIfDifferent(entity, "nospecular", findNamedObject<wxCheckBox>(this, "LightInspectorSkipSpecular")->GetValue() ? "1" : "0");
setEntityValueIfDifferent(entity, "nodiffuse", findNamedObject<wxCheckBox>(this, "LightInspectorSkipDiffuse")->GetValue() ? "1" : "0");
setEntityValueIfDifferent(entity, "noshadows", findNamedObject<wxCheckBox>(this, "LightInspectorNoShadows")->GetValue() ? "1" : "0");

if (_supportsAiSee)
{
setEntityValueIfDifferent(entity, "ai_see", findNamedObject<wxCheckBox>(this, "LightInspectorAiSee")->GetValue() ? "1" : "0");
}
}

void LightInspector::_onOptionsToggle(wxCommandEvent& ev)
Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/lightinspector/LightInspector.h
Expand Up @@ -48,6 +48,8 @@ class LightInspector :
// Disables callbacks if set to TRUE (during widget updates)
bool _updateActive;

bool _supportsAiSee;

sigc::connection _selectionChanged;
sigc::connection _undoHandler;
sigc::connection _redoHandler;
Expand Down

0 comments on commit 4786c15

Please sign in to comment.