Exemplo n.º 1
0
        public void ModSetMayor()
        {
            UIAlert.Prompt("", "Enter an avatar name to set as the mayor of this Neighborhood.", true, (search) =>
            {
                if (search == null)
                {
                    return;
                }

                var cont = FSOFacade.Kernel.Get <GenericSearchController>();
                cont.Search(search, true, avas =>
                {
                    if (avas == null || avas.Count == 0)
                    {
                        UIAlert.Alert("", "Could not find that avatar.", true);
                        return;
                    }
                    var target = avas[0];
                    UIAlert.YesNo("", $"This action will replace the current mayor with {target.Result.Name}. Is this OK?", true,
                                  (response) =>
                    {
                        if (response)
                        {
                            View.FindController <CoreGameScreenController>().NeighborhoodProtocol.SetMayor(NeighId, target.Result.EntityId,
                                                                                                           (success) =>
                            {
                                if (success == Server.Protocol.Electron.Packets.NhoodResponseCode.SUCCESS)
                                {
                                    UIAlert.Alert("", $"Successfully set the Mayor to {target.Result.Name}", true);
                                    ChangeTopic();
                                }
                            });
                        }
                    });
                });
            });
        }
Exemplo n.º 2
0
        private void NhoodGameplayBan(uint avatarID)
        {
            var controller = UIScreen.Current.FindController <FSO.Client.Controllers.CoreGameScreenController>();

            UIAlert.Prompt("Neighborhood Gameplay Ban", "Ban this user for how long? (in days, 0 for perma)", true, (result) =>
            {
                if (result == null)
                {
                    return;
                }
                uint dayCount;
                if (!uint.TryParse(result, out dayCount))
                {
                    UIAlert.Alert("Neighborhood Gameplay Ban", "Invalid number of days. Please try again.", true);
                }
                uint untilDate = (dayCount == 0) ? uint.MaxValue : ClientEpoch.Now + dayCount * 60 * 60 * 24;

                UIAlert.Prompt("Neighborhood Gameplay Ban", "What message do you want to leave? (optional)", true, (result2) =>
                {
                    if (result2 == null)
                    {
                        return;
                    }
                    if (controller != null)
                    {
                        controller.NeighborhoodProtocol.BanUser(avatarID, untilDate, result2, (code) =>
                        {
                            //response
                            if (code == Server.Protocol.Electron.Packets.NhoodResponseCode.SUCCESS)
                            {
                                UIAlert.Alert("Neighborhood Gameplay Ban", "Ban has been submitted. Note that if you ban someone twice your second ban will overwrite the first.", true);
                            }
                        });
                    }
                });
            });
        }
