Browse Source

Adding TextImporter, additions to UIEditField, refresh content with Resource folder at project load

Josh Engebretson 10 years ago
parent
commit
c33c90beab

+ 4 - 1
Script/AtomicEditor/ui/frames/ProjectFrame.ts

@@ -11,6 +11,7 @@ class ProjectFrame extends ScriptWidget {
     folderList: Atomic.UIListView;
     folderList: Atomic.UIListView;
     menu: ProjectFrameMenu;
     menu: ProjectFrameMenu;
     currentFolder: ToolCore.Asset;
     currentFolder: ToolCore.Asset;
+    resourceFolder: ToolCore.Asset;
     assetGUIDToItemID = {};
     assetGUIDToItemID = {};
     resourcesID: number = -1;
     resourcesID: number = -1;
 
 
@@ -90,6 +91,7 @@ class ProjectFrame extends ScriptWidget {
                 var id = folderList.addRootItem(asset.name, "Folder.icon", asset.guid);
                 var id = folderList.addRootItem(asset.name, "Folder.icon", asset.guid);
                 this.resourcesID = id;
                 this.resourcesID = id;
                 this.assetGUIDToItemID[asset.guid] = id;
                 this.assetGUIDToItemID[asset.guid] = id;
+                this.resourceFolder = asset;
 
 
             } else {
             } else {
                 var parentItemID = this.assetGUIDToItemID[parent.guid];
                 var parentItemID = this.assetGUIDToItemID[parent.guid];
@@ -308,13 +310,14 @@ class ProjectFrame extends ScriptWidget {
 
 
         this.folderList.rootList.value = 0;
         this.folderList.rootList.value = 0;
         this.folderList.setExpanded(this.resourcesID, true);
         this.folderList.setExpanded(this.resourcesID, true);
-        this.sendEvent(EditorEvents.ContentFolderChanged, { path: ToolCore.toolSystem.project.resourcePath });
+        this.refreshContent(this.resourceFolder);
 
 
     }
     }
 
 
     handleProjectUnloaded(data) {
     handleProjectUnloaded(data) {
 
 
         this.folderList.deleteAllItems();
         this.folderList.deleteAllItems();
+        this.resourceFolder = null;
 
 
         var container: Atomic.UILayout = <Atomic.UILayout> this.getWidget("contentcontainer");
         var container: Atomic.UILayout = <Atomic.UILayout> this.getWidget("contentcontainer");
         container.deleteAllChildren();
         container.deleteAllChildren();

+ 1 - 1
Script/AtomicEditor/ui/frames/ResourceFrame.ts

@@ -59,7 +59,7 @@ class ResourceFrame extends ScriptWidget {
 
 
         var editor: Editor.ResourceEditor = null;
         var editor: Editor.ResourceEditor = null;
 
 
-        if (ext == ".js") {
+        if (ext == ".js" || ext == ".txt") {
 
 
             editor = new Editor.JSResourceEditor(path, this.tabcontainer);
             editor = new Editor.JSResourceEditor(path, this.tabcontainer);
 
 

+ 39 - 4
Source/Atomic/UI/UIEditField.cpp

@@ -38,6 +38,17 @@ void UIEditField::SetReadOnly(bool readonly)
 
 
 }
 }
 
 
+void UIEditField::SetMultiline(bool multiline)
+{
+    if (!widget_)
+        return;
+
+    TBEditField* w = (TBEditField*) widget_;
+
+    w->SetMultiline(multiline);
+
+}
+
 void UIEditField::SetWrapping(bool wrap)
 void UIEditField::SetWrapping(bool wrap)
 {
 {
     if (!widget_)
     if (!widget_)
@@ -95,7 +106,31 @@ void UIEditField::AppendText(const String& text)
 
 
 }
 }
 
 
-void UIEditField::SetTextAlign(TEXT_ALIGN align)
+void UIEditField::SetAdaptToContentSize(bool adapt)
+{
+    if (!widget_)
+        return;
+
+    TBEditField* w = (TBEditField*) widget_;
+
+    w->SetAdaptToContentSize(adapt);
+
+}
+
+bool UIEditField::GetAdaptToContentSize() const
+{
+    if (!widget_)
+        return false;
+
+    // safe cast?
+    TBEditField* w = (TBEditField*) widget_;
+
+    return w->GetAdaptToContentSize();
+
+}
+
+
+void UIEditField::SetTextAlign(UI_TEXT_ALIGN align)
 {
 {
     if (!widget_)
     if (!widget_)
         return;
         return;
@@ -105,13 +140,13 @@ void UIEditField::SetTextAlign(TEXT_ALIGN align)
 
 
     switch (align)
     switch (align)
     {
     {
-        case TEXT_ALIGN_CENTER:
+        case UI_TEXT_ALIGN_CENTER:
             w->SetTextAlign(TB_TEXT_ALIGN_CENTER);
             w->SetTextAlign(TB_TEXT_ALIGN_CENTER);
             break;
             break;
-        case TEXT_ALIGN_LEFT:
+        case UI_TEXT_ALIGN_LEFT:
             w->SetTextAlign(TB_TEXT_ALIGN_LEFT);
             w->SetTextAlign(TB_TEXT_ALIGN_LEFT);
             break;
             break;
-        case TEXT_ALIGN_RIGHT:
+        case UI_TEXT_ALIGN_RIGHT:
             w->SetTextAlign(TB_TEXT_ALIGN_RIGHT);
             w->SetTextAlign(TB_TEXT_ALIGN_RIGHT);
             break;
             break;
     }
     }

+ 5 - 8
Source/Atomic/UI/UIEditField.h

@@ -8,13 +8,6 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
-enum TEXT_ALIGN
-{
-    TEXT_ALIGN_LEFT,		///< Aligned left
-    TEXT_ALIGN_RIGHT,	///< Aligned right
-    TEXT_ALIGN_CENTER	///< Aligned center
-};
-
 enum UI_EDIT_TYPE {
 enum UI_EDIT_TYPE {
     UI_EDIT_TYPE_TEXT = tb::EDIT_TYPE_TEXT,
     UI_EDIT_TYPE_TEXT = tb::EDIT_TYPE_TEXT,
     UI_EDIT_TYPE_SEARCH = tb::EDIT_TYPE_SEARCH,
     UI_EDIT_TYPE_SEARCH = tb::EDIT_TYPE_SEARCH,
@@ -36,11 +29,15 @@ public:
 
 
     void AppendText(const String& text);
     void AppendText(const String& text);
 
 
-    void SetTextAlign(TEXT_ALIGN align);
+    void SetTextAlign(UI_TEXT_ALIGN align);
+
+    void SetAdaptToContentSize(bool adapt);
+    bool GetAdaptToContentSize() const;
 
 
     void SetEditType(UI_EDIT_TYPE type);
     void SetEditType(UI_EDIT_TYPE type);
 
 
     void SetReadOnly(bool readonly);
     void SetReadOnly(bool readonly);
+    void SetMultiline(bool multiline);
 
 
     void ScrollTo(int x, int y);
     void ScrollTo(int x, int y);
 
 

+ 0 - 8
Source/Atomic/UI/UITextField.h

@@ -6,14 +6,6 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
-/// TB_TEXT_ALIGN specifies horizontal text alignment
-enum UI_TEXT_ALIGN
-{
-    UI_TEXT_ALIGN_LEFT = tb::TB_TEXT_ALIGN_LEFT,
-    UI_TEXT_ALIGN_RIGHT = tb::TB_TEXT_ALIGN_RIGHT,
-    UI_TEXT_ALIGN_CENTER = tb::TB_TEXT_ALIGN_CENTER
-};
-
 class UITextField : public UIWidget
 class UITextField : public UIWidget
 {
 {
     OBJECT(UITextField)
     OBJECT(UITextField)

+ 8 - 0
Source/Atomic/UI/UIWidget.h

@@ -101,6 +101,14 @@ enum UI_WIDGET_Z_REL {
     UI_WIDGET_Z_REL_AFTER = tb::WIDGET_Z_REL_AFTER			///< After the reference widget (visually above reference).
     UI_WIDGET_Z_REL_AFTER = tb::WIDGET_Z_REL_AFTER			///< After the reference widget (visually above reference).
 };
 };
 
 
+/// TB_TEXT_ALIGN specifies horizontal text alignment
+enum UI_TEXT_ALIGN
+{
+    UI_TEXT_ALIGN_LEFT = tb::TB_TEXT_ALIGN_LEFT,
+    UI_TEXT_ALIGN_RIGHT = tb::TB_TEXT_ALIGN_RIGHT,
+    UI_TEXT_ALIGN_CENTER = tb::TB_TEXT_ALIGN_CENTER
+};
+
 class UIView;
 class UIView;
 class UILayoutParams;
 class UILayoutParams;
 class UIFontDescription;
 class UIFontDescription;

+ 5 - 0
Source/ToolCore/Assets/Asset.cpp

@@ -18,6 +18,7 @@
 #include "SpriterImporter.h"
 #include "SpriterImporter.h"
 #include "TMXImporter.h"
 #include "TMXImporter.h"
 #include "PEXImporter.h"
 #include "PEXImporter.h"
+#include "TextImporter.h"
 
 
 #include "AssetEvents.h"
 #include "AssetEvents.h"
 #include "Asset.h"
 #include "Asset.h"
@@ -280,6 +281,10 @@ bool Asset::CreateImporter()
         {
         {
             importer_ = new PEXImporter(context_, this);
             importer_ = new PEXImporter(context_, this);
         }
         }
+        else if (ext == ".txt")
+        {
+            importer_ = new TextImporter(context_, this);
+        }
         else if (textureFormats.Contains(ext))
         else if (textureFormats.Contains(ext))
         {
         {
             importer_ = new TextureImporter(context_, this);
             importer_ = new TextureImporter(context_, this);

+ 54 - 0
Source/ToolCore/Assets/TextImporter.cpp

@@ -0,0 +1,54 @@
+
+#include <Atomic/Resource/ResourceCache.h>
+#include <Atomic/Audio/Sound.h>
+
+#include "Asset.h"
+#include "AssetDatabase.h"
+#include "TextImporter.h"
+
+namespace ToolCore
+{
+
+TextImporter::TextImporter(Context* context, Asset *asset) : AssetImporter(context, asset)
+{
+
+}
+
+TextImporter::~TextImporter()
+{
+
+}
+
+void TextImporter::SetDefaults()
+{
+    AssetImporter::SetDefaults();
+}
+
+bool TextImporter::Import()
+{
+    return true;
+}
+
+bool TextImporter::LoadSettingsInternal()
+{
+    if (!AssetImporter::LoadSettingsInternal())
+        return false;
+
+    JSONValue import = jsonRoot_.GetChild("TextImporter", JSON_OBJECT);
+
+    return true;
+}
+
+bool TextImporter::SaveSettingsInternal()
+{
+    if (!AssetImporter::SaveSettingsInternal())
+        return false;
+
+    JSONValue import = jsonRoot_.CreateChild("TextImporter");
+
+    return true;
+}
+
+
+
+}

+ 29 - 0
Source/ToolCore/Assets/TextImporter.h

@@ -0,0 +1,29 @@
+
+#pragma once
+
+#include "AssetImporter.h"
+
+namespace ToolCore
+{
+
+class TextImporter : public AssetImporter
+{
+    OBJECT(TextImporter);
+
+public:
+    /// Construct.
+    TextImporter(Context* context, Asset* asset);
+    virtual ~TextImporter();
+
+    virtual void SetDefaults();
+
+protected:
+
+    bool Import();
+
+    virtual bool LoadSettingsInternal();
+    virtual bool SaveSettingsInternal();
+
+};
+
+}