Skip to content

Commit

Permalink
draft of feature #6
Browse files Browse the repository at this point in the history
  • Loading branch information
alerdenisov committed Jan 20, 2017
1 parent df8531f commit d51cbbf
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class AbstractAttributeUpdateSystem : IReactiveSystem<IUIPool>,
protected abstract Type[] AttributeTypes { get; }
protected virtual Type[] EnsureTypes => new Type[0];

protected IViewProvider _viewPool;
protected IViewProvider ViewPool;
private HashSet<Entity<IUIPool>> _awaiting = new HashSet<Entity<IUIPool>>();

public void Execute(List<Entity<IUIPool>> entities)
Expand All @@ -33,7 +33,7 @@ private void TrySetup(Entity<IUIPool> entity)
}

var link = entity.Get<ViewLink>();
var view = _viewPool.GetByIdentity(link.Id);
var view = ViewPool.GetByIdentity(link.Id);

if (!view.InScene())
{
Expand Down Expand Up @@ -61,7 +61,7 @@ public void Execute()

public virtual void SetPool(Pool<IUIPool> pool)
{
_viewPool = pool.Get<ViewProvider>().Value;
ViewPool = pool.Get<ViewProvider>().Value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using Rentitas;
using ReUI.Api;
using UnityEngine;

namespace ReUI.Implementation
{
public class UpdateElementParentSystem : AbstractAttributeUpdateSystem
{
protected Pool<IUIPool> UIPool;

protected override Type[] EnsureTypes => new[] {typeof (ChildrenType), typeof (Ready)};
protected override Type[] AttributeTypes => new[] {typeof (Parent)};

protected override void SetupAttribute(Entity<IUIPool> uiEntity, IView view, GameObject go)
{
Debug.Log($"Update parent for {uiEntity.GetAttribute<Name, string>()}");
var parentId = uiEntity.Get<Parent>().Id;
var parent = UIPool.GetElement(parentId);
var parentView = ViewPool.GetByIdentity(parent.Get<ViewLink>().Id);
view.SetParent(parentView);
}

public override void SetPool(Pool<IUIPool> pool)
{
UIPool = pool;
base.SetPool(pool);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void Execute(List<Entity<IUIPool>> entities)
// continue;

// var id = entity.Get<ViewLink>().Id;
// _viewPool.GetByIdentity(id)?.Destroy();
// ViewPool.GetByIdentity(id)?.Destroy();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@ public class SetupElementTypeSystem : IReactiveSystem<IUIPool>
public static HashSet<string> _standardElements = new HashSet<string>
{
"Root",
"Children",
"GameObject",
"Color",
"Image",
"Text",
"Texture",
"Loop"
"Loop",
"Hierarchy",
};

public static Dictionary<string, Elements> _standardTypes = new Dictionary<string, Elements>()
{
{"Root", Elements.Root},
{"Children", Elements.Children},
{"GameObject", Elements.GameObject},
{"Color", Elements.Sprite},
{"Image", Elements.Sprite},
{"Text", Elements.Text},
{"Texture", Elements.RawImage},
{"Loop", Elements.Loop}
{"Loop", Elements.Loop},
{"Hierarchy", Elements.Hierarchy}

};

Expand Down Expand Up @@ -56,11 +60,13 @@ private Entity<IUIPool> SetupType(Entity<IUIPool> element)


return element
.Toggle<ScopeType>(type == Elements.Root)
.Toggle<ScopeType>(type == Elements.Root || type == Elements.Children)
.Toggle<LoopType>(type == Elements.Loop)
.Toggle<TextureType>(type == Elements.RawImage)
.Toggle<SpriteType>(type == Elements.Sprite)
.Toggle<TextType>(type == Elements.Text)
.Toggle<HierarchyType>(type == Elements.Hierarchy)
.Toggle<ChildrenType>(type == Elements.Children)
.ReplaceInstance(viewType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ public class SetupEmbedPropertyInjectionSystem : AbstractSetupAttributeSystem

protected override void SetupFor(Entity<IUIPool> entity, XmlElement xml)
{
var value = "return {}";

if (!string.IsNullOrEmpty(xml.Content) && xml.Content.Contains("return"))
entity.SetAttribute<LuaCodePropertiesInjection, string>(xml.Content);
else if(xml.HasAttribute("Value"))
entity.SetAttribute<LuaCodePropertiesInjection, string>(xml.Attributes["Value"]);
else
entity.SetAttribute<LuaCodePropertiesInjection, string>("return {}");
value = xml.Content;
else if (xml.HasAttribute("Value"))
value = xml.Attributes["Value"];
else if (xml.HasAttribute("Props"))
value = xml.Attributes["Props"];

entity.SetAttribute<LuaCodePropertiesInjection, string>(value);
entity.Add<LuaCode>(code => code.Value.Reset());
entity.Toggle<LuaType>(true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Linq;
using Rentitas;
using ReUI.Api;

namespace ReUI.Implementation.Systems
{
public class SetupNestedHierarchySystem : AbstractSetupAttributeSystem, ISetPool<IUIPool>
{
private Pool<IUIPool> _pool;
protected override Type[] EnsureTypes => new[] {typeof (HierarchyType), typeof(Ready) };

protected override void SetupFor(Entity<IUIPool> entity, XmlElement xml)
{
var scope = _pool.GetScope(entity);
var embed = _pool.GetParent(scope);

var children = _pool.GetChildren(embed).Where(c => c.Has<ChildrenType>());
if (!children.Any())
return;

var child = children.First();

var parent = child.Need<Parent>();
parent.Id = entity.Get<Element>().Id;

child.ReplaceInstance(parent);


// Have no sub hierarchy case
// if (!embed.Has<XmlSubHierarchy>())
// return;

// var root = embed.Get<XmlSubHierarchy>().Root;
// var doc = entity.CreateComponent<XmlDocument>();
// doc.Root = root;
// entity.AddInstance(doc);
}

public void SetPool(Pool<IUIPool> typedPool)
{
_pool = typedPool;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ public class SetupTextContentSystem : AbstractSetupAttributeSystem
protected override void SetupFor(Entity<IUIPool> entity, XmlElement xml)
{
var text = entity.Need<Text>();
text.Value = xml.Content.Trim();
var value = string.Empty;
if (xml.Attributes.ContainsKey("Content"))
value = xml.Attributes["Content"];
else if (!string.IsNullOrEmpty(xml.Content))
value = xml.Content;

value = value.Trim();

text.Value = value;
entity.AddInstance(text);
}
}
Expand Down
3 changes: 3 additions & 0 deletions ReUI.Implementation/UIKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ private ISystem CreateSetupSystems(Pool<IUIPool> uiPool)
.Add(uiPool.CreateSystem(new SetupTextFontSizeSystem()))
.Add(uiPool.CreateSystem(new SetupTextLineHeightSystem()))
.Add(uiPool.CreateSystem(new SetupTextAlignmentSystem()))

.Add(uiPool.CreateSystem(new SetupNestedHierarchySystem()))
;
}

Expand Down Expand Up @@ -164,6 +166,7 @@ private ISystem CreateUpdateSystem(Pool<IUIPool> uiPool)
{
return new Scenario("Update systems")
// Update attributes
.Add(uiPool.CreateSystem(new UpdateElementParentSystem()))
.Add(uiPool.CreateSystem(new UpdateElementTypeSystem()))
.Add(uiPool.CreateSystem(new UpdateElementRectSystem()))
.Add(uiPool.CreateSystem(new UpdateElementPositionSystem()))
Expand Down

0 comments on commit d51cbbf

Please sign in to comment.