Exemplo n.º 3
0
        public override void Update(UpdateState state)
        {
            mp = state.MouseState.Position.ToVector2();
            var md = state.MouseState.LeftButton == ButtonState.Pressed;

            CtrlDown  = state.CtrlDown;
            ShiftDown = state.ShiftDown;

            if (md != MouseWasDown)
            {
                if (md)
                {
                    if (ShiftDown)
                    {
                        var neigh = new CityNeighbourhood()
                        {
                            Location = new Point(256, 256),
                            Name     = "Neigh" + EditTarget.Count
                        };
                        EditTarget.Add(neigh);
                        Selected = neigh;
                    }
                    else
                    {
                        var closest = EditTarget.OrderBy(x => (City.Get2DFromTile(x.Location.X, x.Location.Y) - state.MouseState.Position.ToVector2()).Length()).FirstOrDefault();
                        if (closest != null && (City.Get2DFromTile(closest.Location.X, closest.Location.Y) - state.MouseState.Position.ToVector2()).Length() < 16)
                        {
                            if (CtrlDown)
                            {
                                EditTarget.Remove(closest);
                                City.NeighGeom.Generate(GameFacade.GraphicsDevice);
                            }
                            else
                            {
                                Selected = closest;
                            }
                        }
                    }
                }
                else
                {
                    Selected = null;
                }
                MouseWasDown = md;
            }

            if (state.NewKeys.Contains(Keys.R))
            {
                var proj = City.EstTileAtPosWithScroll(state.MouseState.Position.ToVector2(), null);
                var near = City.NeighGeom.NhoodNearest(proj);

                if (near != -1)
                {
                    var nhood = City.NeighGeom.Data[near];
                    UIAlert.Prompt(new UIAlertOptions()
                    {
                        Message   = "Rename this neighbourhood to what?",
                        TextEntry = true
                    }, (result, alert) =>
                    {
                        if (result)
                        {
                            nhood.Name = alert.ResponseText;
                        }
                    });
                }
            }

            if (state.NewKeys.Contains(Keys.C))
            {
                var proj = City.EstTileAtPosWithScroll(state.MouseState.Position.ToVector2(), null);
                var near = City.NeighGeom.NhoodNearest(proj);

                if (near != -1)
                {
                    var nhood = City.NeighGeom.Data[near];
                    UIAlert.Prompt(new UIAlertOptions()
                    {
                        Message         = "Change this neighbourhood colour to what?",
                        GenericAddition = new UIColorPicker()
                    }, (result, alert) =>
                    {
                        if (result)
                        {
                            var col     = int.Parse(alert.ResponseText);
                            nhood.Color = new Color(col >> 16, (col >> 8) & 0xFF, col & 0xFF);
                        }
                    });
                }
            }

            if (state.NewKeys.Contains(Keys.F10))
            {
                if (state.ShiftDown)
                {
                    using (var file = System.IO.File.Open("Content/edit_neigh.json", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                        using (var writer = new System.IO.StreamWriter(file))
                            writer.Write(Newtonsoft.Json.JsonConvert.SerializeObject(EditTarget, Newtonsoft.Json.Formatting.Indented));
                }
                else
                {
                    using (var file = System.IO.File.Open("Content/edit_neigh.json", System.IO.FileMode.Open, System.IO.FileAccess.Read))
                        using (var reader = new System.IO.StreamReader(file))
                        {
                            EditTarget = JsonConvert.DeserializeObject <List <CityNeighbourhood> >(reader.ReadToEnd());
                            CityNeighbourhood.Init(EditTarget);
                            City.NeighGeom.Data = EditTarget;
                            City.NeighGeom.Generate(GameFacade.GraphicsDevice);
                        }
                }
            }
        }
Exemplo n.º 4
0
        public UIModMenu() : base(UIDialogStyle.Tall | UIDialogStyle.Close, true)
        {
            SetSize(380, 300);
            Caption = "Do what to this user?";

            Position = new Microsoft.Xna.Framework.Vector2(
                (GlobalSettings.Default.GraphicsWidth / 2.0f) - (480 / 2),
                (GlobalSettings.Default.GraphicsHeight / 2.0f) - 150
                );

            IPBanButton                = new UIButton();
            IPBanButton.Caption        = "IP Ban";
            IPBanButton.Position       = new Microsoft.Xna.Framework.Vector2(40, 50);
            IPBanButton.Width          = 300;
            IPBanButton.OnButtonClick += x =>
            {
                var controller = FindController <FSO.Client.Controllers.CoreGameScreenController>();
                if (controller != null)
                {
                    controller.ModRequest(AvatarID, ModerationRequestType.IPBAN_USER);
                }
                UIScreen.RemoveDialog(this);
            };
            Add(IPBanButton);

            var BanButton = new UIButton();

            BanButton.Caption        = "Ban User";
            BanButton.Position       = new Microsoft.Xna.Framework.Vector2(40, 90);
            BanButton.Width          = 300;
            BanButton.OnButtonClick += x =>
            {
                var controller = FindController <FSO.Client.Controllers.CoreGameScreenController>();
                if (controller != null)
                {
                    controller.ModRequest(AvatarID, ModerationRequestType.BAN_USER);
                }
                UIScreen.RemoveDialog(this);
            };
            Add(BanButton);

            var kickButton = new UIButton();

            kickButton.Caption        = "Kick Avatar";
            kickButton.Position       = new Microsoft.Xna.Framework.Vector2(40, 130);
            kickButton.Width          = 300;
            kickButton.OnButtonClick += x =>
            {
                var controller = FindController <FSO.Client.Controllers.CoreGameScreenController>();
                if (controller != null)
                {
                    controller.ModRequest(AvatarID, ModerationRequestType.KICK_USER);
                }
                UIScreen.RemoveDialog(this);
            };
            Add(kickButton);

            var nhoodBanButton = new UIButton();

            nhoodBanButton.Caption        = "Nhood Ban";
            nhoodBanButton.Position       = new Microsoft.Xna.Framework.Vector2(40, 170);
            nhoodBanButton.Width          = 300;
            nhoodBanButton.OnButtonClick += x =>
            {
                var controller = FindController <FSO.Client.Controllers.CoreGameScreenController>();

                UIAlert.Prompt("Neighborhood Gameplay Ban", "Ban this user for how long? (in days, 0 for perma)", true, (result) =>
                {
                    if (result == null)
                    {
                        return;
                    }
                    uint dayCount;
                    if (!uint.TryParse(result, out dayCount))
                    {
                        UIAlert.Alert("Neighborhood Gameplay Ban", "Invalid number of days. Please try again.", true);
                    }
                    uint untilDate = (dayCount == 0) ? uint.MaxValue : ClientEpoch.Now + dayCount * 60 * 60 * 24;

                    UIAlert.Prompt("Neighborhood Gameplay Ban", "What message do you want to leave? (optional)", true, (result2) =>
                    {
                        if (result2 == null)
                        {
                            return;
                        }
                        if (controller != null)
                        {
                            controller.NeighborhoodProtocol.BanUser(AvatarID, untilDate, result2, (code) =>
                            {
                                //response
                                if (code == Server.Protocol.Electron.Packets.NhoodResponseCode.SUCCESS)
                                {
                                    UIAlert.Alert("Neighborhood Gameplay Ban", "Ban has been submitted. Note that if you ban someone twice your second ban will overwrite the first.", true);
                                }
                            });
                        }
                    });
                });
            };
            Add(nhoodBanButton);
            //*MENTORS
            var changeMentorStatusButton = new UIButton();

            changeMentorStatusButton.Caption        = "Toggle Mentor Status";
            changeMentorStatusButton.Position       = new Microsoft.Xna.Framework.Vector2(40, 210);
            changeMentorStatusButton.Width          = 300;
            changeMentorStatusButton.OnButtonClick += x =>
            {
                var controller = FindController <FSO.Client.Controllers.CoreGameScreenController>();
                if (controller != null)
                {
                    controller.ModRequest(AvatarID, ModerationRequestType.CHANGE_MENTOR_STATUS);
                }
                UIScreen.RemoveDialog(this);
            };
            Add(changeMentorStatusButton);

            CloseButton.OnButtonClick += CloseButton_OnButtonClick;
        }
Exemplo n.º 5
0
        public UIDebugMenu() : base(UIDialogStyle.Tall, true)
        {
            SetSize(500, 300);
            Caption = "Debug Tools";

            Position = new Microsoft.Xna.Framework.Vector2(
                (GlobalSettings.Default.GraphicsWidth / 2.0f) - 250,
                (GlobalSettings.Default.GraphicsHeight / 2.0f) - 150
                );

            Add(new UIImage()
            {
                Texture  = GetTexture(0x00000Cbfb00000001),
                Position = new Microsoft.Xna.Framework.Vector2(40, 95)
            });

            ContentBrowserBtn                = new UIButton();
            ContentBrowserBtn.Caption        = "Nhood Global Cycle";
            ContentBrowserBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 50);
            ContentBrowserBtn.Width          = 300;
            ContentBrowserBtn.OnButtonClick += x =>
            {
                UIAlert.Prompt("Force Cycle", "How many days in the future do you want neighbourhoods to process?", true, (response) =>
                {
                    uint result;
                    if (!uint.TryParse(response, out result))
                    {
                        return;
                    }

                    FindController <CoreGameScreenController>()?.NeighborhoodProtocol.PretendDate(ClientEpoch.Now + 60 * 60 * 24 * result, (code) => { });
                });
            };
            Add(ContentBrowserBtn);

            var connectLocalBtn = new UIButton();

            connectLocalBtn.Caption        = (GlobalSettings.Default.UseCustomServer) ? "Use default server (TSO)" : "Use custom defined server";
            connectLocalBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 90);
            connectLocalBtn.Width          = 300;
            connectLocalBtn.OnButtonClick += x =>
            {
                GlobalSettings.Default.UseCustomServer = !GlobalSettings.Default.UseCustomServer;
                connectLocalBtn.Caption = (GlobalSettings.Default.UseCustomServer) ? "Use default server (TSO)" : "Use custom defined server";
                GlobalSettings.Default.Save();
            };
            Add(connectLocalBtn);

            var cityPainterBtn = new UIButton();

            cityPainterBtn.Caption        = "City Painter";
            cityPainterBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 130);
            cityPainterBtn.Width          = 150;
            cityPainterBtn.OnButtonClick += x =>
            {
                var core = (GameFacade.Screens.CurrentUIScreen as CoreGameScreen);
                if (core == null)
                {
                    return;
                }
                if (core.CityRenderer.Plugin == null)
                {
                    core.CityRenderer.Plugin = new Rendering.City.Plugins.MapPainterPlugin(core.CityRenderer);
                    cityPainterBtn.Caption   = "Disable Painter";
                }
                else
                {
                    core.CityRenderer.Plugin = null;
                    cityPainterBtn.Caption   = "City Painter";
                }
            };
            Add(cityPainterBtn);

            var ngbhBtn = new UIButton();

            ngbhBtn.Caption        = "Ngbh Editor";
            ngbhBtn.Position       = new Microsoft.Xna.Framework.Vector2(160 + 150, 130);
            ngbhBtn.Width          = 150;
            ngbhBtn.OnButtonClick += x =>
            {
                var core = (GameFacade.Screens.CurrentUIScreen as CoreGameScreen);
                if (core == null)
                {
                    return;
                }
                if (core.CityRenderer.Plugin == null)
                {
                    core.CityRenderer.Plugin = new Rendering.City.Plugins.NeighbourhoodEditPlugin(core.CityRenderer);
                    ngbhBtn.Caption          = "Disable Editor";
                }
                else
                {
                    core.CityRenderer.Plugin = null;
                    ngbhBtn.Caption          = "Ngbh Editor";
                }
            };
            Add(ngbhBtn);

            var benchmarkBtn = new UIButton();

            benchmarkBtn.Caption        = "VM Performance Benchmark (100k ticks)";
            benchmarkBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 170);
            benchmarkBtn.Width          = 300;
            benchmarkBtn.OnButtonClick += x =>
            {
                var core = (GameFacade.Screens.CurrentUIScreen as IGameScreen);
                if (core == null || core.vm == null)
                {
                    UIScreen.GlobalShowAlert(new UIAlertOptions()
                    {
                        Message = "A VM must be running to benchmark performance."
                    }, true);
                    return;
                }
                var watch = new Stopwatch();
                watch.Start();

                var vm   = core.vm;
                var tick = vm.Scheduler.CurrentTickID + 1;
                for (int i = 0; i < 100000; i++)
                {
                    vm.InternalTick(tick++);
                }

                watch.Stop();

                UIScreen.GlobalShowAlert(new UIAlertOptions()
                {
                    Message = "Ran 100k ticks in " + watch.ElapsedMilliseconds + "ms."
                }, true);
            };
            Add(benchmarkBtn);

            var resyncBtn = new UIButton();

            resyncBtn.Caption        = "Lot Disconnect";
            resyncBtn.Position       = new Microsoft.Xna.Framework.Vector2(160, 210);
            resyncBtn.Width          = 150;
            resyncBtn.OnButtonClick += x =>
            {
                var kernel = FSOFacade.Kernel;
                if (kernel != null)
                {
                    var reg = kernel.Get <Regulators.LotConnectionRegulator>();
                    reg.Client.Disconnect();
                }

                /*
                 * var core = (GameFacade.Screens.CurrentUIScreen as IGameScreen);
                 * if (core == null || core.vm == null)
                 * {
                 *  UIScreen.GlobalShowAlert(new UIAlertOptions()
                 *  {
                 *      Message = "A VM must be running to force a resync."
                 *  }, true);
                 *  return;
                 * }
                 * core.vm.SendCommand(new VMRequestResyncCmd());
                 */
            };
            Add(resyncBtn);

            var cityDCBtn = new UIButton();

            cityDCBtn.Caption        = "City Disconnect";
            cityDCBtn.Position       = new Microsoft.Xna.Framework.Vector2(160 + 150, 210);
            cityDCBtn.Width          = 150;
            cityDCBtn.OnButtonClick += x =>
            {
                var kernel = FSOFacade.Kernel;
                if (kernel != null)
                {
                    var reg = kernel.Get <Regulators.CityConnectionRegulator>();
                    reg.Client.Disconnect();
                }
            };
            Add(cityDCBtn);

            serverNameBox   = new UITextBox();
            serverNameBox.X = 50;
            serverNameBox.Y = 300 - 54;
            serverNameBox.SetSize(500 - 100, 25);
            serverNameBox.CurrentText = GlobalSettings.Default.GameEntryUrl;

            Add(serverNameBox);
        }