| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
- // Please see LICENSE.md in repository root for license information
- // https://github.com/AtomicGameEngine/AtomicGameEngine
- #include "AtomicEditor.h"
- #include <TurboBadger/tb_window.h>
- #include <TurboBadger/tb_editfield.h>
- #include <Atomic/Core/Context.h>
- #include <Atomic/UI/UI.h>
- #include "Resources/AEResourceOps.h"
- #include "UIResourceOps.h"
- namespace AtomicEditor
- {
- // UINewFolder------------------------------------------------
- UINewFolder::UINewFolder(Context* context):
- UIModalOpWindow(context)
- {
- UI* tbui = GetSubsystem<UI>();
- window_->SetText("New Folder");
- tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcenewfolder.tb.txt");
- nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("folder_name"));
- assert(nameField_);
- window_->ResizeToFitContent();
- Center();
- }
- UINewFolder::~UINewFolder()
- {
- }
- bool UINewFolder::OnEvent(const TBWidgetEvent &ev)
- {
- UIModalOps* ops = GetSubsystem<UIModalOps>();
- if (ev.type == EVENT_TYPE_CLICK)
- {
- if (ev.target->GetID() == TBIDC("create"))
- {
- TBStr text;
- nameField_->GetText(text);
- ResourceOps* rops = GetSubsystem<ResourceOps>();
- rops->HandleNewFolder(ops->GetResourcePath() + text.CStr(), true);
- ops->Hide();
- return true;
- }
- if (ev.target->GetID() == TBIDC("cancel"))
- {
- ops->Hide();
- return true;
- }
- }
- return false;
- }
- // UIResourceDelete------------------------------------------------
- UIResourceDelete::UIResourceDelete(Context* context):
- UIModalOpWindow(context)
- {
- UIModalOps* ops = GetSubsystem<UIModalOps>();
- UI* tbui = GetSubsystem<UI>();
- window_->SetText("Delete Resource");
- tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcedelete.tb.txt");
- TBEditField* message = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("message"));
- String msg;
- message->SetText(msg.AppendWithFormat("Are you sure you want to delete resource:\n\n%s\n\nThis operation cannot be undone"
- ,ops->GetResourcePath().CString()).CString());
- window_->ResizeToFitContent();
- Center();
- }
- UIResourceDelete::~UIResourceDelete()
- {
- }
- bool UIResourceDelete::OnEvent(const TBWidgetEvent &ev)
- {
- UIModalOps* ops = GetSubsystem<UIModalOps>();
- if (ev.type == EVENT_TYPE_CLICK)
- {
- if (ev.target->GetID() == TBIDC("delete"))
- {
- ResourceOps* rops = GetSubsystem<ResourceOps>();
- rops->HandleResourceDelete(ops->GetResourcePath());
- ops->Hide();
- return true;
- }
- if (ev.target->GetID() == TBIDC("cancel"))
- {
- ops->Hide();
- return true;
- }
- }
- return false;
- }
- // UICreateComponent------------------------------------------------
- UICreateComponent::UICreateComponent(Context* context):
- UIModalOpWindow(context)
- {
- UI* tbui = GetSubsystem<UI>();
- window_->SetText("Create Javascript Component");
- tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
- nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("component_name"));
- assert(nameField_);
- window_->ResizeToFitContent();
- Center();
- }
- UICreateComponent::~UICreateComponent()
- {
- }
- bool UICreateComponent::OnEvent(const TBWidgetEvent &ev)
- {
- UIModalOps* ops = GetSubsystem<UIModalOps>();
- if (ev.type == EVENT_TYPE_POINTER_MOVE)
- return false;
- if (ev.type == EVENT_TYPE_CLICK)
- {
- if (ev.target->GetID() == TBIDC("create"))
- {
- TBStr text;
- nameField_->GetText(text);
- ResourceOps* rops = GetSubsystem<ResourceOps>();
- rops->HandleCreateComponent(ops->GetResourcePath(), text.CStr(), true, true);
- ops->Hide();
- return true;
- }
- if (ev.target->GetID() == TBIDC("cancel"))
- {
- ops->Hide();
- return true;
- }
- }
- return false;
- }
- // UICreateScript------------------------------------------------
- UICreateScript::UICreateScript(Context* context):
- UIModalOpWindow(context)
- {
- UI* tbui = GetSubsystem<UI>();
- window_->SetText("Create Script");
- tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcecreatescript.tb.txt");
- nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("script_name"));
- assert(nameField_);
- window_->ResizeToFitContent();
- Center();
- }
- UICreateScript::~UICreateScript()
- {
- }
- bool UICreateScript::OnEvent(const TBWidgetEvent &ev)
- {
- UIModalOps* ops = GetSubsystem<UIModalOps>();
- if (ev.type == EVENT_TYPE_POINTER_MOVE)
- return false;
- if (ev.type == EVENT_TYPE_CLICK)
- {
- if (ev.target->GetID() == TBIDC("create"))
- {
- TBStr text;
- nameField_->GetText(text);
- ResourceOps* rops = GetSubsystem<ResourceOps>();
- rops->HandleCreateScript(ops->GetResourcePath(), text.CStr(), true, true);
- ops->Hide();
- return true;
- }
- if (ev.target->GetID() == TBIDC("cancel"))
- {
- ops->Hide();
- return true;
- }
- }
- return false;
- }
- // UICreateModule------------------------------------------------
- UICreateModule::UICreateModule(Context* context):
- UIModalOpWindow(context)
- {
- UI* tbui = GetSubsystem<UI>();
- window_->SetText("Create Module");
- tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcecreatemodule.tb.txt");
- nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("module_name"));
- assert(nameField_);
- window_->ResizeToFitContent();
- Center();
- }
- UICreateModule::~UICreateModule()
- {
- }
- bool UICreateModule::OnEvent(const TBWidgetEvent &ev)
- {
- UIModalOps* ops = GetSubsystem<UIModalOps>();
- if (ev.type == EVENT_TYPE_POINTER_MOVE)
- return false;
- if (ev.type == EVENT_TYPE_CLICK)
- {
- if (ev.target->GetID() == TBIDC("create"))
- {
- TBStr text;
- nameField_->GetText(text);
- ResourceOps* rops = GetSubsystem<ResourceOps>();
- rops->HandleCreateModule(ops->GetResourcePath(), text.CStr(), true, true);
- ops->Hide();
- return true;
- }
- if (ev.target->GetID() == TBIDC("cancel"))
- {
- ops->Hide();
- return true;
- }
- }
- return false;
- }
- // UICreateModule------------------------------------------------
- UICreate2DLevel::UICreate2DLevel(Context* context):
- UIModalOpWindow(context)
- {
- UI* tbui = GetSubsystem<UI>();
- window_->SetText("Create 2D Level");
- tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcecreate2dlevel.tb.txt");
- nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("level_name"));
- assert(nameField_);
- window_->ResizeToFitContent();
- Center();
- }
- UICreate2DLevel::~UICreate2DLevel()
- {
- }
- bool UICreate2DLevel::OnEvent(const TBWidgetEvent &ev)
- {
- UIModalOps* ops = GetSubsystem<UIModalOps>();
- if (ev.type == EVENT_TYPE_POINTER_MOVE)
- return false;
- if (ev.type == EVENT_TYPE_CLICK)
- {
- if (ev.target->GetID() == TBIDC("create"))
- {
- TBStr text;
- nameField_->GetText(text);
- ResourceOps* rops = GetSubsystem<ResourceOps>();
- rops->HandleCreate2DLevel(ops->GetResourcePath(), text.CStr(), true, true);
- ops->Hide();
- return true;
- }
- if (ev.target->GetID() == TBIDC("cancel"))
- {
- ops->Hide();
- return true;
- }
- }
- return false;
- }
- }
|