Skip to content

Commit

Permalink
Progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
FilippoLeon committed Jul 9, 2017
1 parent 38042a1 commit 9debd37
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Assets/Engine/Interfaces/IJobListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public interface IJobListener : IEmitterListener
{
void Schedule(World world);


void Progress(World world);
}
2 changes: 1 addition & 1 deletion Assets/Engine/Jobs/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void NextStage()
currentStage += 1;
}

Stage CurrentStage()
public Stage CurrentStage()
{
return stages[currentStage];
}
Expand Down
5 changes: 5 additions & 0 deletions Assets/Engine/Jobs/Stage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class Stage : Emitter, IXmlSerializable
List<Entity> resources = new List<Entity>();
Job job;

public float CurrentProgress()
{
return completion / (float) cost;
}

public Stage(Stage other, Job job) : base(other)
{
completion = other.completion;
Expand Down
10 changes: 10 additions & 0 deletions Assets/Unity/Components/JobComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public static JobComponent ScheduleJobControllerInWorld(
JobComponent entityComponent = entityObject.AddComponent<JobComponent>();
entityObject.transform.SetParent(worldComponent.transform);

IndicatorBar bar = IndicatorBar.Instantiate(entityObject);
bar.GetSizeCallback = new IndicatorBar.GetSize(
() => { return job.CurrentStage().CurrentProgress(); }
);

entityObject.name = job.id + "_indicator";
entityComponent.job = job;

Expand All @@ -35,4 +40,9 @@ public void Schedule(World world)
{
transform.position = ((World.Coord) job.GetTarget().value).ToVector2();
}

public void Progress(World world)
{

}
}
9 changes: 9 additions & 0 deletions Assets/Unity/Components/Subcomponents.meta

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

60 changes: 60 additions & 0 deletions Assets/Unity/Components/Subcomponents/IndicatorBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class IndicatorBar : MonoBehaviour {

public delegate float GetSize();
public GetSize GetSizeCallback;

MeshRenderer meshRenderer;
Mesh mesh;
private float zLevel = -0.01f;

static public IndicatorBar Instantiate(GameObject parent)
{
GameObject go = new GameObject();
go.transform.SetParent(parent.transform);

go.name = "indicator_bar";

IndicatorBar jobComponent = go.AddComponent<IndicatorBar>();

return jobComponent;
}

// Use this for initialization
void Start () {
gameObject.AddComponent<MeshFilter>();
meshRenderer = gameObject.AddComponent<MeshRenderer>();


mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;

mesh.vertices = new Vector3[] {
new Vector3(0,0,zLevel),
new Vector3(1,0,zLevel),
new Vector3(0,1,zLevel),
new Vector3(1,1,zLevel)
};
mesh.uv = new Vector2[] {
new Vector2(0,0),
new Vector2(1,0),
new Vector2(0,1),
new Vector2(1,1)
};
mesh.triangles = new int[] { 0, 2, 1, 1, 2, 3 };

gameObject.transform.localPosition += new Vector3(-0.6f, -0.5f, 0);
gameObject.transform.localScale = new Vector3(0.1f, 1, 1);
}

// Update is called once per frame
void Update () {
if(GetSizeCallback != null)
{
gameObject.transform.localScale = new Vector3(0.1f, GetSizeCallback(), 1);
}
}
}
12 changes: 12 additions & 0 deletions Assets/Unity/Components/Subcomponents/IndicatorBar.cs.meta

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

33 changes: 12 additions & 21 deletions Project Pu-239.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Unity Subset v3.5</TargetFrameworkProfile>
<CompilerResponseFile>
</CompilerResponseFile>
<CompilerResponseFile></CompilerResponseFile>
<UnityProjectType>Game:1</UnityProjectType>
<UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
<UnityVersion>5.5.4f1</UnityVersion>
<RootNamespace>
</RootNamespace>
<RootNamespace></RootNamespace>
<LangVersion>4</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down Expand Up @@ -113,27 +111,28 @@
<Compile Include="Assets\Engine\Tools\Pathfinding\IWieghtedNode.cs" />
<Compile Include="Assets\Engine\Tools\Pathfinding\Pathfinding.cs" />
<Compile Include="Assets\Unity\Components\EmitterController.cs" />
<Compile Include="Assets\Unity\Components\JobComponent.cs" />
<Compile Include="Assets\Unity\Components\EntityComponent.cs" />
<Compile Include="Assets\Unity\Components\JobComponent.cs" />
<Compile Include="Assets\Unity\Components\MeshComponent.cs" />
<Compile Include="Assets\Unity\Components\OverlayComponent.cs" />
<Compile Include="Assets\Unity\Components\StreamingAssets.cs" />
<Compile Include="Assets\Unity\Components\Subcomponents\IndicatorBar.cs" />
<Compile Include="Assets\Unity\Components\WorldComponent.cs" />
<Compile Include="Assets\Unity\Controllers\CameraController.cs" />
<Compile Include="Assets\Unity\Controllers\CreativeController.cs" />
<Compile Include="Assets\Unity\Controllers\MouseAndKeyboardController.cs" />
<Compile Include="Assets\Unity\Controllers\WorldController.cs" />
<Compile Include="Assets\Unity\GUI\GUIController.cs" />
<Compile Include="Assets\Unity\GUI\Widgets\Label.cs" />
<Compile Include="Assets\Utilities\LUA\Global.cs" />
<Compile Include="Assets\Utilities\PathUtilities.cs" />
<Compile Include="Assets\Unity\GUI\Widgets\Button.cs" />
<Compile Include="Assets\Unity\GUI\Widgets\Interfaces\IWidget.cs" />
<Compile Include="Assets\Unity\GUI\Widgets\Interfaces\IWidgetContainer.cs" />
<Compile Include="Assets\Unity\GUI\Widgets\Button.cs" />
<Compile Include="Assets\Unity\GUI\Widgets\Label.cs" />
<Compile Include="Assets\Unity\GUI\Widgets\Panel.cs" />
<Compile Include="Assets\Unity\GUI\Widgets\Widget.cs" />
<Compile Include="Assets\Utilities\EnumerableUtilities.cs" />
<Compile Include="Assets\Utilities\LUA\Global.cs" />
<Compile Include="Assets\Utilities\LUA\ScriptLoader.cs" />
<Compile Include="Assets\Utilities\PathUtilities.cs" />
<Compile Include="Assets\Utilities\Priority Queue\FastPriorityQueue.cs" />
<Compile Include="Assets\Utilities\Priority Queue\FastPriorityQueueNode.cs" />
<Compile Include="Assets\Utilities\Priority Queue\GenericPriorityQueue.cs" />
Expand All @@ -149,23 +148,15 @@
</ItemGroup>
<ItemGroup>
<None Include="Assets\StreamingAssets\Colormaps\LICENSE.txt" />
<None Include="Assets\StreamingAssets\Data\Buildings.xml">
<SubType>Designer</SubType>
</None>
<None Include="Assets\StreamingAssets\Data\UI\UI.xml">
<SubType>Designer</SubType>
</None>
<None Include="Assets\StreamingAssets\Data\Buildings.xml" />
<None Include="Assets\StreamingAssets\Data\Jobs.xml" />
<None Include="Assets\StreamingAssets\Data\UI\UI.xml" />
<None Include="Assets\StreamingAssets\Sprites\Buildings.xml" />
<None Include="Assets\StreamingAssets\Sprites\Characters.xml" />
<None Include="Assets\StreamingAssets\Sprites\Furniture.xml" />
<None Include="Assets\StreamingAssets\Sprites\UI.xml" />
<None Include="Assets\Utilities\Priority Queue\LICENSE.txt" />
</ItemGroup>
<ItemGroup>
<None Include="Assets\StreamingAssets\Data\Jobs.xml">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="GenerateTargetFrameworkMonikerAttribute" />
</Project>
</Project>

0 comments on commit 9debd37

Please sign in to comment.