Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2065 lines
58 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "stdafx.h"
  7. #include <afxadv.h>
  8. #include <oaidl.h>
  9. #include "hammer.h"
  10. #include "Box3D.h" // For units
  11. #include "EntityReportDlg.h"
  12. #include "FaceEditSheet.h"
  13. #include "MainFrm.h"
  14. #include "MessageWnd.h"
  15. #include "ControlBarIDs.h"
  16. #include "CustomMessages.h"
  17. #include "DynamicDialogWnd.h"
  18. #include "filesystem_tools.h"
  19. #include "GlobalFunctions.h"
  20. #include "Prefabs.h"
  21. #include "PrefabsDlg.h"
  22. #include "MapDoc.h"
  23. #include "Manifest.h"
  24. #include "StatusBarIDs.h"
  25. #include "Splash.h"
  26. #include "Options.h"
  27. #include "OptionProperties.h"
  28. #include "ObjectProperties.h"
  29. #include "OP_Groups.h"
  30. #include "MapView2D.h"
  31. #include "MapViewLogical.h"
  32. #include "MapView3D.h"
  33. #include "ChildFrm.h"
  34. #include "NewDocType.h"
  35. #include "SearchReplaceDlg.h"
  36. #include "TextureBrowser.h"
  37. #include "TextureSystem.h"
  38. #include "ToolManager.h"
  39. #include "Material.h"
  40. #include "materialsystem/IMaterialSystem.h"
  41. #include "materialsystem/MaterialSystem_Config.h"
  42. #include "soundbrowser.h"
  43. #include "lprvwindow.h"
  44. #include "toolframework/ienginetool.h"
  45. #include "toolutils/enginetools_int.h"
  46. #include "foundrytool.h"
  47. #include "cmdhandlers.h"
  48. #include "modelbrowser.h"
  49. #include <wintab.h>
  50. #include "tablet.h"
  51. // memdbgon must be the last include file in a .cpp file!!!
  52. #include <tier0/memdbgon.h>
  53. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  54. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  55. //{{AFX_MSG_MAP(CMainFrame)
  56. ON_WM_CREATE()
  57. ON_COMMAND(ID_EDIT_PROPERTIES, OnEditProperties)
  58. ON_UPDATE_COMMAND_UI(ID_EDIT_PROPERTIES, OnUpdateEditFunction)
  59. ON_COMMAND(ID_VIEW_MESSAGES, OnViewMessages)
  60. ON_UPDATE_COMMAND_UI(ID_VIEW_MESSAGES, OnUpdateViewMessages)
  61. ON_UPDATE_COMMAND_UI(ID_FOUNDRY_SENDSELECTEDENTITIESTOENGINE, OnUpdateFoundrySendSelectedEntitiesToEngine)
  62. ON_COMMAND(ID_FOUNDRY_SENDSELECTEDENTITIESTOENGINE, OnFoundrySendSelectedEntitiesToEngine)
  63. ON_UPDATE_COMMAND_UI(ID_FOUNDRY_MOVEENGINEVIEWTOHAMMER3DVIEW, OnUpdateFoundryMoveEngineViewToHammer3DView)
  64. ON_COMMAND(ID_FOUNDRY_MOVEENGINEVIEWTOHAMMER3DVIEW, OnFoundryMoveEngineViewToHammer3DView)
  65. ON_UPDATE_COMMAND_UI(ID_FOUNDRY_REMOVESELECTEDENTITIESFROMENGINE, OnUpdateFoundryRemoveSelectedEntitiesFromEngine)
  66. ON_COMMAND(ID_FOUNDRY_REMOVESELECTEDENTITIESFROMENGINE, OnFoundryRemoveSelectedEntitiesFromEngine)
  67. ON_UPDATE_COMMAND_UI(ID_FOUNDRY_MOVEFOCUSTOENGINE, OnUpdateFoundryMoveFocusToEngine)
  68. ON_COMMAND(ID_FOUNDRY_MOVEFOCUSTOENGINE, OnFoundryMoveFocusToEngine)
  69. ON_WM_ACTIVATEAPP()
  70. ON_WM_SIZE()
  71. ON_WM_CLOSE()
  72. ON_WM_DESTROY()
  73. ON_WM_PAINT()
  74. ON_WM_TIMER()
  75. ON_COMMAND(ID_TOOLS_OPTIONS, OnToolsOptions)
  76. ON_COMMAND(ID_TOOLS_PREFABFACTORY, OnToolsPrefabfactory)
  77. ON_COMMAND_EX(ID_HELP_TOPICS, OnHelpOpenURL)
  78. ON_COMMAND_EX(ID_HELP_EDITINGSITE, OnHelpOpenURL)
  79. ON_COMMAND_EX(ID_HELP_WORLDCRAFT_SUPPORT_MAIL, OnHelpOpenURL)
  80. ON_COMMAND(ID_EDIT_UNDOREDOACTIVE, OnEditUndoredoactive)
  81. ON_UPDATE_COMMAND_UI(ID_EDIT_UNDOREDOACTIVE, OnUpdateEditUndoredoactive)
  82. ON_COMMAND_EX(ID_FILE_NEW, OnFileNew)
  83. ON_COMMAND(ID_SAVEWINDOWSTATE, OnSavewindowstate)
  84. ON_COMMAND(ID_LOADWINDOWSTATE, OnLoadwindowstate)
  85. ON_COMMAND_EX(ID_MAP_UNITS_NONE, OnUnits)
  86. ON_UPDATE_COMMAND_UI(ID_MAP_UNITS_NONE, OnUpdateUnits)
  87. ON_COMMAND_EX(ID_MAP_UNITS_INCHES, OnUnits)
  88. ON_UPDATE_COMMAND_UI(ID_MAP_UNITS_INCHES, OnUpdateUnits)
  89. ON_COMMAND_EX(ID_MAP_UNITS_FEET_INCHES, OnUnits)
  90. ON_UPDATE_COMMAND_UI(ID_MAP_UNITS_FEET_INCHES, OnUpdateUnits)
  91. ON_UPDATE_COMMAND_UI(ID_VIEW_OPAQUE_MATERIALS, OnUpdateOpaqueMaterials)
  92. ON_UPDATE_COMMAND_UI(ID_VIEW_2DXZ, OnUpdateView2d)
  93. ON_UPDATE_COMMAND_UI(ID_VIEW_2DYZ, OnUpdateView2d)
  94. ON_UPDATE_COMMAND_UI(ID_VIEW_2DXY, OnUpdateView2d)
  95. ON_UPDATE_COMMAND_UI(ID_VIEW_3DWIREFRAME, OnUpdateView3d)
  96. ON_UPDATE_COMMAND_UI(ID_VIEW_3DPOLYGON, OnUpdateView3d)
  97. ON_UPDATE_COMMAND_UI(ID_VIEW_3DTEXTURED, OnUpdateView3d)
  98. //ON_UPDATE_COMMAND_UI(ID_VIEW_3DENGINE, OnUpdateView3d)
  99. ON_COMMAND(ID_VIEW_OPAQUE_MATERIALS, OnOpaqueMaterials)
  100. ON_COMMAND_EX(ID_VIEW3D_BRIGHTER, OnView3dChangeBrightness)
  101. ON_COMMAND_EX(ID_VIEW3D_DARKER, OnView3dChangeBrightness)
  102. ON_UPDATE_COMMAND_UI(ID_VIEW_OBJECTBAR, CFrameWnd::OnUpdateControlBarMenu)
  103. ON_COMMAND_EX(ID_VIEW_OBJECTBAR, CFrameWnd::OnBarCheck)
  104. ON_UPDATE_COMMAND_UI(ID_VIEW_SELECTION_MODE_BAR, CFrameWnd::OnUpdateControlBarMenu)
  105. ON_COMMAND_EX(ID_VIEW_SELECTION_MODE_BAR, CFrameWnd::OnBarCheck)
  106. ON_UPDATE_COMMAND_UI(ID_VIEW_FILTERCONTROL, CFrameWnd::OnUpdateControlBarMenu)
  107. ON_COMMAND_EX(ID_VIEW_FILTERCONTROL, CFrameWnd::OnBarCheck)
  108. ON_UPDATE_COMMAND_UI(ID_VIEW_MAPVIEWBAR, CFrameWnd::OnUpdateControlBarMenu)
  109. ON_COMMAND_EX(ID_VIEW_MAPVIEWBAR, CFrameWnd::OnBarCheck)
  110. ON_UPDATE_COMMAND_UI(ID_VIEW_MAPTOOLSBAR, CFrameWnd::OnUpdateControlBarMenu)
  111. ON_COMMAND_EX(ID_VIEW_MAPTOOLSBAR, CFrameWnd::OnBarCheck)
  112. ON_UPDATE_COMMAND_UI(ID_VIEW_TEXTUREBAR, CFrameWnd::OnUpdateControlBarMenu)
  113. ON_COMMAND_EX(ID_VIEW_TEXTUREBAR, CFrameWnd::OnBarCheck)
  114. ON_UPDATE_COMMAND_UI(ID_VIEW_MANIFEST_BAR, CFrameWnd::OnUpdateControlBarMenu)
  115. ON_COMMAND_EX(ID_VIEW_MANIFEST_BAR, CFrameWnd::OnBarCheck)
  116. //ON_UPDATE_COMMAND_UI(ID_VIEW_ANIMATIONBAR, CFrameWnd::OnUpdateControlBarMenu)
  117. //ON_COMMAND_EX(ID_VIEW_ANIMATIONBAR, CFrameWnd::OnBarCheck)
  118. ON_UPDATE_COMMAND_UI(ID_VIEW_MAPOPSBAR, CFrameWnd::OnUpdateControlBarMenu)
  119. ON_COMMAND_EX(ID_VIEW_MAPOPSBAR, CFrameWnd::OnBarCheck)
  120. ON_COMMAND_EX(ID_TOOLS_POINTER, OnChangeTool)
  121. ON_UPDATE_COMMAND_UI(ID_TOOLS_POINTER, OnUpdateToolUI)
  122. ON_COMMAND_EX(ID_TOOLS_CAMERA, OnChangeTool)
  123. ON_UPDATE_COMMAND_UI(ID_TOOLS_CAMERA, OnUpdateToolUI)
  124. ON_COMMAND_EX(ID_TOOLS_MAGNIFY, OnChangeTool)
  125. ON_UPDATE_COMMAND_UI(ID_TOOLS_MAGNIFY, OnUpdateToolUI)
  126. ON_COMMAND_EX(ID_TOOLS_BLOCK, OnChangeTool)
  127. ON_UPDATE_COMMAND_UI(ID_TOOLS_BLOCK, OnUpdateToolUI)
  128. ON_COMMAND_EX(ID_TOOLS_ENTITY, OnChangeTool)
  129. ON_UPDATE_COMMAND_UI(ID_TOOLS_ENTITY, OnUpdateToolUI)
  130. ON_COMMAND_EX(ID_TOOLS_APPLYDECALS, OnChangeTool)
  131. ON_UPDATE_COMMAND_UI(ID_TOOLS_APPLYDECALS, OnUpdateToolUI)
  132. ON_COMMAND_EX(ID_TOOLS_MORPH, OnChangeTool)
  133. ON_UPDATE_COMMAND_UI(ID_TOOLS_MORPH, OnUpdateToolUI)
  134. ON_COMMAND_EX(ID_TOOLS_SYNC_MESH, OnChangeTool)
  135. ON_UPDATE_COMMAND_UI(ID_TOOLS_SYNC_MESH, OnUpdateToolUI)
  136. ON_COMMAND_EX(ID_TOOLS_CLIPPER, OnChangeTool)
  137. ON_UPDATE_COMMAND_UI(ID_TOOLS_CLIPPER, OnUpdateToolUI)
  138. ON_COMMAND_EX(ID_TOOLS_EDITCORDON, OnChangeTool)
  139. ON_UPDATE_COMMAND_UI(ID_TOOLS_EDITCORDON, OnUpdateToolUI)
  140. ON_COMMAND_EX(ID_TOOLS_PATH, OnChangeTool)
  141. ON_UPDATE_COMMAND_UI(ID_TOOLS_PATH, OnUpdateToolUI)
  142. ON_COMMAND_EX(ID_TOOLS_OVERLAY, OnChangeTool)
  143. ON_UPDATE_COMMAND_UI(ID_TOOLS_OVERLAY, OnUpdateToolUI)
  144. ON_COMMAND_EX(ID_MODE_APPLICATOR, OnApplicator)
  145. ON_COMMAND_EX(ID_TOOLS_SOUND_BROWSER, OnSoundBrowser)
  146. ON_COMMAND(ID_TOOLS_MODEL_BROWSER, OnModelBrowser)
  147. ON_COMMAND_EX(ID_FILE_RELOAD_SOUNDS, OnReloadSounds)
  148. ON_UPDATE_COMMAND_UI(ID_MODE_APPLICATOR, OnUpdateApplicatorUI)
  149. ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
  150. ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
  151. ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
  152. ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
  153. ON_COMMAND(ID_HDR, OnHDR)
  154. ON_WM_HELPINFO()
  155. ON_WM_SYSCOMMAND()
  156. ON_WM_ENTERMENULOOP()
  157. ON_MESSAGE( WT_PACKET, OnWTPacket )
  158. //}}AFX_MSG_MAP
  159. END_MESSAGE_MAP()
  160. static UINT indicators[] =
  161. {
  162. ID_SEPARATOR, // status line indicator
  163. ID_INDICATOR_SELECTION,
  164. ID_INDICATOR_COORDS,
  165. ID_INDICATOR_SIZE,
  166. ID_INDICATOR_GRIDZOOM,
  167. ID_INDICATOR_SNAP
  168. };
  169. const int NUMSTATUSPANES = 7;
  170. const char * WINSTATETAG = "WCWINSTATE";
  171. const int WINSTATEEND = -1;
  172. const int WINSTATE2DVIEW = 0;
  173. const int WINSTATE3DVIEW = 1;
  174. const int WINSTATELOGICALVIEW = 2;
  175. const float fVersion = 0.1f;
  176. struct
  177. {
  178. int nIndex;
  179. UINT nID;
  180. UINT nStyle;
  181. int cxWidth;
  182. } paneinfo[NUMSTATUSPANES] =
  183. {
  184. { SBI_PROMPT, ID_SEPARATOR, SBPS_STRETCH | SBPS_NOBORDERS, 0 },
  185. { SBI_SELECTION, ID_INDICATOR_SELECTION, SBPS_NORMAL, 300 },
  186. { SBI_COORDS, ID_INDICATOR_COORDS, SBPS_NORMAL, 100 },
  187. { SBI_SIZE, ID_INDICATOR_SIZE, SBPS_NORMAL, 180 },
  188. { SBI_GRIDZOOM, ID_INDICATOR_GRIDZOOM, SBPS_NORMAL, 80 },
  189. { SBI_SNAP, ID_INDICATOR_SNAP, SBPS_NORMAL, 135 },
  190. { SBI_LIGHTPROGRESS,ID_INDICATOR_LIGHTPROGRESS, SBPS_NORMAL, 50 }
  191. };
  192. static GameData gd;
  193. static CMainFrame *g_pMainWnd;
  194. //-----------------------------------------------------------------------------
  195. // Purpose: Constructor.
  196. //-----------------------------------------------------------------------------
  197. CMainFrame::CMainFrame(void)
  198. {
  199. pTextureBrowser = NULL;
  200. pObjectProperties = NULL;
  201. m_pModelBrowser = NULL;
  202. m_bUndoActive = TRUE;
  203. m_bShellSessionActive = false;
  204. m_pFaceEditSheet = NULL;
  205. m_bMinimized = false;
  206. m_pSearchReplaceDlg = NULL;
  207. m_pLightingPreviewOutputWindow = NULL;
  208. m_bLightingPreviewOutputWindowShowing = false;
  209. }
  210. //-----------------------------------------------------------------------------
  211. // Purpose: Destructor.
  212. //-----------------------------------------------------------------------------
  213. CMainFrame::~CMainFrame(void)
  214. {
  215. delete pObjectProperties;
  216. delete pTextureBrowser;
  217. delete m_pFaceEditSheet;
  218. delete m_pSearchReplaceDlg;
  219. delete m_pLightingPreviewOutputWindow;
  220. delete m_pModelBrowser;
  221. g_pMainWnd = NULL;
  222. CPrefabLibrary::FreeAllLibraries();
  223. }
  224. //-----------------------------------------------------------------------------
  225. // Purpose: Called through the shell to begin a session of editing the map
  226. // via the shell. The user interface is disabled to prevent a mismatched
  227. // versions between Hammer and the shell client.
  228. //-----------------------------------------------------------------------------
  229. void CMainFrame::BeginShellSession(void)
  230. {
  231. m_bShellSessionActive = true;
  232. }
  233. //-----------------------------------------------------------------------------
  234. // Purpose: Called through the shell to end a session of editing the map
  235. // via the engine. The user interface is enabled.
  236. //-----------------------------------------------------------------------------
  237. void CMainFrame::EndShellSession(void)
  238. {
  239. m_bShellSessionActive = false;
  240. }
  241. //-----------------------------------------------------------------------------
  242. // Purpose: If we get here there is no active 3D view. Uncheck the button.
  243. //-----------------------------------------------------------------------------
  244. void CMainFrame::OnUpdateView3d(CCmdUI *pCmdUI)
  245. {
  246. pCmdUI->SetCheck(FALSE);
  247. }
  248. //-----------------------------------------------------------------------------
  249. // Purpose: If we get here there is no active 3D view. Uncheck the button.
  250. //-----------------------------------------------------------------------------
  251. void CMainFrame::OnUpdateOpaqueMaterials(CCmdUI *pCmdUI)
  252. {
  253. pCmdUI->SetCheck(MaterialSystemConfig().bNoTransparency);
  254. }
  255. void CMainFrame::OnOpaqueMaterials()
  256. {
  257. MaterialSystemConfig().bNoTransparency = !MaterialSystemConfig().bNoTransparency;
  258. MaterialSystemInterface()->OverrideConfig( MaterialSystemConfig(), false );
  259. }
  260. //-----------------------------------------------------------------------------
  261. // Purpose: If we get here there is no active 2D view. Uncheck the button.
  262. //-----------------------------------------------------------------------------
  263. void CMainFrame::OnUpdateView2d(CCmdUI *pCmdUI)
  264. {
  265. pCmdUI->SetCheck(FALSE);
  266. }
  267. void CMainFrame::OnEnterMenuLoop( BOOL bIsTrackPopupMenu )
  268. {
  269. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  270. // if we are translation objects with a tool right now, dont switch to Menu mode
  271. if ( pDoc )
  272. {
  273. CBaseTool *pTool = pDoc->GetTools()->GetActiveTool();
  274. if ( pTool && pTool->IsTranslating() )
  275. {
  276. SendMessage( WM_CANCELMODE );
  277. }
  278. }
  279. }
  280. //-----------------------------------------------------------------------------
  281. // Purpose:
  282. // Input : lpCreateStruct -
  283. // Output :
  284. //-----------------------------------------------------------------------------
  285. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  286. {
  287. const DWORD dwDefStyles = WS_CHILD | WS_VISIBLE | CBRS_TOP;
  288. lpCreateStruct->lpszClass = "VALVEWORLDCRAFT";
  289. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  290. return -1;
  291. if(!wndMDIClient.SubclassWindow(m_hWndMDIClient))
  292. {
  293. TRACE ("Failed to subclass MDI client window\n");
  294. return (-1);
  295. }
  296. //
  297. // Map view toolbar.
  298. //
  299. if (!m_wndMapToolBar.Create(this, dwDefStyles, IDCB_MAPVIEWBAR) || !m_wndMapToolBar.LoadToolBar(IDR_MAPDOC_VALVE))
  300. {
  301. TRACE0("Failed to create toolbar\n");
  302. return -1; // fail to create
  303. }
  304. m_wndMapToolBar.ModifyStyle(0, TBSTYLE_FLAT);
  305. //
  306. // Undo redo toolbar.
  307. //
  308. if (!m_wndUndoRedoToolBar.Create(this, dwDefStyles, IDCB_UNDO_REDO_BAR) || !m_wndUndoRedoToolBar.LoadToolBar(IDR_UNDOREDO))
  309. {
  310. TRACE0("Failed to create toolbar\n");
  311. return -1; // fail to create
  312. }
  313. m_wndUndoRedoToolBar.ModifyStyle(0, TBSTYLE_FLAT);
  314. //
  315. // Map editing toolbar.
  316. //
  317. m_wndMapEditToolBar.Create(this, dwDefStyles, IDCB_MAPTOOLSBAR);
  318. m_wndMapEditToolBar.ModifyStyle(0, TBSTYLE_FLAT);
  319. m_wndMapEditToolBar.LoadToolBar(IDR_MAPEDITTOOLS_VALVE);
  320. m_bmMapEditTools256.LoadBitmap(IDB_MAPEDITTOOLS_256);
  321. m_wndMapEditToolBar.SetBitmap((HBITMAP)m_bmMapEditTools256);
  322. //
  323. // Map operations toolbar.
  324. //
  325. if (!m_wndMapOps.Create(this, dwDefStyles, IDCB_MAPOPERATIONS) || !m_wndMapOps.LoadToolBar(IDR_MAPOPERATIONS_VALVE))
  326. {
  327. TRACE0("Failed to create toolbar\n");
  328. return -1; // fail to create
  329. }
  330. m_wndMapOps.ModifyStyle(0, TBSTYLE_FLAT);
  331. //
  332. // Status bar.
  333. //
  334. if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(NULL, NUMSTATUSPANES))
  335. {
  336. TRACE0("Failed to create status bar\n");
  337. return -1; // fail to create
  338. }
  339. for(int i = 0; i < NUMSTATUSPANES; i++)
  340. {
  341. m_wndStatusBar.SetPaneInfo(paneinfo[i].nIndex, paneinfo[i].nID, paneinfo[i].nStyle, paneinfo[i].cxWidth);
  342. }
  343. EnableDocking(CBRS_ALIGN_ANY);
  344. m_wndMapToolBar.SetBarStyle(m_wndMapToolBar.GetBarStyle() |
  345. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  346. m_wndUndoRedoToolBar.SetBarStyle(m_wndUndoRedoToolBar.GetBarStyle() |
  347. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  348. m_wndMapEditToolBar.SetBarStyle(m_wndMapEditToolBar.GetBarStyle() |
  349. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  350. m_wndMapOps.SetBarStyle(m_wndMapOps.GetBarStyle() |
  351. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  352. m_wndMapToolBar.EnableDocking(CBRS_ALIGN_ANY);
  353. m_wndUndoRedoToolBar.EnableDocking(CBRS_ALIGN_ANY);
  354. m_wndMapEditToolBar.EnableDocking(CBRS_ALIGN_ANY);
  355. m_wndMapOps.EnableDocking(CBRS_ALIGN_ANY);
  356. DockControlBar(&m_wndMapEditToolBar, AFX_IDW_DOCKBAR_LEFT);
  357. // top bars
  358. DockControlBar(&m_wndMapToolBar, AFX_IDW_DOCKBAR_TOP);
  359. DockControlBarLeftOf(&m_wndUndoRedoToolBar, &m_wndMapToolBar );
  360. DockControlBarLeftOf(&m_wndMapOps, &m_wndUndoRedoToolBar);
  361. // rightside control bars
  362. m_ObjectBar.Create(this);
  363. m_ObjectBar.SetBarStyle(m_ObjectBar.GetBarStyle() |
  364. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
  365. m_ObjectBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
  366. DockControlBar(&m_ObjectBar, AFX_IDW_DOCKBAR_RIGHT);
  367. m_FilterControl.Create(this);
  368. m_FilterControl.SetBarStyle(m_FilterControl.GetBarStyle() |
  369. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
  370. m_FilterControl.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
  371. DockControlBarLeftOf(&m_FilterControl, &m_ObjectBar);
  372. m_TextureBar.Create(this);
  373. m_TextureBar.SetBarStyle(m_TextureBar.GetBarStyle() |
  374. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
  375. m_TextureBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
  376. DockControlBarLeftOf(&m_TextureBar, &m_FilterControl);
  377. m_ManifestFilterControl.Create(this);
  378. m_ManifestFilterControl.SetBarStyle(m_ManifestFilterControl.GetBarStyle() |
  379. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
  380. m_ManifestFilterControl.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
  381. DockControlBar(&m_ManifestFilterControl, AFX_IDW_DOCKBAR_RIGHT);
  382. m_pFaceEditSheet = new CFaceEditSheet( "Face Edit Sheet", this );
  383. m_pFaceEditSheet->Setup();
  384. m_pFaceEditSheet->Create( this );
  385. m_pFaceEditSheet->SetVisibility( false );
  386. m_pLightingPreviewOutputWindow = NULL;
  387. //
  388. // Create the animation dialog bar.
  389. //
  390. //m_AnimationDlg.Create(this);
  391. //m_AnimationDlg.SetBarStyle(m_TextureBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
  392. //m_AnimationDlg.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
  393. //DockControlBarLeftOf(&m_AnimationDlg, &m_TextureBar);
  394. //
  395. // Create the selection mode dialog bar.
  396. //
  397. m_SelectModeDlg.Create(this);
  398. m_SelectModeDlg.SetBarStyle(m_TextureBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
  399. m_SelectModeDlg.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT);
  400. DockControlBarLeftOf(&m_SelectModeDlg, &m_TextureBar);
  401. //
  402. // Create object properties sheet - not visible yet.
  403. //
  404. pObjectProperties = new CObjectProperties;
  405. pObjectProperties->SetupPages();
  406. CWnd *pPropertiesParent = this;
  407. if ( APP()->IsFoundryMode() )
  408. pPropertiesParent = NULL;
  409. pObjectProperties->Create(pPropertiesParent, WS_SYSMENU | WS_POPUP | WS_CAPTION | DS_MODALFRAME | WS_THICKFRAME);
  410. g_pMainWnd = this;
  411. //
  412. // Create the smoothing group visualization dialog.
  413. //
  414. m_SmoothingGroupDlg.Create( IDD_SMOOTHING_GROUP_VISUAL, this );
  415. //
  416. // Create message window.
  417. //
  418. CRect clientrect;
  419. wndMDIClient.GetClientRect(clientrect);
  420. g_pwndMessage->CreateMessageWindow( this, CRect( 0, clientrect.Height() - 90, clientrect.Width(), clientrect.Height() ) );
  421. CPrefabLibrary::LoadAllLibraries();
  422. ToolManager()->SetTool(TOOL_POINTER);
  423. pTextureBrowser = new CTextureBrowser(this);
  424. // HACK: Spackle up the maximized window position to (0, 0) to fix an intermittent bug. =(
  425. WINDOWPLACEMENT wp;
  426. ZeroMemory(&wp, sizeof(wp));
  427. wp.length = sizeof(wp);
  428. SetWindowPlacement(&wp);
  429. //
  430. // !!!NOTE: Always do this last to ensure that the layout does not get recalculated before the
  431. // window is maximized. This prevents control bars from being incorrectly wrapped to
  432. // the next column.
  433. //
  434. if (VerifyBarState())
  435. {
  436. LoadBarState("Barstate");
  437. }
  438. return 0;
  439. }
  440. void CMainFrame::DockControlBarLeftOf(CControlBar* Bar, CControlBar* LeftOf)
  441. {
  442. CRect rect;
  443. DWORD dw;
  444. UINT n;
  445. // get MFC to adjust the dimensions of all docked ToolBars
  446. // so that GetWindowRect will be accurate
  447. RecalcLayout();
  448. LeftOf->GetWindowRect(&rect);
  449. rect.OffsetRect(1,0);
  450. dw=LeftOf->GetBarStyle();
  451. n = 0;
  452. n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
  453. n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
  454. n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
  455. n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
  456. // When we take the default parameters on rect, DockControlBar will dock
  457. // each Toolbar on a seperate line. By calculating a rectangle, we in effect
  458. // are simulating a Toolbar being dragged to that location and docked.
  459. DockControlBar(Bar,n,&rect);
  460. }
  461. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  462. {
  463. cs.style |= WS_MAXIMIZE;
  464. cs.lpszClass = "VALVEWORLDCRAFT";
  465. return CMDIFrameWnd::PreCreateWindow(cs);
  466. }
  467. /////////////////////////////////////////////////////////////////////////////
  468. // CMainFrame diagnostics
  469. #ifdef _DEBUG
  470. void CMainFrame::AssertValid() const
  471. {
  472. CMDIFrameWnd::AssertValid();
  473. }
  474. void CMainFrame::Dump(CDumpContext& dc) const
  475. {
  476. CMDIFrameWnd::Dump(dc);
  477. }
  478. #endif //_DEBUG
  479. //-----------------------------------------------------------------------------
  480. // Purpose: Maps menu IDs to tool IDs.
  481. // Input : uMsg - Menu ID from a WM_COMMAND message.
  482. //-----------------------------------------------------------------------------
  483. static ToolID_t _ToolMsgToEnum(UINT uMsg)
  484. {
  485. struct ToolIDMap_t
  486. {
  487. UINT uMsg;
  488. ToolID_t eToolID;
  489. };
  490. ToolIDMap_t nIDMap[] =
  491. {
  492. { ID_TOOLS_POINTER, TOOL_POINTER },
  493. { ID_TOOLS_BLOCK, TOOL_BLOCK },
  494. { ID_TOOLS_ENTITY, TOOL_ENTITY },
  495. { ID_TOOLS_CAMERA, TOOL_CAMERA },
  496. { ID_TOOLS_MAGNIFY, TOOL_MAGNIFY },
  497. { ID_TOOLS_MORPH, TOOL_MORPH },
  498. { ID_TOOLS_CLIPPER, TOOL_CLIPPER },
  499. { ID_TOOLS_EDITCORDON, TOOL_EDITCORDON },
  500. { ID_TOOLS_OVERLAY, TOOL_OVERLAY },
  501. { ID_TOOLS_APPLYDECALS, TOOL_DECAL },
  502. { ID_MODE_APPLICATOR, TOOL_FACEEDIT_MATERIAL },
  503. };
  504. for (int i = 0; i < sizeof(nIDMap) / sizeof(nIDMap[0]); i++)
  505. {
  506. if (uMsg == nIDMap[i].uMsg)
  507. {
  508. return nIDMap[i].eToolID;
  509. }
  510. }
  511. return TOOL_POINTER;
  512. }
  513. class CToolHandler_Disabled : public IToolHandlerInfo
  514. {
  515. public:
  516. virtual BOOL UpdateCmdUI( CCmdUI *pCmdUI );
  517. virtual BOOL Execute( UINT uMsg );
  518. }
  519. g_ToolHandlerDisabled;
  520. BOOL CToolHandler_Disabled::UpdateCmdUI( CCmdUI *pCmdUI )
  521. {
  522. pCmdUI->Enable( FALSE );
  523. pCmdUI->SetCheck( FALSE );
  524. return TRUE;
  525. }
  526. BOOL CToolHandler_Disabled::Execute( UINT uMsg )
  527. {
  528. uMsg;
  529. return TRUE;
  530. }
  531. IToolHandlerInfo * _ToolToHanderInfo(UINT uMsg)
  532. {
  533. extern IToolHandlerInfo *g_pToolHandlerSyncMesh;
  534. switch ( uMsg )
  535. {
  536. case ID_TOOLS_SYNC_MESH:
  537. return g_pToolHandlerSyncMesh;
  538. default:
  539. return NULL;
  540. // return &g_ToolHandlerDisabled to make a control look disabled
  541. }
  542. }
  543. //-----------------------------------------------------------------------------
  544. // Purpose: activates the current tool toolbar button
  545. // Input : pUI - interface to button that has had a action happen
  546. //-----------------------------------------------------------------------------
  547. void CMainFrame::OnUpdateToolUI(CCmdUI *pUI)
  548. {
  549. if (IsShellSessionActive())
  550. {
  551. pUI->Enable(FALSE);
  552. }
  553. else
  554. {
  555. //
  556. // check for button enabling
  557. //
  558. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  559. bool bIsEditable = ( pDoc ? pDoc->IsSelectionEditable() : false );
  560. if ( pUI->m_nID == ID_TOOLS_APPLYDECALS ||
  561. pUI->m_nID == ID_TOOLS_OVERLAY ||
  562. pUI->m_nID == ID_TOOLS_CLIPPER ||
  563. pUI->m_nID == ID_TOOLS_MORPH )
  564. {
  565. }
  566. else
  567. {
  568. bIsEditable = ( pDoc ? true : false );
  569. }
  570. #if 0
  571. //
  572. // Only enable the displacement toolbar button while editing HalfLife 2 maps.
  573. //
  574. if ( pUI->m_nID == ID_TOOLS_DISPLACE )
  575. {
  576. if ( pDoc != NULL )
  577. {
  578. pUI->Enable(pDoc->GetMapFormat() == mfHalfLife2);
  579. }
  580. else
  581. {
  582. pUI->Enable( pDoc != NULL );
  583. }
  584. }
  585. else
  586. #endif
  587. {
  588. pUI->Enable( bIsEditable );
  589. }
  590. // Obtain custom tool handler
  591. IToolHandlerInfo *pHandlerInfo = _ToolToHanderInfo( pUI->m_nID );
  592. BOOL bHandled = pHandlerInfo ? pHandlerInfo->UpdateCmdUI( pUI ) : FALSE;
  593. // Use default handler if custom tool handler didn't work
  594. if ( !bHandled )
  595. {
  596. ToolID_t eToolID = _ToolMsgToEnum(pUI->m_nID);
  597. pUI->Enable(bIsEditable);
  598. pUI->SetCheck(eToolID == ToolManager()->GetActiveToolID());
  599. }
  600. }
  601. }
  602. //-----------------------------------------------------------------------------
  603. // Purpose: Handles toolbar and menu messages that change the active tool.
  604. // Input : nMessageID - the id of the menu item
  605. // Output : Returns TRUE to indicate that the message was handled.
  606. //-----------------------------------------------------------------------------
  607. BOOL CMainFrame::OnChangeTool(UINT nMessageID)
  608. {
  609. //
  610. // Changing tool -- exit face edit mode if necessary.
  611. // This is here because face edit mode encompasses two tools: the
  612. // material tool and the displacement tool. Which tool we use is set
  613. // by the OnSetActive handler of each page of the face edit sheet.
  614. //
  615. if (IsInFaceEditMode())
  616. {
  617. EnableFaceEditMode(false);
  618. }
  619. // Obtain custom tool handler
  620. IToolHandlerInfo *pHandlerInfo = _ToolToHanderInfo( nMessageID );
  621. BOOL bHandled = pHandlerInfo ? pHandlerInfo->Execute( nMessageID ) : FALSE;
  622. if ( !bHandled )
  623. {
  624. //
  625. // Activate the new tool.
  626. //
  627. ToolID_t eToolID = _ToolMsgToEnum(nMessageID);
  628. ToolManager()->SetTool(eToolID);
  629. }
  630. return TRUE;
  631. }
  632. //-----------------------------------------------------------------------------
  633. // Purpose: Brings up the
  634. //-----------------------------------------------------------------------------
  635. void CMainFrame::OnViewMessages(void)
  636. {
  637. g_pwndMessage->ToggleMessageWindow();
  638. }
  639. //-----------------------------------------------------------------------------
  640. // Purpose: Manages the state of the view messages menu item.
  641. //-----------------------------------------------------------------------------
  642. void CMainFrame::OnUpdateViewMessages(CCmdUI *pCmdUI)
  643. {
  644. pCmdUI->SetCheck( g_pwndMessage->IsVisible() );
  645. }
  646. //-----------------------------------------------------------------------------
  647. // Purpose: Brings up the Object Properties dialog.
  648. //-----------------------------------------------------------------------------
  649. void CMainFrame::OnEditProperties(void)
  650. {
  651. pObjectProperties->ShowWindow(pObjectProperties->IsWindowVisible() ? SW_HIDE : SW_SHOW);
  652. }
  653. //-----------------------------------------------------------------------------
  654. // Purpose: Tell all the documents to redraw all their views.
  655. //-----------------------------------------------------------------------------
  656. void CMainFrame::UpdateAllDocViews(DWORD dwCmd)
  657. {
  658. for ( int i=0; i<CMapDoc::GetDocumentCount(); i++ )
  659. {
  660. CMapDoc *pDoc = CMapDoc::GetDocument(i);
  661. if (pDoc->GetGame() != NULL)
  662. {
  663. pDoc->UpdateAllViews( dwCmd );
  664. }
  665. }
  666. if (dwCmd & MAPVIEW_UPDATE_VISGROUP_ALL)
  667. {
  668. // This updates everything, so it takes priority.
  669. m_FilterControl.UpdateGroupList();
  670. }
  671. else if (dwCmd & MAPVIEW_UPDATE_VISGROUP_STATE)
  672. {
  673. // Only update the hidden/shown state of the visgroups.
  674. m_FilterControl.UpdateGroupListChecks();
  675. }
  676. }
  677. //-----------------------------------------------------------------------------
  678. // Purpose: Informs our application object when we are activated or deactivated.
  679. // Input : bActive - TRUE to activate, FALSE to deactivate.
  680. // hTask - task becoming active.
  681. //-----------------------------------------------------------------------------
  682. #if _MSC_VER < 1300
  683. void CMainFrame::OnActivateApp(BOOL bActive, HTASK hTask)
  684. #else
  685. void CMainFrame::OnActivateApp(BOOL bActive, DWORD hTask)
  686. #endif
  687. {
  688. CMDIFrameWnd::OnActivateApp(bActive, hTask);
  689. // Had to change this code to not call GetWindowPlacement because for some reason
  690. // that prevented Hammer from maximizing properly -- it would leave space on top.
  691. // So I cache the minimized state instead, which fixes the problem. Sigh.
  692. if (!m_bMinimized)
  693. {
  694. MaterialSystemInterface()->EvictManagedResources();
  695. APP()->OnActivateApp(bActive == TRUE);
  696. }
  697. }
  698. //-----------------------------------------------------------------------------
  699. // Purpose:
  700. // Input : nID -
  701. // lParam -
  702. //-----------------------------------------------------------------------------
  703. void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
  704. {
  705. CMDIFrameWnd::OnSysCommand(nID, lParam);
  706. if (nID == SC_MINIMIZE)
  707. {
  708. m_bMinimized = true;
  709. APP()->OnActivateApp(false);
  710. }
  711. else if ((nID == SC_MAXIMIZE) || (nID == SC_RESTORE))
  712. {
  713. m_bMinimized = false;
  714. APP()->OnActivateApp(true);
  715. }
  716. }
  717. //-----------------------------------------------------------------------------
  718. // Purpose: Called when the active document is deleted.
  719. //-----------------------------------------------------------------------------
  720. void CMainFrame::OnDeleteActiveDocument(void)
  721. {
  722. pObjectProperties->MarkDataDirty();
  723. }
  724. //-----------------------------------------------------------------------------
  725. // Purpose: Handles resize messages. Resizes any children that depend on our size.
  726. // Input : nType -
  727. // cx -
  728. // cy -
  729. //-----------------------------------------------------------------------------
  730. void CMainFrame::OnSize(UINT nType, int cx, int cy)
  731. {
  732. CMDIFrameWnd::OnSize(nType, cx, cy);
  733. //
  734. // Resize the message window if it exists.
  735. //
  736. if ( g_pwndMessage != NULL )
  737. {
  738. CRect clientrect;
  739. wndMDIClient.GetClientRect(clientrect);
  740. g_pwndMessage->Resize(CRect(0, clientrect.Height() - 130, clientrect.Width(), clientrect.Height()));
  741. }
  742. }
  743. //-----------------------------------------------------------------------------
  744. // Purpose: Returns a pointer to the main frame window.
  745. //-----------------------------------------------------------------------------
  746. CMainFrame *GetMainWnd(void)
  747. {
  748. return g_pMainWnd;
  749. }
  750. //-----------------------------------------------------------------------------
  751. // Purpose:
  752. // Input : nIndex -
  753. // pszText -
  754. //-----------------------------------------------------------------------------
  755. void SetStatusText(int nIndex, LPCTSTR pszText)
  756. {
  757. GetMainWnd()->GetStatusBar()->SetPaneText(nIndex, pszText);
  758. }
  759. //-----------------------------------------------------------------------------
  760. // Purpose: Invokes the configuration dialog, saving the options if the user
  761. // hits the OK button.
  762. //-----------------------------------------------------------------------------
  763. void CMainFrame::Configure(void)
  764. {
  765. COptionProperties dlg("Configure Hammer", NULL, 0);
  766. if (dlg.DoModal() == IDOK)
  767. {
  768. Options.Write( TRUE, TRUE );
  769. }
  770. }
  771. //-----------------------------------------------------------------------------
  772. // Purpose: Invokes the configuration dialog.
  773. //-----------------------------------------------------------------------------
  774. void CMainFrame::OnToolsOptions(void)
  775. {
  776. Configure();
  777. }
  778. //-----------------------------------------------------------------------------
  779. // Purpose: Called when the main frame is closing. Cleans up the dialog bars
  780. // and saves the options to the registry.
  781. //-----------------------------------------------------------------------------
  782. void CMainFrame::OnClose()
  783. {
  784. // Copied from CFrameWnd::OnClose. We can't call APP()->BeginClosing if they
  785. // hit cancel in the Save Modified dialog, and CFrameWnd::OnClose doesn't have
  786. // a return code to let us know if we're actually closing. Preposterous.
  787. // Note: only queries the active document
  788. CDocument *pDocument = GetActiveDocument();
  789. if (pDocument != NULL && !pDocument->CanCloseFrame(this))
  790. {
  791. // document can't close right now -- don't close it
  792. return;
  793. }
  794. //
  795. // Save the splitter configuration of the first child window in our list.
  796. //
  797. CChildFrame *pChild = GetNextMDIChildWnd(NULL);
  798. if (pChild != NULL)
  799. {
  800. pChild->SaveOptions();
  801. }
  802. CWinApp *pApp = AfxGetApp();
  803. if (pApp != NULL && pApp->m_pMainWnd == this)
  804. {
  805. // attempt to save all documents
  806. if (pDocument == NULL && !pApp->SaveAllModified())
  807. {
  808. // don't close it
  809. return;
  810. }
  811. pApp->CloseAllDocuments( FALSE );
  812. }
  813. // End of copied stuff.
  814. APP()->BeginClosing();
  815. // want to save the faceeditor as hidden
  816. ShowFaceEditSheetOrTextureBar( false );
  817. SaveBarState("Barstate");
  818. //AfxGetApp()->WriteProfileInt("General", "NewBars", TRUE);
  819. // Remove the smoothing group dialog window.
  820. m_SmoothingGroupDlg.DestroyWindow();
  821. // save options
  822. Options.general.bClosedCorrectly = TRUE;
  823. Options.Write( TRUE, TRUE );
  824. CMDIFrameWnd::OnClose();
  825. }
  826. //-----------------------------------------------------------------------------
  827. //-----------------------------------------------------------------------------
  828. void CMainFrame::OnDestroy(void)
  829. {
  830. CMDIFrameWnd::OnDestroy();
  831. PostQuitMessage(-1);
  832. }
  833. //-----------------------------------------------------------------------------
  834. // Purpose: Sets a timer for destroying the splash screen.
  835. //-----------------------------------------------------------------------------
  836. void CMainFrame::OnPaint(void)
  837. {
  838. static bool bFirst = true;
  839. CPaintDC dc(this); // device context for painting
  840. if (bFirst)
  841. {
  842. bFirst = false;
  843. SetTimer(FIRST_TIMER, 500, NULL);
  844. }
  845. }
  846. //-----------------------------------------------------------------------------
  847. // Purpose: This is called ONCE when the splash wnd is to be destroyed. OnPaint()
  848. // sets the timer. This is now also called for the autosave timer.
  849. // Input : nIDEvent -
  850. //-----------------------------------------------------------------------------
  851. void CMainFrame::OnTimer(UINT nIDEvent)
  852. {
  853. if (!::IsWindow(m_hWnd))
  854. {
  855. return;
  856. }
  857. if( nIDEvent == AUTOSAVE_TIMER )
  858. {
  859. APP()->Autosave();
  860. }
  861. if( nIDEvent == FIRST_TIMER ) //for the splash scren window destruction
  862. {
  863. // only want it once
  864. KillTimer(nIDEvent);
  865. // Don't continue if Hammer isn't configured yet!
  866. if (Options.configs.nConfigs == 0)
  867. return;
  868. Options.SetClosedCorrectly( FALSE );
  869. SetBrightness(Options.textures.fBrightness);
  870. // repaint texture window
  871. m_TextureBar.Invalidate();
  872. //when hammer is ready, start the autosave timer.
  873. if ( Options.general.iMaxAutosavesPerMap != 0 )
  874. {
  875. SetTimer( AUTOSAVE_TIMER, Options.general.iTimeBetweenSaves * 60 * 1000, NULL );
  876. }
  877. }
  878. }
  879. //-----------------------------------------------------------------------------
  880. // Purpose: Called when timer value is changed in the options
  881. // Input : void
  882. //-----------------------------------------------------------------------------
  883. void CMainFrame::ResetAutosaveTimer( void )
  884. {
  885. if ( Options.general.iMaxAutosavesPerMap != 0 )
  886. {
  887. SetTimer( AUTOSAVE_TIMER, Options.general.iTimeBetweenSaves * 60 * 1000, NULL );
  888. }
  889. else
  890. {
  891. KillTimer( AUTOSAVE_TIMER );
  892. }
  893. }
  894. //-----------------------------------------------------------------------------
  895. // Purpose:
  896. // Input : fBrightness -
  897. //-----------------------------------------------------------------------------
  898. void CMainFrame::SetBrightness(float fBrightness)
  899. {
  900. if(fBrightness < 0.1f || fBrightness > 5.0f)
  901. return;
  902. // update options
  903. Options.textures.fBrightness = fBrightness;
  904. // update display
  905. for(int i = 0; i < Options.configs.nConfigs; i++)
  906. Options.configs.Configs[i]->Palette.SetBrightness(fBrightness);
  907. g_Textures.InformPaletteChanged();
  908. //
  909. // if current tool isn't the material tool, then redraw the texture bar
  910. //
  911. if ( ToolManager()->GetActiveToolID() != TOOL_FACEEDIT_MATERIAL )
  912. {
  913. m_TextureBar.RedrawWindow();
  914. }
  915. else
  916. {
  917. m_pFaceEditSheet->RedrawWindow();
  918. }
  919. // tell all the documents to redraw 3d views
  920. UpdateAllDocViews( MAPVIEW_UPDATE_ONLY_3D | MAPVIEW_UPDATE_COLOR );
  921. }
  922. //-----------------------------------------------------------------------------
  923. // Purpose:
  924. // Input : nID -
  925. // Output : Returns TRUE on success, FALSE on failure.
  926. //-----------------------------------------------------------------------------
  927. BOOL CMainFrame::OnView3dChangeBrightness(UINT nID)
  928. {
  929. float fBrightness = Options.textures.fBrightness;
  930. float fModify = (nID == ID_VIEW3D_BRIGHTER) ? 0.2f : -0.2f;
  931. SetBrightness(fBrightness + fModify);
  932. return TRUE;
  933. }
  934. //-----------------------------------------------------------------------------
  935. // Purpose: Brings up the sound browser
  936. //-----------------------------------------------------------------------------
  937. BOOL CMainFrame::OnSoundBrowser(UINT nID)
  938. {
  939. CSoundBrowser dlg("");
  940. dlg.DoModal();
  941. return TRUE;
  942. }
  943. //-----------------------------------------------------------------------------
  944. //-----------------------------------------------------------------------------
  945. CModelBrowser *CMainFrame::GetModelBrowser()
  946. {
  947. delete m_pModelBrowser;
  948. m_pModelBrowser = NULL;
  949. if (m_pModelBrowser == NULL)
  950. {
  951. m_pModelBrowser = new CModelBrowser( this );
  952. }
  953. return m_pModelBrowser;
  954. }
  955. //-----------------------------------------------------------------------------
  956. // Brings up the model browser.
  957. //-----------------------------------------------------------------------------
  958. void CMainFrame::OnModelBrowser()
  959. {
  960. CModelBrowser *pModelBrowser = GetModelBrowser();
  961. pModelBrowser->Show();
  962. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  963. CUtlVector<AssetUsageInfo_t> usedModels;
  964. pDoc->GetUsedModels( usedModels );
  965. pModelBrowser->SetUsedModelList( usedModels );
  966. int nRet = pModelBrowser->DoModal();
  967. pModelBrowser->Hide();
  968. if ( nRet == ID_FIND_ASSET )
  969. {
  970. // They hit the Find button in the model browser. Invoke the Entity Report dialog
  971. // to find all occurences of the chosen model.
  972. char szModelName[1024];
  973. pModelBrowser->GetModelName( szModelName, sizeof( szModelName ) );
  974. EntityReportFilterParms_t filter;
  975. filter.FilterByKeyValue( "model", szModelName );
  976. CEntityReportDlg::ShowEntityReport( pDoc, this, &filter );
  977. }
  978. }
  979. //-----------------------------------------------------------------------------
  980. // Purpose: Brings up the sound browser
  981. //-----------------------------------------------------------------------------
  982. BOOL CMainFrame::OnReloadSounds(UINT nID)
  983. {
  984. for ( int i = 0; i < SOUND_TYPE_COUNT; ++i )
  985. {
  986. g_Sounds.BuildSoundList( (SoundType_t)i );
  987. }
  988. return TRUE;
  989. }
  990. //-----------------------------------------------------------------------------
  991. // Purpose: Toggles face edit mode, which encompasses two different tools, the
  992. // materials editing tool and the displacement editing tool.
  993. //
  994. // The tool itself is set by the OnSetActive handler for each property
  995. // page of the face properties sheet.
  996. //-----------------------------------------------------------------------------
  997. BOOL CMainFrame::OnApplicator(UINT nID)
  998. {
  999. bool bNewFaceEditMode = !IsInFaceEditMode();
  1000. //
  1001. // Show/hide face edit sheet/texturebar and update the selection set if need be.
  1002. //
  1003. EnableFaceEditMode(bNewFaceEditMode);
  1004. if (!bNewFaceEditMode)
  1005. {
  1006. ToolManager()->SetTool(TOOL_POINTER);
  1007. }
  1008. return TRUE;
  1009. }
  1010. //-----------------------------------------------------------------------------
  1011. // Purpose: Enables or disables face edit mode, updating the UI as necessary.
  1012. // When we are in face edit mode, the texture bar is hidden and the
  1013. // face edit property sheet is shown. The active tool is changed
  1014. // to either the material tool or the displacement tool based on which
  1015. // page in the property sheet is active.
  1016. //-----------------------------------------------------------------------------
  1017. void CMainFrame::EnableFaceEditMode(bool bEnable)
  1018. {
  1019. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  1020. if (!pDoc)
  1021. {
  1022. return;
  1023. }
  1024. ShowFaceEditSheetOrTextureBar(bEnable);
  1025. pDoc->UpdateForApplicator(bEnable);
  1026. }
  1027. //-----------------------------------------------------------------------------
  1028. // Purpose: Returns true if we are in face edit mode, false if not.
  1029. //-----------------------------------------------------------------------------
  1030. bool CMainFrame::IsInFaceEditMode()
  1031. {
  1032. if ((ToolManager()->GetActiveToolID() == TOOL_FACEEDIT_MATERIAL) || (ToolManager()->GetActiveToolID() == TOOL_FACEEDIT_DISP))
  1033. {
  1034. return true;
  1035. }
  1036. return false;
  1037. }
  1038. //-----------------------------------------------------------------------------
  1039. // Purpose: Manages the state of the texture applicator toobar button and menu item.
  1040. //-----------------------------------------------------------------------------
  1041. void CMainFrame::OnUpdateApplicatorUI(CCmdUI *pUI)
  1042. {
  1043. if (IsShellSessionActive())
  1044. {
  1045. pUI->Enable(FALSE);
  1046. }
  1047. else
  1048. {
  1049. pUI->SetCheck(IsInFaceEditMode());
  1050. pUI->Enable(CMapDoc::GetActiveMapDoc() ? TRUE : FALSE);
  1051. }
  1052. }
  1053. //-----------------------------------------------------------------------------
  1054. // Purpose: Invokes the prefab manager dialog.
  1055. //-----------------------------------------------------------------------------
  1056. void CMainFrame::OnToolsPrefabfactory(void)
  1057. {
  1058. CPrefabsDlg dlg;
  1059. dlg.DoModal();
  1060. CPrefabLibrary::LoadAllLibraries();
  1061. m_ObjectBar.UpdateListForTool( ToolManager()->GetActiveToolID());
  1062. }
  1063. //-----------------------------------------------------------------------------
  1064. // Purpose:
  1065. //-----------------------------------------------------------------------------
  1066. void CMainFrame::OnHelpFinder(void)
  1067. {
  1068. APP()->OpenURL(ID_HELP_TOPICS, GetMainWnd()->GetSafeHwnd());
  1069. }
  1070. //-----------------------------------------------------------------------------
  1071. // Purpose:
  1072. // Input : pHelpInfo -
  1073. // Output : Returns TRUE on success, FALSE on failure.
  1074. //-----------------------------------------------------------------------------
  1075. BOOL CMainFrame::OnHelpInfo(HELPINFO *pHelpInfo)
  1076. {
  1077. return(Default());
  1078. }
  1079. //-----------------------------------------------------------------------------
  1080. // Purpose: Opens a URL in the default web browser.
  1081. //-----------------------------------------------------------------------------
  1082. void CMainFrame::OpenURL(const char *pszURL)
  1083. {
  1084. APP()->OpenURL(pszURL, m_hWnd);
  1085. }
  1086. //-----------------------------------------------------------------------------
  1087. // Purpose: Opens a URL in the default web browser by string ID.
  1088. //-----------------------------------------------------------------------------
  1089. void CMainFrame::OpenURL(UINT nID)
  1090. {
  1091. APP()->OpenURL(nID, m_hWnd);
  1092. }
  1093. //-----------------------------------------------------------------------------
  1094. // Purpose: Opens the URL that corresponds to the given string ID. This is used
  1095. // to hook menu items to URLs in the string table.
  1096. //-----------------------------------------------------------------------------
  1097. BOOL CMainFrame::OnHelpOpenURL(UINT nID)
  1098. {
  1099. OpenURL(nID);
  1100. return TRUE;
  1101. }
  1102. //-----------------------------------------------------------------------------
  1103. // Purpose: Activates or deactivates Undo/Redo.
  1104. //-----------------------------------------------------------------------------
  1105. void CMainFrame::SetUndoActive(BOOL bActive)
  1106. {
  1107. m_bUndoActive = bActive;
  1108. CMapDoc::GetActiveMapDoc()->SetUndoActive(bActive == TRUE);
  1109. }
  1110. //-----------------------------------------------------------------------------
  1111. // Purpose: Toggles the active state of Undo/Redo.
  1112. //-----------------------------------------------------------------------------
  1113. void CMainFrame::OnEditUndoredoactive(void)
  1114. {
  1115. SetUndoActive(!m_bUndoActive);
  1116. }
  1117. //-----------------------------------------------------------------------------
  1118. // Purpose: Manages the state of the Enable/Disable Undo/Redo menu item.
  1119. //-----------------------------------------------------------------------------
  1120. void CMainFrame::OnUpdateEditUndoredoactive(CCmdUI *pCmdUI)
  1121. {
  1122. pCmdUI->Enable(IsShellSessionActive() ? FALSE : TRUE);
  1123. pCmdUI->SetText(m_bUndoActive ? "Disable Undo/Redo" : "Enable Undo/Redo");
  1124. }
  1125. //-----------------------------------------------------------------------------
  1126. // Purpose:
  1127. // Input : nCode -
  1128. //-----------------------------------------------------------------------------
  1129. void CMainFrame::GlobalNotify(int nCode)
  1130. {
  1131. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  1132. switch (nCode)
  1133. {
  1134. //
  1135. // Active document changed. Update visgroup lists.
  1136. //
  1137. case WM_MAPDOC_CHANGED:
  1138. {
  1139. //
  1140. // Update the visgroups & cordons.
  1141. //
  1142. m_FilterControl.UpdateGroupList();
  1143. m_FilterControl.UpdateCordonList();
  1144. //
  1145. // If the Object Properties dialog has a Groups tab, update
  1146. // the groups tab.
  1147. //
  1148. if (pObjectProperties != NULL)
  1149. {
  1150. pObjectProperties->UpdateGrouplist();
  1151. }
  1152. if (pDoc != NULL)
  1153. {
  1154. pDoc->UpdateStatusbar();
  1155. //m_AnimationDlg.SelectionChanged(*pDoc->Selection_GetList());
  1156. }
  1157. m_ManifestFilterControl.UpdateManifestList();
  1158. break;
  1159. }
  1160. //
  1161. // Game configuration changed. Update texture and entity lists.
  1162. //
  1163. case WM_GAME_CHANGED:
  1164. {
  1165. pTextureBrowser->SetTextureFormat(g_pGameConfig->GetTextureFormat());
  1166. m_TextureBar.NotifyGraphicsChanged();
  1167. m_pFaceEditSheet->NotifyGraphicsChanged();
  1168. if (pDoc != NULL)
  1169. m_ObjectBar.UpdateListForTool( pDoc->GetTools()->GetActiveToolID());
  1170. break;
  1171. }
  1172. //
  1173. // Lighting preview window closed
  1174. //
  1175. case LPRV_WINDOWCLOSED:
  1176. {
  1177. m_bLightingPreviewOutputWindowShowing = false;
  1178. break;
  1179. }
  1180. }
  1181. }
  1182. //-----------------------------------------------------------------------------
  1183. // Purpose:
  1184. // Input : UINT -
  1185. // Output : Returns TRUE on success, FALSE on failure.
  1186. //-----------------------------------------------------------------------------
  1187. BOOL CMainFrame::OnFileNew(UINT)
  1188. {
  1189. return FALSE;
  1190. CNewDocType dlg;
  1191. dlg.m_iNewType = 0;
  1192. if(dlg.DoModal() != IDOK)
  1193. return TRUE;
  1194. return FALSE;
  1195. }
  1196. //-----------------------------------------------------------------------------
  1197. // Purpose: Saves the position and types of all 2D and 3D views in the active document.
  1198. // dvs: This really needs to be a text file instead of a binary file!
  1199. // Input : *pFile -
  1200. //-----------------------------------------------------------------------------
  1201. void CMainFrame::SaveWindowStates(std::fstream *pFile)
  1202. {
  1203. char szRootDir[MAX_PATH];
  1204. char szFullPath[MAX_PATH];
  1205. APP()->GetDirectory(DIR_PROGRAM, szRootDir);
  1206. Q_MakeAbsolutePath( szFullPath, MAX_PATH, "winstate.wc", szRootDir );
  1207. std::fstream file(szFullPath, std::ios::out | std::ios::binary);
  1208. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  1209. if (pDoc == NULL)
  1210. {
  1211. return;
  1212. }
  1213. file.write(WINSTATETAG, sizeof WINSTATETAG);
  1214. file.write((char*) &fVersion, sizeof fVersion);
  1215. CRect rectClient;
  1216. ::GetClientRect(m_hWndMDIClient, &rectClient);
  1217. // write out each view
  1218. POSITION p = pDoc->GetFirstViewPosition();
  1219. while (p != NULL)
  1220. {
  1221. CView *pView = pDoc->GetNextView(p);
  1222. //
  1223. // Determine what type of view it is.
  1224. //
  1225. int iDrawType;
  1226. if (pView->IsKindOf(RUNTIME_CLASS(CMapView2D)))
  1227. {
  1228. file.write((char*) &WINSTATE2DVIEW, sizeof WINSTATE2DVIEW);
  1229. iDrawType = (int)((CMapView2D*)pView)->GetDrawType();
  1230. }
  1231. else if (pView->IsKindOf(RUNTIME_CLASS(CMapView3D)))
  1232. {
  1233. file.write((char*) &WINSTATE3DVIEW, sizeof WINSTATE3DVIEW);
  1234. iDrawType = (int)((CMapView3D*)pView)->GetDrawType();
  1235. }
  1236. else if (pView->IsKindOf(RUNTIME_CLASS(CMapViewLogical)))
  1237. {
  1238. file.write((char*) &WINSTATELOGICALVIEW, sizeof WINSTATELOGICALVIEW);
  1239. iDrawType = (int)((CMapViewLogical*)pView)->GetDrawType();
  1240. }
  1241. else
  1242. {
  1243. //
  1244. // It's a view type whose state we do not save - skip it.
  1245. //
  1246. continue;
  1247. }
  1248. //
  1249. // Write view's draw type.
  1250. //
  1251. file.write((char*) &iDrawType, sizeof iDrawType);
  1252. //
  1253. // Write position of view.
  1254. //
  1255. CRect rectView;
  1256. pView->GetParentFrame()->GetWindowRect(&rectView);
  1257. CPoint pt1 = rectView.TopLeft(), pt2 = rectView.BottomRight();
  1258. ::ScreenToClient(m_hWndMDIClient, &pt1);
  1259. ::ScreenToClient(m_hWndMDIClient, &pt2);
  1260. double left, top, right, bottom;
  1261. left = double(pt1.x) / double(rectClient.right);
  1262. top = double(pt1.y) / double(rectClient.bottom);
  1263. right = double(pt2.x) / double(rectClient.right);
  1264. bottom = double(pt2.y) / double(rectClient.bottom);
  1265. file.write((char*) &left, sizeof left);
  1266. file.write((char*) &top, sizeof top);
  1267. file.write((char*) &right, sizeof right);
  1268. file.write((char*) &bottom, sizeof bottom);
  1269. }
  1270. file.write((char *)&WINSTATEEND, sizeof WINSTATEEND);
  1271. }
  1272. //-----------------------------------------------------------------------------
  1273. // Purpose:
  1274. // Input : pFile -
  1275. //-----------------------------------------------------------------------------
  1276. void CMainFrame::LoadWindowStates(std::fstream *pFile)
  1277. {
  1278. char szRootDir[MAX_PATH];
  1279. char szFullPath[MAX_PATH];
  1280. APP()->GetDirectory(DIR_PROGRAM, szRootDir);
  1281. Q_MakeAbsolutePath( szFullPath, MAX_PATH, "winstate.wc", szRootDir );
  1282. std::fstream file( szFullPath, std::ios::in | std::ios::binary );
  1283. if (!file.is_open())
  1284. {
  1285. return;
  1286. }
  1287. char tag[sizeof(WINSTATETAG)];
  1288. file.read(tag, sizeof tag);
  1289. if(memcmp(tag, WINSTATETAG, sizeof tag))
  1290. {
  1291. file.seekg(-int(sizeof(tag)));
  1292. return;
  1293. }
  1294. float fThisVersion;
  1295. file.read((char*) &fThisVersion, sizeof fThisVersion);
  1296. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  1297. if(!pDoc)
  1298. return;
  1299. // get client rect of MDI CHILD for relative positioning information
  1300. CRect rectClient;
  1301. ::GetClientRect(m_hWndMDIClient, &rectClient);
  1302. // keep list of views we've already modified, so if there
  1303. // are other views, we have to create them. this prevents
  1304. // us from having to delete all views and start over,
  1305. // which is a slower process than simply moving existing
  1306. // views.
  1307. CTypedPtrList<CPtrList, CView*> UsedViews;
  1308. SetDefaultChildType(FALSE);
  1309. while (1)
  1310. {
  1311. int iViewType;
  1312. file.read((char *)&iViewType, sizeof iViewType);
  1313. if ((file.eof()) || (iViewType == WINSTATEEND))
  1314. {
  1315. break;
  1316. }
  1317. int iDrawType;
  1318. file.read((char *)&iDrawType, sizeof iDrawType);
  1319. CView *pView = NULL;
  1320. // find a view we haven't used
  1321. POSITION p = pDoc->GetFirstViewPosition();
  1322. while (p != NULL)
  1323. {
  1324. CView *pThisView = pDoc->GetNextView(p);
  1325. // already used?
  1326. if (UsedViews.Find(pThisView))
  1327. continue;
  1328. // make sure it's the right type ..
  1329. if (iViewType == WINSTATE2DVIEW && !pThisView->IsKindOf(RUNTIME_CLASS(CMapView2D)))
  1330. continue;
  1331. if (iViewType == WINSTATELOGICALVIEW && !pThisView->IsKindOf(RUNTIME_CLASS(CMapViewLogical)))
  1332. continue;
  1333. if (iViewType == WINSTATE3DVIEW && !pThisView->IsKindOf(RUNTIME_CLASS(CMapView3D)))
  1334. continue;
  1335. // yes! so modify this one.
  1336. pView = pThisView;
  1337. UsedViews.AddTail(pView);
  1338. break;
  1339. }
  1340. CChildFrame *pFrame = NULL;
  1341. BOOL bNew = FALSE;
  1342. CDocTemplate *pTemplate = NULL;
  1343. if(!pView)
  1344. {
  1345. // if no view was created, we have to create a new one.
  1346. CMDIChildWnd* pActiveChild = MDIGetActive();
  1347. pTemplate = pDoc->GetDocTemplate();
  1348. pFrame = (CChildFrame*) pTemplate->CreateNewFrame(pDoc, pActiveChild);
  1349. pFrame->SetRedraw(FALSE);
  1350. pTemplate->InitialUpdateFrame(pFrame, pDoc, FALSE);
  1351. // find view in new frame
  1352. pView = pFrame->GetActiveView();
  1353. UsedViews.AddTail(pView);
  1354. bNew = TRUE;
  1355. }
  1356. else
  1357. {
  1358. // find frame based on this view
  1359. pFrame = (CChildFrame*) pView->GetParentFrame();
  1360. if(pFrame->bUsingSplitter)
  1361. pFrame->SetSplitterMode(FALSE);
  1362. }
  1363. // no redraws right now, please.
  1364. pFrame->SetRedraw(FALSE);
  1365. if (iViewType == WINSTATE3DVIEW)
  1366. {
  1367. //
  1368. // Handle import of old WinState files before draw types were consolidated
  1369. // into a single enumeration.
  1370. //
  1371. if ((iDrawType >= VIEW2D_XY) && (iDrawType <= VIEW2D_XZ))
  1372. {
  1373. iDrawType += 3;
  1374. }
  1375. pFrame->SetViewType((DrawType_t)iDrawType);
  1376. }
  1377. else if (iViewType == WINSTATE2DVIEW)
  1378. {
  1379. pFrame->SetViewType((DrawType_t)iDrawType);
  1380. }
  1381. else if (iViewType == WINSTATELOGICALVIEW)
  1382. {
  1383. pFrame->SetViewType( (DrawType_t)iDrawType );
  1384. }
  1385. // read positioning info
  1386. double left, top, right, bottom;
  1387. file.read((char*) &left, sizeof left);
  1388. file.read((char*) &top, sizeof top);
  1389. file.read((char*) &right, sizeof right);
  1390. file.read((char*) &bottom, sizeof bottom);
  1391. CRect r;
  1392. r.left = int(left * double(rectClient.right));
  1393. r.top = int(top * double(rectClient.bottom));
  1394. r.right = int(right * double(rectClient.right));
  1395. r.bottom = int(bottom * double(rectClient.bottom));
  1396. // Set the frame's position.
  1397. pFrame->MoveWindow(&r, FALSE);
  1398. // Call OnInitialUpdate before any rendering takes place.
  1399. if (bNew)
  1400. {
  1401. pTemplate->InitialUpdateFrame(pFrame, pDoc, TRUE);
  1402. }
  1403. // Enable WM_PAINT messages for the frame window.
  1404. pFrame->SetRedraw(TRUE);
  1405. // Update the window.
  1406. pFrame->Invalidate();
  1407. pFrame->UpdateWindow();
  1408. }
  1409. Invalidate();
  1410. UpdateWindow();
  1411. }
  1412. void CMainFrame::OnInitMenu( CMenu *pMenu )
  1413. {
  1414. }
  1415. void CMainFrame::OnHDR( void )
  1416. {
  1417. CMenu *pMenu= GetMenu();
  1418. UINT state = pMenu->GetMenuState(ID_HDR, MF_BYCOMMAND);
  1419. if (state & MF_CHECKED)
  1420. {
  1421. pMenu->CheckMenuItem(ID_HDR, MF_UNCHECKED | MF_BYCOMMAND);
  1422. g_bHDR = false;
  1423. }
  1424. else
  1425. {
  1426. pMenu->CheckMenuItem(ID_HDR, MF_CHECKED | MF_BYCOMMAND);
  1427. g_bHDR = true;
  1428. }
  1429. DrawMenuBar();
  1430. SignalUpdate( EVTYPE_LIGHTING_CHANGED );
  1431. }
  1432. //-----------------------------------------------------------------------------
  1433. // Purpose:
  1434. //-----------------------------------------------------------------------------
  1435. void CMainFrame::OnSavewindowstate(void)
  1436. {
  1437. SaveWindowStates();
  1438. }
  1439. //-----------------------------------------------------------------------------
  1440. // Purpose:
  1441. //-----------------------------------------------------------------------------
  1442. void CMainFrame::OnLoadwindowstate(void)
  1443. {
  1444. LoadWindowStates();
  1445. }
  1446. //-----------------------------------------------------------------------------
  1447. // Purpose: Changes the format of the units displayed in the status bar.
  1448. // Input : nID - Menu ID corresponding to a units format.
  1449. //-----------------------------------------------------------------------------
  1450. BOOL CMainFrame::OnUnits(UINT nID)
  1451. {
  1452. switch (nID)
  1453. {
  1454. case ID_MAP_UNITS_NONE:
  1455. {
  1456. Box3D::SetWorldUnits(Units_None);
  1457. break;
  1458. }
  1459. case ID_MAP_UNITS_INCHES:
  1460. {
  1461. Box3D::SetWorldUnits(Units_Inches);
  1462. break;
  1463. }
  1464. case ID_MAP_UNITS_FEET_INCHES:
  1465. {
  1466. Box3D::SetWorldUnits(Units_Feet_Inches);
  1467. break;
  1468. }
  1469. }
  1470. CMapDoc::GetActiveMapDoc()->UpdateStatusbar();
  1471. return TRUE;
  1472. }
  1473. //-----------------------------------------------------------------------------
  1474. // Purpose: Manages the state of decal application toolbar button.
  1475. //-----------------------------------------------------------------------------
  1476. void CMainFrame::OnUpdateUnits(CCmdUI *pCmdUI)
  1477. {
  1478. pCmdUI->Enable(!IsShellSessionActive());
  1479. if (pCmdUI->m_nID == ID_MAP_UNITS_NONE)
  1480. {
  1481. pCmdUI->SetCheck(Box3D::GetWorldUnits() == Units_None);
  1482. }
  1483. else if (pCmdUI->m_nID == ID_MAP_UNITS_INCHES)
  1484. {
  1485. pCmdUI->SetCheck(Box3D::GetWorldUnits() == Units_Inches);
  1486. }
  1487. else if (pCmdUI->m_nID == ID_MAP_UNITS_FEET_INCHES)
  1488. {
  1489. pCmdUI->SetCheck(Box3D::GetWorldUnits() == Units_Feet_Inches);
  1490. }
  1491. }
  1492. //-----------------------------------------------------------------------------
  1493. // Purpose:
  1494. // Input : pMsg -
  1495. // Output : Returns TRUE on success, FALSE on failure.
  1496. //-----------------------------------------------------------------------------
  1497. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
  1498. {
  1499. //
  1500. // See if the message is a keydown and the current focus window is the
  1501. // ComboBox in the ObjectBar!
  1502. //
  1503. /*
  1504. if (pMsg->message == WM_KEYDOWN)
  1505. {
  1506. if ((GetFocus() == &m_ObjectBar) || (GetFocus() == &this->m_FilterControl))
  1507. {
  1508. AfxMessageBox("Ok");
  1509. return(TRUE);
  1510. }
  1511. }
  1512. */
  1513. return(CMDIFrameWnd::PreTranslateMessage(pMsg));
  1514. }
  1515. //-----------------------------------------------------------------------------
  1516. // Purpose: Finds the next CChildFrame in the list of MDI child windows.
  1517. // Input : pCurChild - Child to search from.
  1518. //-----------------------------------------------------------------------------
  1519. CChildFrame *CMainFrame::GetNextMDIChildWnd(CChildFrame *pCurChild)
  1520. {
  1521. return GetNextMDIChildWndRecursive(pCurChild);
  1522. }
  1523. //-----------------------------------------------------------------------------
  1524. // Purpose:
  1525. //-----------------------------------------------------------------------------
  1526. CChildFrame *CMainFrame::GetNextMDIChildWndRecursive(CWnd *pCurChild)
  1527. {
  1528. CWnd *pNextChild = NULL;
  1529. if (pCurChild == NULL)
  1530. {
  1531. // Get the first child window.
  1532. pNextChild = wndMDIClient.GetWindow(GW_CHILD);
  1533. }
  1534. else
  1535. {
  1536. // Get the next child window in the list.
  1537. pNextChild = pCurChild->GetWindow(GW_HWNDNEXT);
  1538. if (!pNextChild)
  1539. {
  1540. // No child windows exist in the MDIClient,
  1541. // or you are at the end of the list. This check
  1542. // will terminate any recursion.
  1543. return NULL;
  1544. }
  1545. }
  1546. // Check the kind of window
  1547. if (!pNextChild->GetWindow(GW_OWNER))
  1548. {
  1549. if (pNextChild->IsKindOf(RUNTIME_CLASS(CChildFrame)))
  1550. {
  1551. return (CChildFrame *)pNextChild;
  1552. }
  1553. }
  1554. // Not one we are interested in. Try the next one.
  1555. // Recurse over the window manager's list of windows.
  1556. return GetNextMDIChildWndRecursive(pNextChild);
  1557. }
  1558. //-----------------------------------------------------------------------------
  1559. // Purpose: Returns true if we are currently editing via the engine, false if not.
  1560. //-----------------------------------------------------------------------------
  1561. bool CMainFrame::IsShellSessionActive(void)
  1562. {
  1563. return(m_bShellSessionActive);
  1564. }
  1565. //-----------------------------------------------------------------------------
  1566. // Purpose: Manages the state of all Edit menu items and toolbar buttons.
  1567. //-----------------------------------------------------------------------------
  1568. void CMainFrame::OnUpdateEditFunction(CCmdUI *pCmdUI)
  1569. {
  1570. pCmdUI->Enable(!IsShellSessionActive());
  1571. }
  1572. //-----------------------------------------------------------------------------
  1573. //-----------------------------------------------------------------------------
  1574. void CMainFrame::ShowFaceEditSheetOrTextureBar( bool bShowFaceEditSheet )
  1575. {
  1576. if( bShowFaceEditSheet )
  1577. {
  1578. m_pFaceEditSheet->SetVisibility( true );
  1579. ShowControlBar( &m_TextureBar, FALSE, TRUE );
  1580. }
  1581. else
  1582. {
  1583. m_pFaceEditSheet->SetVisibility( false );
  1584. m_pFaceEditSheet->CloseAllPageDialogs();
  1585. ShowControlBar( &m_TextureBar, TRUE, TRUE );
  1586. }
  1587. }
  1588. //-----------------------------------------------------------------------------
  1589. // Purpose: Displays the search/replace dialog. It will be hide itself when the
  1590. // user closes it.
  1591. //-----------------------------------------------------------------------------
  1592. void CMainFrame::ShowSearchReplaceDialog(void)
  1593. {
  1594. if (m_pSearchReplaceDlg == NULL)
  1595. {
  1596. m_pSearchReplaceDlg = new CSearchReplaceDlg;
  1597. m_pSearchReplaceDlg->Create(this);
  1598. }
  1599. m_pSearchReplaceDlg->ShowWindow(SW_SHOW);
  1600. m_pSearchReplaceDlg->SetFocus();
  1601. }
  1602. //-----------------------------------------------------------------------------
  1603. // Purpose: Code found on codeproject.com.
  1604. //
  1605. // Makes sure we don't have bogus dialog bar information in the registry.
  1606. // This prevents a crash in the MFC code if a version of the editor with
  1607. // different toolbars was run before us.
  1608. //
  1609. // TODO: fix the registry settings if they are bad so we can still load the bar state
  1610. //
  1611. // Output : Returns true if it is safe to load the toolbar settings, false if not.
  1612. //-----------------------------------------------------------------------------
  1613. bool CMainFrame::VerifyBarState(void)
  1614. {
  1615. CDockState state;
  1616. state.LoadState("BarState");
  1617. for (int i = 0; i < state.m_arrBarInfo.GetSize(); i++)
  1618. {
  1619. CControlBarInfo* pInfo = (CControlBarInfo*)state.m_arrBarInfo[i];
  1620. Assert(pInfo != NULL);
  1621. int nDockedCount = pInfo->m_arrBarID.GetSize();
  1622. if (nDockedCount > 0)
  1623. {
  1624. for (int j = 0; j < nDockedCount; j++)
  1625. {
  1626. UINT nID = (UINT) pInfo->m_arrBarID[j];
  1627. if (nID == 0)
  1628. {
  1629. continue; // row separator
  1630. }
  1631. if (nID > 0xFFFF)
  1632. {
  1633. nID &= 0xFFFF; // placeholder - get the ID
  1634. }
  1635. if (GetControlBar(nID) == NULL)
  1636. {
  1637. return false;
  1638. }
  1639. }
  1640. }
  1641. if (!pInfo->m_bFloating) // floating dockbars can be created later
  1642. {
  1643. if (GetControlBar(pInfo->m_nBarID) == NULL)
  1644. {
  1645. return false; // invalid bar ID
  1646. }
  1647. }
  1648. }
  1649. return true;
  1650. }
  1651. //-----------------------------------------------------------------------------
  1652. // Purpose:
  1653. // Input : dwData -
  1654. // nCmd -
  1655. //-----------------------------------------------------------------------------
  1656. void CMainFrame::WinHelp(DWORD dwData, UINT nCmd)
  1657. {
  1658. // dvs: HACK: just punt them to the main help page
  1659. APP()->OpenURL(ID_HELP_TOPICS, m_hWnd);
  1660. }
  1661. void CMainFrame::OnUpdateFoundrySendSelectedEntitiesToEngine( CCmdUI *pCmdUI )
  1662. {
  1663. pCmdUI->Enable( true );
  1664. }
  1665. void CMainFrame::OnFoundrySendSelectedEntitiesToEngine()
  1666. {
  1667. if ( !g_pFoundryTool )
  1668. return;
  1669. g_pFoundryTool->ConsoleCommand( "foundry_send_ents_to_engine" );
  1670. }
  1671. void CMainFrame::OnUpdateFoundryMoveEngineViewToHammer3DView( CCmdUI *pCmdUI )
  1672. {
  1673. // TODO: This should only be on if Foundry is around.
  1674. pCmdUI->Enable( true );
  1675. }
  1676. void CMainFrame::OnFoundryMoveEngineViewToHammer3DView()
  1677. {
  1678. if ( !g_pFoundryTool )
  1679. return;
  1680. g_pFoundryTool->ConsoleCommand( "foundry_sync_engine_view" );
  1681. }
  1682. void CMainFrame::OnUpdateFoundryRemoveSelectedEntitiesFromEngine( CCmdUI *pCmdUI )
  1683. {
  1684. pCmdUI->Enable( true );
  1685. }
  1686. void CMainFrame::OnFoundryRemoveSelectedEntitiesFromEngine()
  1687. {
  1688. if ( !g_pFoundryTool )
  1689. return;
  1690. g_pFoundryTool->ConsoleCommand( "foundry_remove_selected" );
  1691. }
  1692. void CMainFrame::OnUpdateFoundryMoveFocusToEngine( CCmdUI *pCmdUI )
  1693. {
  1694. pCmdUI->Enable( true );
  1695. }
  1696. void CMainFrame::OnFoundryMoveFocusToEngine()
  1697. {
  1698. if ( !g_pFoundryTool )
  1699. return;
  1700. g_pFoundryTool->ConsoleCommand( "foundry_move_focus_to_engine" );
  1701. }
  1702. LRESULT CMainFrame::OnWTPacket(WPARAM wSerial, LPARAM hCtx)
  1703. {
  1704. WinTab_Packet( wSerial, hCtx );
  1705. return TRUE;
  1706. }