Beispiel #1
0
        // https://forum.unity.com/attachments/unity-drawline-math-jpg.64496/
        // for the relevant maths
        public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float width, bool drawDouble = false)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (Prefs.UIScale > 1)
            {
                Widgets.DrawLine(pointA, pointB, color, width);
                return;
            }

            // current rect (0, 0, 1, 1)
            // dx = pointB.x - pointA.x
            // dy = pointB.y - pointA.y
            // len = sqrt(dx^2 + dy^2)
            // desired rotation = atan2(dy, dx)
            // desired scale = (width*3), len
            // desired translation = (width * dy / len), (width * dx / len)

            var diffX = pointB.x - pointA.x;
            var diffY = pointB.y - pointA.y;
            var len   = Mathf.Sqrt(diffX * diffX + diffY * diffY);

            if (len < 0.001f)
            {
                return;
            }

            width *= 3.0f;
            var sinX = (width * diffY / len);
            var cosX = (width * diffX / len);

            var matrix = Matrix4x4.identity;

            // Scale
            matrix[0, 0] = (float)(diffX);
            matrix[1, 0] = (float)(diffY);

            // Rotate
            matrix[0, 1] = (float)-sinX;
            matrix[1, 1] = (float)cosX;

            var translation = pointA + new Vector2(0.5f * sinX, -0.5f * cosX);

            // Transate
            matrix[0, 3] = translation.x;
            matrix[1, 3] = translation.y;

            GL.PushMatrix();
            GL.MultMatrix(matrix);

            for (var i = 0; i < (drawDouble ? 2 : 1); i++)
            {
                Graphics.DrawTexture(lineRect, aaLineTex, lineRect, 0, 0, 0, 0, color, blendMaterial);
            }

            GL.PopMatrix();
        }
Beispiel #2
0
        public override void DoWindowContents(Rect inRect)
        {
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Tiny;

            Rect DragRect = new Rect(inRect.x, inRect.y, inRect.width - 50f, 25f);

            GUI.DragWindow(DragRect);

            Widgets.DrawLine(new Vector2(DragRect.x, DragRect.y + DragRect.height * 0.25f),
                             new Vector2(DragRect.xMax, DragRect.y + DragRect.height * 0.25f), Color.gray, 1f);
            Widgets.DrawLine(new Vector2(DragRect.x, DragRect.y + DragRect.height * 0.75f),
                             new Vector2(DragRect.xMax, DragRect.y + DragRect.height * 0.75f), Color.gray, 1f);

            GUI.color = Color.grey;
            Widgets.Label(DragRect, "Drag");
            GUI.color = Color.white;

            DragRect.x     = DragRect.xMax;
            DragRect.width = 25f;

            inRect = inRect.ContractedBy(10f);
            Rect MenuSection = inRect;

            MenuSection.y += 10f;
            HSB(ref MenuSection);

            Text.Anchor = TextAnchor.UpperLeft;
            Text.Font   = GameFont.Small;
        }
Beispiel #3
0
        public static void DrawLinesCustomPrerequisites(ResearchProjectDef project, ResearchTabDef curTab, Vector2 start, Vector2 end, ResearchProjectDef selectedProject, int i)
        {
            List <ResearchProjectDef> projects = SRTSMod.mod.settings.defProperties[srtsDefProjects.FirstOrDefault(x => x.Value == project).Key.defName].CustomResearch;

            start.x = project.ResearchViewX * 190f + 140f;
            start.y = project.ResearchViewY * 100f + 25f;
            foreach (ResearchProjectDef proj in projects)
            {
                if (proj != null && proj.tab == curTab)
                {
                    end.x = proj.ResearchViewX * 190f;
                    end.y = proj.ResearchViewY * 100f + 25f;
                    if (selectedProject == project || selectedProject == proj)
                    {
                        if (i == 1)
                        {
                            Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                        }
                    }
                    if (i == 0)
                    {
                        Widgets.DrawLine(start, end, new Color(255, 215, 0, 0.25f), 2f);
                    }
                }
            }
        }
Beispiel #4
0
        private static void DrawMarker(int col, int row, int size, Vector2 pos, float progress, Color color)
        {
            var start = new Vector2((col + Mathf.Clamp01(progress)) * size, row * size - 2) + pos;
            var end   = new Vector2((col + Mathf.Clamp01(progress)) * size, (row + 1) * size + 1) + pos;

            Widgets.DrawLine(start, end, color, 1);
        }
Beispiel #5
0
        public static void DrawBiDirectionalArrow(Vector2 from, Vector2 to, Color color)
        {
            // get the normalized direction of the line, offset for parallel lines, and directions of arrow head lines
            Vector2 direction       = from.DirectionTo(to);
            Vector2 arrowDirectionA = direction.RotatedBy(145f);
            Vector2 arrowDirectionB = direction.RotatedBy(215f);

            // start a little away from 'real' start, and offset to avoid overlapping
            from += direction * 35f;

            // end 40 px away from 'real' end
            to -= direction * 35f;

            // arrow end points
            Vector2 arrowA1 = to + arrowDirectionA * 6f;
            Vector2 arrowA2 = to + arrowDirectionB * 6f;
            Vector2 arrowB1 = from - arrowDirectionA * 6f;
            Vector2 arrowB2 = from - arrowDirectionB * 6f;

            // draw the lines
            Widgets.DrawLine(from, to, color, 1f);
            Widgets.DrawLine(to, arrowA1, color, 1f);
            Widgets.DrawLine(to, arrowA2, color, 1f);
            Widgets.DrawLine(from, arrowB1, color, 1f);
            Widgets.DrawLine(from, arrowB2, color, 1f);
        }
