Skip to content

Commit

Permalink
Improved GUIs (#663)
Browse files Browse the repository at this point in the history
* Add feedback on player hud when jumping

* Fix issue where health percentage could be 0% due to rounding error

* Fix correct ready color after network players join host lobby

* Add user names to bidding platforms 

- (Also made them slightly wider)

* Fix #516
  • Loading branch information
Fueredoriku committed May 31, 2024
1 parent 749f3a7 commit 4d081e6
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 100 deletions.
1 change: 1 addition & 0 deletions Assets/Prefabs/Input/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
hud: {fileID: 3570743071879246586}
hudParent: {fileID: 5051670465698078307}
healthBar: {fileID: 8325376438412411157}
healthText: {fileID: 6360493330995005632}
healthMax: {r: 0.4571684, g: 0.9607843, b: 0.23921566, a: 1}
Expand Down
100 changes: 9 additions & 91 deletions Assets/Prefabs/Item Platform.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: LEADING BID
m_text: STARTING BID
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: aa99fff0688574ba78204625170fa6e0, type: 2}
m_sharedMaterial: {fileID: 7168929159514863053, guid: aa99fff0688574ba78204625170fa6e0, type: 2}
Expand Down Expand Up @@ -374,7 +374,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 53.8, y: -61.1}
m_AnchoredPosition: {x: 70, y: -61.1}
m_SizeDelta: {x: 65, y: 65}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &5825703025208661481
Expand Down Expand Up @@ -770,7 +770,6 @@ RectTransform:
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 6968452648127290458}
- {fileID: 3899621017521807042}
m_Father: {fileID: 6968452648790667550}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -1301,7 +1300,7 @@ RectTransform:
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_ConstrainProportionsScale: 1
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6968452647022882779}
m_Father: {fileID: 6968452648790667550}
Expand Down Expand Up @@ -1399,7 +1398,7 @@ RectTransform:
m_GameObject: {fileID: 6968452648316269152}
m_LocalRotation: {x: 0.7071068, y: -0.7071068, z: 0, w: 0}
m_LocalPosition: {x: 0, y: 0, z: 0.0001}
m_LocalScale: {x: 0.0005, y: 0.0005, z: 0.0005}
m_LocalScale: {x: 0.0004, y: 0.0005, z: 0.0005}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6968452647793446167}
Expand All @@ -1410,7 +1409,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: -0.00022300007, y: -0.000143}
m_SizeDelta: {x: 107.62216, y: 207.24443}
m_SizeDelta: {x: 142.2, y: 207.24443}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!223 &6968452648316269157
Canvas:
Expand Down Expand Up @@ -1664,8 +1663,8 @@ Transform:
m_GameObject: {fileID: 7762653921494732740}
m_LocalRotation: {x: -0.5, y: 0.5, z: 0.5, w: 0.5}
m_LocalPosition: {x: -6, y: -0.5, z: -1.55}
m_LocalScale: {x: 100, y: 100, z: 100}
m_ConstrainProportionsScale: 1
m_LocalScale: {x: 100, y: 120, z: 100}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1026795433267283404}
- {fileID: 6968452648316269153}
Expand All @@ -1689,8 +1688,9 @@ MonoBehaviour:
syncInterval: 0
item: {fileID: 0}
chips: 0
leadingBidder: {fileID: 0}
leadingBidder: 255
audioSource: {fileID: 2218216803175393329}
leadingBidText: {fileID: 1590617989931081979}
itemNameText: {fileID: 6968452647816228154}
itemDescriptionText: {fileID: 6968452647022882780}
itemCostText: {fileID: 6968452648127290460}
Expand Down Expand Up @@ -1936,85 +1936,3 @@ MonoBehaviour:
serverOnly: 0
visibility: 0
hasSpawned: 0
--- !u!1001 &3597755679751034970
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 6968452647381300963}
m_Modifications:
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_RootOrder
value: 5
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalScale.x
value: 805.6
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalScale.y
value: 805.6
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalScale.z
value: 805.6
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalPosition.x
value: 24.8
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_ConstrainProportionsScale
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1652744153996658575, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
propertyPath: m_Name
value: Chip
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
--- !u!4 &3899621017521807042 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 573073282140243608, guid: 07a746de7e3746f4d890544bb6e655b4, type: 3}
m_PrefabInstance: {fileID: 3597755679751034970}
m_PrefabAsset: {fileID: 0}
8 changes: 6 additions & 2 deletions Assets/Scripts/Auction/BiddingPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class BiddingPlatform : NetworkBehaviour
[SerializeField]
private AudioSource audioSource;

