public static bool DoAreaSelectorPrefix(Rect rect, Pawn p, Area area)
        {
            MouseoverSounds.DoRegion(rect);
            rect = rect.ContractedBy(1f);
            GUI.DrawTexture(rect, (area == null) ? BaseContent.GreyTex : area.ColorTexture);
            Text.Anchor = TextAnchor.MiddleLeft;
            string text  = AreaUtility.AreaAllowedLabel_Area(area);
            Rect   rect2 = rect;

            rect2.xMin += 3f;
            rect2.yMin += 2f;
            Widgets.Label(rect2, text);

            bool            dragging         = (bool)FieldInfos.dragging.GetValue(null);
            Area            currentArea      = p.playerSettings.AreaRestriction;
            AreaExt         currentAreaExt   = p.playerSettings.AreaRestriction as AreaExt;
            AreaExtOperator currentAreaExtOp = currentAreaExt?.GetAreaOperator(area?.ID ?? -1) ?? AreaExtOperator.None;

            // null area인 경우, 현재 구역의 첫 구역이 exclusion이면 inclusion으로 선택된것처럼 출력해준다. (실제로는 아님)
            if (area == null)
            {
                if (currentArea == null || (currentAreaExt != null && currentAreaExt.IsWholeExclusive))
                {
                    GUI.color = Color.white;
                    Widgets.DrawBox(rect, 2);
                    GUI.color = Color.white;
                }
            }
            else
            {
                if (currentAreaExt != null)
                {
                    if (currentAreaExtOp == AreaExtOperator.Inclusion)
                    {
                        GUI.color = Color.white;
                        Widgets.DrawBox(rect, 2);
                        GUI.color = Color.white;
                    }
                    else if (currentAreaExtOp == AreaExtOperator.Exclusion)
                    {
                        GUI.color = Color.red;
                        Widgets.DrawBox(rect, 2);
                        GUI.color = Color.white;
                    }
                }
                else
                {
                    if (currentArea == area)
                    {
                        Widgets.DrawBox(rect, 2);
                    }
                }
            }

            bool mouseOver   = Mouse.IsOver(rect);
            bool leftButton  = Event.current.button == 0;
            bool rightButton = Event.current.button == 1;

            if (mouseOver && area != null)
            {
                area.MarkForDraw();
            }

            if (editMode == AreaAllowedEditMode.None)
            {
                if (mouseOver && dragging)
                {
                    if (leftButton)
                    {
                        // 구역이 null이 아니면서, 현재 선택되어있다면 Remove, 아니면 Inclusion
                        if (area != null && (currentArea == area || currentAreaExtOp == AreaExtOperator.Inclusion))
                        {
                            editMode = AreaAllowedEditMode.Remove;
                        }
                        else
                        {
                            editMode = AreaAllowedEditMode.AddInclusion;
                        }
                    }
                    else if (rightButton)
                    {
                        // 이미 Exclusion으로 선택된것만 Remove, 아니면 Exclusion으로 덮어쓰거나 수정하지 않음
                        if (currentAreaExtOp == AreaExtOperator.Exclusion)
                        {
                            editMode = AreaAllowedEditMode.Remove;
                        }
                        else if (area != null)
                        {
                            editMode = AreaAllowedEditMode.AddExclusion;
                        }
                    }
                }
            }

            if (editMode == AreaAllowedEditMode.AddInclusion)
            {
                if (mouseOver && dragging)
                {
                    if (currentArea != area)
                    {
                        if (area == null)
                        {
                            p.playerSettings.AreaRestriction = null;
                        }
                        else
                        {
                            if (currentArea == null)
                            {
                                p.playerSettings.AreaRestriction = area;
                            }
                            else
                            {
                                if (currentAreaExt != null)
                                {
                                    if (!currentAreaExt.Contains(area, AreaExtOperator.Inclusion))
                                    {
                                        p.playerSettings.AreaRestriction = currentAreaExt.CloneWithOperationArea(AreaExtOperator.Inclusion, area);
                                    }
                                }
                                else
                                {
                                    p.playerSettings.AreaRestriction = new AreaExt(currentArea.Map, AreaExtOperator.Inclusion, currentArea).CloneWithOperationArea(AreaExtOperator.Inclusion, area);
                                }
                            }
                        }
                    }
                }
                else if (!dragging)
                {
                    editMode = AreaAllowedEditMode.None;
                }
            }
            else if (editMode == AreaAllowedEditMode.AddExclusion)
            {
                if (mouseOver && dragging)
                {
                    if (currentArea != area)
                    {
                        if (area == null)
                        {
                            p.playerSettings.AreaRestriction = null;
                        }
                        else
                        {
                            if (currentArea == null)
                            {
                                p.playerSettings.AreaRestriction = new AreaExt(area.Map, AreaExtOperator.Exclusion, area);
                            }
                            else
                            {
                                if (currentAreaExt != null)
                                {
                                    if (!currentAreaExt.Contains(area, AreaExtOperator.Exclusion))
                                    {
                                        p.playerSettings.AreaRestriction = currentAreaExt.CloneWithOperationArea(AreaExtOperator.Exclusion, area);
                                    }
                                }
                                else
                                {
                                    p.playerSettings.AreaRestriction = new AreaExt(currentArea.Map, AreaExtOperator.Inclusion, currentArea).CloneWithOperationArea(AreaExtOperator.Exclusion, area);
                                }
                            }
                        }
                    }
                }
                else if (!dragging)
                {
                    editMode = AreaAllowedEditMode.None;
                }
            }
            else if (editMode == AreaAllowedEditMode.Remove)
            {
                if (mouseOver && dragging)
                {
                    if (currentArea != null && area != null)
                    {
                        if (currentArea == area)
                        {
                            p.playerSettings.AreaRestriction = null;
                        }
                        else if (currentAreaExt != null && currentAreaExt.Contains(area))
                        {
                            p.playerSettings.AreaRestriction = currentAreaExt.CloneWithOperationArea(AreaExtOperator.None, area);
                        }
                    }
                }
                else if (!dragging)
                {
                    editMode = AreaAllowedEditMode.None;
                }
            }

            Text.Anchor = TextAnchor.UpperLeft;
            TooltipHandler.TipRegion(rect, text);

            return(false);
        }
