| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "wxutil/dialog/DialogBase.h" |
| 4 |
#include "wxutil/XmlResourceBasedWidget.h" |
| 5 |
#include "wxutil/WindowPosition.h" |
| 6 |
#include "wxutil/dataview/TreeView.h" |
| 7 |
|
| 8 |
#include "ObjectiveCondition.h" |
| 9 |
#include "ObjectiveEntity.h" |
| 10 |
|
| 11 |
class wxChoice; |
| 12 |
|
| 13 |
namespace objectives |
| 14 |
{ |
| 15 |
|
| 16 |
/** |
| 17 |
* Dialog for editing objective conditions (for use in TDM campaigns). |
| 18 |
*/ |
| 19 |
class ObjectiveConditionsDialog : |
| 20 |
public wxutil::DialogBase, |
| 21 |
private wxutil::XmlResourceBasedWidget |
| 22 |
{ |
| 23 |
private: |
| 24 |
// The objective entity we're working on |
| 25 |
ObjectiveEntity& _objectiveEnt; |
| 26 |
|
| 27 |
// UI struct defining an objective condition list entry |
| 28 |
struct ObjectiveConditionListColumns : |
| 29 |
public wxutil::TreeModel::ColumnRecord |
| 30 |
{ |
| 31 |
ObjectiveConditionListColumns() : |
| 32 |
conditionNumber(add(wxutil::TreeModel::Column::Integer)), |
| 33 |
description(add(wxutil::TreeModel::Column::String)) |
| 34 |
{} |
| 35 |
|
| 36 |
wxutil::TreeModel::Column conditionNumber; |
| 37 |
wxutil::TreeModel::Column description; |
| 38 |
}; |
| 39 |
|
| 40 |
// List of target_addobjectives entities |
| 41 |
ObjectiveConditionListColumns _objConditionColumns; |
| 42 |
wxutil::TreeModel::Ptr _objectiveConditionList; |
| 43 |
wxutil::TreeView* _conditionsView; |
| 44 |
|
| 45 |
// Iterators for current objective condition |
| 46 |
wxDataViewItem _curCondition; |
| 47 |
|
| 48 |
// The position/size memoriser |
| 49 |
wxutil::WindowPosition _windowPosition; |
| 50 |
|
| 51 |
// The working set of conditions, will be written to the ObjEntity on save |
| 52 |
ObjectiveEntity::ConditionMap _objConditions; |
| 53 |
|
| 54 |
// Source objective state choice |
| 55 |
wxChoice* _srcObjState; |
| 56 |
|
| 57 |
// The action type |
| 58 |
wxChoice* _type; |
| 59 |
|
| 60 |
// The action value |
| 61 |
wxChoice* _value; |
| 62 |
|
| 63 |
// The target objective choice field, complete with model |
| 64 |
wxChoice* _targetObj; |
| 65 |
|
| 66 |
// Flag to block callbacks |
| 67 |
bool _updateActive; |
| 68 |
|
| 69 |
public: |
| 70 |
|
| 71 |
// Constructor creates widgets |
| 72 |
ObjectiveConditionsDialog(wxWindow* parent, ObjectiveEntity& objectiveEnt); |
| 73 |
|
| 74 |
// Override DialogBase |
| 75 |
int ShowModal(); |
| 76 |
|
| 77 |
private: |
| 78 |
// Widget construction helpers |
| 79 |
void setupConditionsPanel(); |
| 80 |
void setupConditionEditPanel(); |
| 81 |
|
| 82 |
void _onCancel(wxCommandEvent& ev); |
| 83 |
void _onOK(wxCommandEvent& ev); |
| 84 |
|
| 85 |
void _onConditionSelectionChanged(wxDataViewEvent& ev); |
| 86 |
void _onAddObjCondition(wxCommandEvent& ev); |
| 87 |
void _onDelObjCondition(wxCommandEvent& ev); |
| 88 |
|
| 89 |
void _onSrcMissionChanged(wxSpinEvent& ev); |
| 90 |
void _onSrcObjChanged(wxSpinEvent& ev); |
| 91 |
void _onSrcStateChanged(wxCommandEvent& ev); |
| 92 |
void _onTargetObjChanged(wxCommandEvent& ev); |
| 93 |
void _onTypeChanged(wxCommandEvent& ev); |
| 94 |
void _onValueChanged(wxCommandEvent& ev); |
| 95 |
|
| 96 |
void updateSentence(); |
| 97 |
|
| 98 |
// returns true if there is a condition highlighted |
| 99 |
bool isConditionSelected(); |
| 100 |
|
| 101 |
// Populate the dialog widgets with appropriate state from the objective entity |
| 102 |
void populateWidgets(); |
| 103 |
|
| 104 |
// Refresh the condition editing panel from the selected condition |
| 105 |
void loadValuesFromCondition(); |
| 106 |
|
| 107 |
void refreshPossibleValues(); |
| 108 |
|
| 109 |
// Return the currently-selected objective condition |
| 110 |
ObjectiveCondition& getCurrentObjectiveCondition(); |
| 111 |
|
| 112 |
// Helper method to get a brief description of the given condition |
| 113 |
static std::string getDescription(const ObjectiveCondition& cond); |
| 114 |
|
| 115 |
// Helper to get a human-readable sentence what the given condition is doing |
| 116 |
std::string getSentence(const ObjectiveCondition& cond); |
| 117 |
|
| 118 |
// Clears the internal containers |
| 119 |
void clear(); |
| 120 |
|
| 121 |
// Save changes to objectives entity |
| 122 |
void save(); |
| 123 |
}; |
| 124 |
|
| 125 |
} |