Skip to content

Commit

Permalink
UI
Browse files Browse the repository at this point in the history
  • Loading branch information
FilippoLeon committed Jul 2, 2017
1 parent 4df45fa commit b249887
Show file tree
Hide file tree
Showing 49 changed files with 984 additions and 33 deletions.
5 changes: 4 additions & 1 deletion Assets/Engine/Emitters/Entities/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using MoonSharp.Interpreter;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using UnityEngine;

[MoonSharpUserData]
public class Entity : Emitter, IXmlSerializable {

public string id;
Expand All @@ -16,6 +18,7 @@ public struct SpriteInfo {
public string id;
public string type;
}

public SpriteInfo spriteInfo = new SpriteInfo();

public Vector2 Position
Expand Down
4 changes: 3 additions & 1 deletion Assets/Engine/Emitters/Entities/EntityBuilding.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using MoonSharp.Interpreter;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using UnityEngine;

[MoonSharpUserData]
public class EntityBuilding : EntityInanimated, IXmlSerializable
{
bool installed = false;
Expand Down
2 changes: 2 additions & 0 deletions Assets/Engine/Emitters/Entities/EntityInanimated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Xml.Schema;
using System.Xml.Serialization;
using UnityEngine;
using MoonSharp.Interpreter;

[MoonSharpUserData]
public class EntityInanimated : Entity, IXmlSerializable
{

Expand Down
9 changes: 8 additions & 1 deletion Assets/Engine/Emitters/Tile.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Priority_Queue;
using MoonSharp.Interpreter;
using Priority_Queue;
using System;
using System.Collections.Generic;
using UnityEngine;

[MoonSharpUserData]
public class Tile : Emitter, IFormattable, IWieghtedNode<Tile>
{
public World.Coord coord;
Expand Down Expand Up @@ -502,6 +504,11 @@ internal void OnNeighbourChanged(World world, Tile neighbour)
}

public string ToString(string format, IFormatProvider formatProvider)
{
return ToString();
}

public override string ToString()
{
return String.Format("Tile at {0}x{1}", coord.x, coord.y);
}
Expand Down
20 changes: 18 additions & 2 deletions Assets/Engine/Emitters/World.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using MoonSharp.Interpreter;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[MoonSharpUserData]
public class World : Emitter {

Tile[,] tiles;
Expand All @@ -11,6 +13,7 @@ public class World : Emitter {

List<EntityAnimated> characters = new List<EntityAnimated>();
Emitter selected;
public Tile selectedTile;

public Emitter Selected
{
Expand All @@ -25,7 +28,8 @@ public Emitter Selected
}
}

public struct Coord
[MoonSharpUserData]
public struct Coord : IFormattable
{
public int x, y;

Expand Down Expand Up @@ -98,6 +102,18 @@ public Coord Rotate()
{
return new Coord(-y, x);
}

public string ToString(string format = null, IFormatProvider formatProvider = null)
{
return String.Format("{0}x{1}", x, y);
}
}

public EntityRegistry registry;

internal void SetRegistry(EntityRegistry entityRegistry)
{
registry = entityRegistry;
}

internal EntityAnimated GetCharacter(string name)
Expand Down
4 changes: 3 additions & 1 deletion Assets/Engine/Registry/EntityRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using UnityEngine;
using System.IO;
using System;
using MoonSharp.Interpreter;

[MoonSharpUserData]
public class EntityRegistry {

static string path = "Data";
static private Dictionary<string, EntityBuilding> buildingsRegistry = new Dictionary<string, EntityBuilding>();
static public Dictionary<string, EntityBuilding> buildingsRegistry = new Dictionary<string, EntityBuilding>();

public EntityRegistry()
{
Expand Down
9 changes: 9 additions & 0 deletions Assets/Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
25 changes: 25 additions & 0 deletions Assets/Plugins/MoonSharp.Interpreter.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
25 changes: 25 additions & 0 deletions Assets/Plugins/Newtonsoft.Json.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/StreamingAssets/Data/UI.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Assets/StreamingAssets/Data/UI.xml

This file was deleted.

18 changes: 18 additions & 0 deletions Assets/StreamingAssets/Data/UI/UI.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Canvas>
<Panel id="creative_panel" anchorMin="0,0" anchorMax="1,0.1">
<Action name="OnCreate">buildBuildingPlacementPanel</Action>
</Panel>
<Panel id="slection_view" layout="grid" gridX="2" anchorMin="0,0.9" anchorMax="1,1">
<Label><Text>Tile</Text></Label>
<Label><Text>Tile2</Text></Label>
<Label><Text>Coord:</Text></Label>
<Label id="tile_coord"><Text>N/D</Text></Label>
<Button>
<Text>Button</Text>
<Action name="OnClick"></Action>
</Button>

<Action name="OnUpdate">SelectionViewOnUpdate</Action>
</Panel>
</Canvas>
File renamed without changes.
9 changes: 9 additions & 0 deletions Assets/StreamingAssets/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/StreamingAssets/Scripts/UI.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Assets/StreamingAssets/Scripts/UI/UI.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /usr/bin/env lua
--

function buildBuildingPlacementPanel(UI, world)
panel = Panel.Create("buildingPrototypes")
panel.SetLayout(WidgetLayout.Vertical)
for key, prototype in pairs(world.registry.buildingsRegistry)
do
print(prototype.id)
button = Button.Create(prototype.id)
panel.Add(button)
button.Text = prototype.id
function printID()
print(prototype.id)
end
button.OnClick(printID)
end
end

function SelectionViewOnUpdate(UI, world)
if world.selectedTile != nil then
UI["tile_coord"].Text = world.selectedTile.ToString()
end
end
8 changes: 8 additions & 0 deletions Assets/StreamingAssets/Scripts/UI/UI.lua.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Assets/StreamingAssets/Scripts/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env lua

--
function test()
return true
end
8 changes: 8 additions & 0 deletions Assets/StreamingAssets/Scripts/test.lua.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/StreamingAssets/Sprites/UI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions Assets/StreamingAssets/Sprites/UI.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<SpriteSheet defaultSize="32,32" defaultPivot="0.5,0.5">
<Sprite start="0,0" category="indicator" border="2,2,2,2">selector</Sprite>
<SpriteSheet defaultSize="32,32" defaultPivot="0.5,0.5" defaultPpu="64">
<Sprite start="0,0" category="UI">selector</Sprite>
<Sprite start="1,0" category="UI" border="2,2,2,2">panel_background</Sprite>
<Sprite start="2,0" category="UI" border="5,5,5,5">button_background</Sprite>
</SpriteSheet>
8 changes: 5 additions & 3 deletions Assets/Unity/Components/WorldComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ public void Update()
Vector2 pos = MouseToVector2(Input.mousePosition);

EntityComponent entityComponent = GetEmitterAt(pos);
if(entityComponent == null)
if(entityComponent != null)
{
return;
world.Selected = entityComponent.Emitter;
} else
{
world.selectedTile = world.GetTileAt(pos);
}
world.Selected = entityComponent.Emitter;
}
}

Expand Down
9 changes: 7 additions & 2 deletions Assets/Unity/Controllers/WorldController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class WorldController : MonoBehaviour {

private static World world;

public static World StaticWorld;
public bool Paused
{
get
Expand All @@ -29,6 +30,7 @@ public World World
set
{
world = value;
StaticWorld = world;
}
}

Expand All @@ -51,6 +53,7 @@ public World World
private static int maxSpeed = speedRatio.Length - 1;
private static int minSpeed = 0;

private EntityRegistry entityRegistry;
internal void IncreaseSpeed()
{
speed = Math.Min(speed + 1, maxSpeed);
Expand All @@ -73,7 +76,7 @@ internal void SetSpeed(int newSpeed)

void PreInit()
{
new EntityRegistry();
entityRegistry = new EntityRegistry();

inputController = gameObject.AddComponent<MouseAndKeyboardController>();
inputController.worldController = this;
Expand All @@ -83,6 +86,7 @@ void PreInit()
cameraController.worldController = this;

SpriteLoader.Load();
new LUA.ScriptLoader();

guiController = gameObject.AddComponent<GUIController>();
guiController.worldController = this;
Expand All @@ -92,7 +96,8 @@ void PreInit()
void Start () {
PreInit();

world = new World(200, 200);
World = new World(200, 200);
world.SetRegistry(entityRegistry);

GameObject worldObject = new GameObject();
WorldComponent worldComponent = worldObject.AddComponent<WorldComponent>();
Expand Down
Loading

0 comments on commit b249887

Please sign in to comment.