public AreaExt CloneWithOperationArea(AreaExtOperator op, Area area)
        {
            List <KeyValuePair <int, AreaExtOperator> > newAreaList = new List <KeyValuePair <int, AreaExtOperator> >(areaExtID.Areas);

            newAreaList.RemoveAll(x => x.Key == area.ID);

            AreaExtID newID = areaExtID;

            if (op == AreaExtOperator.Inclusion)
            {
                newAreaList.Insert(0, new KeyValuePair <int, AreaExtOperator>(area.ID, AreaExtOperator.Inclusion));
            }
            else if (op == AreaExtOperator.Exclusion)
            {
                newAreaList.Add(new KeyValuePair <int, AreaExtOperator>(area.ID, AreaExtOperator.Exclusion));
            }
            else
            {
                if (newAreaList.Count == 0)
                {
                    return(null);
                }
            }

            newID = new AreaExtID(areaManager.map.uniqueID, newAreaList);
            return(new AreaExt(newID));
        }
        public AreaExt(Map map, AreaExtOperator op, Area area)
        {
            var areaIDList = new List <KeyValuePair <int, AreaExtOperator> >();

            areaIDList.Add(new KeyValuePair <int, AreaExtOperator>(area.ID, op));

            this.areaExtID = new AreaExtID(map.uniqueID, areaIDList);
            this.Init();

            AreaExtEventManager.Register(this);
        }
 public bool Contains(Area area, AreaExtOperator op) => areaExtID.Areas.Any(x => x.Key == area?.ID && x.Value == op);
        public void Update()
        {
#if DEBUG
            var watch = System.Diagnostics.Stopwatch.StartNew();
#endif

            Map map = Find.Maps.Find(x => x.uniqueID == areaExtID.MapID);
            if (map == null)
            {
                return;
            }

            this.areaManager = map.areaManager;

            var innerAreas = InnerAreas;

            BoolGrid innerGrid = (BoolGrid)FieldInfos.innerGrid.GetValue(this);
            bool[]   arr       = (bool[])FieldInfos.boolGridArr.GetValue(innerGrid);

            BitArray arrBA = new BitArray(arr);
            if (innerAreas.Count > 0 && innerAreas.Any(x => x.Value == AreaExtOperator.Inclusion))
            {
                arrBA.SetAll(false);
            }
            else
            {
                arrBA.SetAll(true);
            }

            var areaNameBuilder = new StringBuilder();
            for (int i = 0; i < innerAreas.Count; ++i)
            {
                var kv = innerAreas[i];

                Area            area = kv.Key;
                AreaExtOperator op   = kv.Value;

                BitArray targetArrBA = GetAreaBitArray(area);
                if (op == AreaExtOperator.Inclusion)
                {
                    arrBA = arrBA.Or(targetArrBA);
                    if (i > 0)
                    {
                        areaNameBuilder.Append("+");
                    }
                }
                else if (op == AreaExtOperator.Exclusion)
                {
                    arrBA = arrBA.And(targetArrBA.Not());
                    areaNameBuilder.Append("-");
                }

                areaNameBuilder.Append(area.Label);
            }

            arrBA.CopyTo(arr, 0);
            FieldInfos.boolGridArr.SetValue(innerGrid, arr);
            FieldInfos.boolGridTrueCount.SetValue(innerGrid, arr.Count(x => x));

            cachedLabel = areaNameBuilder.ToString();

            if (innerAreas.Count == 1)
            {
                cachedColor = innerAreas[0].Key.Color;
            }
            else
            {
                cachedColor = Color.black;
            }

            initialized  = true;
            drawer.dirty = true;

#if DEBUG
            watch.Stop();
            Log.Message(string.Format("Update elapsed : {0}", watch.ElapsedMilliseconds));
#endif
        }
예제 #5
0
        public void RegenerateMesh()
        {
            foreach (var m in meshes)
            {
                m.Clear();
            }
            meshes.Clear();

            float y = AltitudeLayer.MapDataOverlay.AltitudeFor();

            int            cells  = 0;
            List <Vector3> verts  = new List <Vector3>();
            List <Color>   colors = new List <Color>();
            List <int>     tris   = new List <int>();
            Mesh           mesh   = new Mesh();

            var mapSize = parentAreaExt.Map.Size;

            BitArray exclusionBA         = null;
            bool     needToCalcExclusion = true;

            var innerAreas = parentAreaExt.InnerAreas;

            for (int i = 0; i < innerAreas.Count; ++i)
            {
                Area            area = innerAreas[i].Key;
                AreaExtOperator op   = innerAreas[i].Value;

                if (op == AreaExtOperator.Inclusion)
                {
                    if (needToCalcExclusion)
                    {
                        exclusionBA = new BitArray(mapSize.x * mapSize.z);
                        exclusionBA.SetAll(false);

                        for (int j = i + 1; j < innerAreas.Count; ++j)
                        {
                            if (innerAreas[j].Value != AreaExtOperator.Exclusion)
                            {
                                continue;
                            }

                            exclusionBA = exclusionBA.Or(AreaExt.GetAreaBitArray(innerAreas[j].Key));
                        }

                        exclusionBA = exclusionBA.Not();
                    }

                    CellRect cellRect = new CellRect(0, 0, mapSize.x, mapSize.z);
                    for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                    {
                        for (int k = cellRect.minZ; k <= cellRect.maxZ; k++)
                        {
                            int index = CellIndicesUtility.CellToIndex(j, k, mapSize.x);
                            if (area[index] && exclusionBA[index])
                            {
                                verts.Add(new Vector3((float)j, y, (float)k));
                                verts.Add(new Vector3((float)j, y, (float)(k + 1)));
                                verts.Add(new Vector3((float)(j + 1), y, (float)(k + 1)));
                                verts.Add(new Vector3((float)(j + 1), y, (float)k));
                                colors.Add(area.Color);
                                colors.Add(area.Color);
                                colors.Add(area.Color);
                                colors.Add(area.Color);

                                int count = verts.Count;
                                tris.Add(count - 4);
                                tris.Add(count - 3);
                                tris.Add(count - 2);
                                tris.Add(count - 4);
                                tris.Add(count - 2);
                                tris.Add(count - 1);

                                cells++;
                                if (cells >= 16383)
                                {
                                    mesh.SetVertices(verts);
                                    mesh.SetColors(colors);
                                    mesh.SetTriangles(tris, 0);

                                    verts.Clear();
                                    colors.Clear();
                                    tris.Clear();

                                    meshes.Add(mesh);
                                    mesh = new Mesh();

                                    cells = 0;
                                }
                            }
                        }
                    }
                }
                else
                {
                    needToCalcExclusion = true;
                }
            }

            if (verts.Count > 0)
            {
#if DEBUG
                Log.Message(string.Format("Vertices: {0}", verts.Count));
#endif
                mesh.SetVertices(verts);
                mesh.SetColors(colors);
                mesh.SetTriangles(tris, 0);
                meshes.Add(mesh);
            }

            if (material == null)
            {
                material             = SolidColorMaterials.SimpleSolidColorMaterial(new Color(1f, 1f, 1f, opacity), true);
                material.renderQueue = 3600;
            }

            dirty = false;
        }
        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);
        }
예제 #7
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);
        }