private void ChangeChargeMode(bool scrollUp) { index = GetChargeModeIndex(); if (scrollUp) { index--; } else { index++; } index = Utilities.Clamp(index, 1, 3); if (index == 1) { battery.ChargeMode = ChargeMode.Auto; } else if (index == 2) { battery.ChargeMode = ChargeMode.Discharge; } else if (index == 3) { battery.ChargeMode = ChargeMode.Recharge; } }
private void OnSubmit(float percent) { OnUpdateAction((float)Math.Round(Utilities.Clamp(min + (range * percent), min, max), rounding)); Element.InitialPercent = GetCurrentValue(); Element.Text = Name; start = GetCurrentValue(); }
/// <summary> /// Updates scrollable index, range of visible scrollables and input for selected property. /// </summary> private void UpdateSelection() { int scrolllDir = GetScrollDir(), action = index - target.Properties.Count; if (Binds.select.IsNewPressed) { if (index >= target.Properties.Count) { target.Actions[action].Action(); } else { selection = (selection == -1) ? index : -1; } } if (selection != -1 && index < target.Properties.Count) { if (scrolllDir > 0) { target.Properties[index].ScrollUp(); } else if (scrolllDir < 0) { target.Properties[index].ScrollDown(); } } else { index -= scrolllDir; index = Utilities.Clamp(index, 0, target.ScrollableCount - 1); } }
/// <summary> /// Updates text colors and resets alive time for fallback hud. /// </summary> private void UpdateText() { int elements = Utilities.Clamp(visEnd - visStart, 0, Cfg.maxVisible), i, action; header.Show(); header.ResetAliveTime(); header.Text = $"{headerText} ({visStart + 1} - {visEnd} of {target.ScrollableCount})"; for (int notif = 0; notif < elements; notif++) { if (list[notif] == null) { list[notif] = MyAPIGateway.Utilities.CreateNotification(""); } i = notif + visStart; action = i - target.Properties.Count; // make sure its still being shown list[notif].Show(); list[notif].ResetAliveTime(); // get name if (i >= target.Properties.Count) { list[notif].Text = target.Actions[action].GetDisplay(); } else { list[notif].Text = target.Properties[i].GetDisplay(); } // get color if (i == selection) { list[notif].Font = MyFontEnum.Green; } else if (i == index) { list[notif].Font = MyFontEnum.Red; } else { list[notif].Font = MyFontEnum.White; } } // hide everything else for (int n = elements; n < list.Length; n++) { if (list[n] == null) { list[n] = MyAPIGateway.Utilities.CreateNotification(""); } list[n].Text = ""; list[n].Hide(); } }
/// <summary> /// Gets finished string for the Text HUD API to display. /// </summary> private void UpdateText() { int elements = Utilities.Clamp(visEnd - visStart, 0, Cfg.maxVisible), i, action; StringBuilder[] list = new StringBuilder[elements]; string colorCode; menu.HeaderText = new StringBuilder($"<color={Cfg.colors.headerText}>{headerText}"); for (int n = 0; n < elements; n++) { i = n + visStart; action = i - target.Properties.Count; if (i == selection) { colorCode = $"<color={Cfg.colors.selectedText}>"; } else if (i == index) { colorCode = $"<color={Cfg.colors.highlightText}>"; } else { colorCode = $"<color={Cfg.colors.bodyText}>"; } if (i >= target.Properties.Count) { list[n] = new StringBuilder(colorCode + target.Actions[action].GetDisplay()); } else { list[n] = new StringBuilder( $"<color={Cfg.colors.bodyText}>{target.Properties[i].GetName()}: {colorCode}{target.Properties[i].GetValue()}"); } } menu.ListText = list; menu.FooterLeftText = new StringBuilder( $"<color={Cfg.colors.headerText}>[{visStart + 1} - {visEnd} of {target.ScrollableCount}]"); if (target.IsWorking) { menu.FooterRightText = new StringBuilder( $"<color={Cfg.colors.headerText}>[Working]"); } else if (target.IsFunctional) { menu.FooterRightText = new StringBuilder( $"<color={Cfg.colors.headerText}>[Functional]"); } else { menu.FooterRightText = new StringBuilder( $"<color={Cfg.colors.blockIncText}>[Incomplete]"); } }
/// <summary> /// Changes property float value based on given delta. /// </summary> private void ChangePropValue(float delta) { float current = prop.GetValue(pBlock.TBlock); if (float.IsInfinity(current)) { current = 0f; } prop.SetValue(pBlock.TBlock, (float)Math.Round(Utilities.Clamp((current + delta), minValue, maxValue), 3)); }
/// <summary> /// Changes property color value based on given color delta. /// </summary> private void ChangePropValue(bool increment) { Color curr = property.GetValue(pBlock.TBlock); int r = curr.R, g = curr.G, b = curr.B, sign = increment ? 1 : -1, mult = GetIncrement(); r += (sign * mult * delta.R); g += (sign * mult * delta.G); b += (sign * mult * delta.B); curr.R = (byte)Utilities.Clamp(r, minValue, maxValue); curr.G = (byte)Utilities.Clamp(g, minValue, maxValue); curr.B = (byte)Utilities.Clamp(b, minValue, maxValue); property.SetValue(pBlock.TBlock, curr); }
/// <summary> /// Determines what range of the block's properties are visible based on index and total number of properties. /// </summary> protected virtual void GetVisibleProperties() { if (target.ScrollableCount <= maxVisible) { visEnd = target.ScrollableCount; } else { if (index >= (visStart + maxVisible)) { visStart++; } else if (index < visStart) { visStart = index; } visEnd = Utilities.Clamp((visStart + maxVisible), 0, target.ScrollableCount); visStart = Utilities.Clamp(visEnd - maxVisible, 0, visEnd); } }
/// <summary> /// Updates position of menu on screen. /// </summary> private void UpdatePos() { Vector3D targetPos, worldPos; Vector2D screenPos, screenBounds; if (!Cfg.forceToCenter) { if (LocalPlayer.IsLookingInBlockDir(target.TBlock)) { targetPos = target.GetPosition(); worldPos = LocalPlayer.GetWorldToScreenPos(targetPos); screenPos = new Vector2D(worldPos.X, worldPos.Y); screenBounds = new Vector2D(1d, 1d) - menu.Size / 2; if (Cfg.clampHudPos) { screenPos.X = Utilities.Clamp(screenPos.X, -screenBounds.X, screenBounds.X); screenPos.Y = Utilities.Clamp(screenPos.Y, -screenBounds.Y, screenBounds.Y); } } else if (Cfg.hideIfNotVis) { menu.Visible = false; screenPos = Vector2D.Zero; } else { screenPos = Vector2D.Zero; } } else { screenPos = Vector2D.Zero; } menu.ScaledPos = screenPos; menu.SelectionIndex = index - visStart; }
private object GetSliderValue(float percent) { OnUpdateAction((float)Math.Round(Utilities.Clamp(min + (range * percent), min, max), rounding)); return($"{Math.Round(min + range * percent, rounding)}"); }
private void OnCancel() { OnUpdateAction((float)Math.Round(Utilities.Clamp(min + (range * start), min, max), rounding)); Element.InitialPercent = start; Element.Text = Name; }