UIMainFrame.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <TurboBadger/tb_message_window.h>
  6. #include <TurboBadger/tb_editfield.h>
  7. #include <Atomic/Core/ProcessUtils.h>
  8. #include <Atomic/UI/TBUI.h>
  9. #include <Atomic/IO/Log.h>
  10. #include <Atomic/Core/Context.h>
  11. #include <Atomic/Graphics/Graphics.h>
  12. #include <Atomic/Graphics/GraphicsEvents.h>
  13. #include <Atomic/Resource/ResourceCache.h>
  14. #include <Atomic/IO/File.h>
  15. #include <Atomic/IO/FileSystem.h>
  16. #include "UIMainFrame.h"
  17. #include "UIMainToolbar.h"
  18. #include "UIProjectFrame.h"
  19. #include "UIHierarchyFrame.h"
  20. #include "UIInspectorFrame.h"
  21. #include "UIPlayerWidget.h"
  22. #include "UIResourceFrame.h"
  23. #include "UIWelcomeFrame.h"
  24. #include "UI/Modal/UIModalOps.h"
  25. #include "UI/Modal/UIMessageModal.h"
  26. #include "License/AEVersionCheck.h"
  27. #include "UIFindTextWidget.h"
  28. #include "AEEvents.h"
  29. #include "AEEditor.h"
  30. #include "AEEditorStrings.h"
  31. #include "AEEditorShortcuts.h"
  32. #include "AEPreferences.h"
  33. #include "AEJavascript.h"
  34. #include "Player/AEPlayer.h"
  35. #include "Project/AEProject.h"
  36. #include "Project/ProjectUtils.h"
  37. #include "Editors/ResourceEditor.h"
  38. #include "Tools/External/AEExternalTooling.h"
  39. using namespace tb;
  40. namespace AtomicEditor
  41. {
  42. MainFrame::MainFrame(Context* context) :
  43. AEWidget(context),
  44. consoletext_(0),
  45. resourceviewcontainer_(0),
  46. platformIndicator_(0)
  47. {
  48. context->RegisterSubsystem(this);
  49. InitializeMenuSources();
  50. TBUI* tbui = GetSubsystem<TBUI>();
  51. tbui->LoadResourceFile(delegate_, "AtomicEditor/editor/ui/mainframe.tb.txt");
  52. Graphics* graphics = GetSubsystem<Graphics>();
  53. delegate_->SetSize(graphics->GetWidth(), graphics->GetHeight());
  54. tbui->GetRootWidget()->AddChild(delegate_);
  55. maintoolbar_ = new MainToolbar(context_);
  56. TBLayout* maintoolbarcontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("maintoolbarcontainer"));
  57. assert(maintoolbarcontainer);
  58. TBWidget* wd = maintoolbar_->GetWidgetDelegate();
  59. TBRect rect = maintoolbarcontainer->GetRect();
  60. wd->SetSize(rect.w, rect.h);
  61. maintoolbarcontainer->AddChild(wd);
  62. projectframe_ = new ProjectFrame(context_);
  63. TBLayout* projectviewcontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("projectviewcontainer"));
  64. assert(projectviewcontainer);
  65. // better way to do this? projectviewcontainer isn't a layout
  66. wd = projectframe_->GetWidgetDelegate();
  67. rect = projectviewcontainer->GetRect();
  68. wd->SetSize(rect.w, rect.h);
  69. projectviewcontainer->AddChild(wd);
  70. hierarchyframe_ = new HierarchyFrame(context_);
  71. TBLayout* hierarchycontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("hierarchycontainer"));
  72. assert(hierarchycontainer);
  73. // better way to do this? projectviewcontainer isn't a layout
  74. wd = hierarchyframe_->GetWidgetDelegate();
  75. rect = hierarchycontainer->GetRect();
  76. wd->SetSize(rect.w, rect.h);
  77. hierarchycontainer->AddChild(wd);
  78. inspectorlayout_ = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("inspectorlayout"));
  79. assert(inspectorlayout_);
  80. inspectorframe_ = new InspectorFrame(context_);
  81. TBLayout* inspectorcontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("inspectorcontainer"));
  82. assert(inspectorcontainer);
  83. // better way to do this? inspectorcontainer isn't a layout
  84. wd = inspectorframe_->GetWidgetDelegate();
  85. rect = inspectorcontainer->GetRect();
  86. wd->SetSize(rect.w, rect.h);
  87. inspectorcontainer->AddChild(wd);
  88. resourceviewcontainer_ = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("resourceviewcontainer"));
  89. assert(resourceviewcontainer_);
  90. rect = resourceviewcontainer_->GetRect();
  91. // player widget
  92. playerwidget_ = new PlayerWidget(context_);
  93. wd = playerwidget_->GetWidgetDelegate();
  94. wd->SetSize(rect.w, rect.h);
  95. // welcome frame
  96. welcomeframe_ = new WelcomeFrame(context_);
  97. wd = welcomeframe_->GetWidgetDelegate();
  98. wd->SetSize(rect.w, rect.h);
  99. resourceframe_ = new ResourceFrame(context_);
  100. // better way to do this? projectviewcontainer isn't a layout
  101. wd = resourceframe_->GetWidgetDelegate();
  102. wd->SetSize(rect.w, rect.h);
  103. platformIndicator_ = delegate_->GetWidgetByIDAndType<TBSkinImage>(TBIDC("current_platform_indicator"));
  104. assert(platformIndicator_);
  105. consoletext_ = delegate_->GetWidgetByIDAndType<TBEditField>(TBIDC("consoletext"));
  106. consoletext_->SetText("Atomic Editor Initialized");
  107. TBContainer* consolecontainer = delegate_->GetWidgetByIDAndType<TBContainer>(TBIDC("consolecontainer"));
  108. assert(consolecontainer);
  109. consolecontainer->SetVisibilility(WIDGET_VISIBILITY_INVISIBLE);
  110. consolecontainer->GetParent()->RemoveChild(consolecontainer);
  111. findtextwidget_ = new FindTextWidget(context_);
  112. UpdateFindTextWidget();
  113. SubscribeToEvent(E_SCREENMODE, HANDLER(MainFrame, HandleScreenMode));
  114. SubscribeToEvent(E_JAVASCRIPTSAVED, HANDLER(MainFrame, HandleJavascriptSaved));
  115. SubscribeToEvent(E_PLATFORMCHANGE, HANDLER(MainFrame, HandlePlatformChange));
  116. SubscribeToEvent(E_EDITORSHUTDOWN, HANDLER(MainFrame, HandleEditorShutdown));
  117. SubscribeToEvent(E_EDITORRESOURCEEDITORCHANGED, HANDLER(MainFrame, HandleResourceEditorChanged));
  118. messageModal_ = new MessageModal(context_);
  119. uiModalOps_ = new UIModalOps(context_);
  120. ShowInspectorFrame(false);
  121. // show welcome frame to start
  122. ShowWelcomeFrame();
  123. }
  124. MainFrame::~MainFrame()
  125. {
  126. }
  127. void MainFrame::InitializeMenuSources()
  128. {
  129. // Instead of TBGenericStringItem here, we need custom item so can have shortcuts be right aligned
  130. menuAtomicEditorSource.AddItem(new MenubarItem("About Atomic Editor", TBIDC("about atomic editor")));
  131. menuAtomicEditorSource.AddItem(new MenubarItem("-"));
  132. menuAtomicEditorSource.AddItem(new MenubarItem("Manage License", TBIDC("manage license")));
  133. menuAtomicEditorSource.AddItem(new MenubarItem("-"));
  134. menuAtomicEditorSource.AddItem(new MenubarItem("Check for Updates", TBIDC("check update")));
  135. menuAtomicEditorSource.AddItem(new MenubarItem("-"));
  136. menuAtomicEditorSource.AddItem(new MenubarItem("Quit", TBIDC("quit")));
  137. menuFileSource.AddItem(new MenubarItem("New Project", TBIDC("new project")));
  138. menuFileSource.AddItem(new MenubarItem("Open Project", TBIDC("open project")));
  139. menuFileSource.AddItem(new MenubarItem("Save Project", TBIDC("save project")));
  140. menuFileSource.AddItem(new MenubarItem("-"));
  141. menuFileSource.AddItem(new MenubarItem("Close Project", TBIDC("close project")));
  142. menuFileSource.AddItem(new MenubarItem("-"));
  143. menuFileSource.AddItem(new MenubarItem("Save File", TBIDC("save file"), EDITOR_STRING(ShortcutSaveFile)));
  144. menuFileSource.AddItem(new MenubarItem("Close File", TBIDC("close file"), EDITOR_STRING(ShortcutCloseFile)));
  145. menuBuildSource.AddItem(new MenubarItem("Build", TBIDC("project_build"), EDITOR_STRING(ShortcutBuild)));
  146. menuBuildSource.AddItem(new MenubarItem("-"));
  147. menuBuildSource.AddItem(new MenubarItem("Build Settings", TBIDC("project_build_settings"), EDITOR_STRING(ShortcutBuildSettings)));
  148. menuToolsSource.AddItem(new MenubarItem("Tiled Map Editor", TBIDC("tools tiled")));
  149. menuEditSource.AddItem(new MenubarItem("Undo", TBIDC("edit undo"), EDITOR_STRING(ShortcutUndo)));
  150. menuEditSource.AddItem(new MenubarItem("Redo", TBIDC("edit redo"), EDITOR_STRING(ShortcutRedo)));
  151. menuEditSource.AddItem(new MenubarItem("-"));
  152. menuEditSource.AddItem(new MenubarItem("Cut", TBIDC("edit cut"), EDITOR_STRING(ShortcutCut)));
  153. menuEditSource.AddItem(new MenubarItem("Copy", TBIDC("edit copy"), EDITOR_STRING(ShortcutCopy)));
  154. menuEditSource.AddItem(new MenubarItem("Paste", TBIDC("edit paste"), EDITOR_STRING(ShortcutPaste)));
  155. menuEditSource.AddItem(new MenubarItem("Select All", TBIDC("edit select all"), EDITOR_STRING(ShortcutSelectAll)));
  156. menuEditSource.AddItem(new MenubarItem("-"));
  157. menuEditSource.AddItem(new MenubarItem("Find", TBIDC("edit find"), EDITOR_STRING(ShortcutFind)));
  158. menuEditSource.AddItem(new MenubarItem("Find Next", TBIDC("edit find next"), EDITOR_STRING(ShortcutFindNext)));
  159. menuEditSource.AddItem(new MenubarItem("Find Prev", TBIDC("edit find prev"), EDITOR_STRING(ShortcutFindPrev)));
  160. menuEditSource.AddItem(new MenubarItem("-"));
  161. menuEditSource.AddItem(new MenubarItem("Format Code", TBIDC("edit format code"), EDITOR_STRING(ShortcutBeautify)));
  162. menuEditSource.AddItem(new MenubarItem("-"));
  163. menuEditSource.AddItem(new MenubarItem("Play", TBIDC("edit play"), EDITOR_STRING(ShortcutPlay)));
  164. menuHelpSource.AddItem(new MenubarItem("API Documentation", TBIDC("help_api")));
  165. menuHelpSource.AddItem(new MenubarItem("-"));
  166. menuHelpSource.AddItem(new MenubarItem("Forums", TBIDC("help_forums")));
  167. menuHelpSource.AddItem(new MenubarItem("-"));
  168. menuHelpSource.AddItem(new MenubarItem("Atomic Game Engine on GitHub", TBIDC("help_github")));
  169. menuDeveloperSource.AddItem(new MenubarItem("Set 1920x1080 Resolution", TBIDC("developer_resolution")));
  170. }
  171. ProjectFrame* MainFrame::GetProjectFrame()
  172. {
  173. return projectframe_;
  174. }
  175. ResourceFrame* MainFrame::GetResourceFrame()
  176. {
  177. return resourceframe_;
  178. }
  179. FindTextWidget* MainFrame::GetFindTextWidget()
  180. {
  181. return findtextwidget_;
  182. }
  183. MainToolbar* MainFrame::GetMainToolbar()
  184. {
  185. return maintoolbar_;
  186. }
  187. PlayerWidget* MainFrame::GetPlayerWidget()
  188. {
  189. return playerwidget_;
  190. }
  191. MessageModal* MainFrame::GetMessageModal()
  192. {
  193. return messageModal_;
  194. }
  195. UIModalOps* MainFrame::GetUIModalOps()
  196. {
  197. return uiModalOps_;
  198. }
  199. InspectorFrame* MainFrame::GetInspectorFrame()
  200. {
  201. return inspectorframe_;
  202. }
  203. void MainFrame::ShowInspectorFrame(bool show)
  204. {
  205. if (!show)
  206. inspectorlayout_->SetVisibilility(WIDGET_VISIBILITY_GONE);
  207. else
  208. inspectorlayout_->SetVisibilility(WIDGET_VISIBILITY_VISIBLE);
  209. }
  210. bool MainFrame::InspectorFrameVisible()
  211. {
  212. return inspectorlayout_->GetVisibility() == WIDGET_VISIBILITY_VISIBLE;
  213. }
  214. void MainFrame::HandleJavascriptSaved(StringHash eventType, VariantMap& eventData)
  215. {
  216. UpdateJavascriptErrors();
  217. }
  218. bool MainFrame::UpdateJavascriptErrors()
  219. {
  220. // parse errors
  221. bool hasErrors = false;
  222. AEJavascript* aejs = GetSubsystem<AEJavascript>();
  223. aejs->CheckJSErrors();
  224. const Vector<JSError>& errors = aejs->GetJSErrors();
  225. if (errors.Size())
  226. {
  227. hasErrors = true;
  228. resourceframe_->ShowIssuesWidget();
  229. }
  230. else
  231. {
  232. resourceframe_->ShowIssuesWidget(false);
  233. }
  234. AEPlayer* player = GetSubsystem<AEPlayer>();
  235. if (player)
  236. {
  237. const Vector<AEPlayerError>& playererrors = player->GetErrors();
  238. if (playererrors.Size())
  239. {
  240. hasErrors = true;
  241. resourceframe_->ShowErrorsWidget();
  242. }
  243. else
  244. resourceframe_->ShowErrorsWidget(false);
  245. }
  246. return hasErrors;
  247. }
  248. bool MainFrame::ResourceFrameVisible()
  249. {
  250. TBWidget *child;
  251. for (child = resourceviewcontainer_->GetFirstChild(); child; child = child->GetNext())
  252. {
  253. if (child == resourceframe_->GetWidgetDelegate())
  254. break;
  255. }
  256. return child != NULL;
  257. }
  258. bool MainFrame::WelcomeFrameVisible()
  259. {
  260. TBWidget *child;
  261. for (child = resourceviewcontainer_->GetFirstChild(); child; child = child->GetNext())
  262. {
  263. if (child == welcomeframe_->GetWidgetDelegate())
  264. break;
  265. }
  266. return child != NULL;
  267. }
  268. void MainFrame::ShowResourceFrame(bool show)
  269. {
  270. if (show && ResourceFrameVisible())
  271. return;
  272. if (show && WelcomeFrameVisible())
  273. ShowWelcomeFrame(false);
  274. TBWidget *child;
  275. for (child = resourceviewcontainer_->GetFirstChild(); child; child = child->GetNext())
  276. {
  277. if (child == resourceframe_->GetWidgetDelegate())
  278. break;
  279. }
  280. if (show)
  281. {
  282. if (!child)
  283. {
  284. resourceviewcontainer_->AddChild(resourceframe_->GetWidgetDelegate());
  285. }
  286. }
  287. else
  288. {
  289. if (child)
  290. resourceviewcontainer_->RemoveChild(child);
  291. }
  292. }
  293. void MainFrame::ShowWelcomeFrame(bool show)
  294. {
  295. if (show && WelcomeFrameVisible())
  296. return;
  297. if (show && ResourceFrameVisible())
  298. ShowResourceFrame(false);
  299. TBWidget *child;
  300. for (child = resourceviewcontainer_->GetFirstChild(); child; child = child->GetNext())
  301. {
  302. if (child == welcomeframe_->GetWidgetDelegate())
  303. break;
  304. }
  305. if (show)
  306. {
  307. ShowInspectorFrame(false);
  308. welcomeframe_->UpdateRecentProjects();
  309. if (!child)
  310. {
  311. resourceviewcontainer_->AddChild(welcomeframe_->GetWidgetDelegate());
  312. }
  313. }
  314. else
  315. {
  316. if (child)
  317. resourceviewcontainer_->RemoveChild(child);
  318. }
  319. }
  320. bool MainFrame::IsProjectLoaded()
  321. {
  322. Editor* editor = GetSubsystem<Editor>();
  323. Project* project = editor->GetProject();
  324. if (!project)
  325. return false;
  326. return true;
  327. }
  328. bool MainFrame::HandleMenubarEvent(const TBWidgetEvent &ev)
  329. {
  330. if (ev.type == EVENT_TYPE_CLICK)
  331. {
  332. if (ev.target->GetID() == TBIDC("menu atomic editor"))
  333. {
  334. if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("atomic editor popup")))
  335. {
  336. menu->Show(&menuAtomicEditorSource, TBPopupAlignment());
  337. }
  338. return true;
  339. }
  340. else if (ev.target->GetID() == TBIDC("menu edit"))
  341. {
  342. if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("edit popup")))
  343. menu->Show(&menuEditSource, TBPopupAlignment());
  344. return true;
  345. }
  346. else if (ev.target->GetID() == TBIDC("menu file"))
  347. {
  348. if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("file popup")))
  349. menu->Show(&menuFileSource, TBPopupAlignment());
  350. return true;
  351. }
  352. else if (ev.target->GetID() == TBIDC("menu build"))
  353. {
  354. if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("build popup")))
  355. menu->Show(&menuBuildSource, TBPopupAlignment());
  356. return true;
  357. }
  358. else if (ev.target->GetID() == TBIDC("menu tools"))
  359. {
  360. if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("tools popup")))
  361. menu->Show(&menuToolsSource, TBPopupAlignment());
  362. return true;
  363. }
  364. else if (ev.target->GetID() == TBIDC("menu issues"))
  365. {
  366. resourceframe_->ShowIssuesWidget(!resourceframe_->IssuesWidgetVisible());
  367. return true;
  368. }
  369. else if (ev.target->GetID() == TBIDC("menu console"))
  370. {
  371. resourceframe_->ShowConsoleWidget(!resourceframe_->ConsoleWidgetVisible());
  372. return true;
  373. }
  374. else if (ev.target->GetID() == TBIDC("menu errors"))
  375. {
  376. resourceframe_->ShowErrorsWidget(!resourceframe_->ErrorsWidgetVisible());
  377. return true;
  378. }
  379. else if (ev.target->GetID() == TBIDC("menu help"))
  380. {
  381. if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("help popup")))
  382. menu->Show(&menuHelpSource, TBPopupAlignment());
  383. return true;
  384. }
  385. else if (ev.target->GetID() == TBIDC("menu developer"))
  386. {
  387. if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("developer popup")))
  388. menu->Show(&menuDeveloperSource, TBPopupAlignment());
  389. return true;
  390. }
  391. }
  392. return false;
  393. }
  394. bool MainFrame::HandlePopupMenuEvent(const TBWidgetEvent &ev)
  395. {
  396. EditorShortcuts* shortcuts = GetSubsystem<EditorShortcuts>();
  397. if (ev.type == EVENT_TYPE_CLICK)
  398. {
  399. Editor* editor = GetSubsystem<Editor>();
  400. if (ev.target->GetID() == TBIDC("file popup"))
  401. {
  402. if (ev.ref_id == TBIDC("new project"))
  403. {
  404. if (editor->IsProjectLoaded())
  405. {
  406. editor->PostModalError("Close Project", "Please close the current project before creating a new one");
  407. }
  408. else
  409. {
  410. uiModalOps_->ShowNewProject();
  411. }
  412. }
  413. else if (ev.ref_id == TBIDC("open project"))
  414. {
  415. if (editor->IsProjectLoaded())
  416. {
  417. editor->PostModalError("Close Project", "Please close the current project before opening a new one");
  418. return true;
  419. }
  420. else
  421. {
  422. GetSubsystem<ProjectUtils>()->OpenProjectFileDialog();
  423. return true;
  424. }
  425. }
  426. else if (ev.ref_id == TBIDC("close project"))
  427. {
  428. //TODO: Confirmation
  429. editor->CloseProject();
  430. }
  431. else if (ev.ref_id == TBIDC("close file"))
  432. {
  433. shortcuts->InvokeFileClose();
  434. }
  435. else if (ev.ref_id == TBIDC("save file"))
  436. {
  437. shortcuts->InvokeFileSave();
  438. }
  439. return true;
  440. }
  441. if (ev.target->GetID() == TBIDC("atomic editor popup"))
  442. {
  443. if (ev.ref_id == TBIDC("about atomic editor"))
  444. {
  445. uiModalOps_->ShowAbout();
  446. return true;
  447. }
  448. else if (ev.ref_id == TBIDC("manage license"))
  449. {
  450. uiModalOps_->ShowManageLicense();
  451. return true;
  452. }
  453. else if (ev.ref_id == TBIDC("check update"))
  454. {
  455. GetSubsystem<VersionCheck>()->DoVersionCheck();
  456. return true;
  457. }
  458. else if (ev.ref_id == TBIDC("quit"))
  459. {
  460. // TODO: confirmation
  461. // shenanigens, need to delete the popup on quit
  462. // otherwise it is still live with a source at exit
  463. ev.target->GetParent()->RemoveChild(ev.target);
  464. delete ev.target;
  465. TBWidgetEvent* eptr = (TBWidgetEvent*) &ev;
  466. eptr->target = NULL;
  467. editor->RequestExit();
  468. }
  469. return true;
  470. }
  471. if (ev.target->GetID() == TBIDC("build popup"))
  472. {
  473. if (ev.ref_id == TBIDC("project_build_settings"))
  474. {
  475. shortcuts->InvokeBuildSettings();
  476. }
  477. else if (ev.ref_id == TBIDC("project_build"))
  478. {
  479. shortcuts->InvokeBuild();
  480. }
  481. return true;
  482. }
  483. if (ev.target->GetID() == TBIDC("edit popup"))
  484. {
  485. if (ev.ref_id == TBIDC("edit cut"))
  486. {
  487. shortcuts->InvokeEditCut();
  488. }
  489. else if (ev.ref_id == TBIDC("edit copy"))
  490. {
  491. shortcuts->InvokeEditCopy();
  492. }
  493. else if (ev.ref_id == TBIDC("edit paste"))
  494. {
  495. shortcuts->InvokeEditPaste();
  496. }
  497. else if (ev.ref_id == TBIDC("edit select all"))
  498. {
  499. shortcuts->InvokeEditSelectAll();
  500. }
  501. else if (ev.ref_id == TBIDC("edit undo"))
  502. {
  503. shortcuts->InvokeEditUndo();
  504. }
  505. else if (ev.ref_id == TBIDC("edit redo"))
  506. {
  507. shortcuts->InvokeEditRedo();
  508. }
  509. else if (ev.ref_id == TBIDC("edit find"))
  510. {
  511. shortcuts->InvokeEditFind();
  512. }
  513. else if (ev.ref_id == TBIDC("edit find next"))
  514. {
  515. shortcuts->InvokeEditFindNext();
  516. }
  517. else if (ev.ref_id == TBIDC("edit find prev"))
  518. {
  519. shortcuts->InvokeEditFindPrev();
  520. }
  521. else if (ev.ref_id == TBIDC("edit format code"))
  522. {
  523. shortcuts->InvokeEditFormatCode();
  524. }
  525. else if (ev.ref_id == TBIDC("edit play"))
  526. {
  527. shortcuts->InvokePlayStop();
  528. }
  529. return true;
  530. }
  531. if (ev.target->GetID() == TBIDC("tools popup"))
  532. {
  533. if (ev.ref_id == TBIDC("tools tiled"))
  534. {
  535. ExternalTooling* tooling = GetSubsystem<ExternalTooling>();
  536. tooling->LaunchOrOpen("AtomicTiled", "");
  537. }
  538. return true;
  539. }
  540. if (ev.target->GetID() == TBIDC("help popup"))
  541. {
  542. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  543. if (ev.ref_id == TBIDC("help_forums"))
  544. {
  545. fileSystem->SystemOpen("http://www.atomicgameengine.com/forum");
  546. }
  547. if (ev.ref_id == TBIDC("help_github"))
  548. {
  549. fileSystem->SystemOpen("https://github.com/AtomicGameEngine/AtomicGameEngine");
  550. }
  551. else if (ev.ref_id == TBIDC("help_api"))
  552. {
  553. #ifdef ATOMIC_PLATFORM_OSX
  554. String docSourceDir = fileSystem->GetAppBundleResourceFolder();
  555. #else
  556. String docSourceDir = fileSystem->GetProgramDir();
  557. #endif
  558. docSourceDir += "Docs/index.html";
  559. fileSystem->SystemOpen("file://" + docSourceDir);
  560. }
  561. return true;
  562. }
  563. if (ev.target->GetID() == TBIDC("developer popup"))
  564. {
  565. if (ev.ref_id == TBIDC("developer_resolution"))
  566. {
  567. Graphics* graphics = GetSubsystem<Graphics>();
  568. graphics->SetWindowSize(1920, 1080);
  569. graphics->CenterWindow();
  570. }
  571. return true;
  572. }
  573. }
  574. return false;
  575. }
  576. bool MainFrame::OnEvent(const TBWidgetEvent &ev)
  577. {
  578. if (HandleMenubarEvent(ev))
  579. return true;
  580. if (HandlePopupMenuEvent(ev))
  581. return true;
  582. if (ev.type == EVENT_TYPE_CLICK)
  583. {
  584. if (ev.target->GetID() == TBIDC("unsaved_modifications_dialog"))
  585. {
  586. resourceframe_->FocusCurrentTab();
  587. return true;
  588. }
  589. }
  590. return false;
  591. }
  592. void MainFrame::UpdateFindTextWidget()
  593. {
  594. TBRect rect = delegate_->GetRect();
  595. findtextwidget_->SetUISize(rect.w, rect.h);
  596. }
  597. void MainFrame::HandleScreenMode(StringHash eventType, VariantMap& eventData)
  598. {
  599. using namespace ScreenMode;
  600. int width = eventData[P_WIDTH].GetInt();
  601. int height = eventData[P_HEIGHT].GetInt();
  602. delegate_->SetSize(width, height);
  603. UpdateFindTextWidget();
  604. }
  605. void MainFrame::RevealInFinder()
  606. {
  607. Editor* editor = context_->GetSubsystem<Editor>();
  608. Project* project = editor->GetProject();
  609. if (!project)
  610. return;
  611. String resourcePath = projectframe_->GetCurrentContentFolder();
  612. if (!resourcePath.Length())
  613. resourcePath = project->GetResourcePath();
  614. ProjectUtils* utils = context_->GetSubsystem<ProjectUtils>();
  615. utils->RevealInFinder(resourcePath);
  616. }
  617. void MainFrame::HandleResourceEditorChanged(StringHash eventType, VariantMap& eventData)
  618. {
  619. ResourceEditor* editor = static_cast<ResourceEditor*>(eventData[EditorResourceEditorChanged::P_RESOURCEEDITOR].GetPtr());
  620. if (!editor || !editor->RequiresInspector())
  621. {
  622. ShowInspectorFrame(false);
  623. maintoolbar_->Show3DWidgets(false);
  624. }
  625. else
  626. {
  627. ShowInspectorFrame(true);
  628. maintoolbar_->Show3DWidgets(true);
  629. }
  630. }
  631. void MainFrame::HandlePlatformChange(StringHash eventType, VariantMap& eventData)
  632. {
  633. using namespace PlatformChange;
  634. AEEditorPlatform platform = (AEEditorPlatform) eventData[P_PLATFORM].GetUInt();
  635. if (platform == AE_PLATFORM_MAC)
  636. platformIndicator_->SetSkinBg(TBIDC("LogoMac"));
  637. else if (platform == AE_PLATFORM_WINDOWS)
  638. platformIndicator_->SetSkinBg(TBIDC("LogoWindows"));
  639. else if (platform == AE_PLATFORM_ANDROID)
  640. platformIndicator_->SetSkinBg(TBIDC("LogoAndroid"));
  641. else if (platform == AE_PLATFORM_HTML5)
  642. platformIndicator_->SetSkinBg(TBIDC("LogoHTML5"));
  643. else if (platform == AE_PLATFORM_IOS)
  644. platformIndicator_->SetSkinBg(TBIDC("LogoIOS"));
  645. }
  646. void MainFrame::HandleEditorShutdown(StringHash eventType, VariantMap& eventData)
  647. {
  648. messageModal_= 0;
  649. context_->RemoveSubsystem(GetType());
  650. }
  651. }