Skip to content

Commit

Permalink
Show pile counts only on mouseover
Browse files Browse the repository at this point in the history
Resolve #31.
  • Loading branch information
dagguh committed May 5, 2019
1 parent 3b7119e commit d6ee89b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 1 addition & 3 deletions Assets/Scripts/View/GUI/CorpViewConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public CorpView Display(Game game)
servers.Represent(zones);
var archives = servers.Box(zones.archives).gameObject;
var hq = servers.Box(zones.hq).Printer.Print(game.corp.identity);
var hqCount = new GameObject("HQ card count");
hqCount.AttachTo(hq);
servers.Box(zones.rd);
zones.hq.ObserveCount(hqCount.AddComponent<PileCount>());
zones.hq.ObserveCount(hq.AddComponent<PileCount>());
zones.archives.Observe(archives.AddComponent<ArchivesPile>());
return new CorpView(servers);
}
Expand Down
24 changes: 18 additions & 6 deletions Assets/Scripts/View/GUI/PileCount.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using model.zones;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace view.gui {
public class PileCount : MonoBehaviour, IZoneCountObserver {
public class PileCount : MonoBehaviour, IZoneCountObserver, IPointerEnterHandler, IPointerExitHandler {
private Text text;

void Awake() {
text = gameObject.AddComponent<Text>();
void Awake() {
var count = new GameObject("Pile Count");
text = count.AddComponent<Text>();
text.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
var rectangle = text.rectTransform;
rectangle.anchorMin = new Vector2(0.2f, 0.2f);
Expand All @@ -18,13 +20,23 @@ void Awake() {
text.resizeTextForBestFit = true;
text.resizeTextMinSize = 1;
text.resizeTextMaxSize = 100;
text.alignment = TextAnchor.MiddleCenter;
var outline = gameObject.AddComponent<Outline>();
outline.effectDistance = new Vector2(2, 2);
text.alignment = TextAnchor.MiddleCenter;
text.enabled = false;
var outline = count.AddComponent<Outline>();
outline.effectDistance = new Vector2(2, 2);
count.AttachTo(gameObject);
}

void IZoneCountObserver.NotifyCount(int count) {
text.text = count.ToString();
}

void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) {
text.enabled = true;
}

void IPointerExitHandler.OnPointerExit(PointerEventData eventData) {
text.enabled = false;
}
}
}
4 changes: 1 addition & 3 deletions Assets/Scripts/View/GUI/RunnerViewConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public void Display(Game game, CorpView corpView)
var rigZone = GameObject.Find("Rig").AddComponent<DropZone>();
var heapZone = GameObject.Find("Heap").AddComponent<DropZone>();
var gripZone = GameObject.Find("Grip").AddComponent<DropZone>();
var stackCount = new GameObject("Stack card count");
stackCount.AttachTo(stackPile.gameObject);
grip.Construct(game, playZone, rigZone, heapZone);
stackPile.Construct(game, gripZone);
rig.Construct(game, playZone);
Expand All @@ -36,7 +34,7 @@ public void Display(Game game, CorpView corpView)

game.runner.credits.Observe(GameObject.Find("Runner/Right hand/Credits/Credits text").AddComponent<CreditPoolText>());
var zones = game.runner.zones;
zones.stack.ObserveCount(stackCount.AddComponent<PileCount>());
zones.stack.ObserveCount(stackPile.gameObject.AddComponent<PileCount>());
zones.stack.ObservePopping(stackPile);
zones.grip.ObserveAdditions(grip);
zones.grip.ObserveRemovals(grip);
Expand Down

0 comments on commit d6ee89b

Please sign in to comment.