[SerializeField]
private TMP_Text leadingBidText;

[SerializeField]
private TMP_Text itemNameText;

Expand Down Expand Up @@ -193,7 +196,8 @@ private void RpcAcceptBid(uint playerID)

chips++;
playerIdentity.UpdateChip(-chips);
itemCostText.text = chips.ToString();
itemCostText.text = chips.ToString() + "<sprite name=\"chip\">";
leadingBidText.text = playerIdentity.playerName.ToUpper()+":";
LeanTween.value(
gameObject,
(color) => material.SetColor("_BidderColor", color),
Expand Down Expand Up @@ -275,7 +279,7 @@ private void RpcSetItem(string itemID)
this.item = item;
itemNameText.text = item.displayName;
itemDescriptionText.text = item.displayDescription;
itemCostText.text = chips.ToString();
itemCostText.text = chips.ToString() + "<sprite name=\"chip\">";
switch (item.augmentType)
{
case AugmentType.Body:
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/Control&Input/PlayerInputManagerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void Awake()
#endregion Singleton boilerplate
PlayerInputManager = PlayerInputManager.instance;
DontDestroyOnLoad(gameObject);
Cursor.visible = false;
}

public void RemoveJoinListener()
Expand Down Expand Up @@ -81,6 +82,7 @@ private void OnPlayerJoined(PlayerInput playerInput)
inputManager.PlayerCamera.enabled = false;
LocalPlayerInputs.Add(inputManager);
onPlayerInputJoined?.Invoke(inputManager);
// TODO: Make cursor visible if mouseandkeyboard input joims when our buttons can be clicked by a mouse..

if (NetworkManager.singleton.isNetworkActive)
NetworkClient.Send(new PlayerConnectedMessage(LocalPlayerInputs.Count - 1));
Expand Down
6 changes: 4 additions & 2 deletions Assets/Scripts/Control&Input/PlayerMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public class PlayerMovement : MonoBehaviour
public Vector2 AimAngle => aimAngle;

public delegate void MovementEventBody(Rigidbody body);
public MovementEventBody onMove;
public MovementEventBody OnMove;
public MovementEventBody OnJumpPerformed;

private int gunCrouchPerformedTween;
private int cameraCrouchPerformedTween;
Expand Down Expand Up @@ -236,6 +237,7 @@ private void OnJump(InputAction.CallbackContext ctx)
break;
}
}
OnJumpPerformed?.Invoke(body);
}

private void OnZoom(InputAction.CallbackContext ctx)
Expand Down Expand Up @@ -531,7 +533,7 @@ private void Update()
{
UpdateRotation();
UpdateAnimatorParameters();
onMove?.Invoke(body);
OnMove?.Invoke(body);
}

private void OnDestroy()
Expand Down
14 changes: 11 additions & 3 deletions Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ public void SetPlayerInput(InputManager playerInput)
var playerMovement = GetComponent<PlayerMovement>();
playerMovement.enabled = true;
playerMovement.SetPlayerInput(inputManager);
playerMovement.onMove += UpdateHudOnMove;
playerMovement.OnMove += UpdateHudOnMove;
playerMovement.OnJumpPerformed += UpdateHudOnJump;
// Subscribe relevant input events
inputManager.onFirePerformed += Fire;
inputManager.onFireCanceled += FireEnd;
Expand All @@ -246,7 +247,7 @@ public void SetPlayerInput(InputManager playerInput)
{
var canvas = hudController.GetComponent<Canvas>();
canvas.worldCamera = inputManager.GetComponentInChildren<Camera>();
canvas.planeDistance = 0.11f;
canvas.planeDistance = 0.21f;
identity.onChipChange += hudController.OnChipChange;
}

Expand Down Expand Up @@ -285,7 +286,8 @@ void OnDestroy()
}
if (TryGetComponent(out PlayerMovement playerMovement))
{
playerMovement.onMove -= UpdateHudOnMove;
playerMovement.OnMove -= UpdateHudOnMove;
playerMovement.OnJumpPerformed -= UpdateHudOnJump;
}
if (hudController)
identity.onChipChange -= hudController.OnChipChange;
Expand Down Expand Up @@ -342,6 +344,12 @@ private void UpdateHudOnMove(Rigidbody body)
hudController.SetSpeedLines(body.velocity);
}

