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

Commit

Permalink
UI Hookup for build queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Amatsugu committed Sep 2, 2020
1 parent 9c2d5cc commit d55cc0a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Assets/GameData/Databases/Unit Database.asset
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ MonoBehaviour:
_ids: 00000000
_defs:
- id: 0
unit: {fileID: 11400000, guid: 8c4dc19ef577e654494f91bd6a995810, type: 2}
info: {fileID: 11400000, guid: 8c4dc19ef577e654494f91bd6a995810, type: 2}
7 changes: 3 additions & 4 deletions Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 110.043015, g: 289.74753, b: 676.34375, a: 1}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -6411,7 +6411,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 2102994817}
m_Direction: 2
m_Value: 0
m_Size: 1
m_Size: 0.9999917
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
Expand Down Expand Up @@ -12672,7 +12672,6 @@ MonoBehaviour:
banner: {fileID: 1107210684}
inidcatorOffset: 0.01
hQTile: {fileID: 11400000, guid: 1c0ee8cb1827bb24abbb94b009332008, type: 2}
dropPod: {fileID: 11400000, guid: e62d3f653db9df84fbc5fd56f75ae0fe, type: 2}
contentArea: {fileID: 212590880}
nothingUnlockedText: {fileID: 180323678}
showPowerRange: 30
Expand Down Expand Up @@ -13245,7 +13244,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -443.00003}
m_AnchoredPosition: {x: 0, y: -442.9975}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1427279150
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Data Store/Databases/UnitDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public void OnAfterDeserialize()
entityIds = new Dictionary<MobileUnitEntity, int>();
for (int i = 0; i < _ids.Length; i++)
{
if(_defs[i].info == null)
{
Debug.LogError($"Unit failed to deserialize: {_ids[i]}");
continue;
}
unitEntites.Add(_ids[i], _defs[i]);
entityIds.Add(_defs[i].info, _ids[i]);
if(_ids[i] > nextId)
Expand Down
13 changes: 8 additions & 5 deletions Assets/Scripts/Game Logic/Systems/BuildQueueSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class BuildQueueSystem : ComponentSystem
protected override void OnCreate()
{
GameEvents.OnMapLoaded += InitBuildQueue;
_factoryReady = new Dictionary<HexCoords, bool>();
}

protected override void OnDestroy()
Expand Down Expand Up @@ -61,23 +62,25 @@ protected override void OnUpdate()
/// <param name="building">The tile info of the building to build</param>
private void QueueBuilding(Tile tile, BuildingTileEntity building)
{
var orderID = _curOrderID++;
_pendingBuildOrders.Add(orderID, new BuildOrder
var orderId = _curOrderID++;
_pendingBuildOrders.Add(orderId, new BuildOrder
{
building = building,
dstTile = tile
});
_readyToBuildOrders.Add(orderID);
_readyToBuildOrders.Add(orderId);
}

private void QueueUnit(FactoryBuildingTile factory, UnitIdentifier unit)
public void QueueUnit(FactoryBuildingTile factory, UnitIdentifier unit)
{
var orderId = _curOrderID++;
_pendingBuildOrders.Add(orderId, new BuildOrder
{
factory = factory,
unit = unit
unit = unit,
orderType = OrderType.Unit
});
_readyToBuildOrders.Add(orderId);
if (!_factoryReady.ContainsKey(factory.Coords))
_factoryReady.Add(factory.Coords, true);
}
Expand Down
13 changes: 7 additions & 6 deletions Assets/Scripts/Game Logic/UI/GameUI/UIBuildPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class UIBuildPanel : UITabPanel
public UIInfoBanner banner;
public float inidcatorOffset = .5f;
public HQTileEntity hQTile;
public MeshEntityRotatable dropPod;
public RectTransform contentArea;
public GameObject nothingUnlockedText;
public float showPowerRange = 20;
Expand All @@ -48,6 +47,7 @@ public class UIBuildPanel : UITabPanel
private BuildingDatabase _buildingDatabase;
private FactoryBuildingTile _selectedFactory;
private UnitDatabase _unitDatabase;
private BuildQueueSystem _buildQueue;

public enum BuildState
{
Expand All @@ -74,6 +74,7 @@ protected override void Awake()
_buildingDatabase = GameRegistry.BuildingDatabase;
_unitDatabase = GameRegistry.UnitDatabase;
indicatorManager = new IndicatorManager(World.DefaultGameObjectInjectionWorld.EntityManager, inidcatorOffset, floatingText);
_buildQueue = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<BuildQueueSystem>();
base.Awake();
}

Expand Down Expand Up @@ -113,7 +114,6 @@ private void OnTick()
return;
if(state == BuildState.UnitConstruction)
{

return;
}
var buildings = _buildingDatabase[_lastCategory];
Expand Down 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.Idle;
state = BuildState.UnitConstruction;
_selectedFactory = factoryTile;
var units = _selectedFactory.factoryInfo.unitsToBuild;
bool hasIcons = false;
Expand All @@ -156,7 +156,8 @@ public void Show(FactoryBuildingTile factoryTile)
}
if (j < units.Length)
{
var unit = _unitDatabase.unitEntites[units[j].id].info;
var unitId = units[j];
var unit = _unitDatabase.unitEntites[unitId.id].info;
if ( unit.tier == _tier)
{
_icons[i].SetActive(false);
Expand All @@ -169,7 +170,7 @@ public void Show(FactoryBuildingTile factoryTile)
_icons[i].OnHover += () => infoPanel.ShowInfo(unit);
_icons[i].OnClick += () =>
{

_buildQueue.QueueUnit(factoryTile, unitId);
};
_icons[i].SetActive(true);
hasIcons = true;
Expand Down Expand Up @@ -397,7 +398,7 @@ private void PlaceBuilding(Tile selectedTile)
{
if (state == BuildState.Placement)
ResourceSystem.ConsumeResourses(_selectedBuilding.cost);
BuildQueueSystem.QueueBuilding(_selectedBuilding, selectedTile, dropPod);
BuildQueueSystem.QueueBuilding(_selectedBuilding, selectedTile);
if (state == BuildState.HQPlacement)
{
_selectedBuilding = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public FactoryBuildingTile(HexCoords coords, float height, Map map, FactoryTileE

public virtual void StartConstruction(MobileUnitEntity unitEntity)
{

Debug.Log($"Unit starting construction: {unitEntity.GetNameString()}");
}

public virtual void FinishConstruction()
Expand Down

0 comments on commit d55cc0a

Please sign in to comment.