Beispiel #2
0
        public static bool DoAreaSelectorPrefix(Rect rect, Pawn p, Area area)
        {
            MouseoverSounds.DoRegion(rect);
            rect = rect.ContractedBy(1f);
            GUI.DrawTexture(rect, (area == null) ? BaseContent.GreyTex : area.ColorTexture);
            Text.Anchor = TextAnchor.MiddleLeft;
            string text  = AreaUtility.AreaAllowedLabel_Area(area);
            Rect   rect2 = rect;

            rect2.xMin += 3f;
            rect2.yMin += 2f;
            Widgets.Label(rect2, text);

            bool    dragging       = (bool)FieldInfos.dragging.GetValue(null);
            Area    currentArea    = p.playerSettings.AreaRestriction;
            AreaExt currentAreaExt = p.playerSettings.AreaRestriction as AreaExt;

            if (area != null && currentAreaExt != null)
            {
                AreaExtOperator areaOp = currentAreaExt.GetAreaOperator(area.ID);
                if (areaOp == AreaExtOperator.Inclusion)
                {
                    GUI.color = Color.white;
                    Widgets.DrawBox(rect, 2);
                    GUI.color = Color.white;
                }
                else if (areaOp == AreaExtOperator.Exclusion)
                {
                    GUI.color = Color.red;
                    Widgets.DrawBox(rect, 2);
                    GUI.color = Color.white;
                }
            }
            else
            {
                if (currentArea == area)
                {
                    Widgets.DrawBox(rect, 2);
                }
            }

            if (Mouse.IsOver(rect))
            {
                if (area != null)
                {
                    area.MarkForDraw();
                }
            }

            if (dragging && Mouse.IsOver(rect))
            {
                if (editMode == AreaAllowedEditMode.None)
                {
                    if (area != null && currentAreaExt != null)
                    {
                        var t = currentAreaExt.GetAreaOperator(area.ID);
                        if (t != AreaExtOperator.None)
                        {
                            if ((Event.current.button == 0 && t == AreaExtOperator.Inclusion) ||
                                (Event.current.button == 1 && t == AreaExtOperator.Exclusion))
                            {
                                editMode = AreaAllowedEditMode.Remove;
                            }
                            else
                            {
                                editMode = Event.current.button == 0 ? AreaAllowedEditMode.AddInclusion : AreaAllowedEditMode.AddExclusion;
                            }
                        }
                        else
                        {
                            editMode = Event.current.button == 0 ? AreaAllowedEditMode.AddInclusion : AreaAllowedEditMode.AddExclusion;
                        }
                    }
                    else
                    {
                        if (currentArea == area)
                        {
                            editMode = AreaAllowedEditMode.Remove;
                        }
                        else
                        {
                            if (Event.current.button == 0)
                            {
                                editMode = AreaAllowedEditMode.AddInclusion;
                            }
                            else if (Event.current.button == 1)
                            {
                                editMode = AreaAllowedEditMode.AddExclusion;
                            }
                        }
                    }
                }

                if (editMode == AreaAllowedEditMode.AddInclusion)
                {
                    if (area == null)
                    {
                        p.playerSettings.AreaRestriction = null;
                        SoundDefOf.Designate_DragStandard_Changed.PlayOneShotOnCamera(null);
                    }
                    else if (currentAreaExt != null)
                    {
                        if (currentAreaExt.GetAreaOperator(area.ID) != AreaExtOperator.Inclusion)
                        {
                            p.playerSettings.AreaRestriction = currentAreaExt.CloneWithOperationArea(AreaExtOperator.Inclusion, area);
                            SoundDefOf.Designate_DragStandard_Changed.PlayOneShotOnCamera(null);
                        }
                    }
                    else
                    {
                        p.playerSettings.AreaRestriction = new AreaExt(area.Map, AreaExtOperator.Inclusion, area);
                        SoundDefOf.Designate_DragStandard_Changed.PlayOneShotOnCamera(null);
                    }
                }

                if (editMode == AreaAllowedEditMode.AddExclusion)
                {
                    if (area == null)
                    {
                        p.playerSettings.AreaRestriction = null;
                        SoundDefOf.Designate_DragStandard_Changed.PlayOneShotOnCamera(null);
                    }
                    else if (currentAreaExt != null)
                    {
                        if (currentAreaExt.GetAreaOperator(area.ID) != AreaExtOperator.Exclusion)
                        {
                            p.playerSettings.AreaRestriction = currentAreaExt.CloneWithOperationArea(AreaExtOperator.Exclusion, area);
                            SoundDefOf.Designate_DragStandard_Changed.PlayOneShotOnCamera(null);
                        }
                    }
                    else
                    {
                        p.playerSettings.AreaRestriction = new AreaExt(area.Map, AreaExtOperator.Exclusion, area);
                        SoundDefOf.Designate_DragStandard_Changed.PlayOneShotOnCamera(null);
                    }
                }

                if (editMode == AreaAllowedEditMode.Remove)
                {
                    if (currentAreaExt != null)
                    {
                        if (area != null)
                        {
                            if (currentAreaExt.GetAreaOperator(area.ID) != AreaExtOperator.None)
                            {
                                p.playerSettings.AreaRestriction = currentAreaExt.CloneWithOperationArea(AreaExtOperator.None, area);
                                SoundDefOf.Designate_DragStandard_Changed.PlayOneShotOnCamera(null);
                            }
                        }
                    }
                    else
                    {
                        if (currentArea != null)
                        {
                            p.playerSettings.AreaRestriction = null;
                            SoundDefOf.Designate_DragStandard_Changed.PlayOneShotOnCamera(null);
                        }
                    }
                }
            }

            Text.Anchor = TextAnchor.UpperLeft;
            TooltipHandler.TipRegion(rect, text);

            return(false);
        }