public void SetFriendHud(PlayerList someConnectedPlayers) { if (!isLocalPlayer) { return; } myFriendList.Clear(); foreach (Transform child in myFriendList.gameObject.transform) { CmdUnsubscribe(child.gameObject); Destroy(child.gameObject); } for (int index = 0; index < someConnectedPlayers.Count; index++) { if (someConnectedPlayers[index].netId == myCharacter.GetComponent <NetworkIdentity>().netId) { continue; } GameObject player = ClientScene.FindLocalObject(someConnectedPlayers[index].netId); GameObject friend = Instantiate(myFriendList.myFriendlistHudPrefab, myFriendList.transform); friend.GetComponent <FriendHud>().SetCharacter(player); friend.GetComponent <FriendHud>().SetParent(myCharacter.GetComponent <PlayerCharacter>()); PlayerCharacter playerCharacter = player.GetComponent <PlayerCharacter>(); CharacterHUD hud = friend.GetComponent <CharacterHUD>(); hud.SetName(playerCharacter.Name); hud.SetHealthBarFillAmount(player.GetComponent <Health>().GetHealthPercentage()); myFriendList.AddHud(hud, someConnectedPlayers[index].netId, myCharacter.GetComponent <PlayerCharacter>().Name); CmdSubscribe(player); } }
private void DrawCharacterInfo(SpriteBatch spriteBatch, Character target, float alpha = 1.0f) { Vector2 hudPos = GameMain.GameScreen.Cam.WorldToScreen(target.DrawPosition); hudPos += Vector2.UnitX * 50.0f; List<string> texts = new List<string>(); List<Color> textColors = new List<Color>(); texts.Add(target.Info == null ? target.DisplayName : target.Info.DisplayName); textColors.Add(GUI.Style.TextColor); if (target.IsDead) { texts.Add(TextManager.Get("Deceased")); textColors.Add(GUI.Style.Red); if (target.CauseOfDeath != null) { texts.Add( target.CauseOfDeath.Affliction?.CauseOfDeathDescription ?? TextManager.AddPunctuation(':', TextManager.Get("CauseOfDeath"), TextManager.Get("CauseOfDeath." + target.CauseOfDeath.Type.ToString()))); textColors.Add(GUI.Style.Red); } } else { if (!string.IsNullOrEmpty(target.customInteractHUDText) && target.AllowCustomInteract) { texts.Add(target.customInteractHUDText); textColors.Add(GUI.Style.Green); } if (!target.IsIncapacitated && target.IsPet) { texts.Add(CharacterHUD.GetCachedHudText("PlayHint", GameMain.Config.KeyBindText(InputType.Use))); textColors.Add(GUI.Style.Green); } if (target.CharacterHealth.UseHealthWindow && equipper?.FocusedCharacter == target && equipper.CanInteractWith(target, 160f, false)) { texts.Add(CharacterHUD.GetCachedHudText("HealHint", GameMain.Config.KeyBindText(InputType.Health))); textColors.Add(GUI.Style.Green); } if (target.CanBeDragged) { texts.Add(CharacterHUD.GetCachedHudText("GrabHint", GameMain.Config.KeyBindText(InputType.Grab))); textColors.Add(GUI.Style.Green); } if (target.IsUnconscious) { texts.Add(TextManager.Get("Unconscious")); textColors.Add(GUI.Style.Orange); } if (target.Stun > 0.01f) { texts.Add(TextManager.Get("Stunned")); textColors.Add(GUI.Style.Orange); } int oxygenTextIndex = MathHelper.Clamp((int)Math.Floor((1.0f - (target.Oxygen / 100.0f)) * OxygenTexts.Length), 0, OxygenTexts.Length - 1); texts.Add(OxygenTexts[oxygenTextIndex]); textColors.Add(Color.Lerp(GUI.Style.Red, GUI.Style.Green, target.Oxygen / 100.0f)); if (target.Bleeding > 0.0f) { int bleedingTextIndex = MathHelper.Clamp((int)Math.Floor(target.Bleeding / 100.0f) * BleedingTexts.Length, 0, BleedingTexts.Length - 1); texts.Add(BleedingTexts[bleedingTextIndex]); textColors.Add(Color.Lerp(GUI.Style.Orange, GUI.Style.Red, target.Bleeding / 100.0f)); } var allAfflictions = target.CharacterHealth.GetAllAfflictions(); Dictionary<AfflictionPrefab, float> combinedAfflictionStrengths = new Dictionary<AfflictionPrefab, float>(); foreach (Affliction affliction in allAfflictions) { if (affliction.Strength < affliction.Prefab.ShowInHealthScannerThreshold || affliction.Strength <= 0.0f) continue; if (combinedAfflictionStrengths.ContainsKey(affliction.Prefab)) { combinedAfflictionStrengths[affliction.Prefab] += affliction.Strength; } else { combinedAfflictionStrengths[affliction.Prefab] = affliction.Strength; } } foreach (AfflictionPrefab affliction in combinedAfflictionStrengths.Keys) { texts.Add(TextManager.AddPunctuation(':', affliction.Name, ((int)combinedAfflictionStrengths[affliction]).ToString() + " %")); textColors.Add(Color.Lerp(GUI.Style.Orange, GUI.Style.Red, combinedAfflictionStrengths[affliction] / affliction.MaxStrength)); } } GUI.DrawString(spriteBatch, hudPos, texts[0], textColors[0] * alpha, Color.Black * 0.7f * alpha, 2, GUI.SubHeadingFont); hudPos.X += 5.0f; hudPos.Y += 24.0f; hudPos.X = (int)hudPos.X; hudPos.Y = (int)hudPos.Y; for (int i = 1; i < texts.Count; i++) { GUI.DrawString(spriteBatch, hudPos, texts[i], textColors[i] * alpha, Color.Black * 0.7f * alpha, 2, GUI.SmallFont); hudPos.Y += 18.0f; } }
public void AddHud(CharacterHUD aCharacterHud, NetworkInstanceId anID, string aName) { myCharacterHuds.Add(anID, aCharacterHud); }
public virtual void Initialize(CharacterParameterModel model) { this.characterMove = GetComponent<CharacterMove>(); this.animationController = new AnimationController(); animationController.SetAnimator(transform.FindChild("Model").GetComponent<Animator>()); hud = transform.FindChild("HUD").GetComponent<CharacterHUD>(); hud.InitHUD(); InitCharacterParam (model); canMove = true; isInitialized = true; canDrag = true; ChangeState(ActionState.Idle); }