Beispiel #6
0
            public static void Postfix(Pawn __instance)
            {
                if (!Finder.debug)
                {
                    return;
                }

                List <Thing> others = __instance.Map.GetComponent <ProximityComponent>().GetThingsInRange(__instance.positionInt, 10).ToList();

                if (others == null)
                {
                    return;
                }

                var        selPos   = __instance.DrawPos.MapToUIPosition();
                var        offset   = new Vector2(12, 12);
                GameFont   textSize = Text.Font;
                TextAnchor anchor   = Text.Anchor;

                Text.Font   = GameFont.Tiny;
                Text.Anchor = TextAnchor.MiddleCenter;

                foreach (Thing thing in others)
                {
                    if (thing == null || thing == __instance)
                    {
                        continue;
                    }
                    var drawPos = thing.DrawPos.MapToUIPosition();


                    var distance = Vector2.Distance(drawPos, selPos);
                    if (distance < 24)
                    {
                        continue;
                    }

                    var midPoint     = (drawPos + selPos) / 2;
                    var rect         = new Rect(midPoint - offset, offset * 2);
                    var realDistance = Mathf.RoundToInt(thing.Position.DistanceTo(__instance.Position));
                    if (realDistance <= 10)
                    {
                        var color = new Color(0.1f, 0.5f, 0.1f);
                        Widgets.DrawLine(drawPos, selPos, color, 1);
                        Widgets.DrawWindowBackgroundTutor(rect);
                        Widgets.Label(rect, "" + Mathf.RoundToInt(thing.Position.DistanceTo(__instance.Position)));
                    }
                    else
                    {
                        var color = new Color(1f, 0.1f, 0.1f);
                        Widgets.DrawLine(drawPos, selPos, color, 1);
                        Widgets.DrawBoxSolid(rect, new Color(0.1f, 0.1f, 0.1f));
                        Widgets.Label(rect, "" + Mathf.RoundToInt(thing.Position.DistanceTo(__instance.Position)));
                    }
                }

                Text.Font   = textSize;
                Text.Anchor = anchor;
            }
 public static bool Reorderable(int groupID, Rect rect)
 {
     if (Event.current.type == EventType.Repaint)
     {
         ReorderableInstance item = default(ReorderableInstance);
         item.groupID = groupID;
         item.rect    = rect;
         item.absRect = new Rect(UI.GUIToScreenPoint(rect.position), rect.size);
         ReorderableWidget.reorderables.Add(item);
         int num = ReorderableWidget.reorderables.Count - 1;
         if (ReorderableWidget.draggingReorderable != -1 && Vector2.Distance(ReorderableWidget.clickedAt, Event.current.mousePosition) > 5.0)
         {
             if (!ReorderableWidget.dragBegun)
             {
                 SoundDefOf.TickTiny.PlayOneShotOnCamera(null);
                 ReorderableWidget.dragBegun = true;
             }
             if (ReorderableWidget.draggingReorderable == num)
             {
                 GUI.color = ReorderableWidget.HighlightColor;
                 Widgets.DrawHighlight(rect);
                 GUI.color = Color.white;
             }
             if (ReorderableWidget.lastInsertAt == num)
             {
                 ReorderableInstance reorderableInstance = ReorderableWidget.reorderables[ReorderableWidget.lastInsertAt];
                 Rect    rect2         = reorderableInstance.rect;
                 Vector2 mousePosition = Event.current.mousePosition;
                 float   y             = mousePosition.y;
                 Vector2 center        = rect2.center;
                 bool    flag          = y < center.y;
                 GUI.color = ReorderableWidget.LineColor;
                 if (flag)
                 {
                     Widgets.DrawLine(rect2.position, new Vector2(rect2.x + rect2.width, rect2.y), ReorderableWidget.LineColor, 2f);
                 }
                 else
                 {
                     Widgets.DrawLine(new Vector2(rect2.x, rect2.yMax), new Vector2(rect2.x + rect2.width, rect2.yMax), ReorderableWidget.LineColor, 2f);
                 }
                 GUI.color = Color.white;
             }
         }
         return(ReorderableWidget.draggingReorderable == num && ReorderableWidget.dragBegun);
     }
     if (Event.current.rawType == EventType.MouseUp)
     {
         ReorderableWidget.released = true;
     }
     if (Event.current.type == EventType.MouseDown && Mouse.IsOver(rect))
     {
         ReorderableWidget.clicked       = true;
         ReorderableWidget.clickedAt     = Event.current.mousePosition;
         ReorderableWidget.clickedInRect = rect;
     }
     return(false);
 }
Beispiel #8
0
        internal static void DrawGrid(Rect rect)
        {
            var yIncrement = rect.height / 4f;

            for (var i = 0; i < 5; i++)
            {
                Widgets.DrawLine(new Vector2(rect.x, i * yIncrement), new Vector2(GraphSettings.showGrid ? rect.xMax : rect.x + 2f, i * yIncrement), gray, 1f);
            }
        }
