Ejemplo n.º 1
0
        public override void DoWindowContents(Rect inRect)
        {
            this.SetSizeAndPosition();

            List <PrimaryWork> primariesList = Controller.GetPrimaries.PrimaryWorkList;

            //Build rects
            Rect toggleButtonRect = new Rect(inRect.x - this.horizontalOffset, inRect.y + Utilities.TinyTextLineHeight, Utilities.ShortSpacing + Utilities.SpaceForPawnLabel, Utilities.SmallRowHeight);
            Rect primariesRect    = new Rect(toggleButtonRect.xMax, toggleButtonRect.y, inRect.width - toggleButtonRect.width, Utilities.SmallRowHeight);

            Rect scrollViewBox       = new Rect(inRect.x, primariesRect.yMax, inRect.width, inRect.height - Utilities.SmallRowHeight - Utilities.TinyTextLineHeight);
            Rect scrollViewOuterRect = scrollViewBox.ContractedBy(Utilities.ShortSpacing);
            Rect scrollViewInnerRect = new Rect(scrollViewOuterRect.x, scrollViewOuterRect.y, Utilities.SpaceForPawnLabel + Utilities.SmallSurfaceWidth, this.cachedPawnSurfaces.Count * Utilities.SmallRowHeight);

            if (scrollViewInnerRect.width > scrollViewOuterRect.width)
            {
                scrollViewInnerRect.yMax += Utilities.SpaceForScrollBar;
            }

            //Draw window title and list outline
            if (Event.current.type == EventType.Repaint)
            {
                this.DrawWindowTitle(inRect);

                Utilities.BoxOutline(scrollViewBox);
            }

            //Toggle Displayed Pawns button
            if (Widgets.ButtonText(toggleButtonRect.ContractedBy(Utilities.ShortSpacing), this.ToggleButtonText, true, false, true))
            {
                Controller.ColonistSkillsVisibleMap = !Controller.ColonistSkillsVisibleMap;

                this.mustRecacheColonists = true;

                Utilities.UserFeedbackChain(WorkSound.CompareSkillsMapChanged);
            }

            //Draw primaries
            Vector2 positionSetter = new Vector2(primariesRect.x + Utilities.ShortSpacing + Utilities.SmallDraggableDiameter / 2f, primariesRect.center.y);

            for (int i = 0; i < primariesList.Count; i++)
            {
                PrimaryWork primary = primariesList[i];

                this.primariesPositions[primary.def] = positionSetter.x;

                Rect drawRect = positionSetter.ToWorkRect(Utilities.SmallDraggableDiameter);

                if (Event.current.type == EventType.Repaint)
                {
                    primary.DrawTexture(drawRect);

                    if (drawRect.Contains(Event.current.mousePosition))
                    {
                        primary.OnHover(drawRect, true);
                    }

                    //Draw little arrow indicator below work type
                    if (this.sortingOrder != SortOrder.Undefined && this.sortingDef == primary.def)
                    {
                        Texture2D icon          = this.sortingOrder == SortOrder.Descending ? Utilities.SortingDescendingIcon : Utilities.SortingAscendingIcon;
                        Rect      iconRect      = new Rect(drawRect.xMax - icon.width, drawRect.yMax + 1f, icon.width, icon.height);
                        Rect      highlightRect = new Rect(drawRect.xMin - 3f, drawRect.yMin - 3f, drawRect.width + 6f, drawRect.height + 6f);

                        GUI.DrawTexture(iconRect, icon);

                        Widgets.DrawHighlight(highlightRect);
                    }
                }

                else if (Event.current.type == EventType.MouseDown && drawRect.Contains(Event.current.mousePosition))
                {
                    this.DoSortingChecks(primary.def);
                }

                positionSetter.x += Utilities.SmallDraggableDiameter + Utilities.ShortSpacing;
            }

            Widgets.BeginScrollView(scrollViewOuterRect, ref this.scrollPosition, scrollViewInnerRect, true);

            float dynamicVerticalY = scrollViewInnerRect.yMin;

            //Determine which surfaces will actually be seen
            DingoUtils.CacheScrollview(false, this.scrollPosition.y, scrollViewOuterRect.height, Utilities.SmallRowHeight, this.cachedPawnSurfaces.Count, ref dynamicVerticalY, out int firstItem, out int lastItem);

            for (int j = firstItem; j <= lastItem; j++)
            {
                PawnSurface surface = this.cachedPawnSurfaces[j];

                Rect  nameRect           = new Rect(scrollViewInnerRect.x, dynamicVerticalY, Utilities.SpaceForPawnLabel, Utilities.SmallRowHeight);
                Rect  surfaceRect        = new Rect(nameRect.xMax, dynamicVerticalY, Utilities.SmallSurfaceWidth, Utilities.SmallRowHeight);
                float surfaceRectCenterY = surfaceRect.center.y;

                if (Event.current.type == EventType.Repaint)
                {
                    if (j != 0)
                    {
                        Utilities.ListSeparator(scrollViewInnerRect, dynamicVerticalY);
                    }

                    //Draw surface
                    for (int p = 0; p < primariesList.Count; p++)
                    {
                        WorkTypeDef   def               = primariesList[p].def;
                        DraggableWork draggable         = surface.childByDef[def];
                        Vector2       draggablePosition = new Vector2(this.primariesPositions[def], surfaceRectCenterY);
                        Rect          drawRect          = draggablePosition.ToWorkRect(Utilities.SmallDraggableDiameter);

                        draggable.DrawTexture(drawRect);

                        if (drawRect.Contains(Event.current.mousePosition))
                        {
                            draggable.OnHover(drawRect, true);
                        }
                    }
                }

                Utilities.PawnLabel(nameRect, surface.pawn);

                dynamicVerticalY += Utilities.SmallRowHeight;
            }

            Widgets.EndScrollView();
        }
