Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Improved Colorization of rarity texts
Browse files Browse the repository at this point in the history
  • Loading branch information
Amatsugu committed Aug 30, 2020
1 parent efb2e4b commit f40bc8f
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 16 deletions.
7 changes: 5 additions & 2 deletions Assets/Scripts/Data Store/Databases/ResourceDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ public static int GetResourceId(string name)
throw new System.Exception($"Resource '{name}' does not exits");
}

public static string GetResourceName(int id, string locale = "en")
public static string GetResourceName(int id, bool color = false, string locale = "en")
{
return INST.resourceList.resourceDefinations[id].name;
var res = INST.resourceList.resourceDefinations[id];
if (color)
return GameRegistry.RarityColors.ColorizeAsString(res.name, res.tier);
return res.name;
}

public static int GetSpriteId(int id)
Expand Down
18 changes: 18 additions & 0 deletions Assets/Scripts/Data Store/RarityColors.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using System.Text;

using UnityEngine;

[CreateAssetMenu(menuName = "Game Data/Rarity Colors")]
public class RarityColors : ScriptableObject
{
public Color[] Colors;

public string ColorizeAsString(string name, int rarity)
{
return Colorize(name, rarity).ToString();
}

public StringBuilder Colorize(string name, int rarity)
{
var sb = new StringBuilder();
sb.Append("<color=#");
sb.Append(ColorUtility.ToHtmlStringRGB(Colors[rarity]));
sb.Append('>');
sb.Append(name);
sb.Append("</color>");
return sb;
}
}
5 changes: 4 additions & 1 deletion Assets/Scripts/Data Store/ResourceDefination.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using UnityEngine;
using JetBrains.Annotations;

using UnityEngine;

[System.Serializable]
public class ResourceDefination
{
public string name;
public Sprite sprite;
public int spriteID;
public int tier;
}
8 changes: 5 additions & 3 deletions Assets/Scripts/Game Logic/UI/GameUI/UIBuildPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void Show(FactoryBuildingTile factoryTile)
{
if (state == BuildState.HQPlacement) //This should never happen, but just in case
return;
state = BuildState.UnitConstruction;
state = BuildState.Idle;
_selectedFactory = factoryTile;
var units = _selectedFactory.factoryInfo.unitsToBuild;
bool hasIcons = false;
Expand Down Expand Up @@ -243,7 +243,7 @@ public void UpdateState()
switch(state)
{
case BuildState.Disabled:
UnitFactoryLogic();
InfoPanelLogic();
break;
case BuildState.Idle:
ReadBackInput();
Expand All @@ -265,12 +265,14 @@ public void UpdateState()
}
}

void UnitFactoryLogic()
void InfoPanelLogic()
{
infoPanel.Hide();
var tile = GetTileUnderCursor();
if (tile is BuildingTile b)
infoPanel.ShowInfo(b.buildingInfo);
else if(tile is ResourceTile r)
infoPanel.ShowInfo(r.resInfo);
if (Input.GetKeyUp(KeyCode.Mouse0) && tile is FactoryBuildingTile f)
Show(f);

Expand Down
15 changes: 15 additions & 0 deletions Assets/Scripts/Game Logic/UI/GameUI/UIInfoPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Collections;
using System.Collections.Generic;
using System.Text;

using TMPro;
using UnityEngine;

Expand All @@ -19,6 +21,19 @@ public void ShowInfo(BuildingTileEntity building)
SetActive(true);
}

public void ShowInfo(ResourceTileInfo tile)
{
titleText.SetText(tile.GetNameString());
descriptionText.SetText(tile.description);
var sb = new StringBuilder();
for (int i = 0; i < tile.resourceYields.Length; i++)
{
sb.Append($"{ResourceDatabase.GetResourceName(tile.resourceYields[i].id)}");
}
productionText.SetText(sb);
SetActive(true);
}

public void ShowInfo(MobileUnitEntity unitEntity)
{
titleText.SetText(unitEntity.GetNameString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ public FactoryBuildingTile(HexCoords coords, float height, Map map, FactoryTileE
factoryInfo = tInfo;
}


}
}
4 changes: 3 additions & 1 deletion Assets/Scripts/Map/Tiles/MappedTiles/Buildings/MetaTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using System.Collections;
using System.Collections.Generic;
using System.Text;

using UnityEngine;


Expand Down Expand Up @@ -56,7 +58,7 @@ public override string GetDescription()
return _parent.GetDescription();
}

public override string GetName()
public override StringBuilder GetName()
{
return _parent.GetName();
}
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Map/Tiles/MappedTiles/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Collections.Generic;
using System.Linq;
using System.Text;

using Unity.Collections;
using Unity.Entities;
Expand Down Expand Up @@ -59,7 +60,7 @@ public Tile SetBiome(int biome, float moisture, float temperature)
return this;
}

public virtual string GetName()
public virtual StringBuilder GetName()
{
return info.GetNameString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ public virtual StringBuilder GetUpkeepString()
return upkeepString;
}

public override string GetNameString()
public override StringBuilder GetNameString()
{
return $"<color=#{ColorUtility.ToHtmlStringRGB(GameRegistry.RarityColors.Colors[tier])}>{name}</color>";
return GameRegistry.RarityColors.Colorize(name, tier);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Amatsugu.Phos.TileEntities
{
public class FactoryTileEntity : BuildingTileEntity
{
[Header("Factory")]
public UnitIdentifier[] unitsToBuild;

public override Tile CreateTile(Map map, HexCoords pos, float height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override StringBuilder GetProductionString()
for (int i = 0; i < buildingsToUnlock.Length; i++)
{
prod.Append("\t");
prod.AppendLine(GameRegistry.BuildingDatabase[buildingsToUnlock[i]].info.GetNameString());
prod.AppendLine(GameRegistry.BuildingDatabase[buildingsToUnlock[i]].info.GetNameString().ToString());
}
return prod;
}
Expand Down
6 changes: 4 additions & 2 deletions Assets/Scripts/Map/Tiles/TileInfo/TileEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
Expand Down Expand Up @@ -99,9 +101,9 @@ public void OnBeforeSerialize()
#endif
}

public virtual string GetNameString()
public virtual StringBuilder GetNameString()
{
return name;
return new StringBuilder(name);
}

public void OnAfterDeserialize()
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/Map/Units/MobileUnitEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Unity.Entities;
using Unity.Mathematics;
Expand Down Expand Up @@ -129,9 +130,9 @@ public Entity Instantiate(float3 pos, Quaternion rotation, int id, Faction facti
return e;
}

internal string GetNameString()
internal StringBuilder GetNameString()
{
return name;
return GameRegistry.RarityColors.Colorize(name, tier);
}

internal string GetCostString()
Expand Down

0 comments on commit f40bc8f

Please sign in to comment.