Beispiel #9
0
 internal static void DebugDraw()
 {
     foreach (Node v in Nodes)
     {
         foreach (Node w in v.OutNodes)
         {
             Widgets.DrawLine(v.Right, w.Left, Color.white, 1);
         }
     }
 }
        public static void SelectChild(Building_ReligionBuilding parent)
        {
            DebugTools.curTool = new DebugTool("ReligiousBuilgingAssigner_SelectABuilding".Translate(), (Action)(() =>
            {
                foreach (Thing thing in Find.CurrentMap.thingGrid.ThingsAt(UI.MouseCell()).ToList <Thing>())
                {
                    if (thing is Building_ReligionBuilding child)
                    {
                        if (parent == child)
                        {
                            TryToUnassignAllBuildings(parent);
                            SelectParent();
                            return;
                        }

                        if (child.AvaliableToAssign)
                        {
                            TryToAssignBuilding(parent, child);
                            SelectParent();
                            return;
                        }
                        else
                        {
                            Messages.Message("ReligiousBuilgingAssigner_BuildingIsNotCompleteToAssign".Translate(), MessageTypeDefOf.NeutralEvent);
                        }

                        DebugTools.curTool = null;
                    }
                }
            }), (Action)(() =>
            {
                foreach (Building_ReligionBuilding building in Find.CurrentMap.listerBuildings.AllBuildingsColonistOfClass <Building_ReligionBuilding>())
                {
                    if (building != parent)
                    {
                        if (parent.MayAssignBuilding(building) && building.MayAssignBuilding(parent))
                        {
                            Widgets.DrawTextureFitted(new Rect(building.Position.ToUIPosition() - new Vector2(10, 10), new Vector2(20, 20)), GraphicsCache.CheckboxOnTex, 1);
                        }
                        else
                        {
                            Widgets.DrawTextureFitted(new Rect(building.Position.ToUIPosition() - new Vector2(10, 10), new Vector2(20, 20)), GraphicsCache.CheckboxOffTex, 1);
                        }
                    }
                }
                foreach (Building_ReligionBuilding assigned in parent.AssignedBuildings)
                {
                    Widgets.DrawLine(parent.Position.ToUIPosition(), assigned.Position.ToUIPosition(), Color.green, 2f);
                }
                if (UI.MouseCell().InBounds(Find.CurrentMap))
                {
                    Widgets.DrawLine(parent.Position.ToUIPosition(), UI.MouseCell().ToUIPosition(), Color.white, 2f);
                }
            }));
        }
Beispiel #11
0
        public static void DrawMarker(Rect canvas, float hour, float thickness, Color color, float start, float end)
        {
            var angle  = (hour / 6 - .5f) * Mathf.PI;                         // should start at top...
            var radius = Mathf.Min(canvas.width, canvas.height) / 2f;
            var vector = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
            var from   = radius * start * vector + canvas.center;
            var to     = radius * end * vector + canvas.center;

//            Logger.Debug( $"{canvas}, {from}, {to}" );
            Widgets.DrawLine(from, to, color, thickness);
        }
Beispiel #12
0
        public override void MapComponentOnGUI()
        {
            base.MapComponentOnGUI();
            if (!Controller.settings.DebugGenClosetPawn)
            {
                return;
            }
            if (Find.Selector.SelectedObjects.Count == 0)
            {
                return;
            }
            var thing = Find.Selector.SelectedObjects.Where(s => s is Thing).Select(s => s as Thing).First();

            if (IsValidTrackableThing(thing))
            {
                IEnumerable <Thing> others;
                if (thing is Pawn)
                {
                    others = GenClosest.PawnsInRange(thing.Position, map, 50);
                }
                else if (thing is AmmoThing)
                {
                    others = GenClosest.AmmoInRange(thing.Position, map, 50);
                }
                else if (thing.def.IsApparel)
                {
                    others = GenClosest.ApparelInRange(thing.Position, map, 50);
                }
                else if (thing.def.IsWeapon)
                {
                    others = GenClosest.WeaponsInRange(thing.Position, map, 50);
                }
                else
                {
                    others = GenClosest.SimilarInRange(thing, 50);
                }
                Vector2 a = UI.MapToUIPosition(thing.DrawPos);
                Vector2 b;
                Vector2 mid;
                Rect    rect;
                int     index = 0;
                foreach (var other in others)
                {
                    b = UI.MapToUIPosition(other.DrawPos);
                    Widgets.DrawLine(a, b, Color.red, 1);

                    mid  = (a + b) / 2;
                    rect = new Rect(mid.x - 25, mid.y - 15, 50, 30);
                    Widgets.DrawBox(rect);
                    Widgets.Label(rect, $"({index++}). {other.Position.DistanceTo(thing.Position)}m");
                }
            }
        }
