!XT (BREAK-16) (Sandbox) Remove double-newlines at the end of files.
[CRYENGINE.git] / Code / Sandbox / Plugins / SmartObjectEditor / SmartObjectActionDialog.cpp
blob540c3e08ce94c4546433be07113e263a89f3b1fb
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #include "stdafx.h"
4 #include <CryAISystem/IAISystem.h>
5 #include <CryAISystem/IAgent.h>
6 #include "AI/AIManager.h"
7 #include "HyperGraph/FlowGraphManager.h"
8 #include "HyperGraph/FlowGraph.h"
10 #include "SmartObjectActionDialog.h"
12 // CSmartObjectActionDialog dialog
14 IMPLEMENT_DYNAMIC(CSmartObjectActionDialog, CDialog)
15 CSmartObjectActionDialog::CSmartObjectActionDialog(CWnd* pParent /*=NULL*/)
16 : CDialog(CSmartObjectActionDialog::IDD, pParent)
20 CSmartObjectActionDialog::~CSmartObjectActionDialog()
24 void CSmartObjectActionDialog::DoDataExchange(CDataExchange* pDX)
26 CDialog::DoDataExchange(pDX);
27 DDX_Control(pDX, IDC_ANCHORS, m_wndActionList);
30 BEGIN_MESSAGE_MAP(CSmartObjectActionDialog, CDialog)
31 ON_LBN_DBLCLK(IDC_ANCHORS, OnLbnDblClk)
32 ON_LBN_SELCHANGE(IDC_ANCHORS, OnLbnSelchangeAction)
33 ON_BN_CLICKED(IDC_NEW, OnNewBtn)
34 ON_BN_CLICKED(IDEDIT, OnEditBtn)
35 ON_BN_CLICKED(IDREFRESH, OnRefreshBtn)
36 END_MESSAGE_MAP()
38 // CSmartObjectStateDialog message handlers
40 void CSmartObjectActionDialog::OnNewBtn()
42 string filename;
43 if (GetIEditor()->GetAIManager()->NewAction(filename))
45 m_sSOAction = PathUtil::GetFileName((const char*)filename);
46 IAIAction* pAction = gEnv->pAISystem->GetAIActionManager()->GetAIAction(m_sSOAction);
47 if (pAction)
49 CFlowGraphManager* pManager = GetIEditor()->GetFlowGraphManager();
50 CHyperFlowGraph* pFlowGraph = pManager->FindGraphForAction(pAction);
51 assert(pFlowGraph);
52 if (pFlowGraph)
53 pManager->OpenView(pFlowGraph);
55 EndDialog(IDOK);
60 void CSmartObjectActionDialog::OnEditBtn()
62 // EndDialog( IDCANCEL );
64 IAIAction* pAction = gEnv->pAISystem->GetAIActionManager()->GetAIAction(m_sSOAction);
65 if (pAction)
67 CFlowGraphManager* pManager = GetIEditor()->GetFlowGraphManager();
68 CHyperFlowGraph* pFlowGraph = pManager->FindGraphForAction(pAction);
69 assert(pFlowGraph);
70 if (pFlowGraph)
71 pManager->OpenView(pFlowGraph);
75 void CSmartObjectActionDialog::OnRefreshBtn()
77 // add empty string item
78 m_wndActionList.ResetContent();
79 m_wndActionList.AddString("");
81 IAIManager* pAIMgr = GetIEditor()->GetAIManager();
82 ASSERT(pAIMgr);
83 typedef std::vector<string> TSOActionsVec;
84 TSOActionsVec vecSOActions;
85 pAIMgr->GetSmartObjectActions(vecSOActions);
86 for (TSOActionsVec::iterator it = vecSOActions.begin(); it != vecSOActions.end(); ++it)
87 m_wndActionList.AddString((*it).GetString());
88 m_wndActionList.SelectString(-1, m_sSOAction);
91 void CSmartObjectActionDialog::OnLbnDblClk()
93 if (m_wndActionList.GetCurSel() >= 0)
94 EndDialog(IDOK);
97 void CSmartObjectActionDialog::OnLbnSelchangeAction()
99 SetDlgItemText(IDCANCEL, "Cancel");
100 GetDlgItem(IDOK)->EnableWindow(TRUE);
102 int nSel = m_wndActionList.GetCurSel();
103 if (nSel == LB_ERR)
104 return;
105 m_wndActionList.GetText(nSel, m_sSOAction);
108 BOOL CSmartObjectActionDialog::OnInitDialog()
110 CDialog::OnInitDialog();
111 SetWindowText("AI Actions");
112 SetDlgItemText(IDC_LISTCAPTION, "&Choose AI Action:");
114 GetDlgItem(IDC_NEW)->EnableWindow(TRUE);
115 GetDlgItem(IDEDIT)->EnableWindow(TRUE);
116 GetDlgItem(IDDELETE)->EnableWindow(FALSE);
117 GetDlgItem(IDREFRESH)->EnableWindow(TRUE);
119 OnRefreshBtn();
121 return TRUE; // return TRUE unless you set the focus to a control
122 // EXCEPTION: OCX Property Pages should return FALSE