Create StatusUI

This commit is contained in:
henriquenakashima 2020-09-20 22:45:42 -04:00
parent dd9b360bfc
commit 03ca23d484
11 changed files with 484 additions and 17 deletions

View file

@ -5,8 +5,9 @@ using UnityEngine;
public class BattleParticipant
{
public delegate void DeathAction(BattleParticipant participant);
public event DeathAction OnDeath;
public delegate void BattleParticipantUpdateAction(BattleParticipant participant);
public event BattleParticipantUpdateAction OnDeath;
public event BattleParticipantUpdateAction OnStatusChanged;
protected bool isHero;
protected string displayName;
@ -55,6 +56,7 @@ public class BattleParticipant
public void CheckState() {
if (this.hp <= 0) {
this.dead = true;
WipeStatus();
TriggerOnDeath();
}
}
@ -99,20 +101,35 @@ public class BattleParticipant
}
public int AddStatus(BattleStatus status, int amount) {
if (amount <= 0) {
return 0;
}
int currentAmount;
this.statuses.TryGetValue(status, out currentAmount);
this.statuses[status] = currentAmount + amount;
TriggerOnStatusChanged();
return amount;
}
public void TickStatuses() {
if (this.statuses.Count > 0) {
Dictionary<BattleStatus, int> newStatuses = new Dictionary<BattleStatus, int>();
foreach (KeyValuePair<BattleStatus, int> pair in this.statuses) {
if (pair.Value >= 1) {
if (pair.Value > 1) {
newStatuses[pair.Key] = pair.Value - 1;
}
}
this.statuses = newStatuses;
TriggerOnStatusChanged();
}
}
public void WipeStatus() {
if (this.statuses.Count > 0) {
this.statuses = new Dictionary<BattleStatus, int>();
TriggerOnStatusChanged();
}
}
public bool CanUseCard(BaseCard card) {
@ -122,4 +139,18 @@ public class BattleParticipant
public bool HasStatus(BattleStatus status) {
return this.statuses.ContainsKey(status);
}
public int GetStatusAmount(BattleStatus status) {
if (!this.statuses.ContainsKey(status)) {
return 0;
} else {
return this.statuses[status];
}
}
private void TriggerOnStatusChanged() {
if (this.OnStatusChanged != null) {
this.OnStatusChanged(this);
}
}
}

View file

@ -11,6 +11,8 @@ public class GolemChargeMCard : MonsterCard
}
public override IEnumerator Use(IBattleEffectApplier effectApplier, MonsterViewpoint monsterViewpoint) {
yield return new WaitForSeconds(0.5f);
BattleParticipant target = AIUtils.GetFarthestHero(monsterViewpoint, this.owner);
DealDamageEffect damageEffect = new DealDamageEffect(target, 4);
effectApplier.Apply(damageEffect);

View file

@ -10,11 +10,11 @@ public class GraniteDefenseMCard : MonsterCard
}
public override IEnumerator Use(IBattleEffectApplier effectApplier, MonsterViewpoint monsterViewpoint) {
yield return new WaitForSeconds(1f);
yield return new WaitForSeconds(0.6f);
foreach (BattleMonster monster in monsterViewpoint.Monsters) {
if (monster != this.owner) {
effectApplier.Apply(new BlockEffect(monster, 5));
yield return new WaitForSeconds(1f);
yield return new WaitForSeconds(0.3f);
}
}
}

View file

