Beispiel #1
0
        private void DrowLimitLine(Rect rect, float percent)
        {
            float num = Mathf.Round((rect.width - 8f) * percent);

            GUI.DrawTexture(new Rect
            {
                x      = rect.x + 3f + num,
                y      = rect.y,
                width  = 2f,
                height = rect.height
            }, Resources.Texture2Ds.PsyfocusTargetTex);
            float num2  = Widgets.AdjustCoordToUIScalingFloor(rect.x + 2f + num);
            float xMax  = Widgets.AdjustCoordToUIScalingCeil(num2 + 4f);
            Rect  rect2 = new Rect
            {
                y      = rect.y - 3f,
                height = 5f,
                xMin   = num2,
                xMax   = xMax
            };

            GUI.DrawTexture(rect2, Resources.Texture2Ds.PsyfocusTargetTex);
            Rect position = rect2;

            position.y = rect.yMax - 2f;
            GUI.DrawTexture(position, Resources.Texture2Ds.PsyfocusTargetTex);
        }
        private void DrawPsyfocusTarget(Rect rect, float percent)
        {
            float num      = Mathf.Round((rect.width - 8f) * percent);
            Rect  position = default(Rect);

            position.x      = rect.x + 3f + num;
            position.y      = rect.y;
            position.width  = 2f;
            position.height = rect.height;
            GUI.DrawTexture(position, PsyfocusTargetTex);
            float num2 = Widgets.AdjustCoordToUIScalingFloor(rect.x + 2f + num);
            float xMax = Widgets.AdjustCoordToUIScalingCeil(num2 + 4f);

            position        = default(Rect);
            position.y      = rect.y - 3f;
            position.height = 5f;
            position.xMin   = num2;
            position.xMax   = xMax;
            Rect rect2 = position;

            GUI.DrawTexture(rect2, PsyfocusTargetTex);
            Rect position2 = rect2;

            position2.y = rect.yMax - 2f;
            GUI.DrawTexture(position2, PsyfocusTargetTex);
        }
Beispiel #3
0
            public static void LabelFree(Rect rect, string label, GUIStyle style)
            {
                var position = rect;
                var f        = Prefs.UIScale / 2f;

                if (Prefs.UIScale > 1.0 && Math.Abs(f - Mathf.Floor(f)) > 1.40129846432482E-45)
                {
                    position.xMin = Widgets.AdjustCoordToUIScalingFloor(rect.xMin);
                    position.yMin = Widgets.AdjustCoordToUIScalingFloor(rect.yMin);
                    position.xMax = Widgets.AdjustCoordToUIScalingCeil(rect.xMax + 1E-05f);
                    position.yMax = Widgets.AdjustCoordToUIScalingCeil(rect.yMax + 1E-05f);
                }

                GUI.Label(position, label, style);
            }
        public void Draw(Rect rect)
        {
            Rect drawRect = new Rect(rect);

            drawRect.width = 30f;
            drawRect.xMax  = Widgets.AdjustCoordToUIScalingCeil(drawRect.xMax);
            Rect drawRect2 = new Rect(rect);

            drawRect2.width = 30f;
            drawRect2.x     = rect.x + rect.width - 30f;
            Rect uvRect    = new Rect(17f / 32f, 0f, 15f / 32f, 1f);
            Rect drawRect3 = new Rect(rect);

            drawRect3.x     += drawRect.width;
            drawRect3.width -= 60f;
            drawRect3.xMin   = Widgets.AdjustCoordToUIScalingFloor(drawRect3.xMin);
            drawRect3.xMax   = Widgets.AdjustCoordToUIScalingCeil(drawRect3.xMax);
            Rect uvRect2 = new Rect(30f, 0f, 4f, TabAtlas.height).ToUVRect(new Vector2(TabAtlas.width, TabAtlas.height));

            Widgets.DrawTexturePart(drawRect, new Rect(0f, 0f, 15f / 32f, 1f), TabAtlas);
            Widgets.DrawTexturePart(drawRect3, uvRect2, TabAtlas);
            Widgets.DrawTexturePart(drawRect2, uvRect, TabAtlas);
            Rect rect2 = rect;

            rect2.width -= 10f;
            if (Mouse.IsOver(rect2))
            {
                GUI.color = Color.yellow;
                rect2.x  += 2f;
                rect2.y  -= 2f;
            }
            Text.WordWrap = false;
            Widgets.Label(rect2, label);
            Text.WordWrap = true;
            GUI.color     = Color.white;
            if (!Selected)
            {
                Rect drawRect4 = new Rect(rect);
                drawRect4.y     += rect.height;
                drawRect4.y     -= 1f;
                drawRect4.height = 1f;
                Widgets.DrawTexturePart(uvRect: new Rect(0.5f, 0.01f, 0.01f, 0.01f), drawRect: drawRect4, tex: TabAtlas);
            }
        }
