/
OrthoContextMenu.cpp
689 lines (565 loc) · 21.3 KB
/
OrthoContextMenu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#include "OrthoContextMenu.h"
#include "i18n.h"
#include "selectionlib.h"
#include "ibrush.h"
#include "isound.h"
#include "ieventmanager.h"
#include "iresourcechooser.h"
#include "idialogmanager.h"
#include "entitylib.h" // EntityFindByClassnameWalker
#include "ientity.h" // Node_getEntity()
#include "iregistry.h"
#include "iuimanager.h"
#include "imainframe.h"
#include "map/Map.h"
#include "modulesystem/ModuleRegistry.h"
#include "wxutil/dialog/MessageBox.h"
#include "wxutil/menu/IconTextMenuItem.h"
#include "wxutil/menu/CommandMenuItem.h"
#include "selection/algorithm/Group.h"
#include "selection/algorithm/ModelFinder.h"
#include "selection/algorithm/Entity.h"
#include "ui/modelselector/ModelSelector.h"
#include "ui/entitychooser/EntityClassChooser.h"
#include "string/convert.h"
#include "math/AABB.h"
#include <wx/window.h>
#include <wx/menu.h>
#include "modulesystem/StaticModule.h"
namespace ui
{
namespace {
/* CONSTANTS */
const char* LIGHT_CLASSNAME = "light";
const char* MODEL_CLASSNAME = "func_static";
const char* SPEAKER_CLASSNAME = "speaker";
const char* PLAYERSTART_CLASSNAME = "info_player_start";
// Angle key for the player start
const char* ANGLE_KEY_NAME = "angle";
const char* DEFAULT_ANGLE = "90"; // north
const char* ADD_ENTITY_TEXT = N_("Create entity...");
const char* ADD_ENTITY_ICON = "cmenu_add_entity.png";
const char* ADD_PLAYERSTART_TEXT = N_("Create player start here");
const char* ADD_PLAYERSTART_ICON = "player_start16.png";
const char* MOVE_PLAYERSTART_TEXT = N_("Move player start here");
const char* MOVE_PLAYERSTART_ICON = "player_start16.png";
const char* ADD_MODEL_TEXT = N_("Create model...");
const char* ADD_MODEL_ICON = "cmenu_add_model.png";
const char* ADD_MONSTERCLIP_TEXT = N_("Surround with monsterclip");
const char* ADD_MONSTERCLIP_ICON = "monsterclip16.png";
const char* ADD_LIGHT_TEXT = N_("Create light...");
const char* ADD_LIGHT_ICON = "cmenu_add_light.png";
const char* ADD_PREFAB_TEXT = N_("Insert prefab...");
const char* ADD_PREFAB_ICON = "cmenu_add_prefab.png";
const char* ADD_SPEAKER_TEXT = N_("Create speaker...");
const char* ADD_SPEAKER_ICON = "icon_sound.png";
const char* CONVERT_TO_STATIC_TEXT = N_("Convert to func_static");
const char* CONVERT_TO_STATIC_ICON = "cmenu_convert_static.png";
const char* REPARENT_PRIMITIVES_TEXT = N_("Reparent primitives");
const char* REVERT_TO_WORLDSPAWN_TEXT = N_("Revert to worldspawn");
const char* REVERT_TO_WORLDSPAWN_PARTIAL_TEXT = N_("Revert part to worldspawn");
const char* REVERT_TO_WORLDSPAWN_ICON = "cmenu_revert_worldspawn.png";
const char* MERGE_ENTITIES_ICON = "cmenu_merge_entities.png";
const char* MERGE_ENTITIES_TEXT = N_("Merge Entities");
const char* MAKE_VISPORTAL = N_("Make Visportal");
const char* MAKE_VISPORTAL_ICON = "make_visportal.png";
}
// Define the static OrthoContextMenu module
module::StaticModule<OrthoContextMenu> orthoContextMenuModule;
OrthoContextMenu& OrthoContextMenu::Instance()
{
return *std::static_pointer_cast<OrthoContextMenu>(
module::GlobalModuleRegistry().getModule("OrthoContextMenu"));
}
// Constructor
OrthoContextMenu::OrthoContextMenu()
{}
// Show the menu
void OrthoContextMenu::Show(wxWindow* parent, const Vector3& point)
{
_lastPoint = point;
analyseSelection();
// Perform the visibility/sensitivity tests
for (MenuSections::const_iterator sec = _sections.begin(); sec != _sections.end(); ++sec)
{
for (MenuItems::const_iterator i = sec->second.begin(); i != sec->second.end(); ++i)
{
ui::IMenuItem& item = *(*i);
bool visible = item.isVisible();
if (visible)
{
// Visibility check passed
// Run the preshow command
item.preShow();
item.getMenuItem()->Enable(item.isSensitive());
}
else
{
// Visibility check failed, skip sensitivity check
item.getMenuItem()->Enable(false);
}
}
}
parent->PopupMenu(_widget.get());
}
void OrthoContextMenu::analyseSelection()
{
const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();
bool anythingSelected = info.totalCount > 0;
bool noEntities = info.entityCount == 0;
bool noComponents = info.componentCount == 0;
_selectionInfo.anythingSelected = anythingSelected;
_selectionInfo.onlyPrimitivesSelected = anythingSelected && noEntities && noComponents;
_selectionInfo.onlyBrushesSelected = anythingSelected && info.totalCount == info.brushCount;
_selectionInfo.onlyPatchesSelected = anythingSelected && info.totalCount == info.patchCount;
_selectionInfo.singlePrimitiveSelected = info.totalCount == 1 && (info.brushCount + info.patchCount == 1);
_selectionInfo.onlyEntitiesSelected = anythingSelected && info.totalCount == info.entityCount;
if (_selectionInfo.onlyEntitiesSelected)
{
// Check for group nodes
selection::algorithm::GroupNodeChecker walker;
GlobalSelectionSystem().foreachSelected(walker);
_selectionInfo.onlyGroupsSelected = walker.onlyGroupsAreSelected();
_selectionInfo.singleGroupSelected = walker.selectedGroupCount() == 1 && !Node_isWorldspawn(walker.getFirstSelectedGroupNode());
// Create a ModelFinder and check whether only models were selected
selection::algorithm::ModelFinder visitor;
GlobalSelectionSystem().foreachSelected(visitor);
// enable the "Add MonsterClip" entry only if at least one model is selected
_selectionInfo.onlyModelsSelected = !visitor.empty() && visitor.onlyModels();
}
else
{
_selectionInfo.onlyGroupsSelected = false;
_selectionInfo.singleGroupSelected = false;
_selectionInfo.onlyModelsSelected = false;
}
// Check if a playerStart already exists
EntityNodeFindByClassnameWalker walker(PLAYERSTART_CLASSNAME);
GlobalSceneGraph().root()->traverse(walker);
_selectionInfo.playerStartExists = walker.getEntity() != NULL;
}
bool OrthoContextMenu::checkMakeVisportal()
{
return _selectionInfo.onlyBrushesSelected;
}
// Check if the convert to static command should be enabled
bool OrthoContextMenu::checkConvertStatic()
{
// Command should be enabled if there is at least one selected
// primitive and no non-primitive selections.
return _selectionInfo.onlyPrimitivesSelected;
}
bool OrthoContextMenu::checkAddMonsterclip()
{
return _selectionInfo.onlyModelsSelected;
}
bool OrthoContextMenu::checkAddEntity()
{
return !_selectionInfo.anythingSelected || _selectionInfo.onlyPrimitivesSelected;
}
bool OrthoContextMenu::checkAddModel()
{
return !_selectionInfo.anythingSelected;
}
bool OrthoContextMenu::checkAddPlayerStart()
{
return !_selectionInfo.anythingSelected && !_selectionInfo.playerStartExists;
}
bool OrthoContextMenu::checkMovePlayerStart()
{
return !_selectionInfo.anythingSelected && _selectionInfo.playerStartExists;
}
bool OrthoContextMenu::checkRevertToWorldspawn()
{
return _selectionInfo.onlyGroupsSelected;
}
bool OrthoContextMenu::checkMergeEntities()
{
return _selectionInfo.onlyGroupsSelected && !_selectionInfo.singleGroupSelected;
}
bool OrthoContextMenu::checkReparentPrimitives()
{
return selection::algorithm::curSelectionIsSuitableForReparent();
}
bool OrthoContextMenu::checkRevertToWorldspawnPartial()
{
if (_selectionInfo.singlePrimitiveSelected)
{
// Check the selected node
scene::INodePtr node = GlobalSelectionSystem().ultimateSelected();
// Only allow revert partial if the parent node is a groupnode
if (node != NULL && Node_isPrimitive(node))
{
scene::INodePtr parent = node->getParent();
return parent != NULL && scene::hasChildPrimitives(parent) && !Node_isWorldspawn(parent);
}
}
return false;
}
// Get a registry key with a default value
std::string OrthoContextMenu::getRegistryKeyWithDefault(
const std::string& key, const std::string& defaultVal
)
{
std::string value = GlobalRegistry().get(key);
if (value.empty())
return defaultVal;
else
return value;
}
void OrthoContextMenu::addEntity()
{
UndoableCommand command("createEntity");
// Display the chooser to select an entity classname
std::string cName = EntityClassChooser::chooseEntityClass();
if (!cName.empty())
{
// Create the entity. We might get an EntityCreationException if the
// wrong number of brushes is selected.
try
{
selection::algorithm::createEntityFromSelection(cName, _lastPoint);
}
catch (selection::algorithm::EntityCreationException& e)
{
wxutil::Messagebox::ShowError(e.what());
}
}
}
void OrthoContextMenu::addPlayerStart()
{
UndoableCommand command("addPlayerStart");
try
{
// Create the player start entity
scene::INodePtr playerStartNode = selection::algorithm::createEntityFromSelection(
PLAYERSTART_CLASSNAME, _lastPoint
);
Entity* playerStart = Node_getEntity(playerStartNode);
// Set a default angle
playerStart->setKeyValue(ANGLE_KEY_NAME, DEFAULT_ANGLE);
}
catch (selection::algorithm::EntityCreationException& e) {
wxutil::Messagebox::ShowError(e.what());
}
}
void OrthoContextMenu::callbackMovePlayerStart()
{
UndoableCommand _cmd("movePlayerStart");
EntityNodeFindByClassnameWalker walker(PLAYERSTART_CLASSNAME);
GlobalSceneGraph().root()->traverse(walker);
Entity* playerStart = walker.getEntity();
if (playerStart != NULL)
{
playerStart->setKeyValue("origin", string::to_string(_lastPoint));
}
}
void OrthoContextMenu::callbackAddLight()
{
UndoableCommand command("addLight");
try
{
selection::algorithm::createEntityFromSelection(LIGHT_CLASSNAME, _lastPoint);
}
catch (selection::algorithm::EntityCreationException&)
{
wxutil::Messagebox::ShowError(_("Unable to create light, classname not found."));
}
}
void OrthoContextMenu::callbackAddPrefab()
{
// Pass the call to the map algorithm and give the lastPoint coordinate as argument
GlobalMap().loadPrefabAt(_lastPoint);
}
void OrthoContextMenu::callbackAddSpeaker()
{
ISoundShaderPtr soundShader;
// If we have an active sound module, query the desired shader from the user
if (module::GlobalModuleRegistry().moduleExists(MODULE_SOUNDMANAGER))
{
IResourceChooser* chooser = GlobalDialogManager().createSoundShaderChooser();
// Use a SoundChooser dialog to get a selection from the user
std::string shaderPath = chooser->chooseResource();
chooser->destroyDialog();
if (shaderPath.empty())
{
return; // user cancelled the dialog, don't do anything
}
soundShader = GlobalSoundManager().getSoundShader(shaderPath);
}
UndoableCommand command("addSpeaker");
// Cancel all selection
GlobalSelectionSystem().setSelectedAll(false);
try
{
// Create the speaker entity
scene::INodePtr spkNode = selection::algorithm::createEntityFromSelection(
SPEAKER_CLASSNAME, _lastPoint
);
if (soundShader)
{
// Set the shader keyvalue
Entity* entity = Node_getEntity(spkNode);
assert(entity);
entity->setKeyValue("s_shader", soundShader->getName());
// Initialise the speaker with suitable distance values
SoundRadii radii = soundShader->getRadii();
entity->setKeyValue("s_mindistance", string::to_string(radii.getMin(true)));
entity->setKeyValue("s_maxdistance",
(radii.getMax(true) > 0 ? string::to_string(radii.getMax(true)) : "10")
);
}
}
catch (selection::algorithm::EntityCreationException&)
{
wxutil::Messagebox::ShowError(_("Unable to create speaker, classname not found."));
}
}
void OrthoContextMenu::callbackAddModel()
{
UndoableCommand command("addModel");
const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();
// To create a model selection must be empty
if (info.totalCount == 0)
{
// Display the model selector and block waiting for a selection (may be empty)
ModelSelectorResult ms = ui::ModelSelector::chooseModel("", true, true);
// If a model was selected, create the entity and set its model key
if (!ms.model.empty())
{
try {
scene::INodePtr modelNode = selection::algorithm::createEntityFromSelection(
MODEL_CLASSNAME,
_lastPoint
);
//Node_getTraversable(GlobalSceneGraph().root())->insert(modelNode);
Node_getEntity(modelNode)->setKeyValue("model", ms.model);
Node_getEntity(modelNode)->setKeyValue("skin", ms.skin);
// If 'createClip' is ticked, create a clip brush
if (ms.createClip)
{
GlobalCommandSystem().execute("SurroundWithMonsterclip");
}
}
catch (selection::algorithm::EntityCreationException&)
{
wxutil::Messagebox::ShowError(_("Unable to create model, classname not found."));
}
}
}
else
{
wxutil::Messagebox::ShowError(
_("Nothing must be selected for model creation")
);
}
}
void OrthoContextMenu::registerDefaultItems()
{
wxutil::MenuItemPtr addEntity(
new wxutil::MenuItem(
new wxutil::IconTextMenuItem(_(ADD_ENTITY_TEXT), ADD_ENTITY_ICON),
std::bind(&OrthoContextMenu::addEntity, this),
std::bind(&OrthoContextMenu::checkAddEntity, this))
);
wxutil::MenuItemPtr addLight(
new wxutil::MenuItem(
new wxutil::IconTextMenuItem(_(ADD_LIGHT_TEXT), ADD_LIGHT_ICON),
std::bind(&OrthoContextMenu::callbackAddLight, this),
std::bind(&OrthoContextMenu::checkAddEntity, this)) // same as create entity
);
wxutil::MenuItemPtr addPrefab(
new wxutil::MenuItem(
new wxutil::IconTextMenuItem(_(ADD_PREFAB_TEXT), ADD_PREFAB_ICON),
std::bind(&OrthoContextMenu::callbackAddPrefab, this),
std::bind(&OrthoContextMenu::checkAddEntity, this)) // same as create entity
);
wxutil::MenuItemPtr addSpeaker(
new wxutil::MenuItem(
new wxutil::IconTextMenuItem(_(ADD_SPEAKER_TEXT), ADD_SPEAKER_ICON),
std::bind(&OrthoContextMenu::callbackAddSpeaker, this),
std::bind(&OrthoContextMenu::checkAddEntity, this)) // same as create entity
);
wxutil::MenuItemPtr addModel(
new wxutil::MenuItem(
new wxutil::IconTextMenuItem(_(ADD_MODEL_TEXT), ADD_MODEL_ICON),
std::bind(&OrthoContextMenu::callbackAddModel, this),
std::bind(&OrthoContextMenu::checkAddModel, this))
);
wxutil::CommandMenuItemPtr surroundWithMonsterClip(
new wxutil::CommandMenuItem(
new wxutil::IconTextMenuItem(_(ADD_MONSTERCLIP_TEXT), ADD_MONSTERCLIP_ICON),
"SurroundWithMonsterclip",
std::bind(&OrthoContextMenu::checkAddMonsterclip, this),
std::bind(&OrthoContextMenu::checkAddMonsterclip, this))
);
wxutil::MenuItemPtr addPlayerStart(
new wxutil::MenuItem(
new wxutil::IconTextMenuItem(_(ADD_PLAYERSTART_TEXT), ADD_PLAYERSTART_ICON),
std::bind(&OrthoContextMenu::addPlayerStart, this),
std::bind(&OrthoContextMenu::checkAddPlayerStart, this),
std::bind(&OrthoContextMenu::checkAddPlayerStart, this))
);
wxutil::MenuItemPtr movePlayerStart(
new wxutil::MenuItem(
new wxutil::IconTextMenuItem(_(MOVE_PLAYERSTART_TEXT), MOVE_PLAYERSTART_ICON),
std::bind(&OrthoContextMenu::callbackMovePlayerStart, this),
std::bind(&OrthoContextMenu::checkMovePlayerStart, this))
);
wxutil::CommandMenuItemPtr convertStatic(
new wxutil::CommandMenuItem(
new wxutil::IconTextMenuItem(_(CONVERT_TO_STATIC_TEXT), CONVERT_TO_STATIC_ICON),
"ConvertSelectedToFuncStatic",
std::bind(&OrthoContextMenu::checkConvertStatic, this))
);
wxutil::CommandMenuItemPtr revertWorldspawn(
new wxutil::CommandMenuItem(
new wxutil::IconTextMenuItem(_(REVERT_TO_WORLDSPAWN_TEXT), REVERT_TO_WORLDSPAWN_ICON),
"RevertToWorldspawn",
std::bind(&OrthoContextMenu::checkRevertToWorldspawn, this))
);
wxutil::CommandMenuItemPtr mergeEntities(
new wxutil::CommandMenuItem(
new wxutil::IconTextMenuItem(_(MERGE_ENTITIES_TEXT), MERGE_ENTITIES_ICON),
"MergeSelectedEntities",
std::bind(&OrthoContextMenu::checkMergeEntities, this))
);
wxutil::CommandMenuItemPtr revertToWorldspawnPartial(
new wxutil::CommandMenuItem(
new wxutil::IconTextMenuItem(_(REVERT_TO_WORLDSPAWN_PARTIAL_TEXT), REVERT_TO_WORLDSPAWN_ICON),
"ParentSelectionToWorldspawn",
std::bind(&OrthoContextMenu::checkRevertToWorldspawnPartial, this))
);
wxutil::CommandMenuItemPtr reparentPrimitives(
new wxutil::CommandMenuItem(
new wxutil::IconTextMenuItem(_(REPARENT_PRIMITIVES_TEXT), CONVERT_TO_STATIC_ICON),
"ParentSelection",
std::bind(&OrthoContextMenu::checkReparentPrimitives, this))
);
wxutil::CommandMenuItemPtr makeVisportal(
new wxutil::CommandMenuItem(
new wxutil::IconTextMenuItem(_(MAKE_VISPORTAL), MAKE_VISPORTAL_ICON),
"MakeVisportal",
std::bind(&OrthoContextMenu::checkMakeVisportal, this))
);
// Register all constructed items
addItem(addEntity, SECTION_CREATE);
addItem(addModel, SECTION_CREATE);
addItem(addLight, SECTION_CREATE);
addItem(addSpeaker, SECTION_CREATE);
addItem(addPrefab, SECTION_CREATE);
addItem(addPlayerStart, SECTION_ACTION);
addItem(movePlayerStart, SECTION_ACTION);
addItem(convertStatic, SECTION_ACTION);
addItem(revertWorldspawn, SECTION_ACTION);
addItem(revertToWorldspawnPartial, SECTION_ACTION);
addItem(mergeEntities, SECTION_ACTION);
addItem(reparentPrimitives, SECTION_ACTION);
addItem(makeVisportal, SECTION_ACTION);
addItem(surroundWithMonsterClip, SECTION_ACTION);
}
void OrthoContextMenu::onItemClick(wxCommandEvent& ev)
{
int commandId = ev.GetId();
// Find the menu item with that ID
for (MenuSections::const_iterator sec = _sections.begin(); sec != _sections.end(); ++sec)
{
for (MenuItems::const_iterator i = sec->second.begin();
i != sec->second.end(); ++i)
{
ui::IMenuItem& item = *(*i);
if (item.getMenuItem()->GetId() == commandId)
{
item.execute();
break;
}
}
}
ev.Skip();
}
void OrthoContextMenu::constructMenu()
{
_widget.reset(new wxMenu);
// Add all sections to menu
addSectionItems(SECTION_CREATE, true); // no spacer for first category
addSectionItems(SECTION_ACTION);
addSectionItems(SECTION_SELECTION_GROUPS);
addSectionItems(SECTION_FILTER);
addSectionItems(SECTION_LAYER);
// Add the rest of the sections
for (MenuSections::const_iterator sec = _sections.lower_bound(SECTION_LAYER+1);
sec != _sections.end(); ++sec)
{
addSectionItems(sec->first);
}
_widget->Connect(wxEVT_MENU, wxCommandEventHandler(OrthoContextMenu::onItemClick), NULL, this);
}
void OrthoContextMenu::addSectionItems(int section, bool noSpacer)
{
if (_sections.find(section) == _sections.end()) return;
const MenuItems& items = _sections[section];
if (!noSpacer && !items.empty())
{
_widget->AppendSeparator();
}
for (MenuItems::const_iterator i = items.begin(); i != items.end(); ++i)
{
_widget->Append((*i)->getMenuItem());
}
}
const std::string& OrthoContextMenu::getName() const
{
static std::string _name(MODULE_ORTHOCONTEXTMENU);
return _name;
}
const StringSet& OrthoContextMenu::getDependencies() const
{
static StringSet _dependencies;
if (_dependencies.empty())
{
_dependencies.insert(MODULE_UIMANAGER);
_dependencies.insert(MODULE_COMMANDSYSTEM);
_dependencies.insert(MODULE_EVENTMANAGER);
_dependencies.insert(MODULE_RADIANT_APP);
}
return _dependencies;
}
void OrthoContextMenu::initialiseModule(const ApplicationContext& ctx)
{
GlobalRadiant().signal_radiantStarted().connect(
sigc::mem_fun(this, &OrthoContextMenu::constructMenu)
);
registerDefaultItems();
}
void OrthoContextMenu::shutdownModule()
{
_sections.clear();
_widget.reset();
}
void OrthoContextMenu::addItem(const IMenuItemPtr& item, int section)
{
// Create section if not existing
if (_sections.find(section) == _sections.end())
{
_sections.insert(MenuSections::value_type(section, MenuSections::mapped_type()));
}
_sections[section].push_back(item);
}
void OrthoContextMenu::removeItem(const IMenuItemPtr& item)
{
for (MenuSections::iterator sec = _sections.begin(); sec != _sections.end(); ++sec)
{
MenuItems::iterator found = std::find(sec->second.begin(), sec->second.end(), item);
if (found != sec->second.end())
{
sec->second.erase(found);
// Remove empty sections
if (sec->second.empty())
{
_sections.erase(sec);
}
break;
}
}
}
} // namespace ui