@ -34,8 +34,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -36, y: 0}
m_SizeDelta: {x: 17, y: 14.8}
m_AnchoredPosition: {x: -36, y: 0.40002}
m_SizeDelta: {x: 17, y: 16.915695}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7203125139980703040
CanvasRenderer:
@ -66,8 +66,8 @@ MonoBehaviour:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 12
m_FontStyle: 0
m_FontSize: 14
m_FontStyle: 1
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
@ -78,6 +78,154 @@ MonoBehaviour:
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 56
--- !u!1 &3426763279947371280
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2365314723301749520}
- component: {fileID: 2687845506595039125}
- component: {fileID: 7861691439794345590}
m_Layer: 5
m_Name: BG
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2365314723301749520
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3426763279947371280}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 5364248411365301727}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -53.76, y: 60.32}
m_SizeDelta: {x: 16.523172, y: 17.074677}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2687845506595039125
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3426763279947371280}
m_CullTransparentMesh: 0
--- !u!114 &7861691439794345590
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3426763279947371280}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 0.30588236}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: ff1a435c8e6ef4a46aeb34ba613ce13d, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 0
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &3730468488252910637
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7872829101071880504}
- component: {fileID: 7145260895785022369}
- component: {fileID: 1306121800800203574}
m_Layer: 5
m_Name: StunIcon
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &7872829101071880504
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3730468488252910637}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 5364248411365301727}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -53.76, y: 60.32}
m_SizeDelta: {x: 16.522865, y: 17.07425}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7145260895785022369
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3730468488252910637}
m_CullTransparentMesh: 0
--- !u!114 &1306121800800203574
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3730468488252910637}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 0.9715784, b: 0.3160377, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: dc422435e5172774ca9ddc33364d1a6f, type: 3}
m_Type: 0
m_PreserveAspect: 1
m_FillCenter: 1
m_FillMethod: 0
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &5172729878808660606
GameObject:
m_ObjectHideFlags: 0
@ -193,6 +341,60 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 60}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &5356782115194992290
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5364248411365301727}
- component: {fileID: 2488458570692802998}
m_Layer: 5
m_Name: StatusMarkers
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &5364248411365301727
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5356782115194992290}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2365314723301749520}
- {fileID: 7872829101071880504}
- {fileID: 501555061161187130}
m_Father: {fileID: 6071241564507600362}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2488458570692802998
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5356782115194992290}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d86314823afd5c34396777dcb49e6093, type: 3}
m_Name:
m_EditorClassIdentifier:
backgroundImage: {fileID: 7861691439794345590}
stunImage: {fileID: 1306121800800203574}
turnsText: {fileID: 2986296803404415245}
--- !u!1 &5574000899179897583
GameObject:
m_ObjectHideFlags: 0
@ -227,8 +429,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -36, y: 0}
m_SizeDelta: {x: 17, y: 12}
m_AnchoredPosition: {x: -36, y: 0.4}
m_SizeDelta: {x: 17, y: 16.91568}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &8600655002061634105
CanvasRenderer:
@ -542,7 +744,7 @@ GameObject:
- component: {fileID: 6071241564507600362}
- component: {fileID: 6641511084601005557}
m_Layer: 5
m_Name: HeroUI
m_Name: BattleParticipantUI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -562,6 +764,7 @@ RectTransform:
- {fileID: 6071241564363553667}
- {fileID: 6071241564411437881}
- {fileID: 1054158240845704231}
- {fileID: 5364248411365301727}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -588,3 +791,82 @@ MonoBehaviour:
hpText: {fileID: 2548384344736816241}
blockGroup: {fileID: 5194869534592792291}
blockText: {fileID: 1400733402613879005}
statusUI: {fileID: 2488458570692802998}
--- !u!1 &7709810175605034872
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 501555061161187130}
- component: {fileID: 2941542102252663832}
- component: {fileID: 2986296803404415245}
m_Layer: 5
m_Name: TurnsText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &501555061161187130
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7709810175605034872}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 5364248411365301727}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -61.9, y: 69.1}
m_SizeDelta: {x: 13, y: 13}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2941542102252663832
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7709810175605034872}
m_CullTransparentMesh: 0
--- !u!114 &2986296803404415245
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7709810175605034872}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.8490566, g: 0.8490566, b: 0.8490566, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 10
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 1

View file

@ -13,6 +13,7 @@ public class HeroInfoUI : MonoBehaviour
public Text hpText;
public GameObject blockGroup;
public Text blockText;
public StatusUI statusUI;
private int renderedHP = -1;
private int renderedMaxHP = -1;
@ -26,6 +27,8 @@ public class HeroInfoUI : MonoBehaviour
public void Init(GameObject sprite, BattleParticipant battleParticipant) {
this.target = sprite;
this.battleParticipant = battleParticipant;
this.statusUI.Init(battleParticipant);
}
// Start is called before the first frame update

View file

@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class StatusUI : MonoBehaviour
{
public Image backgroundImage;
public Image stunImage;
public Text turnsText;
private BattleParticipant battleParticipant;
public void Init(BattleParticipant battleParticipant) {
this.battleParticipant = battleParticipant;
this.battleParticipant.OnStatusChanged += this.NotifyBattleStatusChanged;
}
// Start is called before the first frame update
void Start()
{
UpdateAppearance();
}
public void NotifyBattleStatusChanged(BattleParticipant updatedParticipant) {
if (updatedParticipant != this.battleParticipant) {
throw new System.InvalidOperationException(
"NotifyBattleStatusChanged was notified about a different participant.");
}
UpdateAppearance();
}
private void UpdateAppearance() {
int statusCount = 0;
if (battleParticipant.HasStatus(BattleStatus.Stun)) {
statusCount++;
this.stunImage.enabled = true;
this.turnsText.enabled = true;
this.turnsText.text = "" + battleParticipant.GetStatusAmount(BattleStatus.Stun);
} else {
this.stunImage.enabled = false;
this.turnsText.enabled = false;
}
this.backgroundImage.enabled = (statusCount > 0);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d86314823afd5c34396777dcb49e6093
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

View file

@ -0,0 +1,92 @@
fileFormatVersion: 2
guid: dc422435e5172774ca9ddc33364d1a6f
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -3,4 +3,3 @@
- Make hero cards be used in sequence Coroutines, not in parallel
- Do not Highlight unusable cards
- Dim unusable cards
- Add stun marker