UIMainFrame.cpp 24 KB

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