Browse Source

Working on 2D platformer update

Josh Engebretson 10 years ago
parent
commit
6ed30013c5

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

@@ -136,10 +136,10 @@ class ProjectFrame extends ScriptWidget {
 
             if (this.menu.handlePopupMenu(data.target, data.refid))
                 return true;
-            
+
             // create
             if (id == "menu create") {
-                if (!ToolCore.toolSystem.project) return;  
+                if (!ToolCore.toolSystem.project) return;
                 var src = MenuItemSources.getMenuItemSource("project create items");
                 var menu = new Atomic.UIMenuWindow(data.target, "create popup");
                 menu.show(src);
@@ -308,7 +308,7 @@ class ProjectFrame extends ScriptWidget {
 
         var container: Atomic.UILayout = <Atomic.UILayout> this.getWidget("contentcontainer");
         container.deleteAllChildren();
-        
+
     }
 
     private refreshContent(folder: ToolCore.Asset) {
@@ -391,7 +391,7 @@ class ProjectFrame extends ScriptWidget {
         button.id = asset.guid;
         button.layoutParams = lp;
         button.fontDescription = fd;
-        button.text = asset.name;
+        button.text = asset.name + asset.extension;
         button.skinBg = "TBButton.flat";
         blayout.addChild(button);
 

+ 48 - 0
Script/AtomicEditor/ui/frames/inspector/ComponentInspector.ts

@@ -126,6 +126,11 @@ class ComponentInspector extends Atomic.UISection {
             this.addJSComponentUI(attrsVerticalLayout);
         }
 
+        if (component.typeName == "TileMap2D") {
+            this.addTilemap2DUI(attrsVerticalLayout);
+        }
+
+
         if (component.typeName == "StaticModel" || component.typeName == "AnimatedModel" || component.typeName == "Skybox") {
             this.addModelUI(attrsVerticalLayout, component.typeName);
         }
@@ -489,6 +494,49 @@ class ComponentInspector extends Atomic.UISection {
 
     }
 
+    addTilemap2DUI(layout: Atomic.UILayout) {
+
+        var tilemap = <Atomic.TileMap2D> this.component;
+
+        var o = InspectorUtils.createAttrEditFieldWithSelectButton("TMX File", layout);
+        var field = o.editField;
+        field.readOnly = true;
+        field.text = tilemap.tmxFile ? tilemap.tmxFile.name : "";
+
+        var select = o.selectButton;
+
+        select.onClick = () => {
+
+            // this should allow selecting of sprite sheets as well
+            EditorUI.getModelOps().showResourceSelection("Select TMX File", "TMXImporter", function(asset: ToolCore.Asset) {
+
+                tilemap.tmxFile = <Atomic.TmxFile2D> Atomic.cache.getResource("TmxFile2D", asset.path);
+                if (tilemap.tmxFile)
+                    field.text = tilemap.tmxFile.name;
+            });
+
+        }
+
+        // handle dropping of component on field
+        field.subscribeToEvent(field, "DragEnded", (ev: Atomic.DragEndedEvent) => {
+
+            if (ev.target == field) {
+
+                var importer = this.acceptAssetDrag("TextureImporter", ev);
+
+                if (importer) {
+
+                  tilemap.tmxFile = <Atomic.TmxFile2D> Atomic.cache.getResource("TmxFile2D", importer.asset.path);
+                  if (tilemap.tmxFile)
+                      field.text = tilemap.tmxFile.name;
+
+                }
+            }
+
+        });
+
+    }
+
     addLightCascadeParametersUI(layout: Atomic.UILayout) {
 
         var light = <Atomic.Light> this.component;

+ 5 - 0
Script/AtomicEditor/ui/frames/inspector/CreateComponentButton.ts

@@ -9,8 +9,13 @@ audioCreateSource.addItem(new Atomic.UIMenuItem("SoundSource", "SoundSource"));
 audioCreateSource.addItem(new Atomic.UIMenuItem("SoundSource3D", "SoundSource3D"));
 
 var _2DCreateSource = new Atomic.UIMenuItemSource();
+_2DCreateSource.addItem(new Atomic.UIMenuItem("PhysicsWorld2D", "PhysicsWorld2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("StaticSprite2D", "StaticSprite2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("AnimatedSprite2D", "AnimatedSprite2D"));
+_2DCreateSource.addItem(new Atomic.UIMenuItem("RigidBody2D", "RigidBody2D"));
+_2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionBox2D", "CollisionBox2D"));
+_2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionCircle2D", "CollisionCircle2D"));
+_2DCreateSource.addItem(new Atomic.UIMenuItem("TileMap2D", "TileMap2D"));
 
 var geometryCreateSource = new Atomic.UIMenuItemSource();
 

+ 48 - 3
Script/AtomicEditor/ui/frames/inspector/DataBinding.ts

@@ -93,7 +93,7 @@ class DataBinding {
             var lp = new Atomic.UILayoutParams();
             lp.width = 100;
 
-            for (var i:any = 0; i < 3; i++) {
+            for (var i: any = 0; i < 3; i++) {
                 var select = new Atomic.UIInlineSelect();
                 select.id = String(i + 1);
                 select.fontDescription = fd;
@@ -114,7 +114,7 @@ class DataBinding {
             var lp = new Atomic.UILayoutParams();
             lp.width = 70;
 
-            for (var i:any = 0; i < 4; i++) {
+            for (var i: any = 0; i < 4; i++) {
 
                 var select = new Atomic.UIInlineSelect();
                 select.id = String(i + 1);
@@ -124,6 +124,27 @@ class DataBinding {
                 layout.addChild(select);
             }
 
+        } else if (attrInfo.type == Atomic.VAR_VECTOR2) {
+            var layout = new Atomic.UILayout();
+            widget = layout;
+            layout.spacing = 0;
+
+            var lp = new Atomic.UILayoutParams();
+            lp.width = 100;
+
+            for (var i: any = 0; i < 2; i++) {
+                var select = new Atomic.UIInlineSelect();
+                select.id = String(i + 1);
+                select.fontDescription = fd;
+                select.skinBg = "InspectorVectorAttrName";
+                select.setLimits(-10000000, 10000000);
+                var editlp = new Atomic.UILayoutParams();
+                editlp.minWidth = 60;
+                select.editFieldLayoutParams = editlp;
+                select.layoutParams = lp;
+                layout.addChild(select);
+            }
+
         }
 
         if (widget) {
@@ -163,6 +184,18 @@ class DataBinding {
                     select.value = value[i];
             }
 
+        }
+        else if (attrInfo.type == Atomic.VAR_VECTOR2) {
+
+            var value = object.getAttribute(attrInfo.name);
+
+            for (var i = 0; i < 2; i++) {
+
+                var select = widget.getWidget((i + 1).toString());
+                if (select)
+                    select.value = value[i];
+            }
+
         }
         else if (attrInfo.type == Atomic.VAR_QUATERNION) {
 
@@ -254,7 +287,19 @@ class DataBinding {
 
             object.setAttribute(attrInfo.name, value);
 
-        } else if (type == Atomic.VAR_QUATERNION && srcWidget) {
+        } else if (type == Atomic.VAR_VECTOR2 && srcWidget) {
+
+            var value = object.getAttribute(attrInfo.name);
+
+            if (srcWidget.id == "1")
+                value[0] = srcWidget.value;
+            else if (srcWidget.id == "2")
+                value[1] = srcWidget.value;
+
+            object.setAttribute(attrInfo.name, value);
+
+        }
+        else if (type == Atomic.VAR_QUATERNION && srcWidget) {
 
             var value = object.getAttribute(attrInfo.name);
 

+ 1 - 1
Script/Packages/Atomic/Atomic2D.json

@@ -14,7 +14,7 @@
 				 "Light2DGroup", "Light2D", "DirectionalLight2D", "PositionalLight2D", "PointLight2D"],
 	"overloads" : {
 		"AnimatedSprite2D" : {
-			"SetAnimation" : ["AnimationSet2D", "String", "LoopMode2D"]
+			"SetAnimation" : ["String", "LoopMode2D"]
 		},
 		"CollisionBox2D" : {
 			"SetSize" : ["Vector2"]

+ 2 - 1
Script/Packages/Atomic/Scene.json

@@ -39,7 +39,8 @@
 			"getComponents(componentType?:string, recursive?:boolean):Component[];",
 			"getChildAtIndex(index:number):Node;",
 			"createJSComponent(name:string, args?:{});",
-			"getJSComponent(name:string):JSComponent;"
+			"getJSComponent(name:string):JSComponent;",
+			"createChildPrefab(childName:string, prefabPath:string);"
 		],
 		"Scene" : [
 			"getMainCamera():Camera;"

+ 2 - 1
Source/Atomic/Atomic2D/RigidBody2D.cpp

@@ -39,11 +39,12 @@ namespace Atomic
 extern const char* ATOMIC2D_CATEGORY;
 static const BodyType2D DEFAULT_BODYTYPE = BT_STATIC;
 
+// ATOMIC: Make sure these match box2d order
 static const char* bodyTypeNames[] =
 {
     "Static",
-    "Dynamic",
     "Kinematic",
+    "Dynamic",
     0
 };
 

+ 0 - 1
Source/Atomic/Scene/PrefabComponent.h

@@ -7,7 +7,6 @@
 namespace Atomic
 {
 
-/// Helper base class for user-defined game logic components that hooks up to update events and forwards them to virtual functions similar to ScriptInstance class.
 class PrefabComponent : public Component
 {
     OBJECT(PrefabComponent);

+ 34 - 10
Source/AtomicEditor/Editors/SceneEditor3D/SceneView3D.cpp

@@ -36,8 +36,13 @@
 #include <ToolCore/Assets/Asset.h>
 #include <ToolCore/Assets/AssetDatabase.h>
 #include <ToolCore/Assets/ModelImporter.h>
-
 #include <ToolCore/Assets/PrefabImporter.h>
+#include <ToolCore/Assets/SpriterImporter.h>
+#include <ToolCore/Assets/TextureImporter.h>
+
+#include <Atomic/Atomic2D/Sprite2D.h>
+#include <Atomic/Atomic2D/AnimationSet2D.h>
+#include <Atomic/Atomic2D/AnimatedSprite2D.h>
 
 #include "../../EditorMode/AEEditorEvents.h"
 
@@ -490,8 +495,6 @@ void SceneView3D::HandleDragEnterWidget(StringHash eventType, VariantMap& eventD
             dragNode_ = scene_->CreateChild(asset->GetName());
             PrefabComponent* pc = dragNode_->CreateComponent<PrefabComponent>();
             pc->SetPrefabGUID(asset->GetGUID());
-            dragNode_->SetName(asset->GetName());
-
         }
         else if (importerType == ModelImporter::GetTypeNameStatic())
         {
@@ -504,18 +507,39 @@ void SceneView3D::HandleDragEnterWidget(StringHash eventType, VariantMap& eventD
                 return;
 
             dragNode_->LoadXML(xml->GetRoot());
-            dragNode_->SetName(asset->GetName());
+        }
+        else if (importerType == SpriterImporter::GetTypeNameStatic())
+        {
+            AnimationSet2D* animationSet = GetSubsystem<ResourceCache>()->GetResource<AnimationSet2D>(asset->GetPath());
+
+            String animationName;
+
+            if (animationSet && animationSet->GetNumAnimations())
+            {
+                animationName = animationSet->GetAnimation(0)->GetName();
+            }
 
-            /*
             dragNode_ = scene_->CreateChild(asset->GetName());
-            preloadResourceScene_ = new Scene(context_);
 
-            SharedPtr<File> file(new File(context_, asset->GetCachePath()));
+            AnimatedSprite2D* sprite = dragNode_->CreateComponent<AnimatedSprite2D>();
+
+            if (!animationName.Length())
+                sprite->SetAnimationSet(animationSet);
+            else
+                sprite->SetAnimation(animationSet, animationName);
 
-            preloadResourceScene_->LoadAsyncXML(file, LOAD_RESOURCES_ONLY);
-            dragAssetGUID_ = asset->GetGUID();
-            */
         }
+        else if (importerType == TextureImporter::GetTypeNameStatic())
+        {
+            dragNode_ = scene_->CreateChild(asset->GetName());
+
+            Sprite2D* spriteGraphic = GetSubsystem<ResourceCache>()->GetResource<Sprite2D>(asset->GetPath());
+
+            StaticSprite2D* sprite = dragNode_->CreateComponent<StaticSprite2D>();
+
+            sprite->SetSprite(spriteGraphic);
+        }
+
 
         if (dragNode_.NotNull())
         {

+ 41 - 2
Source/AtomicJS/Javascript/JSScene.cpp

@@ -3,11 +3,16 @@
 // https://github.com/AtomicGameEngine/AtomicGameEngine
 
 #include <Atomic/Resource/ResourceCache.h>
+#include <Atomic/Resource/XMLFile.h>
 #include <Atomic/IO/File.h>
 #include <Atomic/Scene/Node.h>
 #include <Atomic/Scene/Scene.h>
 #include <Atomic/Graphics/Camera.h>
 
+#ifdef ATOMIC_3D
+#include <Atomic/Physics/RigidBody.h>
+#endif
+
 #include "JSScene.h"
 #include "JSComponent.h"
 #include "JSVM.h"
@@ -193,6 +198,40 @@ static int Node_SaveXML(duk_context* ctx)
     return 1;
 }
 
+static int Node_CreateChildPrefab(duk_context* ctx)
+{
+    const char* childName = duk_require_string(ctx, 0);
+    const char* prefabName = duk_require_string(ctx, 1);
+
+    duk_push_this(ctx);
+    Node* parent = js_to_class_instance<Node>(ctx, -1, 0);
+
+    Node* prefabNode = parent->CreateChild(childName);
+
+    ResourceCache* cache = parent->GetSubsystem<ResourceCache>();
+    XMLFile* xmlfile = cache->GetResource<XMLFile>(prefabName);
+
+    prefabNode->LoadXML(xmlfile->GetRoot());
+    prefabNode->SetTemporary(true);
+
+    prefabNode->SetPosition(Vector3::ZERO);
+    prefabNode->SetRotation(Quaternion::IDENTITY);
+
+#ifdef ATOMIC_3D
+    PODVector<RigidBody*> bodies;
+    prefabNode->GetComponents<RigidBody>(bodies, true);
+    for (unsigned i = 0; i < bodies.Size(); i++)
+    {
+        RigidBody* body = bodies[i];
+        body->SetTransform(body->GetNode()->GetWorldPosition(), body->GetNode()->GetWorldRotation());
+    }
+#endif
+
+    js_push_class_object_instance(ctx, prefabNode, "Node");
+
+    return 1;
+
+}
 
 static int Scene_LoadXML(duk_context* ctx)
 {
@@ -250,8 +289,6 @@ static int Scene_GetMainCamera(duk_context* ctx)
 
 }
 
-
-
 void jsapi_init_scene(JSVM* vm)
 {
     duk_context* ctx = vm->GetJSContext();
@@ -273,6 +310,8 @@ void jsapi_init_scene(JSVM* vm)
     duk_put_prop_string(ctx, -2, "getChildAtIndex");
     duk_push_c_function(ctx, Node_SaveXML, 1);
     duk_put_prop_string(ctx, -2, "saveXML");
+    duk_push_c_function(ctx, Node_CreateChildPrefab, 2);
+    duk_put_prop_string(ctx, -2, "createChildPrefab");
 
     duk_pop(ctx);
 

+ 17 - 1
Source/ToolCore/Assets/Asset.cpp

@@ -15,6 +15,8 @@
 #include "TextureImporter.h"
 #include "PrefabImporter.h"
 #include "JavascriptImporter.h"
+#include "SpriterImporter.h"
+#include "TMXImporter.h"
 
 #include "AssetEvents.h"
 #include "Asset.h"
@@ -230,7 +232,7 @@ bool Asset::CreateImporter()
     }
     else
     {
-        String ext = GetExtension(path_);
+        String ext = Atomic::GetExtension(path_);
 
         name_ = GetFileName(path_);
 
@@ -265,6 +267,14 @@ bool Asset::CreateImporter()
         {
             importer_ = new MaterialImporter(context_, this);
         }
+        else if (ext == ".scml")
+        {
+            importer_ = new SpriterImporter(context_, this);
+        }
+        else if (ext == ".tmx")
+        {
+            importer_ = new TMXImporter(context_, this);
+        }
         else if (textureFormats.Contains(ext))
         {
             importer_ = new TextureImporter(context_, this);
@@ -287,6 +297,12 @@ String Asset::GetCachePath() const
     return cachePath;
 }
 
+String Asset::GetExtension() const
+{
+
+    return Atomic::GetExtension(path_);
+
+}
 
 bool Asset::SetPath(const String& path)
 {

+ 1 - 0
Source/ToolCore/Assets/Asset.h

@@ -32,6 +32,7 @@ public:
     const String& GetGUID() const { return guid_; }
     const String& GetName() const { return name_; }
     const String& GetPath() const { return path_; }
+    String GetExtension() const;
     /// Get the path relative to project
     String GetRelativePath();
     String GetCachePath() const;

+ 53 - 0
Source/ToolCore/Assets/SpriterImporter.cpp

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

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

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

+ 53 - 0
Source/ToolCore/Assets/TMXImporter.cpp

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

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

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