Beispiel #13
0
 public void Plot(Period period, Rect canvas, float wu, float hu, int sign = 1)
 {
     if (pages[period].Count > 1)
     {
         List <int> hist = pages[period];
         for (var i = 0; i < hist.Count - 1; i++)   // line segments, so up till n-1
         {
             var start = new Vector2(wu * i, canvas.height - hu * hist[i] * sign);
             var end   = new Vector2(wu * (i + 1), canvas.height - hu * hist[i + 1] * sign);
             Widgets.DrawLine(start, end, lineColor, 1f);
         }
     }
 }
        private static void CheckReachability()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            TraverseMode[] array = (TraverseMode[])Enum.GetValues(typeof(TraverseMode));
            for (int i = 0; i < array.Length; i++)
            {
                TraverseMode traverseMode2 = array[i];
                TraverseMode traverseMode  = traverseMode2;
                list.Add(new DebugMenuOption(traverseMode2.ToString(), DebugMenuOptionMode.Action, delegate
                {
                    DebugTool tool = null;
                    IntVec3 from   = default(IntVec3);
                    Pawn fromPawn  = default(Pawn);
                    tool           = new DebugTool("from...", delegate
                    {
                        from        = UI.MouseCell();
                        fromPawn    = from.GetFirstPawn(Find.CurrentMap);
                        string text = "to...";
                        if (fromPawn != null)
                        {
                            text = text + " (pawn=" + fromPawn.LabelShort + ")";
                        }
                        DebugTools.curTool = new DebugTool(text, delegate
                        {
                            DebugTools.curTool = tool;
                        }, delegate
                        {
                            IntVec3 c = UI.MouseCell();
                            bool flag;
                            IntVec3 intVec;
                            if (fromPawn != null)
                            {
                                flag   = fromPawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, canBash: false, traverseMode);
                                intVec = fromPawn.Position;
                            }
                            else
                            {
                                flag   = Find.CurrentMap.reachability.CanReach(from, c, PathEndMode.OnCell, traverseMode, Danger.Deadly);
                                intVec = from;
                            }
                            Color color = flag ? Color.green : Color.red;
                            Widgets.DrawLine(intVec.ToUIPosition(), c.ToUIPosition(), color, 2f);
                        });
                    });
                    DebugTools.curTool = tool;
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
Beispiel #15
0
        internal static void DrawGrid(Rect rect)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            var yIncrement = rect.height / 4f;

            for (var i = 0; i < 5; i++)
            {
                Widgets.DrawLine(new Vector2(rect.x, i * yIncrement), new Vector2(GraphSettings.showGrid ? rect.xMax : rect.x + 2f, i * yIncrement), gray, 1f);
            }
        }
Beispiel #16
0
        public static void DrawTechLevel(TechLevel techlevel, Rect visibleRect)
        {
            // determine positions
            var xMin = (NodeSize.x + NodeMargins.x) * TechLevelBounds[techlevel].min - NodeMargins.x / 2f;
            var xMax = (NodeSize.x + NodeMargins.x) * TechLevelBounds[techlevel].max - NodeMargins.x / 2f;

            GUI.color   = Assets.TechLevelColor;
            Text.Anchor = TextAnchor.MiddleCenter;

            // lower bound
            if (TechLevelBounds[techlevel].min > 0 && xMin > visibleRect.xMin && xMin < visibleRect.xMax)
            {
                // line
                Widgets.DrawLine(new Vector2(xMin, visibleRect.yMin), new Vector2(xMin, visibleRect.yMax), Assets.TechLevelColor, 1f);

                // label
                // NOTE: This is a massive copout, but just don't draw these labels if zoomlevel != 1;
                if (MainTabWindow_ResearchTree.Instance.ZoomLevel - 1f < 1e-4)
                {
                    var labelRect = new Rect(
                        xMin + TechLevelLabelSize.y / 2f - TechLevelLabelSize.x / 2f,
                        visibleRect.center.y - TechLevelLabelSize.y / 2f,
                        TechLevelLabelSize.x,
                        TechLevelLabelSize.y);
                    UI.RotateAroundPivot(-90, labelRect.center);
                    Widgets.Label(labelRect, techlevel.ToStringHuman());
                    UI.RotateAroundPivot(90, labelRect.center);
                }
            }

            // upper bound
            if (TechLevelBounds[techlevel].max <Size.x && xMax> visibleRect.xMin && xMax < visibleRect.xMax)
            {
                // label
                var labelRect = new Rect(
                    xMax - TechLevelLabelSize.y / 2f - TechLevelLabelSize.x / 2f,
                    visibleRect.center.y - TechLevelLabelSize.y / 2f,
                    TechLevelLabelSize.x,
                    TechLevelLabelSize.y);
                UI.RotateAroundPivot(-90, labelRect.center);
                Widgets.Label(labelRect, techlevel.ToStringHuman());
                UI.RotateAroundPivot(90, labelRect.center);
            }

            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
        }
Beispiel #17
0
        public static void DrawLineDashed(Vector2 start, Vector2 end, Color?color = null, float size = 1,
                                          float stroke = 5,
                                          float dash   = 3)
        {
            float   partLength  = dash + stroke;
            float   totalLength = (end - start).magnitude;
            Vector2 direction   = (end - start).normalized;
            float   done        = 0f;

            while (done < totalLength)
            {
                Vector2 _start = start + (done * direction);
                Vector2 _end   = start + (Mathf.Min(done + stroke, totalLength) * direction);
                Widgets.DrawLine(_start, _end, color.GetValueOrDefault(Color.white), size);
                done += partLength;
            }
        }
Beispiel #18
0
        public static void DrawUrl(Rect labelRect, string text, string url)
        {
            Widgets.Label(labelRect, text.Colorize(ColorLibrary.SkyBlue));
            if (Mouse.IsOver(labelRect))
            {
                Vector2 size = Text.CalcSize(text);
                Widgets.DrawLine(
                    new Vector2(labelRect.x, labelRect.y + size.y)
                    , new Vector2(labelRect.x + size.x, labelRect.y + size.y)
                    , ColorLibrary.SkyBlue, 1);
            }

            if (Widgets.ButtonInvisible(labelRect))
            {
                Application.OpenURL(url);
            }
        }
        public override void DoWindowContents(Rect inRect)
        {
            Rect position = new Rect(inRect.x, inRect.y, inRect.width - 40f, 20f).ContractedBy(2f);

            GUI.DragWindow(position);
            Widgets.DrawLine(new Vector2(position.x, position.y + position.height * 0.25f), new Vector2(position.xMax, position.y + position.height * 0.25f), Color.gray, 1f);
            Widgets.DrawLine(new Vector2(position.x, position.y + position.height * 0.75f), new Vector2(position.xMax, position.y + position.height * 0.75f), Color.gray, 1f);
            if (Widgets.ButtonImage(new Rect(inRect.xMax - 20f, inRect.y, 20f, 20f).ContractedBy(2f), Dialog_BeeResearch.CloseXSmall))
            {
                this.Close(true);
            }
            Widgets.DrawTextureFitted(inRect.ContractedBy(3f), theImage, 1f);
            //Text.Font = GameFont.Tiny;
            //Text.Anchor = TextAnchor.MiddleCenter;

            Widgets.Label(new Rect(inRect.x, inRect.y + 445, inRect.width, 30), theText);
        }
Beispiel #20
0
 internal static void DrawDebug()
 {
     foreach (Node v in Leaves)
     {
         if (v != roots[v])
         {
             Widgets.DrawLine(v.Center, roots[v].Center, Color.red, 1);
         }
         if (v != align[v] && Math.Abs(align[v].X - v.X) <= 1)
         {
             Widgets.DrawLine(v.Center, align[v].Center, Color.blue, 4);
         }
         foreach (Node w in v.Below)
         {
             Widgets.DrawLine(v.Right, w.Left, Color.white, 1);
         }
     }
 }
Beispiel #21
0
        public static void DrawTechLevel(TechLevel techlevel, Rect visibleRect)
        {
            // determine positions
            var xMin = (NodeSize.x + NodeMargins.x) * TechLevelBounds[techlevel].min - NodeMargins.x / 2f;
            var xMax = (NodeSize.x + NodeMargins.x) * TechLevelBounds[techlevel].max - NodeMargins.x / 2f;

            GUI.color   = Assets.TechLevelColor;
            Text.Anchor = TextAnchor.MiddleCenter;

            // lower bound
            if (TechLevelBounds[techlevel].min > 0 && xMin > visibleRect.xMin && xMin < visibleRect.xMax)
            {
                // line
                Widgets.DrawLine(new Vector2(xMin, visibleRect.yMin), new Vector2(xMin, visibleRect.yMax),
                                 Assets.TechLevelColor, 1f);

                // label
                var labelRect = new Rect(
                    xMin + TechLevelLabelSize.y / 2f - TechLevelLabelSize.x / 2f,
                    visibleRect.center.y - TechLevelLabelSize.y / 2f,
                    TechLevelLabelSize.x,
                    TechLevelLabelSize.y);

                VerticalLabel(labelRect, techlevel.ToStringHuman());
            }

            // upper bound
            if (TechLevelBounds[techlevel].max <Size.x && xMax> visibleRect.xMin && xMax < visibleRect.xMax)
            {
                // label
                var labelRect = new Rect(
                    xMax - TechLevelLabelSize.y / 2f - TechLevelLabelSize.x / 2f,
                    visibleRect.center.y - TechLevelLabelSize.y / 2f,
                    TechLevelLabelSize.x,
                    TechLevelLabelSize.y);

                VerticalLabel(labelRect, techlevel.ToStringHuman());
            }

            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
        }
Beispiel #22
0
        internal static void DrawBackground(Rect rect, bool drawGridLines, bool axis)
        {
            Widgets.DrawRectFast(rect, Modbase.Settings.GraphCol);
            if (!drawGridLines)
            {
                return;
            }

            var xIncrement = rect.width / 3.0f;
            var yIncrement = rect.height / 3.0f;

            for (int i = 1; i < 3; i++)
            {
                // Horizontal lines
                Widgets.DrawLine(new Vector2(axis ? 25 : 0, i * yIncrement), new Vector2(rect.width, i * yIncrement), gray, 1f);

                // Vertical
                Widgets.DrawLine(new Vector2(i * xIncrement, 0), new Vector2(i * xIncrement, rect.height - (axis ? Text.LineHeight : 0)), gray, 1f);
            }
        }
Beispiel #23
0
        void DrawParentEdges(Vertex v)
        {
            Vector2 start;
            Vector2 end;

            foreach (Vertex parent in v.parents)
            {
                start.x = v.x * LayerWidth;
                start.y = v.y * LayerHeight + (VertexHeight / 2f);
                end.x   = parent.x * LayerWidth + VertexWidth;
                end.y   = parent.y * LayerHeight + VertexHeight / 2f;
                Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                if (parent.isDummy)
                {
                    start.x = end.x - VertexWidth;
                    start.y = end.y;
                    Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                    DrawParentEdges(parent);
                }
            }
        }
Beispiel #24
0
        /******************************************************************************************
        *
        * Auxiliary drawing methods
        *
        *
        ******************************************************************************************/
        void DrawChildrenEdges(Vertex v)
        {
            Vector2 start;
            Vector2 end;

            foreach (Vertex child in v.children)
            {
                start.x = v.x * LayerWidth + VertexWidth;
                start.y = v.y * LayerHeight + (VertexHeight / 2f);
                end.x   = child.x * LayerWidth;
                end.y   = child.y * LayerHeight + VertexHeight / 2f;
                Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                if (child.isDummy)
                {
                    start.x = end.x + VertexWidth;
                    start.y = end.y;
                    Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                    DrawChildrenEdges(child);
                }
            }
        }
Beispiel #25
0
        public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float width, bool drawDouble = false)
        {
            if (Prefs.UIScale > 1)
            {
                Widgets.DrawLine(pointA, pointB, color, width);
                return;
            }

            var dx  = pointB.x - pointA.x;
            var dy  = pointB.y - pointA.y;
            var len = Mathf.Sqrt(dx * dx + dy * dy);

            if (len < 0.001f)
            {
                return;
            }

            width *= 3.0f;
            var wdx = width * dy / len;
            var wdy = width * dx / len;

            var matrix = Matrix4x4.identity;

            matrix.m00 = dx;
            matrix.m01 = -wdx;
            matrix.m03 = pointA.x + 0.5f * wdx;
            matrix.m10 = dy;
            matrix.m11 = wdy;
            matrix.m13 = pointA.y - 0.5f * wdy;

            GL.PushMatrix();
            GL.MultMatrix(matrix);
            for (int i = 0; i < (drawDouble ? 2 : 1); i++)
            {
                Graphics.DrawTexture(lineRect, aaLineTex, lineRect, 0, 0, 0, 0, color, blendMaterial);
            }
            GL.PopMatrix();
        }
Beispiel #26
0
            public static void DrawGeneValueLabel(Rect box, float value, bool strikethrough = false, string extra = "")
            {
                TextAnchor oldTextAnchor = Text.Anchor;
                Color      oldColor      = UnityEngine.GUI.color;

                Text.Anchor           = TextAnchor.MiddleCenter;
                UnityEngine.GUI.color = Utilities.TextColor(value);

                string text = (value * 100).ToString("F0") + "%" + extra;

                Widgets.Label(box, text);

                if (strikethrough)
                {
                    float halfSize = Text.CalcSize(text).x / 2 + 1;
                    float midpoint = (box.xMin + box.xMax) / 2;

                    Widgets.DrawLine(new Vector2(midpoint - halfSize, box.y + box.height / 2 - 1), new Vector2(midpoint + halfSize, box.y + box.height / 2 - 1), new Color(1f, 1f, 1f, 0.5f), 1);
                }

                UnityEngine.GUI.color = oldColor;
                Text.Anchor           = oldTextAnchor;
            }
Beispiel #27
0
        private static void DrawLines()
        {
            Vector2 start = default(Vector2);
            Vector2 end   = default(Vector2);
            List <RoyalTitlePermitDef> allDefsListForReading = DefDatabase <RoyalTitlePermitDef> .AllDefsListForReading;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < allDefsListForReading.Count; j++)
                {
                    RoyalTitlePermitDef royalTitlePermitDef = allDefsListForReading[j];
                    if (!CanDrawPermit(royalTitlePermitDef))
                    {
                        continue;
                    }
                    Vector2 vector = DrawPosition(royalTitlePermitDef);
                    start.x = vector.x;
                    start.y = vector.y + 25f;
                    RoyalTitlePermitDef prerequisite = royalTitlePermitDef.prerequisite;
                    if (prerequisite != null)
                    {
                        Vector2 vector2 = DrawPosition(prerequisite);
                        end.x = vector2.x + 200f;
                        end.y = vector2.y + 25f;
                        if ((i == 1 && selectedPermit == royalTitlePermitDef) || selectedPermit == prerequisite)
                        {
                            Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                        }
                        else if (i == 0)
                        {
                            Widgets.DrawLine(start, end, TexUI.DefaultLineResearchColor, 2f);
                        }
                    }
                }
            }
        }
        public static void DrawCurveLines(Rect rect, SimpleCurveDrawInfo curve, bool drawPoints, Rect viewRect, bool useAALines, bool pointsRemoveOptimization)
        {
            if (curve.curve == null || curve.curve.PointsCount == 0)
            {
                return;
            }
            Rect position = rect;

            position.yMin -= 1f;
            position.yMax += 1f;
            GUI.BeginGroup(position);
            if (Event.current.type == EventType.Repaint)
            {
                if (useAALines)
                {
                    bool    flag       = true;
                    Vector2 start      = default(Vector2);
                    Vector2 curvePoint = default(Vector2);
                    int     num        = curve.curve.Points.Count((CurvePoint x) => x.x >= viewRect.xMin && x.x <= viewRect.xMax);
                    int     num2       = RemovePointsOptimizationFreq(num);
                    for (int i = 0; i < curve.curve.PointsCount; i++)
                    {
                        CurvePoint curvePoint2 = curve.curve[i];
                        if (!pointsRemoveOptimization || i % num2 != 0 || i == 0 || i == num - 1)
                        {
                            curvePoint.x = curvePoint2.x;
                            curvePoint.y = curvePoint2.y;
                            Vector2 vector = CurveToScreenCoordsInsideScreenRect(rect, viewRect, curvePoint);
                            if (flag)
                            {
                                flag = false;
                            }
                            else if ((start.x >= 0f && start.x <= rect.width) || (vector.x >= 0f && vector.x <= rect.width))
                            {
                                Widgets.DrawLine(start, vector, curve.color, 1f);
                            }
                            start = vector;
                        }
                    }
                    Vector2 start2 = CurveToScreenCoordsInsideScreenRect(rect, viewRect, curve.curve[0]);
                    Vector2 start3 = CurveToScreenCoordsInsideScreenRect(rect, viewRect, curve.curve[curve.curve.PointsCount - 1]);
                    Widgets.DrawLine(start2, new Vector2(0f, start2.y), curve.color, 1f);
                    Widgets.DrawLine(start3, new Vector2(rect.width, start3.y), curve.color, 1f);
                }
                else
                {
                    GUI.color = curve.color;
                    float num3 = viewRect.x;
                    float num4 = rect.width / 1f;
                    float num5 = viewRect.width / num4;
                    while (num3 < viewRect.xMax)
                    {
                        num3 += num5;
                        Vector2 vector2 = CurveToScreenCoordsInsideScreenRect(rect, viewRect, new Vector2(num3, curve.curve.Evaluate(num3)));
                        GUI.DrawTexture(new Rect(vector2.x, vector2.y, 1f, 1f), BaseContent.WhiteTex);
                    }
                }
                GUI.color = Color.white;
            }
            if (drawPoints)
            {
                for (int j = 0; j < curve.curve.PointsCount; j++)
                {
                    DrawPoint(CurveToScreenCoordsInsideScreenRect(curvePoint: curve.curve[j].Loc, rect: rect, viewRect: viewRect));
                }
            }
            foreach (float debugInputValue in curve.curve.View.DebugInputValues)
            {
                GUI.color = new Color(0f, 1f, 0f, 0.25f);
                DrawInfiniteVerticalLine(rect, viewRect, debugInputValue);
                float   y           = curve.curve.Evaluate(debugInputValue);
                Vector2 screenPoint = CurveToScreenCoordsInsideScreenRect(curvePoint: new Vector2(debugInputValue, y), rect: rect, viewRect: viewRect);
                GUI.color = Color.green;
                DrawPoint(screenPoint);
                GUI.color = Color.white;
            }
            GUI.EndGroup();
        }
        public static bool Reorderable(int groupID, Rect rect, bool useRightButton = false)
        {
            bool result;

            if (Event.current.type == EventType.Repaint)
            {
                ReorderableWidget.ReorderableInstance item = default(ReorderableWidget.ReorderableInstance);
                item.groupID = groupID;
                item.rect    = rect;
                item.absRect = new Rect(UI.GUIToScreenPoint(rect.position), rect.size);
                ReorderableWidget.reorderables.Add(item);
                int num = ReorderableWidget.reorderables.Count - 1;
                if (ReorderableWidget.draggingReorderable != -1 && (ReorderableWidget.dragBegun || Vector2.Distance(ReorderableWidget.clickedAt, Event.current.mousePosition) > 5f))
                {
                    if (!ReorderableWidget.dragBegun)
                    {
                        SoundDefOf.Tick_Tiny.PlayOneShotOnCamera(null);
                        ReorderableWidget.dragBegun = true;
                    }
                    if (ReorderableWidget.draggingReorderable == num)
                    {
                        GUI.color = ReorderableWidget.HighlightColor;
                        Widgets.DrawHighlight(rect);
                        GUI.color = Color.white;
                    }
                    if (ReorderableWidget.lastInsertNear == num && groupID >= 0 && groupID < ReorderableWidget.groups.Count)
                    {
                        Rect rect2 = ReorderableWidget.reorderables[ReorderableWidget.lastInsertNear].rect;
                        ReorderableWidget.ReorderableGroup reorderableGroup = ReorderableWidget.groups[groupID];
                        if (reorderableGroup.DrawLineExactlyBetween)
                        {
                            if (reorderableGroup.direction == ReorderableDirection.Horizontal)
                            {
                                rect2.xMin -= reorderableGroup.drawLineExactlyBetween_space / 2f;
                                rect2.xMax += reorderableGroup.drawLineExactlyBetween_space / 2f;
                            }
                            else
                            {
                                rect2.yMin -= reorderableGroup.drawLineExactlyBetween_space / 2f;
                                rect2.yMax += reorderableGroup.drawLineExactlyBetween_space / 2f;
                            }
                        }
                        GUI.color = ReorderableWidget.LineColor;
                        if (reorderableGroup.direction == ReorderableDirection.Horizontal)
                        {
                            if (ReorderableWidget.lastInsertNearLeft)
                            {
                                Widgets.DrawLine(rect2.position, new Vector2(rect2.x, rect2.yMax), ReorderableWidget.LineColor, 2f);
                            }
                            else
                            {
                                Widgets.DrawLine(new Vector2(rect2.xMax, rect2.y), new Vector2(rect2.xMax, rect2.yMax), ReorderableWidget.LineColor, 2f);
                            }
                        }
                        else if (ReorderableWidget.lastInsertNearLeft)
                        {
                            Widgets.DrawLine(rect2.position, new Vector2(rect2.xMax, rect2.y), ReorderableWidget.LineColor, 2f);
                        }
                        else
                        {
                            Widgets.DrawLine(new Vector2(rect2.x, rect2.yMax), new Vector2(rect2.xMax, rect2.yMax), ReorderableWidget.LineColor, 2f);
                        }
                        GUI.color = Color.white;
                    }
                }
                result = (ReorderableWidget.draggingReorderable == num && ReorderableWidget.dragBegun);
            }
            else
            {
                if (Event.current.rawType == EventType.MouseUp)
                {
                    ReorderableWidget.released = true;
                }
                if (Event.current.type == EventType.MouseDown && ((useRightButton && Event.current.button == 1) || (!useRightButton && Event.current.button == 0)) && Mouse.IsOver(rect))
                {
                    ReorderableWidget.clicked       = true;
                    ReorderableWidget.clickedAt     = Event.current.mousePosition;
                    ReorderableWidget.clickedInRect = rect;
                }
                result = false;
            }
            return(result);
        }
        /// <summary>
        /// Draw colonies list on Persistent RimWorlds.
        /// </summary>
        /// <param name="inRect"></param>
        /// <param name="margin"></param>
        /// <param name="colonies"></param>
        /// <param name="load"></param>

        public static void DrawColoniesList(ref Rect inRect, float margin, Vector2 closeButtonSize,
                                            List <PersistentColony> colonies, Action <int> load, Action newColony)
        {
            const int perRow = 3;
            var       gap    = (int)margin;

            inRect.width += gap;

            // TODO: Update with sorting option
            SortColoniesOneTime(ref colonies);

            UITools.DrawBoxGridView(out _, out var outRect, ref inRect, ref _scrollPosition, perRow, gap,
                                    (i, boxRect) =>
            {
                if (i >= colonies.Count)
                {
                    return(false);
                }

                var colony = colonies[i];

                if (colony?.ColonyData == null ||
                    (colony.ColonyData.Leader != null && colony.ColonyData.Leader.LoadingTexture))
                {
                    return(false);
                }

                Widgets.DrawAltRect(boxRect);

                Widgets.DrawHighlightIfMouseover(boxRect);

                // Draw whole box button second.
                if (Widgets.ButtonInvisible(boxRect))
                {
                    load(i);
                }

                var texture = GetTexture(colony.ColonyData.ColonyFaction);
                var size    = Mathf.Clamp(boxRect.width * 0.65f, 0, texture.width);

                var textureRect = new Rect(boxRect.x + margin, boxRect.y + boxRect.height / 2 - size / 2, size, size);

                DrawTexture(textureRect, texture, colony.ColonyData.Color);

                DrawLeader(boxRect, colony, margin, 0.56f);

                const float nameMargin = 4f;

                var colonyNameRect = new Rect(boxRect.x + nameMargin, boxRect.y + nameMargin,
                                              boxRect.width - nameMargin,
                                              textureRect.y - boxRect.y);

                DrawNameLabel(colonyNameRect, colony, colony.ColonyData.ColonyFaction);

                return(true);
            }, colonies.Count + 1, (width, height) =>
            {
                /*
                 * New Colony Button
                 */
                var y = width * Mathf.Floor((float)colonies.Count / perRow) +
                        (colonies.Count / perRow) * gap;

                var boxRect = new Rect((width * (colonies.Count % perRow)) + (colonies.Count % perRow) * gap,
                                       y, width,
                                       width);

                Widgets.DrawHighlightIfMouseover(boxRect);
                Widgets.DrawAltRect(boxRect);

                if (Widgets.ButtonInvisible(boxRect))
                {
                    newColony();
                }

                TooltipHandler.TipRegion(boxRect,
                                         "FilUnderscore.PersistentRimWorlds.Create.NewColony".Translate());

                Widgets.DrawLine(new Vector2(boxRect.x + boxRect.width / 2, boxRect.y + boxRect.height / 3),
                                 new Vector2(boxRect.x + boxRect.width / 2, boxRect.y + boxRect.height * 0.66f), Color.white,
                                 1f);

                Widgets.DrawLine(new Vector2(boxRect.x + boxRect.width / 3, boxRect.y + boxRect.height / 2),
                                 new Vector2(boxRect.x + boxRect.width * 0.66f, boxRect.y + boxRect.height / 2), Color.white,
                                 1f);
            }, closeButtonSize);

            outRect.height -= closeButtonSize.y + margin;
        }