Beispiel #5
0
        public static bool Widgets_Label_prefix(Rect rect, string label)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(label))
            {
                return(false);
            }

            float scale = Prefs.UIScale;

            if (scale > 1f)
            {
                float num = scale / 2f;
                if (Math.Abs(num - Mathf.Floor(num)) > Single.Epsilon)
                {
                    rect.xMin = Widgets.AdjustCoordToUIScalingFloor(rect.xMin);
                    rect.yMin = Widgets.AdjustCoordToUIScalingFloor(rect.yMin);
                    rect.xMax = Widgets.AdjustCoordToUIScalingCeil(rect.xMax + 1E-05f);                    // + 0.00001f
                    rect.yMax = Widgets.AdjustCoordToUIScalingCeil(rect.yMax + 1E-05f);
                }
            }

            int      font_index = (int)Text.Font;
            GUIStyle style      = Text.CurFontStyle;
            int      line_count;

            {
                CacheData cache = s_cache.getData(label, font_index);
                if (style.wordWrap)
                {
                    if (cache.wrap_line_count == 0 || cache.wrap_width != (int)rect.width)
                    {
                        WordWrap_Unity.setupFont(style, font_index);
                        cache.wrap_str   = WordWrap.wrap(style.richText, label, (int)rect.width, out cache.wrap_line_count);
                        cache.wrap_width = (int)rect.width;
                    }
                    label      = cache.wrap_str;
                    line_count = cache.wrap_line_count;
                }
                else
                {
                    if (cache.line_count == 0)
                    {
                        cache.line_count = lineCount(label);
                        cache.str        = label;
                    }
                    label      = cache.str;
                    line_count = cache.line_count;
                }
            }


            int text_height = calcHeight(style, font_index, line_count);

            TextAnchor alignment = style.alignment;
            float      offset_y;

            switch (alignment)
            {
            case TextAnchor.MiddleLeft:
                offset_y        = rect.height / 2 - text_height / 2;
                style.alignment = TextAnchor.UpperLeft;
                break;

            case TextAnchor.MiddleCenter:
                offset_y        = rect.height / 2 - text_height / 2;
                style.alignment = TextAnchor.UpperCenter;
                break;

            case TextAnchor.MiddleRight:
                offset_y        = rect.height / 2 - text_height / 2;
                style.alignment = TextAnchor.UpperRight;
                break;

            case TextAnchor.LowerLeft:
                offset_y        = rect.height - text_height;
                style.alignment = TextAnchor.UpperLeft;
                break;

            case TextAnchor.LowerCenter:
                offset_y        = rect.height - text_height;
                style.alignment = TextAnchor.UpperCenter;
                break;

            case TextAnchor.LowerRight:
                offset_y        = rect.height - text_height;
                style.alignment = TextAnchor.UpperRight;
                break;

            default:
                offset_y = 0;
                break;
            }
            rect.y += offset_y;

            bool ww = style.wordWrap;

            style.wordWrap = false;
            GUI.Label(rect, label, style);
            style.wordWrap  = ww;
            style.alignment = alignment;

            return(false);
        }
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            Rect            rect            = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);
            Rect            rect2           = rect.ContractedBy(6f);
            Command_Psycast command_Psycast = ((MainTabWindow_Inspect)MainButtonDefOf.Inspect.TabWindow)?.LastMouseoverGizmo as Command_Psycast;
            float           num             = Mathf.Repeat(Time.time, 0.85f);
            float           num2            = 1f;

            if (num < 0.1f)
            {
                num2 = num / 0.1f;
            }
            else if (num >= 0.25f)
            {
                num2 = 1f - (num - 0.25f) / 0.6f;
            }
            Widgets.DrawWindowBackground(rect);
            Text.Font = GameFont.Small;
            Rect rect3 = rect2;

            rect3.y     += 6f;
            rect3.height = Text.LineHeight;
            Widgets.Label(rect3, "PsychicEntropyShort".Translate());
            Rect rect4 = rect2;

            rect4.y     += 38f;
            rect4.height = Text.LineHeight;
            Widgets.Label(rect4, "PsyfocusLabelGizmo".Translate());
            Rect rect5 = rect2;

            rect5.x     += 63f;
            rect5.y     += 6f;
            rect5.width  = 100f;
            rect5.height = 22f;
            float entropyRelativeValue = tracker.EntropyRelativeValue;

            Widgets.FillableBar(rect5, Mathf.Min(entropyRelativeValue, 1f), EntropyBarTex, EmptyBarTex, doBorder: true);
            if (tracker.EntropyValue > tracker.MaxEntropy)
            {
                Widgets.FillableBar(rect5, Mathf.Min(entropyRelativeValue - 1f, 1f), OverLimitBarTex, EntropyBarTex, doBorder: true);
            }
            if (command_Psycast != null)
            {
                Ability ability = command_Psycast.Ability;
                if (ability.def.EntropyGain > float.Epsilon)
                {
                    Rect  rect6 = rect5.ContractedBy(3f);
                    float width = rect6.width;
                    float num3  = tracker.EntropyToRelativeValue(tracker.EntropyValue + ability.def.EntropyGain);
                    float num4  = entropyRelativeValue;
                    if (num4 > 1f)
                    {
                        num4 -= 1f;
                        num3 -= 1f;
                    }
                    rect6.xMin  = Widgets.AdjustCoordToUIScalingFloor(rect6.xMin + num4 * width);
                    rect6.width = Widgets.AdjustCoordToUIScalingFloor(Mathf.Max(Mathf.Min(num3, 1f) - num4, 0f) * width);
                    GUI.color   = new Color(1f, 1f, 1f, num2 * 0.7f);
                    GenUI.DrawTextureWithMaterial(rect6, EntropyBarTexAdd, null);
                    GUI.color = Color.white;
                }
            }
            if (tracker.EntropyValue > tracker.MaxEntropy)
            {
                foreach (KeyValuePair <PsychicEntropySeverity, float> entropyThreshold in Pawn_PsychicEntropyTracker.EntropyThresholds)
                {
                    if (entropyThreshold.Value > 1f && entropyThreshold.Value < 2f)
                    {
                        DrawThreshold(rect5, entropyThreshold.Value - 1f, entropyRelativeValue);
                    }
                }
            }
            string label = tracker.EntropyValue.ToString("F0") + " / " + tracker.MaxEntropy.ToString("F0");

            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(rect5, label);
            Text.Anchor = TextAnchor.UpperLeft;
            Text.Font   = GameFont.Tiny;
            GUI.color   = Color.white;
            Rect rect7 = rect2;

            rect7.width  = 175f;
            rect7.height = 38f;
            TooltipHandler.TipRegion(rect7, delegate
            {
                float f = tracker.EntropyValue / tracker.RecoveryRate;
                return(string.Format("PawnTooltipPsychicEntropyStats".Translate(), Mathf.Round(tracker.EntropyValue), Mathf.Round(tracker.MaxEntropy), tracker.RecoveryRate.ToString("0.#"), Mathf.Round(f)) + "\n\n" + "PawnTooltipPsychicEntropyDesc".Translate());
            }, Gen.HashCombineInt(tracker.GetHashCode(), 133858));
            Rect rect8 = rect2;

            rect8.x     += 63f;
            rect8.y     += 38f;
            rect8.width  = 100f;
            rect8.height = 22f;
            bool flag = Mouse.IsOver(rect8);

            Widgets.FillableBar(rect8, Mathf.Min(tracker.CurrentPsyfocus, 1f), flag ? PsyfocusBarHighlightTex : PsyfocusBarTex, EmptyBarTex, doBorder: true);
            if (command_Psycast != null)
            {
                float min = command_Psycast.Ability.def.PsyfocusCostRange.min;
                if (min > float.Epsilon)
                {
                    Rect  rect9  = rect8.ContractedBy(3f);
                    float num5   = Mathf.Max(tracker.CurrentPsyfocus - min, 0f);
                    float width2 = rect9.width;
                    rect9.xMin  = Widgets.AdjustCoordToUIScalingFloor(rect9.xMin + num5 * width2);
                    rect9.width = Widgets.AdjustCoordToUIScalingCeil((tracker.CurrentPsyfocus - num5) * width2);
                    GUI.color   = new Color(1f, 1f, 1f, num2);
                    GenUI.DrawTextureWithMaterial(rect9, PsyfocusBarTexReduce, null);
                    GUI.color = Color.white;
                }
            }
            for (int i = 1; i < Pawn_PsychicEntropyTracker.PsyfocusBandPercentages.Count - 1; i++)
            {
                DrawThreshold(rect8, Pawn_PsychicEntropyTracker.PsyfocusBandPercentages[i], tracker.CurrentPsyfocus);
            }
            float num6     = Mathf.Clamp(Mathf.Round((Event.current.mousePosition.x - (rect8.x + 3f)) / (rect8.width - 8f) * 16f) / 16f, 0f, 1f);
            Event current2 = Event.current;

            if (current2.type == EventType.MouseDown && current2.button == 0 && flag)
            {
                selectedPsyfocusTarget = num6;
                draggingPsyfocusBar    = true;
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.MeditationDesiredPsyfocus, KnowledgeAmount.Total);
                SoundDefOf.DragSlider.PlayOneShotOnCamera();
                current2.Use();
            }
            if (current2.type == EventType.MouseDrag && current2.button == 0 && draggingPsyfocusBar && flag)
            {
                if (Math.Abs(num6 - selectedPsyfocusTarget) > float.Epsilon)
                {
                    SoundDefOf.DragSlider.PlayOneShotOnCamera();
                }
                selectedPsyfocusTarget = num6;
                current2.Use();
            }
            if (current2.type == EventType.MouseUp && current2.button == 0 && draggingPsyfocusBar)
            {
                if (selectedPsyfocusTarget >= 0f)
                {
                    tracker.SetPsyfocusTarget(selectedPsyfocusTarget);
                }
                selectedPsyfocusTarget = -1f;
                draggingPsyfocusBar    = false;
                current2.Use();
            }
            UIHighlighter.HighlightOpportunity(rect8, "PsyfocusBar");
            DrawPsyfocusTarget(rect8, draggingPsyfocusBar ? selectedPsyfocusTarget : tracker.TargetPsyfocus);
            GUI.color = Color.white;
            Rect rect10 = rect2;

            rect10.y     += 38f;
            rect10.width  = 175f;
            rect10.height = 38f;
            TooltipHandler.TipRegion(rect10, () => tracker.PsyfocusTipString_NewTemp(selectedPsyfocusTarget), Gen.HashCombineInt(tracker.GetHashCode(), 133873));
            if (tracker.Pawn.IsColonistPlayerControlled)
            {
                float num7   = 32f;
                float num8   = 4f;
                float num9   = rect2.height / 2f - num7 + num8;
                float num10  = rect2.width - num7;
                Rect  rect11 = new Rect(rect2.x + num10, rect2.y + num9, num7, num7);
                if (Widgets.ButtonImage(rect11, tracker.limitEntropyAmount ? LimitedTex : UnlimitedTex))
                {
                    tracker.limitEntropyAmount = !tracker.limitEntropyAmount;
                    if (tracker.limitEntropyAmount)
                    {
                        SoundDefOf.Tick_Low.PlayOneShotOnCamera();
                    }
                    else
                    {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera();
                    }
                }
                TooltipHandler.TipRegionByKey(rect11, "PawnTooltipPsychicEntropyLimit");
            }
            if (tracker.PainMultiplier > 1f)
            {
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleCenter;
                string recoveryBonus = (tracker.PainMultiplier - 1f).ToStringPercent("F0");
                string text          = recoveryBonus;
                float  widthCached   = text.GetWidthCached();
                Rect   rect12        = rect2;
                rect12.x     += rect2.width - widthCached / 2f - 16f;
                rect12.y     += 38f;
                rect12.width  = widthCached;
                rect12.height = Text.LineHeight;
                GUI.color     = PainBoostColor;
                Widgets.Label(rect12, text);
                GUI.color   = Color.white;
                Text.Font   = GameFont.Tiny;
                Text.Anchor = TextAnchor.UpperLeft;
                TooltipHandler.TipRegion(rect12.ContractedBy(-1f), () => "PawnTooltipPsychicEntropyPainFocus".Translate(tracker.Pawn.health.hediffSet.PainTotal.ToStringPercent("F0"), recoveryBonus), Gen.HashCombineInt(tracker.GetHashCode(), 133878));
            }
            return(new GizmoResult(GizmoState.Clear));
        }