EntityListDlg.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "qe3.h"
  23. #include "Radiant.h"
  24. #include "EntityListDlg.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. CEntityListDlg g_EntityListDlg;
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CEntityListDlg dialog
  33. void CEntityListDlg::ShowDialog() {
  34. if (g_EntityListDlg.GetSafeHwnd() == NULL) {
  35. g_EntityListDlg.Create(IDD_DLG_ENTITYLIST);
  36. }
  37. g_EntityListDlg.UpdateList();
  38. g_EntityListDlg.ShowWindow(SW_SHOW);
  39. }
  40. CEntityListDlg::CEntityListDlg(CWnd* pParent /*=NULL*/)
  41. : CDialog(CEntityListDlg::IDD, pParent)
  42. {
  43. //{{AFX_DATA_INIT(CEntityListDlg)
  44. //}}AFX_DATA_INIT
  45. }
  46. void CEntityListDlg::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CDialog::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CEntityListDlg)
  50. DDX_Control(pDX, IDC_LIST_ENTITY, m_lstEntity);
  51. //}}AFX_DATA_MAP
  52. DDX_Control(pDX, IDC_LIST_ENTITIES, listEntities);
  53. }
  54. BEGIN_MESSAGE_MAP(CEntityListDlg, CDialog)
  55. //{{AFX_MSG_MAP(CEntityListDlg)
  56. ON_BN_CLICKED(IDC_SELECT, OnSelect)
  57. ON_WM_CLOSE()
  58. ON_WM_DESTROY()
  59. //}}AFX_MSG_MAP
  60. ON_LBN_SELCHANGE(IDC_LIST_ENTITIES, OnLbnSelchangeListEntities)
  61. ON_LBN_DBLCLK(IDC_LIST_ENTITIES, OnLbnDblclkListEntities)
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CEntityListDlg message handlers
  65. void CEntityListDlg::OnSelect()
  66. {
  67. int index = listEntities.GetCurSel();
  68. if (index != LB_ERR) {
  69. entity_t *ent = reinterpret_cast<entity_t*>(listEntities.GetItemDataPtr(index));
  70. if (ent) {
  71. Select_Deselect();
  72. Select_Brush (ent->brushes.onext);
  73. }
  74. }
  75. Sys_UpdateWindows(W_ALL);
  76. }
  77. void CEntityListDlg::UpdateList() {
  78. listEntities.ResetContent();
  79. for (entity_t* pEntity=entities.next ; pEntity != &entities ; pEntity=pEntity->next) {
  80. int index = listEntities.AddString(pEntity->epairs.GetString("name"));
  81. if (index != LB_ERR) {
  82. listEntities.SetItemDataPtr(index, (void*)pEntity);
  83. }
  84. }
  85. }
  86. void CEntityListDlg::OnSysCommand(UINT nID, LPARAM lParam) {
  87. if (nID == SC_CLOSE) {
  88. DestroyWindow();
  89. }
  90. }
  91. void CEntityListDlg::OnCancel() {
  92. DestroyWindow();
  93. }
  94. BOOL CEntityListDlg::OnInitDialog()
  95. {
  96. CDialog::OnInitDialog();
  97. UpdateList();
  98. CRect rct;
  99. m_lstEntity.GetClientRect(rct);
  100. m_lstEntity.InsertColumn(0, "Key", LVCFMT_LEFT, rct.Width() / 2);
  101. m_lstEntity.InsertColumn(1, "Value", LVCFMT_LEFT, rct.Width() / 2);
  102. m_lstEntity.DeleteColumn(2);
  103. UpdateData(FALSE);
  104. return TRUE; // return TRUE unless you set the focus to a control
  105. // EXCEPTION: OCX Property Pages should return FALSE
  106. }
  107. void CEntityListDlg::OnClose() {
  108. DestroyWindow();
  109. }
  110. void CEntityListDlg::OnLbnSelchangeListEntities()
  111. {
  112. int index = listEntities.GetCurSel();
  113. if (index != LB_ERR) {
  114. m_lstEntity.DeleteAllItems();
  115. entity_t* pEntity = reinterpret_cast<entity_t*>(listEntities.GetItemDataPtr(index));
  116. if (pEntity) {
  117. int count = pEntity->epairs.GetNumKeyVals();
  118. for (int i = 0; i < count; i++) {
  119. int nParent = m_lstEntity.InsertItem(0, pEntity->epairs.GetKeyVal(i)->GetKey());
  120. m_lstEntity.SetItem(nParent, 1, LVIF_TEXT, pEntity->epairs.GetKeyVal(i)->GetValue(), 0, 0, 0, reinterpret_cast<DWORD>(pEntity));
  121. }
  122. }
  123. }
  124. }
  125. void CEntityListDlg::OnLbnDblclkListEntities()
  126. {
  127. OnSelect();
  128. }