Ejemplo n.º 2
0
        public override void DoWindowContents(Rect inRect)
        {
            base.DoWindowContents(inRect);

            //Build rects
            Rect indicatorsRect = new Rect(inRect.xMax - Utilities.PawnSurfaceWidth - Utilities.SpaceForScrollBar + Utilities.ShortSpacing, inRect.y, Utilities.PawnSurfaceWidth - 3f * Utilities.ShortSpacing, Utilities.TinyTextLineHeight);

            float topControlsY = indicatorsRect.yMax + Utilities.ShortSpacing;

            Rect compareSkillsButtonRect = new Rect(inRect.x - this.horizontalOffset + Utilities.ShortSpacing, topControlsY, Utilities.SpaceForPawnLabel, Utilities.DraggableDiameter);
            Rect primaryWorkButtonRect   = new Rect(compareSkillsButtonRect.xMax + 2f * Utilities.ShortSpacing, topControlsY, Utilities.DraggableDiameter, Utilities.DraggableDiameter);
            Rect primariesRect           = new Rect(primaryWorkButtonRect.xMax, topControlsY, Utilities.PawnSurfaceWidth, Utilities.DraggableDiameter);

            Rect scrollViewBox       = new Rect(inRect.x, indicatorsRect.yMax + Utilities.StandardRowHeight, inRect.width, inRect.height - indicatorsRect.height - Utilities.StandardRowHeight);
            Rect scrollViewOuterRect = scrollViewBox.ContractedBy(Utilities.ShortSpacing);
            Rect scrollViewInnerRect = new Rect(scrollViewOuterRect.x, scrollViewOuterRect.y, Utilities.SpaceForPawnLabel + Utilities.SpaceForWorkButton + Utilities.PawnSurfaceWidth, this.cachedPawnSurfaces.Count * Utilities.StandardRowHeight);

            if (scrollViewInnerRect.width > scrollViewOuterRect.width)
            {
                scrollViewInnerRect.yMax += Utilities.SpaceForScrollBar;
            }

            //Draw indicators, primaries and list outline
            if (Event.current.type == EventType.Repaint)
            {
                this.DrawPriorityIndicators(indicatorsRect);

                Controller.GetPrimaries.DrawSurface(primariesRect);

                Utilities.BoxOutline(scrollViewBox);
            }

            //Compare Skills button
            if (Widgets.ButtonText(compareSkillsButtonRect, "DD_WorkTab_Work_CompareSkills".CachedTranslation(), true, false, true))
            {
                Find.WindowStack.Add(new Window_ColonistSkills());

                Utilities.UserFeedbackChain(WorkSound.CompareSkillsMapChanged);
            }

            //Float menu button
            Utilities.WorkButton(primaryWorkButtonRect, null);

            //Check for primary-related GUI triggers
            Controller.GetPrimaries.DoWorkTabEventChecks(primariesRect);

            Widgets.BeginScrollView(scrollViewOuterRect, ref this.scrollPosition, scrollViewInnerRect, true);

            Controller.CurrentDraggable?.OnDrag();             //Update draggable position within the list

            float dynamicVerticalY = scrollViewInnerRect.yMin;

            //Determine which surfaces will actually be seen
            DingoUtils.CacheScrollview(false, this.scrollPosition.y, scrollViewOuterRect.height, Utilities.StandardRowHeight, this.cachedPawnSurfaces.Count, ref dynamicVerticalY, out int firstItem, out int lastItem);

            for (int i = firstItem; i <= lastItem; i++)
            {
                PawnSurface surface = this.cachedPawnSurfaces[i];

                Rect labelRect   = new Rect(scrollViewInnerRect.x, dynamicVerticalY, Utilities.SpaceForPawnLabel, Utilities.StandardRowHeight);
                Rect buttonRect  = new Rect(labelRect.xMax + 2f * Utilities.ShortSpacing, dynamicVerticalY + Utilities.ShortSpacing, Utilities.DraggableDiameter, Utilities.DraggableDiameter);
                Rect surfaceRect = new Rect(buttonRect.xMax, dynamicVerticalY, Utilities.PawnSurfaceWidth, Utilities.StandardRowHeight);

                if (Event.current.type == EventType.Repaint)
                {
                    if (i != 0)
                    {
                        Utilities.ListSeparator(scrollViewInnerRect, dynamicVerticalY);
                    }

                    surface.DrawSurface(surfaceRect);
                }

                Utilities.PawnLabel(labelRect, surface.pawn);

                Utilities.WorkButton(buttonRect, surface);

                surface.DoWorkTabEventChecks(surfaceRect);

                dynamicVerticalY += Utilities.StandardRowHeight;
            }

            //Render current Draggable on top of other textures
            DraggableWork currentDraggable = Controller.CurrentDraggable;

            if (Event.current.type == EventType.Repaint && currentDraggable != null)
            {
                Rect drawRect = currentDraggable.position.ToWorkRect();

                currentDraggable.DrawTexture(drawRect);
            }

            Widgets.EndScrollView();
        }