private void UpdateHudOnJump(Rigidbody body)
{
if (hudController)
hudController.AnimateHudJump();
}

private void UpdateHudFire(GunStats stats)
{
// stats variables must be dereferenced
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/UI/ClientLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ private void AddPlayer(PlayerDetails details)
{
playerSelect.UpdateLobby();
}

private void OnDestroy()
{
((Peer2PeerTransport)NetworkManager.singleton).OnPlayerRecieved -= AddPlayer;
}
}
16 changes: 15 additions & 1 deletion Assets/Scripts/UI/MainMenu/MainMenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ private void Start()
playerInputManagerController.AddJoinListener();
playerInputManagerController.PlayerInputManager.splitScreen = false;
playerInputManagerController.onPlayerInputJoined += AddPlayer;
if (SceneManager.GetActiveScene().name == "Menu")
((Peer2PeerTransport)NetworkManager.singleton).OnPlayerRecieved += UpdateStartButton;
if (playerInputManagerController.LocalPlayerInputs.Count > 0)
{
// Already played, just show the menu.
Expand Down Expand Up @@ -171,6 +173,8 @@ private void OnDestroy()
{
playerInputManagerController.onPlayerInputJoined -= AddPlayer;
playerInputManagerController.onPlayerInputJoined -= ShowSkipText;
if (SceneManager.GetActiveScene().name == "Menu")
((Peer2PeerTransport)NetworkManager.singleton).OnPlayerRecieved -= UpdateStartButton;
}

/// <summary>
Expand Down Expand Up @@ -305,7 +309,17 @@ public void ToggleAI()
aIButton.Toggle();
SelectControl(aIButton.Button);
playerInputManagerController.MatchHasAI = !playerInputManagerController.MatchHasAI;
bool canPlay = (playerInputManagerController.MatchHasAI || playerInputs.Count > 1);
SetStartButtonState();
}

public void UpdateStartButton(PlayerDetails details)
{
SetStartButtonState();
}

private void SetStartButtonState()
{
bool canPlay = (playerInputManagerController.MatchHasAI || Peer2PeerTransport.NumPlayers > 1);
var colors = startButton.colors;
colors.normalColor = canPlay ? colors.highlightedColor : colors.disabledColor;
startButton.colors = colors;
Expand Down
20 changes: 19 additions & 1 deletion Assets/Scripts/UI/PlayerHUDController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class PlayerHUDController : MonoBehaviour
private RectTransform hud;

[Header("Health and ammo")]
[SerializeField]
private RectTransform hudParent;
private float? hudParentLocalY;
private int hudParentJumpTween;

[SerializeField]
private SpriteRenderer healthBar;
Expand Down Expand Up @@ -163,6 +167,20 @@ public void SetSpeedLines(Vector3 velocity)
oldLargeVelocity = magnitude;
}

public void AnimateHudJump()
{
if (!hudParentLocalY.HasValue)
hudParentLocalY = hudParent.localPosition.y;
if (LeanTween.isTweening(hudParentJumpTween))
{
LeanTween.cancel(hudParentJumpTween);
hudParent.localPosition = new Vector3 (hudParent.localPosition.x, hudParentLocalY.Value, hudParent.localPosition.z);
}
hudParentJumpTween = hudParent.LeanMoveLocalY(hudParent.localPosition.y - 10f, 1.3f)
.setEasePunch()
.id;
}

public void OnDamageTaken(float damage, float currentHealth, float maxHealth)
{
UpdateHealthBar(currentHealth, maxHealth);
Expand Down Expand Up @@ -214,7 +232,7 @@ public void UpdateOnReload(float ammoPercent)

private void UpdateHealthBar(float currentHealth, float maxHealth)
{
healthText.text = $"{Mathf.Clamp(Mathf.RoundToInt(currentHealth), 0, 100)}%";
healthText.text = $"{Mathf.Clamp(Mathf.CeilToInt(currentHealth), 0, 100)}%";
if (LeanTween.isTweening(healthTextTween))
{
LeanTween.cancel(healthTextTween);
Expand Down

0 comments on commit 4d081e6

Please sign in to comment.