Exemple #1
0
        private static void UpdateXPBar(Hud __instance)
        {
            Player localPlayer = Player.m_localPlayer;

            if (!Main.showCharacterXP.Value)
            {
                return;
            }
            if (_player == null && localPlayer != null)
            {
                _player = localPlayer;
                Patches.XP.Awake(localPlayer);
                _bar.SetValue(Patches.XP.GetLevelPercentage());
            }

            // For XP Bar Debug

            /*
             * if (_bar != null)
             * {
             *
             * if (_bar.m_value >= 1f) _bar.m_value = 0f;
             * _bar.SetValue(_bar.m_value + 0.001f);
             * }
             */
        }
Exemple #2
0
 public static void Update(float max, float stamina)
 {
     try
     {
         staminaBarFast.SetValue(stamina / max);
         staminaBarSlow.SetValue(stamina / max);
         staminaText.text = $"{Mathf.CeilToInt(stamina)}/{Mathf.CeilToInt(max)}";
     }
     catch (Exception e)
     {
         Debug.LogError($"StaminaBar.Update() {e.Message}");
     }
 }
Exemple #3
0
 public static void Update(float max, float hp)
 {
     try
     {
         healthBarFast.SetMaxValue(max);
         healthBarFast.SetValue(hp);
         healthBarSlow.SetMaxValue(max);
         healthBarSlow.SetValue(hp);
         healthText.text = $"{Mathf.CeilToInt(hp)}/{Mathf.CeilToInt(max)}";
     }
     catch (Exception e)
     {
         Debug.LogError($"HealthBar.Update() {e.Message}");
     }
 }
Exemple #4
0
        public static GuiBar Awake(Hud __instance)
        {
            Transform hudroot = Utils.FindChild(__instance.gameObject.transform, "hudroot");
            GuiBar    xp_bar  = UnityEngine.Object.Instantiate(Hud.instance.m_stealthBar, hudroot, true);

            xp_bar.m_barImage    = Hud.instance.m_stealthBar.m_bar.GetComponent <Image>();
            xp_bar.m_smoothFill  = smoothFill;
            xp_bar.m_smoothDrain = smoothDrain;
            xp_bar.m_smoothSpeed = smoothSpeed;
            xp_bar.Awake();

            xp_bar.name            = "BU_XP_BAR";
            xp_bar.m_originalColor = barColor;
            xp_bar.ResetColor();

            xp_bar.SetMaxValue(maxValue);
            xp_bar.SetValue(0f);

            RectTransform xpRect = (xp_bar.transform as RectTransform);

            xpRect.anchorMin        = Vector2.zero;
            xpRect.anchorMax        = new Vector2(1f, 0f);
            xpRect.anchoredPosition = Vector2.zero;

            xpRect.offsetMin = Vector2.zero;
            xpRect.offsetMax = Vector2.zero;
            xpRect.sizeDelta = new Vector2(0f, 5f);

            xp_bar.m_bar.anchorMin = Vector2.zero;
            xp_bar.m_bar.anchorMax = new Vector2(1f, 0.5f);
            xp_bar.m_bar.offsetMin = Vector2.zero;
            xp_bar.m_bar.offsetMax = Vector2.zero;

            xp_bar.m_bar.sizeDelta = new Vector2(xpRect.rect.width, 5f);
            // Render the XP Bar
            xp_bar.gameObject.SetActive(true);
            _xp_bar = xp_bar;

            return(xp_bar);
        }
Exemple #5
0
        private static void Update(Hud __instance)
        {
            Player localPlayer = Player.m_localPlayer;

            if (Main.showCharacterXP.Value && _player == null && localPlayer != null)
            {
                _player = localPlayer;
                XP.Awake(localPlayer);
                _bar.SetValue(XP.GetLevelPercentage());
            }

            if (!useCustomHud || localPlayer == null)
            {
                return;
            }

            if (Input.GetKeyDown(Main.toggleEditMode.Value))
            {
                isEditing = !isEditing;
                CustomHud.ShowTemplates(isEditing, activeLayer);
                Player.m_localPlayer.Message(MessageHud.MessageType.Center, $"HUD editing is turned {(isEditing ? "ON" : $"OFF")}");
            }
            if (!isEditing)
            {
                return;
            }
            else if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                activeLayer = activeLayer == CustomHud.roots.Count ? 0 : activeLayer + 1;
                Helpers.DebugLine($"Layer changed to: {(Groups)activeLayer}");
                CustomHud.ShowTemplates(isEditing, activeLayer);
                Player.m_localPlayer.Message(MessageHud.MessageType.Center, $"Now editing: {(Groups)activeLayer}");
            }
            float gameScale = GameObject.Find("GUI").GetComponent <CanvasScaler>().scaleFactor;

            Vector3 mousePos  = Input.mousePosition;                // Select element / move element
            float   scrollPos = Input.GetAxis("Mouse ScrollWheel"); // Change scale

            // Could maybe rremove this
            if (!useCustomHud)
            {
                lastMousePos = mousePos;
                return;
            }
            if (lastMousePos == Vector3.zero)
            {
                lastMousePos = mousePos;
            }
            if (lastScrollPos == 0f)
            {
                lastScrollPos = scrollPos;
            }

            // Could we have this list as global? And only update it every render, no need to re-create?
            List <KeyValuePair <string, RectTransform> > rectList = new List <KeyValuePair <string, RectTransform> >();

            // Check every element, if found add to rectList that is then later scanned if mouse is on them.
            // Could we use groups, and then toggle between groups. Ex. activeGroup param.
            foreach (HudElement e in CustomHud.elements)
            {
                try
                {
                    // Get elements only from active layer.
                    RectTransform rt = CustomHud.LocateTemplateRect(e.group, e.name); // Will get every template from different layers..
                    // Add only rects from active layer
                    if (rt && e.group == (Groups)activeLayer)
                    {
                        rectList.Add(new KeyValuePair <string, RectTransform>(e.name, rt));
                    }
                }
                catch
                {
                    Helpers.DebugLine($"Issues while locating UI templates. Your uiData might be corrupted.\nIssue on: {e.name} ({e.displayName})");
                }
            }

            if (Helpers.CheckHeldKey(Main.modKeyPrimary.Value) && rectList.Count > 0)
            {
                if (currentlyDragging != "")
                {
                    var item = rectList.Find(e => e.Key == currentlyDragging);
                    if (item.Key == currentlyDragging)
                    {
                        if (Helpers.CheckHeldKey(Main.modKeySecondary.Value))
                        {
                            CustomHud.UpdateDimensions(item.Key, scrollPos);
                        }
                        else
                        {
                            CustomHud.UpdatePosition(item.Key, (mousePos - lastMousePos) / gameScale, scrollPos);
                        }
                    }
                }
                else
                {
                    foreach (var item in rectList)
                    {
                        if (RectTransformUtility.RectangleContainsScreenPoint(item.Value, mousePos))
                        {
                            CustomHud.UpdatePosition(item.Key, (mousePos - lastMousePos) / gameScale, scrollPos);
                            currentlyDragging = item.Key;
                            break;
                        }
                    }
                }
            }
            else
            {
                currentlyDragging = "";
            }

            lastMousePos  = mousePos;
            lastScrollPos = scrollPos;

            // For XP Bar Debug

            /*
             * if (_bar != null)
             * {
             *
             * if (_bar.m_value >= 1f) _bar.m_value = 0f;
             * _bar.SetValue(_bar.m_value + 0.001f);
             * }
             */
        }