InspectorPanel.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <InspectorPanel.h>
  9. #include <ACETypes.h>
  10. #include <AudioControlsEditorPlugin.h>
  11. #include <IAudioSystemControl.h>
  12. #include <QAudioControlEditorIcons.h>
  13. #include <QMessageBox>
  14. #include <QMimeData>
  15. #include <QDropEvent>
  16. #include <QKeyEvent>
  17. namespace AudioControls
  18. {
  19. //-------------------------------------------------------------------------------------------//
  20. CInspectorPanel::CInspectorPanel(CATLControlsModel* atlControlsModel)
  21. : m_atlControlsModel(atlControlsModel)
  22. , m_selectedType(eACET_NUM_TYPES)
  23. , m_notFoundColor(QColor(255, 128, 128))
  24. , m_allControlsSameType(true)
  25. {
  26. AZ_Assert(m_atlControlsModel, "CInspectorPanel - The ATL Controls model is null!");
  27. setupUi(this);
  28. connect(m_nameLineEditor, SIGNAL(editingFinished()), this, SLOT(FinishedEditingName()));
  29. connect(m_scopeDropDown, SIGNAL(activated(QString)), this, SLOT(SetControlScope(QString)));
  30. connect(m_autoLoadCheckBox, SIGNAL(clicked(bool)), this, SLOT(SetAutoLoadForCurrentControl(bool)));
  31. // data validators
  32. m_nameLineEditor->setValidator(new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), m_nameLineEditor));
  33. m_atlControlsModel->AddListener(this);
  34. Reload();
  35. }
  36. //-------------------------------------------------------------------------------------------//
  37. CInspectorPanel::~CInspectorPanel()
  38. {
  39. m_atlControlsModel->RemoveListener(this);
  40. }
  41. //-------------------------------------------------------------------------------------------//
  42. void CInspectorPanel::Reload()
  43. {
  44. UpdateScopeData();
  45. UpdateInspector();
  46. UpdateConnectionData();
  47. }
  48. //-------------------------------------------------------------------------------------------//
  49. void CInspectorPanel::SetSelectedControls(const ControlList& selectedControls)
  50. {
  51. m_selectedType = eACET_NUM_TYPES;
  52. m_selectedControls.clear();
  53. m_allControlsSameType = true;
  54. const size_t size = selectedControls.size();
  55. for (size_t i = 0; i < size; ++i)
  56. {
  57. CATLControl* control = m_atlControlsModel->GetControlByID(selectedControls[i]);
  58. if (control)
  59. {
  60. m_selectedControls.push_back(control);
  61. if (m_selectedType == eACET_NUM_TYPES)
  62. {
  63. m_selectedType = control->GetType();
  64. }
  65. else if (m_allControlsSameType && (m_selectedType != control->GetType()))
  66. {
  67. m_allControlsSameType = false;
  68. }
  69. }
  70. }
  71. UpdateInspector();
  72. UpdateConnectionData();
  73. }
  74. //-------------------------------------------------------------------------------------------//
  75. void CInspectorPanel::UpdateConnectionListControl()
  76. {
  77. if ((m_selectedControls.size() == 1) && m_allControlsSameType && m_selectedType != eACET_SWITCH)
  78. {
  79. if (m_selectedType == eACET_PRELOAD)
  80. {
  81. m_connectedControlsLabel->setText(QString(tr("Sound Banks:")));
  82. }
  83. else
  84. {
  85. m_connectedControlsLabel->setText(QString(tr("Connected Controls:")));
  86. }
  87. m_connectedControlsLabel->setHidden(false);
  88. m_connectionList->setHidden(false);
  89. }
  90. else
  91. {
  92. m_connectedControlsLabel->setHidden(true);
  93. m_connectionList->setHidden(true);
  94. }
  95. }
  96. //-------------------------------------------------------------------------------------------//
  97. void CInspectorPanel::UpdateScopeControl()
  98. {
  99. const size_t size = m_selectedControls.size();
  100. if (m_allControlsSameType)
  101. {
  102. if (size == 1)
  103. {
  104. CATLControl* control = m_selectedControls[0];
  105. if (control)
  106. {
  107. if (m_selectedType == eACET_SWITCH_STATE)
  108. {
  109. HideScope(true);
  110. }
  111. else
  112. {
  113. QString scope = QString(control->GetScope().c_str());
  114. if (scope.isEmpty())
  115. {
  116. m_scopeDropDown->setCurrentIndex(0);
  117. }
  118. else
  119. {
  120. int index = m_scopeDropDown->findText(scope);
  121. m_scopeDropDown->setCurrentIndex(index);
  122. }
  123. HideScope(false);
  124. }
  125. }
  126. }
  127. else
  128. {
  129. bool isSameScope = true;
  130. AZStd::string scope;
  131. for (int i = 0; i < size; ++i)
  132. {
  133. CATLControl* control = m_selectedControls[i];
  134. if (control)
  135. {
  136. AZStd::string controlScope = control->GetScope();
  137. if (controlScope.empty())
  138. {
  139. controlScope = "Global";
  140. }
  141. if (!scope.empty() && controlScope != scope)
  142. {
  143. isSameScope = false;
  144. break;
  145. }
  146. scope = controlScope;
  147. }
  148. }
  149. if (isSameScope)
  150. {
  151. int index = m_scopeDropDown->findText(QString(scope.c_str()));
  152. m_scopeDropDown->setCurrentIndex(index);
  153. }
  154. else
  155. {
  156. m_scopeDropDown->setCurrentIndex(-1);
  157. }
  158. }
  159. }
  160. else
  161. {
  162. HideScope(true);
  163. }
  164. }
  165. //-------------------------------------------------------------------------------------------//
  166. void CInspectorPanel::UpdateNameControl()
  167. {
  168. const size_t size = m_selectedControls.size();
  169. if (m_allControlsSameType)
  170. {
  171. if (size == 1)
  172. {
  173. CATLControl* control = m_selectedControls[0];
  174. if (control)
  175. {
  176. m_nameLineEditor->setText(QString(control->GetName().c_str()));
  177. m_nameLineEditor->setEnabled(true);
  178. }
  179. }
  180. else
  181. {
  182. m_nameLineEditor->setText(" <" + QString::number(size) + tr(" items selected>"));
  183. m_nameLineEditor->setEnabled(false);
  184. }
  185. }
  186. else
  187. {
  188. m_nameLineEditor->setText(" <" + QString::number(size) + tr(" items selected>"));
  189. m_nameLineEditor->setEnabled(false);
  190. }
  191. }
  192. //-------------------------------------------------------------------------------------------//
  193. void CInspectorPanel::UpdateInspector()
  194. {
  195. if (!m_selectedControls.empty())
  196. {
  197. m_propertiesPanel->setHidden(false);
  198. m_emptyInspectorLabel->setHidden(true);
  199. UpdateNameControl();
  200. UpdateScopeControl();
  201. UpdateAutoLoadControl();
  202. UpdateConnectionListControl();
  203. }
  204. else
  205. {
  206. m_propertiesPanel->setHidden(true);
  207. m_emptyInspectorLabel->setHidden(false);
  208. }
  209. }
  210. //-------------------------------------------------------------------------------------------//
  211. void CInspectorPanel::UpdateConnectionData()
  212. {
  213. if ((m_selectedControls.size() == 1) && m_selectedType != eACET_SWITCH)
  214. {
  215. m_connectionList->SetControl(m_selectedControls[0]);
  216. }
  217. }
  218. //-------------------------------------------------------------------------------------------//
  219. void CInspectorPanel::UpdateAutoLoadControl()
  220. {
  221. if (!m_selectedControls.empty() && m_allControlsSameType && m_selectedType == eACET_PRELOAD)
  222. {
  223. HideAutoLoad(false);
  224. bool hasAutoLoad = false;
  225. bool hasNonAutoLoad = false;
  226. const size_t size = m_selectedControls.size();
  227. for (int i = 0; i < size; ++i)
  228. {
  229. CATLControl* control = m_selectedControls[i];
  230. if (control)
  231. {
  232. if (control->IsAutoLoad())
  233. {
  234. hasAutoLoad = true;
  235. }
  236. else
  237. {
  238. hasNonAutoLoad = true;
  239. }
  240. }
  241. }
  242. if (hasAutoLoad && hasNonAutoLoad)
  243. {
  244. m_autoLoadCheckBox->setTristate(true);
  245. m_autoLoadCheckBox->setCheckState(Qt::PartiallyChecked);
  246. }
  247. else
  248. {
  249. if (hasAutoLoad)
  250. {
  251. m_autoLoadCheckBox->setChecked(true);
  252. }
  253. else
  254. {
  255. m_autoLoadCheckBox->setChecked(false);
  256. }
  257. m_autoLoadCheckBox->setTristate(false);
  258. }
  259. }
  260. else
  261. {
  262. HideAutoLoad(true);
  263. }
  264. }
  265. //-------------------------------------------------------------------------------------------//
  266. void CInspectorPanel::UpdateScopeData()
  267. {
  268. m_scopeDropDown->clear();
  269. for (int j = 0; j < m_atlControlsModel->GetScopeCount(); ++j)
  270. {
  271. SControlScope scope = m_atlControlsModel->GetScopeAt(j);
  272. m_scopeDropDown->insertItem(0, QString(scope.name.c_str()));
  273. if (scope.bOnlyLocal)
  274. {
  275. m_scopeDropDown->setItemData(0, m_notFoundColor, Qt::ForegroundRole);
  276. m_scopeDropDown->setItemData(0, "Level not found but it is referenced by some audio controls", Qt::ToolTipRole);
  277. }
  278. else
  279. {
  280. m_scopeDropDown->setItemData(0, "", Qt::ToolTipRole);
  281. }
  282. }
  283. m_scopeDropDown->insertItem(0, tr("Global"));
  284. }
  285. //-------------------------------------------------------------------------------------------//
  286. void CInspectorPanel::SetControlName(QString name)
  287. {
  288. if (m_selectedControls.size() == 1)
  289. {
  290. if (!name.isEmpty())
  291. {
  292. CUndo undo("Audio Control Name Changed");
  293. AZStd::string newName = name.toUtf8().data();
  294. CATLControl* control = m_selectedControls[0];
  295. if (control && control->GetName() != newName)
  296. {
  297. if (!m_atlControlsModel->IsNameValid(newName, control->GetType(), control->GetScope(), control->GetParent()))
  298. {
  299. newName = m_atlControlsModel->GenerateUniqueName(newName, control->GetType(), control->GetScope(), control->GetParent());
  300. }
  301. control->SetName(newName);
  302. }
  303. }
  304. else
  305. {
  306. UpdateNameControl();
  307. }
  308. }
  309. }
  310. //-------------------------------------------------------------------------------------------//
  311. void CInspectorPanel::SetControlScope(QString scope)
  312. {
  313. CUndo undo("Audio Control Scope Changed");
  314. size_t size = m_selectedControls.size();
  315. for (size_t i = 0; i < size; ++i)
  316. {
  317. CATLControl* control = m_selectedControls[i];
  318. if (control)
  319. {
  320. QString currentScope = QString(control->GetScope().c_str());
  321. if (currentScope != scope && (scope != tr("Global") || currentScope != ""))
  322. {
  323. if (scope == tr("Global"))
  324. {
  325. control->SetScope("");
  326. }
  327. else
  328. {
  329. control->SetScope(scope.toUtf8().data());
  330. }
  331. }
  332. }
  333. }
  334. }
  335. //-------------------------------------------------------------------------------------------//
  336. void CInspectorPanel::SetAutoLoadForCurrentControl(bool isAutoLoad)
  337. {
  338. CUndo undo("Audio Control Auto-Load Property Changed");
  339. size_t size = m_selectedControls.size();
  340. for (size_t i = 0; i < size; ++i)
  341. {
  342. CATLControl* control = m_selectedControls[i];
  343. if (control)
  344. {
  345. control->SetAutoLoad(isAutoLoad);
  346. }
  347. }
  348. }
  349. //-------------------------------------------------------------------------------------------//
  350. void CInspectorPanel::FinishedEditingName()
  351. {
  352. SetControlName(m_nameLineEditor->text());
  353. }
  354. //-------------------------------------------------------------------------------------------//
  355. void CInspectorPanel::OnControlModified(AudioControls::CATLControl* control)
  356. {
  357. size_t size = m_selectedControls.size();
  358. for (size_t i = 0; i < size; ++i)
  359. {
  360. if (m_selectedControls[i] == control)
  361. {
  362. UpdateInspector();
  363. UpdateConnectionData();
  364. break;
  365. }
  366. }
  367. }
  368. //-------------------------------------------------------------------------------------------//
  369. void CInspectorPanel::HideScope(bool hide)
  370. {
  371. m_scopeLabel->setHidden(hide);
  372. m_scopeDropDown->setHidden(hide);
  373. }
  374. //-------------------------------------------------------------------------------------------//
  375. void CInspectorPanel::HideAutoLoad(bool hide)
  376. {
  377. m_autoLoadLabel->setHidden(hide);
  378. m_autoLoadCheckBox->setHidden(hide);
  379. }
  380. } // namespace AudioControls
  381. #include <Source/Editor/moc_InspectorPanel.cpp>