Пример #1
0
 public void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
 {
     if (!string.IsNullOrEmpty(data.ButtonIdentifier) && Enum.TryParse <TimePeriod>(data.ButtonIdentifier, out var tp) && GenerateTimePeriodCommandToolMenu.TryGetValue(tp, out var generateMenu))
     {
         generateMenu(data.Player);
     }
 }
Пример #2
0
 public static void onButtonPushed(ButtonPressCallbackData data)
 {
     if (!data.ButtonIdentifier.StartsWith(MODNAMESPACE))
     {
         return;
     }
     data.ButtonIdentifier = data.ButtonIdentifier.Remove(0, 22);
     if (data.ButtonIdentifier.StartsWith("RemoveType"))
     {
         data.ButtonIdentifier = data.ButtonIdentifier.Remove(0, 11);
         if (ProductionItems[data.Player.ActiveColony.ColonyID].ContainsKey(data.ButtonIdentifier))
         {
             ProductionItems[data.Player.ActiveColony.ColonyID].Remove(data.ButtonIdentifier);
             Chat.Send(data.Player, "<color=yellow>" + data.ButtonIdentifier + " has been removed</color>");
             SendUI(data.Player);
             return;
         }
         Chat.Send(data.Player, "<color=yellow>" + data.ButtonIdentifier + " was not being recorded, could not remove</color>");
     }
     else if (data.ButtonIdentifier.StartsWith("AddType"))
     {
         string typeName = ItemTypes.GetType(data.Player.Inventory.Items[0].Type).Name;
         if (!ProductionItems[data.Player.ActiveColony.ColonyID].ContainsKey(typeName))
         {
             ProductionItems[data.Player.ActiveColony.ColonyID][typeName] = new int[10];
             Chat.Send(data.Player, "<color=yellow>Added " + typeName + " to production chain will take 5 ingame days to see all data</color>");
             SendUI(data.Player);
             return;
         }
         Chat.Send(data.Player, "<color=yellow>" + typeName + " is already being recorded</color>");
     }
 }
Пример #3
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier == GameLoader.NAMESPACE + ".UnemployedLength" && data.Player.ActiveColony != null)
            {
                NetworkMenu menu = new NetworkMenu();
                menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("UnemployedLength", data.Player));
                menu.Width            = 800;
                menu.Height           = 600;
                menu.ForceClosePopups = true;

                List <ValueTuple <IItem, int> > headerItems = new List <ValueTuple <IItem, int> >();

                headerItems.Add((new Label(new LabelData(_localizationHelper.GetLocalizationKey("Colonist"), UnityEngine.Color.black)), 600));
                headerItems.Add((new Label(new LabelData(_localizationHelper.GetLocalizationKey("TimeToLeave"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));

                menu.Items.Add(new HorizontalRow(headerItems));

                for (var i = 0; i < data.Player.ActiveColony.LaborerCount; i++)
                {
                    var npc      = data.Player.ActiveColony.FindLaborer(i);
                    var npcState = ColonistInventory.Get(npc);

                    List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                    items.Add((new Label(new LabelData(npcState.ColonistsName, UnityEngine.Color.black)), 400));
                    items.Add((new Label(new LabelData(Pipliz.Math.RoundToInt(npcState.UnemployedLeaveTime - TimeCycle.TotalHours) + "h", UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                    menu.Items.Add(new HorizontalRow(items));
                }

                NetworkMenuManager.SendServerPopup(data.Player, menu);
            }
        }
Пример #4
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            if (!data.ButtonIdentifier.Contains(GameLoader.NAMESPACE + ".NewSettlers") &&
                !data.ButtonIdentifier.Contains("Decline"))
            {
                return;
            }

            var replaceOne = data.ButtonIdentifier.Replace(GameLoader.NAMESPACE + ".NewSettlers.", "");
            var val        = replaceOne.Substring(0, replaceOne.IndexOf('.'));

            if (int.TryParse(val, out int colonyId) && ServerManager.ColonyTracker.ColoniesByID.TryGetValue(colonyId, out var colony))
            {
                foreach (var p in colony.Owners)
                {
                    if (p.IsConnected())
                    {
                        NetworkMenuManager.CloseServerPopup(p);
                    }
                }

                if (data.ButtonIdentifier.Contains(".Decline"))
                {
                    return;
                }

                var recruitmentInfoStr = replaceOne.Substring(val.Length).Replace(".Accept.", "");
                var unparsedString     = recruitmentInfoStr.Split('.');
                var addCount           = int.Parse(unparsedString[0]);
                var numbSkilled        = int.Parse(unparsedString[1]);
                var state = ColonyState.GetColonyState(colony);

                AddNewSettlers(addCount, numbSkilled, state);
            }
        }
Пример #5
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier == GameLoader.NAMESPACE + ".BedLocations" &&
                data.Player.ActiveColony != null &&
                BedCache.TryGetValue(data.Player.ActiveColony, out var bso))
            {
                NetworkMenu menu = new NetworkMenu();
                menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("BedLocations", data.Player));
                menu.Width            = 800;
                menu.Height           = 600;
                menu.ForceClosePopups = true;

                List <ValueTuple <IItem, int> > headerItems = new List <ValueTuple <IItem, int> >();

                headerItems.Add((new Label(new LabelData(_localizationHelper.GetLocalizationKey("Position"), UnityEngine.Color.black)), 400));
                headerItems.Add((new Label(new LabelData(_localizationHelper.GetLocalizationKey("Occupied"), UnityEngine.Color.black)), 200));
                headerItems.Add((new Label(new LabelData(_localizationHelper.GetLocalizationKey("Placement"), UnityEngine.Color.black)), 200));

                menu.Items.Add(new HorizontalRow(headerItems));

                foreach (var bed in bso.Beds)
                {
                    List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();

                    items.Add((new Label(new LabelData(string.Format("x:{0} y:{1} z:{2}", bed.Value.Position.x, bed.Value.Position.y, bed.Value.Position.z), UnityEngine.Color.black)), 400));
                    items.Add((new Label(new LabelData(bed.Value.Taken ? _localizationHelper.GetLocalizationKey("Yes") : _localizationHelper.GetLocalizationKey("No"), UnityEngine.Color.black)), 200));
                    items.Add((new Label(new LabelData(bed.Value.IsHappy ? _localizationHelper.GetLocalizationKey("Good") : _localizationHelper.GetLocalizationKey("Bad"), UnityEngine.Color.black)), 200));

                    menu.Items.Add(new HorizontalRow(items));
                }

                NetworkMenuManager.SendServerPopup(data.Player, menu);
            }
        }
Пример #6
0
 public static void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
 {
     if (data.ButtonIdentifier == GameLoader.NAMESPACE + ".Wiki.Help")
     {
         UIManager.SendMenu(data.Player, "Wiki.MainMenu");
     }
 }
Пример #7
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            if (!data.ButtonIdentifier.Contains(GameLoader.NAMESPACE + ".NewSettlers.Accept.") &&
                !data.ButtonIdentifier.Contains(GameLoader.NAMESPACE + ".NewSettlers.Decline"))
            {
                return;
            }

            foreach (var p in data.Player.ActiveColony.Owners)
            {
                if (p.IsConnected())
                {
                    NetworkMenuManager.CloseServerPopup(p);
                }
            }

            if (data.ButtonIdentifier.Contains(GameLoader.NAMESPACE + ".NewSettlers.Accept."))
            {
                var recruitmentInfoStr = data.ButtonIdentifier.Replace(GameLoader.NAMESPACE + ".NewSettlers.Accept.", "");
                var unparsedString     = recruitmentInfoStr.Split('.');
                var addCount           = int.Parse(unparsedString[0]);
                var numbSkilled        = int.Parse(unparsedString[1]);
                var state = ColonyState.GetColonyState(data.Player.ActiveColony);

                AddNewSettlers(addCount, numbSkilled, state);
            }
        }
Пример #8
0
        public static void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier.StartsWith("Khanx.Warning."))
            {
                int category = data.Storage.GetAs <int>("Khanx.Warning.categoryDropDown");

                Warning.SendSetWarningsUI(data.Player, category);
            }
        }
Пример #9
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier.StartsWith(GameLoader.NAMESPACE + ".link_"))
            {
                string url = data.ButtonIdentifier.Substring(data.ButtonIdentifier.IndexOf("_") + 1);

                SendMenu(data.Player, url);
            }
        }
Пример #10
0
        public void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier != GameInitializer.NAMESPACE + ".cancelalltorials")
            {
                return;
            }

            var ps = PlayerState.GetPlayerState(data.Player);

            foreach (var tut in Tutorials.Keys)
            {
                ps.Tutorials[tut] = true;
            }
        }
Пример #11
0
        public void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
        {
            switch (data.ButtonIdentifier)
            {
            case "wingdings.replacer":
                JSONNode payload = new JSONNode(NodeType.Object).SetAs <int>("wingdings.construction.selection", 1);
                NetworkMenuManager.TriggerTypeSelectionPopup(data.Player, 640, 480, EAreaItemSelectionFilter.ComboDiggable, payload);
                return;

            case "windings.shapes":
                SendShapeMenu(data.Player);
                return;

            default:
                return;
            }
        }
Пример #12
0
        public static void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
        {
            if (!data.ButtonIdentifier.StartsWith("Khanx.AdvancedForester."))
            {
                return;
            }

            Log.Write("Forester ID:" + data.ButtonIdentifier.Substring(data.ButtonIdentifier.LastIndexOf(".") + 1));

            int foresterID = int.Parse(data.ButtonIdentifier.Substring(data.ButtonIdentifier.LastIndexOf(".") + 1));

            if (last_forester.ContainsKey(data.Player.ID))
            {
                last_forester.Remove(data.Player.ID);
            }

            last_forester.Add(data.Player.ID, foresterID);
        }
Пример #13
0
        public static void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier == GameLoader.NAMESPACE + ".ChatHistory")
            {
                SettlersLogger.Log(data.ButtonIdentifier);

                NetworkMenu menu = new NetworkMenu();
                var         file = Path.Combine(GameLoader.SAVE_LOC, "ChatLog.log");
                menu.ForceClosePopups = true;
                menu.Width            = 1000;
                menu.Height           = 700;
                menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("ChatHistory", data.Player));

                if (File.Exists(file))
                {
                    foreach (var item in File.ReadAllLines(file))
                    {
                        menu.Items.Add(new Label(new LabelData(item, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.None)));
                    }
                }

                NetworkMenuManager.SendServerPopup(data.Player, menu);
            }
        }
Пример #14
0
        public void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
        {
            if (!CommandToolManager.TryStartCommandToolSelection(data.Player, data.ButtonIdentifier))
            {
                switch (data.ButtonIdentifier)
                {
                case "Khanx.AdvancedForester":
                    NetworkMenu networkMenu = CommandToolManager.GenerateMenuBase(data.Player, showBackButton: true);
                    CommandToolManager.GenerateThreeColumnCenteredRow(networkMenu, new EmptySpace(), CommandToolManager.GetButtonTool(data.Player, "pipliz.temperateforest", "popup.tooljob.forester", 200), new EmptySpace());
                    networkMenu.Items.Add(new EmptySpace(10));

                    CommandToolManager.GenerateThreeColumnCenteredRow(networkMenu, CommandToolManager.GetButtonTool(data.Player, "Khanx.CherryForest", "popup.tooljob.cherryforester", 200), CommandToolManager.GetButtonTool(data.Player, "Khanx.TaigaForest", "popup.tooljob.taigaforester", 200), CommandToolManager.GetButtonTool(data.Player, "Khanx.OliveForest", "popup.tooljob.oliveforester", 200));
                    networkMenu.Items.Add(new EmptySpace(10));

                    CommandToolManager.GenerateThreeColumnCenteredRow(networkMenu, CommandToolManager.GetButtonTool(data.Player, "Khanx.AutummRedForester", "popup.tooljob.autumredforester", 200), CommandToolManager.GetButtonTool(data.Player, "Khanx.AutummOrangeForester", "popup.tooljob.autummorangeforester", 200), CommandToolManager.GetButtonTool(data.Player, "Khanx.AutummYellowForester", "popup.tooljob.autumyellowforester", 200));
                    networkMenu.Items.Add(new EmptySpace(10));

                    CommandToolManager.GenerateThreeColumnCenteredRow(networkMenu, CommandToolManager.GetButtonTool(data.Player, "Khanx.DarkTemperateForester", "popup.tooljob.darktemperateforester", 200), CommandToolManager.GetButtonTool(data.Player, "Khanx.TemperateForester", "popup.tooljob.temperateforester", 200), CommandToolManager.GetButtonTool(data.Player, "Khanx.LightTemperateForester", "popup.tooljob.lighttemperateforester", 200));

                    NetworkMenuManager.SendServerPopup(data.Player, networkMenu);
                    break;
                }
            }
        }
Пример #15
0
        public static void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier.Equals("Khanx.Compass.CardinalDirection"))
            {
                SendCardinalDirectionToPlayer(data.Player);

                if (last_Compass_Action.ContainsKey(data.Player.ID))
                {
                    last_Compass_Action.Remove(data.Player.ID);
                }

                last_Compass_Action.Add(data.Player.ID, new CompassLastAction(CompassAction.CardinalDirection));
                return;
            }

            if (data.ButtonIdentifier.Equals("Khanx.Compass.PlayerDeath"))
            {
                CompassWaypoints compassWaypoints = CompassManager.Waypoints.GetValueOrDefault(data.Player.ID, null);

                if (compassWaypoints == null)
                {
                    return;
                }

                Orientation orientation = Helper.GetOrientationToPositionFromPlayer(data.Player, compassWaypoints.playerDeath);

                SendOrientationToPlayer(data.Player, orientation);

                UIManager.AddorUpdateWorldMarker("Khanx.Compass.Goal" + data.Player.Name,
                                                 (data.Player.Name.Substring(data.Player.Name.Length - 1).Equals("s")) ? data.Player.Name + "' tomb" : data.Player.Name + "'s tomb",
                                                 compassWaypoints.playerDeath,
                                                 "Khanx.Compass",
                                                 ToggleType.ItemSelected,
                                                 "Khanx.Compass",
                                                 data.Player);

                if (last_Compass_Action.ContainsKey(data.Player.ID))
                {
                    last_Compass_Action.Remove(data.Player.ID);
                }

                last_Compass_Action.Add(data.Player.ID, new CompassLastAction(CompassAction.PlayerDeath, compassWaypoints.playerDeath));
                return;
            }

            if (data.ButtonIdentifier.Equals("Khanx.Compass.ColonistDeath"))
            {
                CompassWaypoints compassWaypoints = CompassManager.Waypoints.GetValueOrDefault(data.Player.ID, null);

                if (compassWaypoints == null)
                {
                    return;
                }

                Orientation orientation = Helper.GetOrientationToPositionFromPlayer(data.Player, compassWaypoints.colonistDeath);

                SendOrientationToPlayer(data.Player, orientation);

                UIManager.AddorUpdateWorldMarker("Khanx.Compass.Goal" + data.Player.Name,
                                                 "Colonist Death",
                                                 compassWaypoints.colonistDeath,
                                                 "Khanx.Compass",
                                                 ToggleType.ItemSelected,
                                                 "Khanx.Compass",
                                                 data.Player);


                if (last_Compass_Action.ContainsKey(data.Player.ID))
                {
                    last_Compass_Action.Remove(data.Player.ID);
                }

                last_Compass_Action.Add(data.Player.ID, new CompassLastAction(CompassAction.ColonistDeath, compassWaypoints.colonistDeath));
                return;
            }

            if (data.ButtonIdentifier.Equals("Khanx.Compass.ColonyDirection"))
            {
                int colonyInt = data.Storage.GetAs <int>("Khanx.Compass.Colony");

                Pipliz.Vector3Int colonyPosition = GetColonyPosition(colonyInt, data.Player);
                Orientation       orientation    = Helper.GetOrientationToPositionFromPlayer(data.Player, colonyPosition);

                SendOrientationToPlayer(data.Player, orientation);

                UIManager.AddorUpdateWorldMarker("Khanx.Compass.Goal" + data.Player.Name,
                                                 data.Player.Colonies[colonyInt].Name,
                                                 colonyPosition,
                                                 "Khanx.Compass",
                                                 ToggleType.ItemSelected,
                                                 "Khanx.Compass",
                                                 data.Player);

                if (last_Compass_Action.ContainsKey(data.Player.ID))
                {
                    last_Compass_Action.Remove(data.Player.ID);
                }

                last_Compass_Action.Add(data.Player.ID, new CompassLastAction(CompassAction.ColonyDirection, colonyPosition));
                return;
            }

            if (data.ButtonIdentifier.Equals("Khanx.Compass.WaypointDirection"))
            {
                int waypointInt = data.Storage.GetAs <int>("Khanx.Compass.Waypoint");

                CompassWaypoints compassWaypoints = CompassManager.Waypoints.GetValueOrDefault(data.Player.ID, null);

                if (compassWaypoints == null || compassWaypoints.waypoints == null && compassWaypoints.waypoints.Count == 0)
                {
                    Chatting.Chat.Send(data.Player, "Error: WaypointSelection, contact with the author of the mod");
                    return;
                }

                Orientation orientation = Helper.GetOrientationToPositionFromPlayer(data.Player, compassWaypoints.waypoints[waypointInt].position);

                SendOrientationToPlayer(data.Player, orientation);

                UIManager.AddorUpdateWorldMarker("Khanx.Compass.Goal" + data.Player.Name,
                                                 compassWaypoints.waypoints[waypointInt].name,
                                                 compassWaypoints.waypoints[waypointInt].position,
                                                 "Khanx.Compass",
                                                 ToggleType.ItemSelected,
                                                 "Khanx.Compass",
                                                 data.Player);

                if (last_Compass_Action.ContainsKey(data.Player.ID))
                {
                    last_Compass_Action.Remove(data.Player.ID);
                }

                last_Compass_Action.Add(data.Player.ID, new CompassLastAction(CompassAction.WayPoint, compassWaypoints.waypoints[waypointInt].position));
                return;
            }

            if (data.ButtonIdentifier.Equals("Khanx.Compass.WaypointUIAdd"))
            {
                NetworkMenu menu = new NetworkMenu();
                menu.Identifier = "Compass";
                menu.LocalStorage.SetAs("header", "Compass");
                InputField waypointName = new InputField("Khanx.Compass.waypointName");

                ButtonCallback WayPointAdd = new ButtonCallback("Khanx.Compass.WaypointAdd",
                                                                new LabelData("Add waypoint", UnityEngine.Color.white),
                                                                200,
                                                                30,
                                                                ButtonCallback.EOnClickActions.ClosePopup);

                ButtonCallback WayPointRemove = new ButtonCallback("Khanx.Compass.WaypointCancel",
                                                                   new LabelData("Cancel", UnityEngine.Color.white),
                                                                   200,
                                                                   30,
                                                                   ButtonCallback.EOnClickActions.ClosePopup);

                HorizontalRow WaypointManage = new HorizontalRow(new List <(IItem, int)> {
                    (WayPointAdd, 200), (WayPointRemove, 200)
                });

                menu.Items.Add(waypointName);
                menu.Items.Add(WaypointManage);
                NetworkMenuManager.SendServerPopup(data.Player, menu);
                return;
            }

            if (data.ButtonIdentifier.Equals("Khanx.Compass.WaypointAdd"))
            {
                string waypointName = data.Storage.GetAs <string>("Khanx.Compass.waypointName");

                if (waypointName.Equals(""))
                {
                    Chatting.Chat.Send(data.Player, "The waypoint has NOT been added, the name was not suitable");
                    return;
                }

                CompassWaypoints compassWaypoints = CompassManager.Waypoints.GetValueOrDefault(data.Player.ID, null);

                if (compassWaypoints == null || compassWaypoints.waypoints == null)
                {
                    compassWaypoints = new CompassWaypoints(Vector3Int.invalidPos, Vector3Int.invalidPos, new List <WayPoint>()
                    {
                        new WayPoint(waypointName, new Vector3Int(data.Player.Position))
                    });
                    CompassManager.Waypoints.Add(data.Player.ID, compassWaypoints);
                }
                else
                {
                    compassWaypoints.waypoints.Add(new WayPoint(waypointName, new Vector3Int(data.Player.Position)));
                }

                Chatting.Chat.Send(data.Player, "Waypoint " + waypointName + " has been added");
            }

            if (data.ButtonIdentifier.Equals("Khanx.Compass.WaypointRemove"))
            {
                int waypointInt = data.Storage.GetAs <int>("Khanx.Compass.Waypoint");

                CompassWaypoints compassWaypoints = CompassManager.Waypoints.GetValueOrDefault(data.Player.ID, null);

                //This should not happen
                if (compassWaypoints == null || compassWaypoints.waypoints == null && compassWaypoints.waypoints.Count == 0)
                {
                    Chatting.Chat.Send(data.Player, "Error: WaypointRemoving, contact with the author of the mod");
                    return;
                }

                Chatting.Chat.Send(data.Player, "Waypoint " + compassWaypoints.waypoints[waypointInt].name + " has been removed");

                compassWaypoints.waypoints.RemoveAt(waypointInt);

                if (last_Compass_Action.ContainsKey(data.Player.ID))
                {
                    last_Compass_Action.Remove(data.Player.ID);
                }

                UIManager.RemoveMarker("Khanx.Compass.Goal" + data.Player.Name, data.Player);

                return;
            }
        }
Пример #16
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            if ((!data.ButtonIdentifier.Contains(".RecruitButton") &&
                 !data.ButtonIdentifier.Contains(".FireButton") &&
                 !data.ButtonIdentifier.Contains(".MoveFired") &&
                 !data.ButtonIdentifier.Contains(".ColonyToolMainMenu") &&
                 !data.ButtonIdentifier.Contains(".KillFired") &&
                 !data.ButtonIdentifier.Contains(".CallToArms")) || data.Player.ActiveColony == null)
            {
                return;
            }

            Dictionary <string, JobCounts> jobCounts = GetJobCounts(data.Player.ActiveColony);

            if (data.ButtonIdentifier.Contains(".ColonyToolMainMenu"))
            {
                NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
            }
            else if (data.ButtonIdentifier.Contains(".FireButton"))
            {
                foreach (var job in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(job.Key))
                    {
                        var recruit = data.Storage.GetAs <int>(job.Key + ".Recruit");
                        var count   = GetCountValue(recruit);
                        var menu    = BuildMenu(data.Player, jobCounts, true, job.Key, count);

                        menu.LocalStorage.SetAs(GameInitializer.NAMESPACE + ".FiredJobName", job.Key);
                        menu.LocalStorage.SetAs(GameInitializer.NAMESPACE + ".FiredJobCount", count);

                        NetworkMenuManager.SendServerPopup(data.Player, menu);
                        break;
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".KillFired"))
            {
                var firedJob = data.Storage.GetAs <string>(GameInitializer.NAMESPACE + ".FiredJobName");
                var count    = data.Storage.GetAs <int>(GameInitializer.NAMESPACE + ".FiredJobCount");

                foreach (var job in jobCounts)
                {
                    if (job.Key == firedJob)
                    {
                        if (count > job.Value.TakenCount)
                        {
                            count = job.Value.TakenCount;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var npc = job.Value.TakenJobs[i].NPC;
                            npc.ClearJob();
                            npc.OnDeath();
                        }

                        break;
                    }
                }

                data.Player.ActiveColony.SendCommonData();
                jobCounts = GetJobCounts(data.Player.ActiveColony);
                NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
            }
            else if (data.ButtonIdentifier.Contains(".MoveFired"))
            {
                var firedJob = data.Storage.GetAs <string>(GameInitializer.NAMESPACE + ".FiredJobName");
                var count    = data.Storage.GetAs <int>(GameInitializer.NAMESPACE + ".FiredJobCount");

                foreach (var job in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(job.Key))
                    {
                        if (count > job.Value.AvailableCount)
                        {
                            count = job.Value.AvailableCount;
                        }

                        if (jobCounts.TryGetValue(firedJob, out var firedJobCounts))
                        {
                            for (int i = 0; i < count; i++)
                            {
                                if (firedJobCounts.TakenCount > i)
                                {
                                    var npc = firedJobCounts.TakenJobs[i].NPC;
                                    npc.ClearJob();
                                    npc.TakeJob(job.Value.AvailableJobs[i]);
                                    data.Player.ActiveColony.JobFinder.Remove(job.Value.AvailableJobs[i]);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }

                        data.Player.ActiveColony.SendCommonData();
                        break;
                    }
                }

                jobCounts = GetJobCounts(data.Player.ActiveColony);
                NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
            }
            else if (data.ButtonIdentifier.Contains(".RecruitButton"))
            {
                foreach (var job in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(job.Key))
                    {
                        var recruit = data.Storage.GetAs <int>(job.Key + ".Recruit");
                        var count   = GetCountValue(recruit);

                        if (count > job.Value.AvailableCount)
                        {
                            count = job.Value.AvailableCount;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var num = 0f;
                            data.Player.ActiveColony.HappinessData.RecruitmentCostCalculator.GetCost(data.Player.ActiveColony.HappinessData.CachedHappiness, data.Player.ActiveColony, out float foodCost);
                            if (data.Player.ActiveColony.Stockpile.TotalFood < foodCost ||
                                !data.Player.ActiveColony.Stockpile.TryRemoveFood(ref num, foodCost))
                            {
                                PandaChat.Send(data.Player, _localizationHelper, "Notenoughfood", ChatColor.red);
                                break;
                            }
                            else
                            {
                                var newGuy = new NPCBase(data.Player.ActiveColony, data.Player.ActiveColony.GetClosestBanner(new Vector3Int(data.Player.Position)).Position);
                                newGuy.FoodHoursCarried = ServerManager.ServerSettings.NPCs.InitialFoodCarriedHours;
                                data.Player.ActiveColony.RegisterNPC(newGuy);
                                ColonistInventory.Get(newGuy);
                                NPCTracker.Add(newGuy);
                                ModLoader.Callbacks.OnNPCRecruited.Invoke(newGuy);

                                if (newGuy.IsValid)
                                {
                                    newGuy.TakeJob(job.Value.AvailableJobs[i]);
                                    data.Player.ActiveColony.JobFinder.Remove(job.Value.AvailableJobs[i]);
                                }
                            }
                        }


                        data.Player.ActiveColony.SendCommonData();

                        jobCounts = GetJobCounts(data.Player.ActiveColony);
                        NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
                    }
                }
            }
        }
Пример #17
0
        public static NetworkMenu ToolbarMenu(ButtonPressCallbackData data, bool error = false, bool?selectAll = null)
        {
            NetworkMenu menu = new NetworkMenu();

            menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("MoveItemsToBackpack", data.Player));
            menu.Width  = 1000;
            menu.Height = 600;

            try
            {
                if (error)
                {
                    menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("invalidNumber"), UnityEngine.Color.red)));
                }

                List <ValueTuple <IItem, int> > headerItems = new List <ValueTuple <IItem, int> >();
                headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Numberofitems"), UnityEngine.Color.black)), 333));
                headerItems.Add(ValueTuple.Create <IItem, int>(new InputField("Backpack.NumberOfItems"), 333));
                headerItems.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Backpack.MoveItemsToBackpackFromToolbar", new LabelData(_localizationHelper.GetLocalizationKey("MoveItemsToBackpack"), UnityEngine.Color.black)), 333));
                menu.Items.Add(new HorizontalRow(headerItems));
                menu.Items.Add(new Line(UnityEngine.Color.black));

                List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Backpack.MainMenu", new LabelData(_localizationHelper.GetLocalizationKey("Back"), UnityEngine.Color.black)), 250));
                items.Add(ValueTuple.Create <IItem, int>(new EmptySpace(), 250));
                items.Add(ValueTuple.Create <IItem, int>(new EmptySpace(), 250));

                bool selected = false;

                if (selectAll == true)
                {
                    selected = true;
                }
                else if (selectAll == false)
                {
                    selected = false;
                }

                if (selected)
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Backpack.SelectNoneInBackpackToolbar", new LabelData(_localizationHelper.GetLocalizationKey("SelectNone"), UnityEngine.Color.black)), 250));
                }
                else
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Backpack.SelectAllInBackpackToolbar", new LabelData(_localizationHelper.GetLocalizationKey("SelectAll"), UnityEngine.Color.black)), 250));
                }

                menu.Items.Add(new HorizontalRow(items));
                menu.Items.Add(new Line(UnityEngine.Color.black));
                var invRef     = data.Player.Inventory;
                var backpackID = ItemId.GetItemId(Backpack.NAME);

                foreach (var itemKvp in invRef.Items)
                {
                    if (itemKvp.Type != ColonyBuiltIn.ItemTypes.AIR.Id && itemKvp.Type != backpackID)
                    {
                        items = new List <ValueTuple <IItem, int> >();
                        items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(itemKvp.Type), 250));
                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(ItemId.GetItemId(itemKvp.Type), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Toolbar", data.Player) + ": " + itemKvp.Amount.ToString(), UnityEngine.Color.black)), 250));
                        items.Add(ValueTuple.Create <IItem, int>(new Toggle(new LabelData(_localizationHelper.LocalizeOrDefault("Select", data.Player), UnityEngine.Color.black), "Backpack." + itemKvp.Type + ".ItemSelected"), 250));

                        if (selectAll == null)
                        {
                            menu.LocalStorage.TryGetAs("Backpack." + itemKvp.Type + ".ItemSelected", out selected);
                        }

                        menu.LocalStorage.SetAs("Backpack." + itemKvp.Type + ".ItemSelected", selected);
                        menu.Items.Add(new HorizontalRow(items));
                    }
                }
            }
            catch (Exception ex)
            {
                SettlersLogger.LogError(ex);
            }

            return(menu);
        }
Пример #18
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier == "Backpack.GetItemsFromStockpile")
            {
                NetworkMenu menu = StockpileMenu(data);
                NetworkMenuManager.SendServerPopup(data.Player, menu);
            }
            else if (data.ButtonIdentifier == "Backpack.MainMenu")
            {
                NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
            }
            else if (data.ButtonIdentifier == "Backpack.GetItemsFromToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data));
            }
            else if (data.ButtonIdentifier == "Backpack.SelectAllInBackpack")
            {
                NetworkMenuManager.SendServerPopup(data.Player, StockpileMenu(data, false, true));
            }
            else if (data.ButtonIdentifier == "Backpack.SelectNoneInBackpack")
            {
                NetworkMenuManager.SendServerPopup(data.Player, StockpileMenu(data, false, false));
            }
            else if (data.ButtonIdentifier == "Backpack.SelectAllInToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data, false, true));
            }
            else if (data.ButtonIdentifier == "Backpack.SelectNoneInToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data, false, false));
            }
            else if (data.ButtonIdentifier == "Backpack.SelectNoneInBackpackMain")
            {
                NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, false, false));
            }
            else if (data.ButtonIdentifier == "Backpack.SelectAllInBackpackMain")
            {
                NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, false, true));
            }
            else if (data.ButtonIdentifier == "Backpack.SelectNoneInBackpackToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data, false, false));
            }
            else if (data.ButtonIdentifier == "Backpack.SelectAllInBackpackToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data, false, true));
            }
            else if (data.ButtonIdentifier == "Backpack.MoveItemsToStockpile")
            {
                if (data.Storage.TryGetAs("Backpack.NumberOfItems", out string strNumItems) && int.TryParse(strNumItems, out int numItems))
                {
                    Dictionary <ushort, int> removeItems = new Dictionary <ushort, int>();
                    var ps = PlayerState.GetPlayerState(data.Player);

                    foreach (var itemKvp in ps.Backpack)
                    {
                        if (data.Storage.TryGetAs("Backpack." + itemKvp.Key + ".ItemSelected", out bool selected) && selected)
                        {
                            int takeNum = System.Math.Min(numItems, itemKvp.Value);
                            removeItems[itemKvp.Key] = takeNum;
                        }
                    }

                    foreach (var item in removeItems)
                    {
                        ps.Backpack[item.Key] -= item.Value;

                        if (ps.Backpack[item.Key] <= 0)
                        {
                            ps.Backpack.Remove(item.Key);
                        }

                        data.Player.ActiveColony.Stockpile.Add(item.Key, item.Value);
                    }

                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
                }
                else
                {
                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, true));
                }
            }
            else if (data.ButtonIdentifier == "Backpack.MoveItemsToToolbar")
            {
                if (data.Storage.TryGetAs("Backpack.NumberOfItems", out string strNumItems) && int.TryParse(strNumItems, out int numItems))
                {
                    Dictionary <ushort, int> removeItems = new Dictionary <ushort, int>();
                    var ps     = PlayerState.GetPlayerState(data.Player);
                    var invRef = data.Player.Inventory;

                    foreach (var itemKvp in ps.Backpack)
                    {
                        if (data.Storage.TryGetAs("Backpack." + itemKvp.Key + ".ItemSelected", out bool selected) && selected)
                        {
                            int takeNum = System.Math.Min(numItems, itemKvp.Value);
                            removeItems[itemKvp.Key] = takeNum;
                        }
                    }

                    foreach (var item in removeItems)
                    {
                        if (invRef.TryAdd(item.Key, item.Value))
                        {
                            ps.Backpack[item.Key] -= item.Value;

                            if (ps.Backpack[item.Key] <= 0)
                            {
                                ps.Backpack.Remove(item.Key);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
                }
                else
                {
                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, true));
                }
            }
            else if (data.ButtonIdentifier == "Backpack.MoveItemsToBackpackFromStockpile")
            {
                if (data.Storage.TryGetAs("Backpack.NumberOfItems", out string strNumItems) && int.TryParse(strNumItems, out int numItems))
                {
                    Dictionary <ushort, int> removeItems = new Dictionary <ushort, int>();
                    var ps         = PlayerState.GetPlayerState(data.Player);
                    var backpackID = ItemId.GetItemId(Backpack.NAME);

                    foreach (var itemKvp in data.Player.ActiveColony.Stockpile.Items)
                    {
                        if (itemKvp.Key != backpackID && data.Storage.TryGetAs("Backpack." + itemKvp.Key + ".ItemSelected", out bool selected) && selected)
                        {
                            int takeNum = System.Math.Min(numItems, itemKvp.Value);
                            removeItems[itemKvp.Key] = takeNum;
                        }
                    }

                    foreach (var item in removeItems)
                    {
                        data.Player.ActiveColony.Stockpile.TryRemove(item.Key, item.Value);

                        if (!ps.Backpack.ContainsKey(item.Key))
                        {
                            ps.Backpack.Add(item.Key, item.Value);
                        }
                        else
                        {
                            ps.Backpack[item.Key] += item.Value;
                        }
                    }

                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
                }
                else
                {
                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, true));
                }
            }
            else if (data.ButtonIdentifier == "Backpack.MoveItemsToBackpackFromToolbar")
            {
                if (data.Storage.TryGetAs("Backpack.NumberOfItems", out string strNumItems) && int.TryParse(strNumItems, out int numItems))
                {
                    Dictionary <ushort, int> removeItems = new Dictionary <ushort, int>();
                    var ps         = PlayerState.GetPlayerState(data.Player);
                    var invRef     = data.Player.Inventory;
                    var backpackID = ItemId.GetItemId(Backpack.NAME);

                    foreach (var itemKvp in invRef.Items)
                    {
                        if (itemKvp.Type != backpackID && data.Storage.TryGetAs("Backpack." + itemKvp.Type + ".ItemSelected", out bool selected) && selected)
                        {
                            int takeNum = System.Math.Min(numItems, itemKvp.Amount);
                            removeItems[itemKvp.Type] = takeNum;
                        }
                    }

                    foreach (var item in removeItems)
                    {
                        if (invRef.TryRemove(item.Key, item.Value))
                        {
                            if (!ps.Backpack.ContainsKey(item.Key))
                            {
                                ps.Backpack.Add(item.Key, item.Value);
                            }
                            else
                            {
                                ps.Backpack[item.Key] += item.Value;
                            }
                        }
                    }

                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
                }
                else
                {
                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, true));
                }
            }
        }
        public static void BuildSettlerDetailMenu(ButtonPressCallbackData data, KeyValuePair <string, JobCounts> jobKvp, global::Jobs.IJob job)
        {
            var         inv  = Entities.SettlerInventory.GetSettlerInventory(job.NPC);
            NetworkMenu menu = new NetworkMenu();

            menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("Colonist", data.Player) + " " + inv.SettlerName + " " + _localizationHelper.LocalizeOrDefault("Details", data.Player));
            menu.Width  = 1000;
            menu.Height = 600;

            menu.Items.Add(new Line(UnityEngine.Color.black));
            menu.Items.Add(new ButtonCallback(jobKvp.Key + ".JobDetailsButton", new LabelData(_localizationHelper.GetLocalizationKey("Back"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)));
            menu.Items.Add(new Line(UnityEngine.Color.black));

            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Stats"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 24)));
            menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.GetLocalizationKey("SkillProcChance"), UnityEngine.Color.black)),
                                               new Label(new LabelData((inv.GetSkillModifier() * 100) + "%", UnityEngine.Color.black))));
            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("SkillProcChanceDesc"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 13)));
            SettlerManager.GetSkillInformation(job.NPC, out var nextLevel, out var itt, out var allSkill);
            menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.GetLocalizationKey("ToNextSkillUp"), UnityEngine.Color.black)),
                                               new Label(new LabelData((nextLevel - itt).ToString(), UnityEngine.Color.black))));

            foreach (var statItem in inv.Stats)
            {
                if (ItemTypes.IndexLookup.TryGetIndex(statItem.Key, out var itemIndex))
                {
                    menu.Items.Add(new HorizontalSplit(new Label(new LabelData(statItem.Key, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)),
                                                       new Label(new LabelData(statItem.Value.ToString(), UnityEngine.Color.black))));
                }
                else
                {
                    menu.Items.Add(new HorizontalSplit(new Label(new LabelData(statItem.Key, UnityEngine.Color.black)),
                                                       new Label(new LabelData(statItem.Value.ToString(), UnityEngine.Color.black))));
                }
            }

            menu.Items.Add(new Line(UnityEngine.Color.black));
            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("BonusProcs"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 20)));

            var procItemsHeader = new List <ValueTuple <IItem, int> >();

            procItemsHeader.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Item"), UnityEngine.Color.black)), 150));
            procItemsHeader.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 150));
            procItemsHeader.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Count"), UnityEngine.Color.black)), 150));
            menu.Items.Add(new HorizontalRow(procItemsHeader));

            if (inv.BonusProcs.Count == 0)
            {
                menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("NoneYet"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 20)));
            }

            foreach (var proc in inv.BonusProcs)
            {
                var procItems = new List <ValueTuple <IItem, int> >();
                procItems.Add(ValueTuple.Create <IItem, int>(new ItemIcon(proc.Key), 150));
                procItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(ItemTypes.GetType(proc.Key).Name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 150));
                procItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("x " + proc.Value, UnityEngine.Color.black)), 150));
                menu.Items.Add(new HorizontalRow(procItems));
            }

            menu.Items.Add(new Line(UnityEngine.Color.black));
            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Equiptment"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 24)));
            List <ValueTuple <IItem, int> > wep = new List <ValueTuple <IItem, int> >();

            wep.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Weapon"), UnityEngine.Color.black)), 200));
            wep.Add(ValueTuple.Create <IItem, int>(new ItemIcon(inv.Weapon.Id), 200));

            if (Weapons.WeaponFactory.WeaponLookup.TryGetValue(inv.Weapon.Id, out var wepItem))
            {
                wep.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(wepItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 200));
                wep.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".wep." + job.NPC.ID + ".AddEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Swap"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                wep.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".wep." + job.NPC.ID + ".RemoveEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Remove"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
            }
            else
            {
                wep.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 200));
                wep.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + ".wep." + job.NPC.ID + ".AddEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Add"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
            }

            menu.Items.Add(new HorizontalRow(wep));

            foreach (var armor in inv.Armor)
            {
                List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey(armor.Key.ToString()), UnityEngine.Color.black)), 200));
                items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(armor.Value.Id), 200));

                if (Armor.ArmorFactory.ArmorLookup.TryGetValue(armor.Value.Id, out var arm))
                {
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(arm.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + "." + armor.Key + ".arm." + job.NPC.ID + ".AddEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Swap"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + "." + armor.Key + ".arm." + job.NPC.ID + ".RemoveEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Remove"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                }
                else
                {
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + "." + armor.Key + ".arm." + job.NPC.ID + ".AddEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Add"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                }

                menu.Items.Add(new HorizontalRow(items));
            }


            NetworkMenuManager.SendServerPopup(data.Player, menu);
        }
        private static void BuildPlayerDetailsMenu(ButtonPressCallbackData data)
        {
            NetworkMenu menu = new NetworkMenu();

            menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("PlayerDetails", data.Player));
            menu.Width  = 1000;
            menu.Height = 600;

            var ps = PlayerState.GetPlayerState(data.Player);

            menu.Items.Add(new Line(UnityEngine.Color.black));
            menu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".ColonyToolMainMenu", new LabelData(_localizationHelper.GetLocalizationKey("Back"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)));
            menu.Items.Add(new Line(UnityEngine.Color.black));

            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Stats"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 24)));
            menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("JoinDate", data.Player) + ":", UnityEngine.Color.black)),
                                               new Label(new LabelData(ps.JoinDate.ToString(), UnityEngine.Color.black))));

            menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.GetLocalizationKey("SkillProcChance"), UnityEngine.Color.black)),
                                               new Label(new LabelData((ps.GetSkillModifier() * 100) + "%", UnityEngine.Color.black))));
            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("SkillProcChanceDesc"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 13)));

            menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("BlocksPlaced", data.Player) + ":", UnityEngine.Color.black)),
                                               new Label(new LabelData(ps.ItemsPlaced.Sum(kvp => kvp.Value).ToString(), UnityEngine.Color.black))));
            menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("BlocksRemoved", data.Player) + ":", UnityEngine.Color.black)),
                                               new Label(new LabelData(ps.ItemsRemoved.Sum(kvp => kvp.Value).ToString(), UnityEngine.Color.black))));

            foreach (var statItem in ps.Stats)
            {
                if (ItemTypes.IndexLookup.TryGetIndex(statItem.Key, out var itemIndex))
                {
                    menu.Items.Add(new HorizontalSplit(new Label(new LabelData(statItem.Key, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)),
                                                       new Label(new LabelData(statItem.Value.ToString(), UnityEngine.Color.black))));
                }
                else
                {
                    menu.Items.Add(new HorizontalSplit(new Label(new LabelData(statItem.Key, UnityEngine.Color.black)),
                                                       new Label(new LabelData(statItem.Value.ToString(), UnityEngine.Color.black))));
                }
            }

            var totalArmor = 0f;

            foreach (var a in ps.Armor)
            {
                if (Armor.ArmorFactory.ArmorLookup.TryGetValue(a.Value.Id, out var armorItem))
                {
                    totalArmor += armorItem.ArmorRating;
                }
            }

            menu.Items.Add(new HorizontalSplit(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("DamageReduction", data.Player) + ":", UnityEngine.Color.black)),
                                               new Label(new LabelData((totalArmor * 100) + "%", UnityEngine.Color.black))));

            menu.Items.Add(new Line(UnityEngine.Color.black));
            menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Equiptment"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 24)));

            foreach (var armor in ps.Armor)
            {
                List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(armor.Key.ToString(), UnityEngine.Color.black)), 200));
                items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(armor.Value.Id), 200));

                if (Armor.ArmorFactory.ArmorLookup.TryGetValue(armor.Value.Id, out var arm))
                {
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(arm.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(armor.Key + ".AddPlayerEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Swap"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(armor.Key + ".RemovePlayerEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Remove"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                }
                else
                {
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(armor.Key + ".AddPlayerEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Add"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                }

                menu.Items.Add(new HorizontalRow(items));
            }

            for (int i = 0; i < ps.MaxMagicItems; i++)
            {
                List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("MagicItemLabel"), UnityEngine.Color.black)), 200));

                if (ps.MagicItems[i] != null)
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(ps.MagicItems[i].name), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(ps.MagicItems[i].name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("MagicItem." + i + ".AddPlayerEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Swap"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("MagicItem." + i + ".RemovePlayerEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Remove"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                }
                else
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(ColonyBuiltIn.ItemTypes.AIR.Id), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("", UnityEngine.Color.black)), 200));
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("MagicItem." + i + ".AddPlayerEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Add"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 200));
                }

                menu.Items.Add(new HorizontalRow(items));
            }

            NetworkMenuManager.SendServerPopup(data.Player, menu);
        }
        public static void PressButton(ButtonPressCallbackData data)
        {
            if (data.ButtonIdentifier.Contains(GameLoader.NAMESPACE + ".PlayerDetails"))
            {
                BuildPlayerDetailsMenu(data);
                return;
            }
            else if (data.ButtonIdentifier.Contains(".AddPlayerEquiptmentButton"))
            {
                NetworkMenu menu = new NetworkMenu();
                menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("PlayerEquiptment", data.Player));
                menu.Width  = 1000;
                menu.Height = 600;

                if (data.ButtonIdentifier.Contains("MagicItem."))
                {
                    var id = data.ButtonIdentifier.Replace("AddPlayerEquiptmentButton", "");

                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                    {
                        if (kvp.Value > 0 &&
                            ItemTypes.TryGetType(kvp.Key, out var itemType) &&
                            MagicItemsCache.PlayerMagicItems.TryGetValue(itemType.Name, out var magicItem) &&
                            !Armor.ArmorFactory.ArmorLookup.ContainsKey(kvp.Key) &&
                            !Weapons.WeaponFactory.WeaponLookup.ContainsKey(kvp.Key))
                        {
                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(magicItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Stockpile", data.Player) + ": " + kvp.Value.ToString(), UnityEngine.Color.black)), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(id + kvp.Key + ".AddPlayerSelectedEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Select"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 250));
                            menu.Items.Add(new HorizontalRow(items));
                        }
                    }
                }
                else
                {
                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                    {
                        if (kvp.Value > 0 && Armor.ArmorFactory.ArmorLookup.TryGetValue(kvp.Key, out var armItem) && data.ButtonIdentifier.Contains(armItem.Slot + "."))
                        {
                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(armItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Stockpile", data.Player) + ": " + kvp.Value.ToString(), UnityEngine.Color.black)), 250));
                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(kvp.Key + ".AddPlayerSelectedEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Select"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 250));
                            menu.Items.Add(new HorizontalRow(items));
                        }
                    }
                }

                NetworkMenuManager.SendServerPopup(data.Player, menu);
            }
            else if (data.ButtonIdentifier.Contains(".AddPlayerSelectedEquiptmentButton"))
            {
                if (data.ButtonIdentifier.Contains("MagicItem."))
                {
                    var startPos = data.ButtonIdentifier.Replace("MagicItem.", "");

                    if (int.TryParse(startPos.Substring(0, startPos.IndexOf('.')), out var slot))
                    {
                        var itemId = startPos.Substring(startPos.IndexOf('.') + 1, startPos.LastIndexOf(".") - 2);

                        if (ushort.TryParse(itemId, out var id))
                        {
                            var item = ItemId.GetItemId(id);

                            if (MagicItemsCache.PlayerMagicItems.TryGetValue(item.Name, out var magicItem) && data.Player.ActiveColony.Stockpile.TryRemove(id))
                            {
                                var ps = PlayerState.GetPlayerState(data.Player);
                                ps.MagicItems[slot] = magicItem;
                                ps.RecaclculateMagicItems();
                            }
                        }
                    }

                    BuildPlayerDetailsMenu(data);
                    return;
                }
                else
                {
                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                    {
                        if (Armor.ArmorFactory.ArmorLookup.TryGetValue(kvp.Key, out var armItem) &&
                            data.ButtonIdentifier.Contains(kvp.Key + ".") &&
                            data.Player.ActiveColony.Stockpile.TryRemove(kvp.Key))
                        {
                            var ps = PlayerState.GetPlayerState(data.Player);

                            if (ps.Armor[armItem.Slot].Id != default(ushort))
                            {
                                data.Player.ActiveColony.Stockpile.Add(ps.Armor[armItem.Slot].Id);
                            }

                            ps.Armor[armItem.Slot].Id         = kvp.Key;
                            ps.Armor[armItem.Slot].Durability = armItem.Durability;
                            ps.RecaclculateMagicItems();
                            BuildPlayerDetailsMenu(data);
                            return;
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".RemovePlayerEquiptmentButton"))
            {
                var ps = PlayerState.GetPlayerState(data.Player);

                if (data.ButtonIdentifier.Contains("MagicItem."))
                {
                    if (int.TryParse(data.ButtonIdentifier.Replace("MagicItem.", "").Replace(".RemovePlayerEquiptmentButton", ""), out var id))
                    {
                        data.Player.ActiveColony.Stockpile.Add(ItemId.GetItemId(ps.MagicItems[id].name));
                        ps.MagicItems[id] = null;
                    }
                }
                else
                {
                    foreach (var armor in ps.Armor)
                    {
                        if (data.ButtonIdentifier.Contains(armor.Key + "."))
                        {
                            if (armor.Value.Id != default(ushort))
                            {
                                data.Player.ActiveColony.Stockpile.Add(armor.Value.Id);
                            }

                            armor.Value.Id         = default(ushort);
                            armor.Value.Durability = default(int);
                            break;
                        }
                    }
                }

                ps.RecaclculateMagicItems();
                BuildPlayerDetailsMenu(data);
            }
            else if (data.ButtonIdentifier.Contains(".JobDetailsButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        NetworkMenu menu = new NetworkMenu();
                        menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault(jobKvp.Key.Replace(" ", ""), data.Player) + " " + _localizationHelper.LocalizeOrDefault("JobDetails", data.Player));
                        menu.Width  = 1000;
                        menu.Height = 600;

                        var firstGuy = jobKvp.Value.TakenJobs.FirstOrDefault();
                        var firstInv = Entities.SettlerInventory.GetSettlerInventory(firstGuy.NPC);
                        List <ValueTuple <IItem, int> > headerItems = new List <ValueTuple <IItem, int> >();

                        headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Name"), UnityEngine.Color.black)), 100));
                        headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Weapon"), UnityEngine.Color.black)), 100));

                        foreach (var a in firstInv.Armor)
                        {
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey(a.Key.ToString()), UnityEngine.Color.black)), 100));
                        }

                        menu.Items.Add(new HorizontalRow(headerItems));

                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            var inv = Entities.SettlerInventory.GetSettlerInventory(job.NPC);
                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(inv.SettlerName, UnityEngine.Color.black)), 100));
                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(inv.Weapon.Id), 100));

                            foreach (var armor in inv.Armor)
                            {
                                items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(armor.Value.Id), 100));
                            }

                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(jobKvp.Key + "." + job.NPC.ID + ".EquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Details"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 100));
                            menu.Items.Add(new HorizontalRow(items));
                        }

                        menu.Items.Add(new Line());
                        menu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".ColonyToolMainMenu", new LabelData(_localizationHelper.GetLocalizationKey("Back"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)));

                        NetworkMenuManager.SendServerPopup(data.Player, menu);
                        return;
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".EquiptmentButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            if (data.ButtonIdentifier.Contains("." + job.NPC.ID.ToString() + ".EquiptmentButton"))
                            {
                                BuildSettlerDetailMenu(data, jobKvp, job);
                                return;
                            }
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".AddEquiptmentButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            if (data.ButtonIdentifier.Contains("." + job.NPC.ID.ToString() + "."))
                            {
                                var         inv  = Entities.SettlerInventory.GetSettlerInventory(job.NPC);
                                NetworkMenu menu = new NetworkMenu();
                                menu.LocalStorage.SetAs("header", inv.SettlerName + " " + _localizationHelper.LocalizeOrDefault("Equiptment", data.Player));
                                menu.Width  = 1000;
                                menu.Height = 600;
                                var newButtonID = data.ButtonIdentifier.Replace(".AddEquiptmentButton", "");

                                if (data.ButtonIdentifier.Contains(".wep."))
                                {
                                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                                    {
                                        if (kvp.Value > 0 && Weapons.WeaponFactory.WeaponLookup.TryGetValue(kvp.Key, out var wepItem))
                                        {
                                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(wepItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Stockpile", data.Player) + ": " + kvp.Value.ToString(), UnityEngine.Color.black)), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(newButtonID + "." + kvp.Key + ".AddSelectedEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Select"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 250));
                                            menu.Items.Add(new HorizontalRow(items));
                                        }
                                    }
                                }
                                else if (data.ButtonIdentifier.Contains(".arm."))
                                {
                                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                                    {
                                        if (kvp.Value > 0 && Armor.ArmorFactory.ArmorLookup.TryGetValue(kvp.Key, out var armItem) && data.ButtonIdentifier.Contains("." + armItem.Slot + "."))
                                        {
                                            List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                                            items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(armItem.name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Stockpile", data.Player) + ": " + kvp.Value.ToString(), UnityEngine.Color.black)), 250));
                                            items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback(newButtonID + "." + kvp.Key + ".AddSelectedEquiptmentButton", new LabelData(_localizationHelper.GetLocalizationKey("Select"), UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)), 250));
                                            menu.Items.Add(new HorizontalRow(items));
                                        }
                                    }
                                }

                                NetworkMenuManager.SendServerPopup(data.Player, menu);
                                return;
                            }
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".AddSelectedEquiptmentButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            if (data.ButtonIdentifier.Contains("." + job.NPC.ID.ToString() + "."))
                            {
                                if (data.ButtonIdentifier.Contains(".wep."))
                                {
                                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                                    {
                                        if (Weapons.WeaponFactory.WeaponLookup.TryGetValue(kvp.Key, out var wepItem) &&
                                            data.ButtonIdentifier.Contains("." + kvp.Key + ".") &&
                                            job.NPC.Colony.Stockpile.TryRemove(kvp.Key))
                                        {
                                            var inv = Entities.SettlerInventory.GetSettlerInventory(job.NPC);

                                            if (inv.Weapon.Id != default(ushort))
                                            {
                                                job.NPC.Colony.Stockpile.Add(inv.Weapon.Id);
                                            }

                                            inv.Weapon.Id         = kvp.Key;
                                            inv.Weapon.Durability = wepItem.WepDurability;
                                            BuildSettlerDetailMenu(data, jobKvp, job);
                                            return;
                                        }
                                    }
                                }
                                else if (data.ButtonIdentifier.Contains(".arm."))
                                {
                                    foreach (var kvp in data.Player.ActiveColony.Stockpile.Items)
                                    {
                                        if (Armor.ArmorFactory.ArmorLookup.TryGetValue(kvp.Key, out var armItem) &&
                                            data.ButtonIdentifier.Contains("." + kvp.Key + ".") &&
                                            job.NPC.Colony.Stockpile.TryRemove(kvp.Key))
                                        {
                                            var inv = Entities.SettlerInventory.GetSettlerInventory(job.NPC);

                                            if (inv.Armor[armItem.Slot].Id != default(ushort))
                                            {
                                                job.NPC.Colony.Stockpile.Add(inv.Armor[armItem.Slot].Id);
                                            }

                                            inv.Armor[armItem.Slot].Id         = kvp.Key;
                                            inv.Armor[armItem.Slot].Durability = armItem.Durability;
                                            BuildSettlerDetailMenu(data, jobKvp, job);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".RemoveEquiptmentButton"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);

                foreach (var jobKvp in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(jobKvp.Key))
                    {
                        foreach (var job in jobKvp.Value.TakenJobs)
                        {
                            if (data.ButtonIdentifier.Contains("." + job.NPC.ID.ToString() + ".EquiptmentButton"))
                            {
                                var inv = Entities.SettlerInventory.GetSettlerInventory(job.NPC);

                                if (data.ButtonIdentifier.Contains(".wep."))
                                {
                                    if (inv.Weapon.Id != default(ushort))
                                    {
                                        job.NPC.Colony.Stockpile.Add(inv.Weapon.Id);
                                    }

                                    inv.Weapon.Id         = default(ushort);
                                    inv.Weapon.Durability = default(int);
                                }
                                else if (data.ButtonIdentifier.Contains(".arm."))
                                {
                                    foreach (var armor in inv.Armor)
                                    {
                                        if (data.ButtonIdentifier.Contains("." + armor.Key + "."))
                                        {
                                            if (armor.Value.Id != default(ushort))
                                            {
                                                job.NPC.Colony.Stockpile.Add(armor.Value.Id);
                                            }

                                            armor.Value.Id         = default(ushort);
                                            armor.Value.Durability = default(int);
                                            break;
                                        }
                                    }
                                }

                                BuildSettlerDetailMenu(data, jobKvp, job);
                                return;
                            }
                        }
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".ColonyToolMainMenu"))
            {
                Dictionary <string, JobCounts> jobCounts = ColonyTool.GetJobCounts(data.Player.ActiveColony);
                NetworkMenuManager.SendServerPopup(data.Player, ColonyTool.BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
            }
        }
Пример #22
0
        public static void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
        {
            string itemPrefix = "NACH0.Types.";
            string guard      = ".Guard";
            string night      = guard + ".Nightx+";
            string day        = guard + ".Dayx+";

            if (data.ButtonIdentifier.StartsWith(Nach0Config.Name + ".UIButton."))
            {
                switch (data.ButtonIdentifier)
                {
                case Nach0Config.Name + ".UIButton.Guards":
                    item_placer_option_dict[data.Player] = "Guards";
                    SendCommandUI.SendUI(data.Player);
                    item_placer_option_dict[data.Player] = "";
                    return;

                case Nach0Config.Name + ".UIButton.Back":
                    item_placer_option_dict[data.Player] = "";
                    SendCommandUI.SendUI(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.SlingShot.Night":
                    item_placer_dict[data.Player] = itemPrefix + "Slingshot" + night;
                    AfterItemTypeChanged(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.SlingShot.Day":
                    item_placer_dict[data.Player] = itemPrefix + "Slingshot" + day;
                    AfterItemTypeChanged(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.CompoundBow.Night":
                    item_placer_dict[data.Player] = itemPrefix + "CompoundBow" + night;
                    AfterItemTypeChanged(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.CompoundBow.Day":
                    item_placer_dict[data.Player] = itemPrefix + "CompoundBow" + day;
                    AfterItemTypeChanged(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.Sword.Night":
                    item_placer_dict[data.Player] = itemPrefix + "Sword" + night;
                    AfterItemTypeChanged(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.Sword.Day":
                    item_placer_dict[data.Player] = itemPrefix + "Sword" + day;
                    AfterItemTypeChanged(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.Sniper.Night":
                    item_placer_dict[data.Player] = itemPrefix + "Sniper" + night;
                    AfterItemTypeChanged(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.Sniper.Day":
                    item_placer_dict[data.Player] = itemPrefix + "Sniper" + day;
                    AfterItemTypeChanged(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.Ballista.Night":
                    item_placer_dict[data.Player] = itemPrefix + "Ballista" + night;
                    AfterItemTypeChanged(data.Player);
                    return;

                case Nach0Config.Name + ".UIButton.Ballista.Day":
                    item_placer_dict[data.Player] = itemPrefix + "Ballista" + day;
                    AfterItemTypeChanged(data.Player);
                    return;
                }
            }
        }
Пример #23
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            switch (data.ButtonIdentifier)
            {
            case GameLoader.NAMESPACE + ".SetScemanticName":
                NetworkMenu saveMenu = new NetworkMenu();
                saveMenu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("SaveSchematic", data.Player));
                saveMenu.Width            = 600;
                saveMenu.Height           = 300;
                saveMenu.ForceClosePopups = true;
                saveMenu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("SaveInstructions"), UnityEngine.Color.black)));
                saveMenu.Items.Add(new InputField("Construction.SetArchitectArea"));
                saveMenu.Items.Add(new ButtonCallback(GameLoader.NAMESPACE + ".SetArchitectArea", new LabelData(_localizationHelper.GetLocalizationKey("Start"), UnityEngine.Color.black)));

                NetworkMenuManager.SendServerPopup(data.Player, saveMenu);
                break;

            case GameLoader.NAMESPACE + ".SetArchitectArea":
                NetworkMenuManager.CloseServerPopup(data.Player);
                if (data.Storage.TryGetAs("Construction.SetArchitectArea", out string schematicName))
                {
                    var colonySaves = GameLoader.Schematic_SAVE_LOC + $"\\{data.Player.ActiveColony.ColonyID}\\";

                    if (!Directory.Exists(colonySaves))
                    {
                        Directory.CreateDirectory(colonySaves);
                    }

                    var schematicFile = Path.Combine(colonySaves, schematicName + ".schematic");

                    if (File.Exists(schematicFile))
                    {
                        File.Delete(schematicFile);
                    }

                    var metaDataSave = Path.Combine(GameLoader.Schematic_SAVE_LOC, schematicName + ".schematic.metadata.json");

                    if (File.Exists(metaDataSave))
                    {
                        File.Delete(metaDataSave);
                    }

                    AreaJobTracker.StartCommandToolSelection(data.Player, new GenericCommandToolSettings()
                    {
                        Key                 = "pipliz.constructionarea",
                        TranslationKey      = _localizationHelper.LocalizeOrDefault("Architect", data.Player),
                        JSONData            = new JSONNode().SetAs(ArchitectLoader.NAME + ".ArchitectSchematicName", schematicName).SetAs("constructionType", GameLoader.NAMESPACE + ".Architect"),
                        OneAreaOnly         = true,
                        Maximum3DBlockCount = int.MaxValue,
                        Maximum2DBlockCount = int.MaxValue,
                        MaximumHeight       = int.MaxValue,
                        MinimumHeight       = 1,
                        Minimum2DBlockCount = 1,
                        Minimum3DBlockCount = 1
                    });
                }

                break;

            case GameLoader.NAMESPACE + ".ShowMainMenu":
                SendMainMenu(data.Player);
                break;

            case GameLoader.NAMESPACE + ".ShowBuildDetails":
                List <FileInfo> options = SchematicReader.GetSchematics(data.Player);
                var             index   = data.Storage.GetAs <int>(Selected_Schematic);

                if (options.Count > index)
                {
                    var selectedSchematic = options[index];

                    if (SchematicReader.TryGetSchematicMetadata(selectedSchematic.Name, data.Player.ActiveColony.ColonyID, out SchematicMetadata schematicMetadata))
                    {
                        if (schematicMetadata.Blocks.Count == 1 && schematicMetadata.Blocks.ContainsKey(ColonyBuiltIn.ItemTypes.AIR.Id))
                        {
                            PandaChat.Send(data.Player, _localizationHelper, "invlaidSchematic", ChatColor.red);
                        }
                        {
                            NetworkMenu menu = new NetworkMenu();
                            menu.Width  = 800;
                            menu.Height = 600;
                            menu.LocalStorage.SetAs("header", selectedSchematic.Name.Replace(".schematic", "") + " " + _localizationHelper.LocalizeOrDefault("Details", data.Player));

                            menu.Items.Add(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Height", data.Player) + ": " + schematicMetadata.MaxY, UnityEngine.Color.black)));
                            menu.Items.Add(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Width", data.Player) + ": " + schematicMetadata.MaxZ, UnityEngine.Color.black)));
                            menu.Items.Add(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Length", data.Player) + ": " + schematicMetadata.MaxX, UnityEngine.Color.black)));
                            menu.LocalStorage.SetAs(Selected_Schematic, selectedSchematic.Name);

                            List <ValueTuple <IItem, int> > headerItems = new List <ValueTuple <IItem, int> >();
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData("  ", UnityEngine.Color.black)), 200));
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Item", data.Player), UnityEngine.Color.black)), 200));
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Required", data.Player), UnityEngine.Color.black)), 200));
                            headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("InStockpile", data.Player), UnityEngine.Color.black)), 200));
                            menu.Items.Add(new HorizontalRow(headerItems));

                            foreach (var kvp in schematicMetadata.Blocks)
                            {
                                try
                                {
                                    if (ItemTypes.TryGetType(kvp.Key, out ItemTypes.ItemType item))
                                    {
                                        var stockpileCount = 0;
                                        data.Player.ActiveColony.Stockpile.Items.TryGetValue(item.ItemIndex, out stockpileCount);

                                        List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                                        items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(kvp.Key), 200));
                                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(item.Name, UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 200));
                                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(" x " + kvp.Value.Count, UnityEngine.Color.black)), 200));
                                        items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(" x " + stockpileCount, UnityEngine.Color.black)), 200));
                                        menu.Items.Add(new HorizontalRow(items));
                                    }
                                    else
                                    {
                                        SettlersLogger.Log(ChatColor.orange, "Unknown item for schematic: {0}", kvp.Key);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    SettlersLogger.LogError(ex);
                                }
                            }

                            menu.Items.Add(new DropDown(new LabelData(_localizationHelper.GetLocalizationKey("Rotation"), UnityEngine.Color.black), Selected_Schematic + ".Rotation", _rotation.Select(r => r.ToString()).ToList()));
                            menu.Items.Add(new HorizontalSplit(new ButtonCallback(GameLoader.NAMESPACE + ".ShowMainMenu", new LabelData("Back", UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter)),
                                                               new ButtonCallback(GameLoader.NAMESPACE + ".SetBuildArea", new LabelData("Build", UnityEngine.Color.black, UnityEngine.TextAnchor.MiddleCenter))));
                            menu.LocalStorage.SetAs(Selected_Schematic + ".Rotation", 0);

                            NetworkMenuManager.SendServerPopup(data.Player, menu);
                        }
                    }
                }

                break;

            case GameLoader.NAMESPACE + ".SetBuildArea":
                var scem     = data.Storage.GetAs <string>(Selected_Schematic);
                var rotation = data.Storage.GetAs <int>(Selected_Schematic + ".Rotation");

                SettlersLogger.Log("Schematic: {0}", scem);

                if (SchematicReader.TryGetSchematicMetadata(scem, data.Player.ActiveColony.ColonyID, out SchematicMetadata metadata))
                {
                    if (metadata.Blocks.Count == 1 && metadata.Blocks.ContainsKey(ColonyBuiltIn.ItemTypes.AIR.Id))
                    {
                        PandaChat.Send(data.Player, _localizationHelper, "invlaidSchematic", ChatColor.red);
                    }
                    {
                        _awaitingClick[data.Player] = Tuple.Create(SchematicClickType.Build, scem, _rotation[rotation]);
                        PandaChat.Send(data.Player, _localizationHelper, "instructions");
                        NetworkMenuManager.CloseServerPopup(data.Player);
                    }
                }

                break;
            }
        }
Пример #24
0
        public static void OnPlayerPushedNetworkUIButton(ButtonPressCallbackData data)
        {
            if (data.Player.ActiveColony == null)
            {
                return;
            }

            if (data.ButtonIdentifier.StartsWith("PG.") == false)
            {
                return;
            }

            Pipliz.Collections.SortedList <string, ColonyJobData> colonyinfo = ColonyManager.GetColonyInfo(data.Player.ActiveColony);

            if (data.ButtonIdentifier.Contains("PG.Colony.Management"))
            {
                ColonyManager.SendUI(data.Player);
                return;
            }
            else if (data.ButtonIdentifier.Contains("PG.Jobs."))
            {
                NPCJobs.SendUI(data.Player, data.ButtonIdentifier.Split('.')[2]);
                return;
            }
            else if (data.ButtonIdentifier.Contains("PG.Colony.Itemcount"))
            {
                Itemcount.SendUI(data.Player);
                return;
            }
            else if (data.ButtonIdentifier.Contains("PG.Recruit."))
            {
                foreach (var job in colonyinfo)
                {
                    if (data.ButtonIdentifier.Contains(job.Key))
                    {
                        int recruit = data.Storage.GetAs <int>("PG.Recruit." + job.Key);
                        int count   = ColonyManager.GetCountValue(recruit);

                        if (count > job.Value.Avaible)
                        {
                            count = job.Value.Avaible;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var num = 0f;
                            data.Player.ActiveColony.HappinessData.RecruitmentCostCalculator.GetCost(data.Player.ActiveColony.HappinessData.CachedHappiness, data.Player.ActiveColony, out float foodcost);
                            if (data.Player.ActiveColony.Stockpile.TotalFood < foodcost || data.Player.ActiveColony.Stockpile.TryRemoveFood(ref num, foodcost) == false)
                            {
                                Helpers.Chat.Send(data.Player, "Colony does not have enough food!");
                                break;
                            }
                            if (data.Player.ActiveColony.CalculateBedCount() <= data.Player.ActiveColony.FollowerCount)
                            {
                                Helpers.Chat.Send(data.Player, "Colony does not have enough beds!");
                                break;
                            }
                            else
                            {
                                NPC.NPCBase newguy = new NPC.NPCBase(data.Player.ActiveColony, data.Player.ActiveColony.GetClosestBanner(new Pipliz.Vector3Int(data.Player.Position)).Position);
                                data.Player.ActiveColony.RegisterNPC(newguy);

                                NPC.NPCTracker.Add(newguy);

                                if (newguy.IsValid)
                                {
                                    newguy.TakeJob(job.Value.AvaibleJobs[i]);
                                    data.Player.ActiveColony.JobFinder.Remove(job.Value.AvaibleJobs[i]);
                                }
                            }
                        }
                        data.Player.ActiveColony.SendCommonData();
                        ColonyManager.SendUI(data.Player);
                    }
                }
                return;
            }
        }
Пример #25
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            if ((!data.ButtonIdentifier.Contains(".RecruitButton") &&
                 !data.ButtonIdentifier.Contains(".FireButton") &&
                 !data.ButtonIdentifier.Contains(".SwapJob") &&
                 !data.ButtonIdentifier.Contains(".ColonyToolMainMenu") &&
                 !data.ButtonIdentifier.Contains(".KillFired") &&
                 !data.ButtonIdentifier.Contains(".AutoRecruitment")) || data.Player.ActiveColony == null)
            {
                return;
            }

            Dictionary <string, JobCounts>      jobCounts       = GetJobCounts(data.Player.ActiveColony);
            Dictionary <Players.Player, string> AutoRecruit_Opt = new Dictionary <Players.Player, string>();

            if (data.ButtonIdentifier.Contains(".ColonyToolMainMenu"))
            {
                NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
            }
            else if (data.ButtonIdentifier.Contains(".FireButton"))
            {
                foreach (var job in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(job.Key))
                    {
                        var recruit = data.Storage.GetAs <int>(job.Key + ".Recruit");
                        var count   = GetCountValue(recruit);
                        var menu    = BuildMenu(data.Player, jobCounts, true, job.Key, count);

                        menu.LocalStorage.SetAs(Nach0Config.NAMESPACE + ".FiredJobName", job.Key);
                        menu.LocalStorage.SetAs(Nach0Config.NAMESPACE + ".FiredJobCount", count);

                        NetworkMenuManager.SendServerPopup(data.Player, menu);
                        break;
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".KillFired"))
            {
                var firedJob = data.Storage.GetAs <string>(Nach0Config.NAMESPACE + ".FiredJobName");
                var count    = data.Storage.GetAs <int>(Nach0Config.NAMESPACE + ".FiredJobCount");

                foreach (var job in jobCounts)
                {
                    if (job.Key == firedJob)
                    {
                        if (count > job.Value.TakenCount)
                        {
                            count = job.Value.TakenCount;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var npc = job.Value.TakenJobs[i].NPC;
                            npc.ClearJob();
                            npc.OnDeath();
                        }

                        break;
                    }
                }

                data.Player.ActiveColony.SendCommonData();
                jobCounts = GetJobCounts(data.Player.ActiveColony);
                NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
            }
            else if (data.ButtonIdentifier.Contains(".SwapJob"))
            {
                var firedJob = data.Storage.GetAs <string>(Nach0Config.NAMESPACE + ".FiredJobName");
                var count    = data.Storage.GetAs <int>(Nach0Config.NAMESPACE + ".FiredJobCount");

                foreach (var job in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(job.Key))
                    {
                        if (count > job.Value.AvailableCount)
                        {
                            count = job.Value.AvailableCount;
                        }

                        if (jobCounts.TryGetValue(firedJob, out var firedJobCounts))
                        {
                            for (int i = 0; i < count; i++)
                            {
                                if (firedJobCounts.TakenCount > i)
                                {
                                    var npc = firedJobCounts.TakenJobs[i].NPC;
                                    npc.ClearJob();
                                    npc.TakeJob(job.Value.AvailableJobs[i]);
                                    data.Player.ActiveColony.JobFinder.Remove(job.Value.AvailableJobs[i]);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }

                        data.Player.ActiveColony.SendCommonData();
                        break;
                    }
                }

                jobCounts = GetJobCounts(data.Player.ActiveColony);
                NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
            }
            else if (data.ButtonIdentifier.Contains(".RecruitButton"))
            {
                foreach (var job in jobCounts)
                {
                    if (data.ButtonIdentifier.Contains(job.Key))
                    {
                        var recruit = data.Storage.GetAs <int>(job.Key + ".Recruit");
                        var count   = GetCountValue(recruit);

                        if (count > job.Value.AvailableCount)
                        {
                            count = job.Value.AvailableCount;
                        }

                        for (int i = 0; i < count; i++)
                        {
                            var num = 0f;
                            data.Player.ActiveColony.HappinessData.RecruitmentCostCalculator.GetCost(data.Player.ActiveColony.HappinessData.CachedHappiness, data.Player.ActiveColony, out float foodCost);
                            if (data.Player.ActiveColony.Stockpile.TotalFood < foodCost ||
                                !data.Player.ActiveColony.Stockpile.TryRemoveFood(ref num, foodCost))
                            {
                                //PandaChat.Send(data.Player, _localizationHelper.LocalizeOrDefault("Notenoughfood", data.Player), ChatColor.red);
                                Chat.Send(data.Player, "<color=red>Notenoughfood</color>");
                                break;
                            }
                            else
                            {
                                var newGuy = new NPCBase(data.Player.ActiveColony, data.Player.ActiveColony.GetClosestBanner(new Vector3Int(data.Player.Position)).Position);
                                data.Player.ActiveColony.RegisterNPC(newGuy);
                                //SettlerInventory.GetSettlerInventory(newGuy);
                                NPCTracker.Add(newGuy);
                                //ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCRecruited, newGuy);

                                if (newGuy.IsValid)
                                {
                                    newGuy.TakeJob(job.Value.AvailableJobs[i]);
                                    data.Player.ActiveColony.JobFinder.Remove(job.Value.AvailableJobs[i]);
                                }
                            }
                        }


                        data.Player.ActiveColony.SendCommonData();

                        jobCounts = GetJobCounts(data.Player.ActiveColony);
                        NetworkMenuManager.SendServerPopup(data.Player, BuildMenu(data.Player, jobCounts, false, string.Empty, 0));
                    }
                }
            }
            else if (data.ButtonIdentifier.Contains(".AutoRecruitment"))
            {
                if (AutoRecruit_Opt[data.Player].Equals("on"))
                {
                    AutoRecruit_Opt[data.Player] = "off";
                    Chat.Send(data.Player, "<color=blue>Auto Recruitment is now " + AutoRecruit_Opt[data.Player] + "</color>");
                }
                else
                {
                    AutoRecruit_Opt[data.Player] = "on";
                    Chat.Send(data.Player, "<color=blue>Auto Recruitment is now " + AutoRecruit_Opt[data.Player] + "</color>");
                }
            }
        }
Пример #26
0
        public static void EmpireButtonManager(ButtonPressCallbackData data)
        {
            Empire empire;

            Players.Player plr;

            switch (data.ButtonIdentifier)
            {
            case "Imperium_NewEmpire":
            {
                SendMenuFoundEmpire(data.Player);
            }
            break;

            case "Imperium_FoundEmpire":
            {
                Empire.CreateEmpire(data.Storage.GetAs <string>("EmpireName"), data.Storage.GetAs <string>("EmpireTag"), data.Player);
            }
            break;

            case "Imperium_Apply":
            {
                empire = Empire.GetEmpire(data.ButtonPayload.Value <string>("empire"));

                if (null != empire)
                {
                    empire.ApplyFor(data.Player);
                }
                SendMenuEmpireList(data.Player);
            }
            break;

            case "Imperium_Request":
            {
                empire = Empire.GetEmpire(data.Player);

                if (empire == null)
                {
                    return;
                }

                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    if (data.ButtonPayload.Value <bool>("accept"))
                    {
                        empire.Invite(plr, data.Player);
                    }
                    else
                    {
                        empire.joinRequest.Remove(plr.ID);
                        Chatting.Chat.Send(plr, string.Format("<color=green>{0} has rejected your request of joining.</color>", empire.Name));
                    }
                }

                if (empire.joinRequest.Count > 0)
                {
                    SendMenuEmpireRequest(data.Player);
                }
                else
                {
                    SendMenuEmpire(data.Player);
                }
            }
            break;

            case "Imperium_HELP":
            {
                SendMenuHelp(data.Player);
            }
            break;

            case "Imperium_ApplyManage":
            {
                SendMenuEmpireRequest(data.Player);
            }
            break;

            case "Imperium_BackPermission":
            {
                SendMenuPermissions(data.Player);
            }
            break;

            case "Imperium_SettingsMenu":
            {
                SendMenuEmpireSettings(data.Player);
            }
            break;

            case "Imperium_Manage":
            {
                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    SendMenuEmpireManage(data.Player, plr);
                }
            }
            break;

            case "Imperium_Promote":
            {
                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    empire = Empire.GetEmpire(data.Player);

                    if (null != empire)
                    {
                        empire.Promote(plr, data.Player);
                        SendMenuEmpireManage(data.Player, plr);
                    }
                }
            }
            break;

            case "Imperium_Demote":
            {
                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    empire = Empire.GetEmpire(data.Player);

                    if (null != empire)
                    {
                        empire.Demote(plr, data.Player);
                        SendMenuEmpireManage(data.Player, plr);
                    }
                }
            }
            break;

            case "Imperium_Kick":
            {
                if (Players.TryGetPlayer(NetworkID.Parse(data.ButtonPayload.Value <string>("player")), out plr))
                {
                    empire = Empire.GetEmpire(data.Player);

                    if (null != empire)
                    {
                        empire.Kick(plr, data.Player);
                        SendMenuEmpireManage(data.Player, plr);
                    }
                }
            }
            break;

            case "Imperium_SetSettings":
            {
                empire = Empire.GetEmpire(data.Player);

                if (null != empire)
                {
                    string newName = data.Storage.GetAs <string>("EmpireName");
                    if (!empire.Name.Equals(newName))
                    {
                        empire.SetEmpireName(newName, data.Player);
                    }

                    string newTag = data.Storage.GetAs <string>("EmpireTag");
                    if (!empire.Tag.Equals(newTag))
                    {
                        empire.SetEmpireTag(newTag, data.Player);
                    }

                    bool automaticRequest = data.Storage.GetAs <bool>("AutomaticRequest");
                    if (empire.automaticRequest != automaticRequest)
                    {
                        empire.SetAutomaticRequest(automaticRequest, data.Player);
                    }
                }
            }
            break;

            case "Imperium_Permission":
            {
                int rank = data.ButtonPayload.Value <int>("rank");
                SendMenuPermissionsManagement(data.Player, rank);
            }
            break;

            case "Imperium_SetPermission":
            {
                empire = Empire.GetEmpire(data.Player);

                if (empire != null)
                {
                    int rank = data.ButtonPayload.Value <int>("rank");

                    Permissions newPermission = 0;

                    for (int i = (int)Permissions.Invite; i < (int)Permissions.Disband; i *= 2)
                    {
                        if (data.Storage.GetAs <bool>(((Permissions)i).ToString()))
                        {
                            newPermission |= (Permissions)i;
                        }
                    }

                    empire.SetPermissions(data.Player, (Rank)rank, newPermission);
                }
            }
            break;

            case "Imperium_ManageAsEmperor":
            {
                empire = Empire.GetEmpire(data.ButtonPayload.Value <string>("empire"));

                if (null != empire)
                {
                    empire.AddEmperor(data.Player);
                }
            }
            break;

            case "Imperium_SetRank":
            {
                empire = Empire.GetEmpire(data.Player);

                if (empire == null)
                {
                    return;
                }

                Rank rank = (Rank)data.ButtonPayload.Value <int>("rank");

                empire.SetRank(data.Player, rank);

                Chatting.Chat.Send(data.Player, "Rank set to " + rank.ToString());
            }
            break;
            }
        }
Пример #27
0
        public static void PressButton(ButtonPressCallbackData data)
        {
            if (data.Player == null || data.Player.ActiveColony == null)
            {
                return;
            }

            if (data.ButtonIdentifier == "Crate.GetItemsFromStockpile")
            {
                NetworkMenu menu = StockpileMenu(data);
                NetworkMenuManager.SendServerPopup(data.Player, menu);
            }
            else if (data.ButtonIdentifier == "Crate.MainMenu")
            {
                NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
            }
            else if (data.ButtonIdentifier == "Crate.GetItemsFromToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data));
            }
            else if (data.ButtonIdentifier == "Crate.SelectAllInCrate")
            {
                NetworkMenuManager.SendServerPopup(data.Player, StockpileMenu(data, false, true));
            }
            else if (data.ButtonIdentifier == "Crate.SelectNoneInCrate")
            {
                NetworkMenuManager.SendServerPopup(data.Player, StockpileMenu(data, false, false));
            }
            else if (data.ButtonIdentifier == "Crate.SelectAllInToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data, false, true));
            }
            else if (data.ButtonIdentifier == "Crate.SelectNoneInToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data, false, false));
            }
            else if (data.ButtonIdentifier == "Crate.SelectNoneInCrateMain")
            {
                NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, false, false));
            }
            else if (data.ButtonIdentifier == "Crate.SelectAllInCrateMain")
            {
                NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, false, true));
            }
            else if (data.ButtonIdentifier == "Crate.SelectNoneInCrateToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data, false, false));
            }
            else if (data.ButtonIdentifier == "Crate.SelectAllInCrateToolbar")
            {
                NetworkMenuManager.SendServerPopup(data.Player, ToolbarMenu(data, false, true));
            }
            else if (data.ButtonIdentifier == "Crate.MoveItemsToStockpile")
            {
                if (data.Storage.TryGetAs("Crate.NumberOfItems", out string strNumItems) &&
                    int.TryParse(strNumItems, out int numItems) &&
                    TryGetPlayersCurrentCrate(data.Player, out var crateInventory))
                {
                    List <InventoryItem> itemsMoved = new List <InventoryItem>();

                    foreach (var itemKvp in crateInventory.GetAllItems())
                    {
                        if (data.Storage.TryGetAs("Crate." + itemKvp.Key + ".ItemSelected", out bool selected) && selected)
                        {
                            int takeNum = System.Math.Min(numItems, itemKvp.Value);
                            var item    = new StoredItem(itemKvp.Value.Id, takeNum);
                            itemsMoved.Add(item);
                            crateInventory.TryTake(item);
                        }
                    }

                    data.Player.ActiveColony.Stockpile.Add(itemsMoved);

                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
                }
                else
                {
                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, true));
                }
            }
            else if (data.ButtonIdentifier == "Crate.MoveItemsToToolbar")
            {
                if (data.Storage.TryGetAs("Crate.NumberOfItems", out string strNumItems) &&
                    int.TryParse(strNumItems, out int numItems) &&
                    TryGetPlayersCurrentCrate(data.Player, out var crateInventory))
                {
                    List <StoredItem> itemsMoved = new List <StoredItem>();
                    var invRef = data.Player.Inventory;

                    foreach (var itemKvp in crateInventory.GetAllItems())
                    {
                        if (data.Storage.TryGetAs("Crate." + itemKvp.Key + ".ItemSelected", out bool selected) && selected)
                        {
                            int takeNum = System.Math.Min(numItems, itemKvp.Value);
                            var item    = new StoredItem(itemKvp.Value.Id, takeNum);
                            itemsMoved.Add(item);
                        }
                    }

                    foreach (var item in itemsMoved)
                    {
                        if (invRef.TryAdd(item.Id, item.Amount))
                        {
                            crateInventory.TryTake(item);
                        }
                        else
                        {
                            break;
                        }
                    }

                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
                }
                else
                {
                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, true));
                }
            }
            else if (data.ButtonIdentifier == "Crate.MoveItemsToCrateFromStockpile")
            {
                if (data.Storage.TryGetAs("Crate.NumberOfItems", out string strNumItems) &&
                    int.TryParse(strNumItems, out int numItems) &&
                    TryGetPlayersCurrentCrate(data.Player, out var crateInventory))
                {
                    List <StoredItem> itemsMoved = new List <StoredItem>();

                    foreach (var itemKvp in data.Player.ActiveColony.Stockpile.Items)
                    {
                        if (data.Storage.TryGetAs("Crate." + itemKvp.Key + ".ItemSelected", out bool selected) && selected)
                        {
                            int takeNum = System.Math.Min(numItems, itemKvp.Value);
                            var item    = new StoredItem(itemKvp.Key, takeNum);
                            itemsMoved.Add(item);
                        }
                    }

                    foreach (var item in itemsMoved)
                    {
                        data.Player.ActiveColony.Stockpile.TryRemove(item);
                        var leftover = crateInventory.TryAdd(item);
                        data.Player.ActiveColony.Stockpile.Add(leftover);
                    }

                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
                }
                else
                {
                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, true));
                }
            }
            else if (data.ButtonIdentifier == "Crate.MoveItemsToCrateFromToolbar")
            {
                if (data.Storage.TryGetAs("Crate.NumberOfItems", out string strNumItems) &&
                    int.TryParse(strNumItems, out int numItems) &&
                    TryGetPlayersCurrentCrate(data.Player, out var crateInventory))
                {
                    List <StoredItem> itemsMoved = new List <StoredItem>();
                    var invRef = data.Player.Inventory;

                    foreach (var itemKvp in invRef.Items)
                    {
                        if (data.Storage.TryGetAs("Crate." + itemKvp.Type + ".ItemSelected", out bool selected) && selected)
                        {
                            int takeNum = System.Math.Min(numItems, itemKvp.Amount);
                            var item    = new StoredItem(itemKvp.Type, takeNum);
                            itemsMoved.Add(item);
                        }
                    }

                    foreach (var item in itemsMoved)
                    {
                        if (invRef.TryRemove(item.Id, item.Amount))
                        {
                            invRef.Add(crateInventory.TryAdd(item));
                        }
                    }

                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player));
                }
                else
                {
                    NetworkMenuManager.SendServerPopup(data.Player, MainMenu(data.Player, true));
                }
            }
        }
Пример #28
0
        private static NetworkMenu StockpileMenu(ButtonPressCallbackData data, bool error = false, bool?selectAll = null)
        {
            NetworkMenu menu = new NetworkMenu();

            menu.LocalStorage.SetAs("header", _localizationHelper.LocalizeOrDefault("MoveItemsToCrate", data.Player));
            menu.Width  = 1000;
            menu.Height = 600;

            try
            {
                if (error)
                {
                    menu.Items.Add(new Label(new LabelData(_localizationHelper.GetLocalizationKey("invalidNumber"), UnityEngine.Color.red)));
                }

                List <ValueTuple <IItem, int> > headerItems = new List <ValueTuple <IItem, int> >();
                headerItems.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.GetLocalizationKey("Numberofitems"))), 333));
                headerItems.Add(ValueTuple.Create <IItem, int>(new InputField("Crate.NumberOfItems"), 333));
                headerItems.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Crate.MoveItemsToCrateFromStockpile", new LabelData(_localizationHelper.GetLocalizationKey("MoveItemsToCrate"))), 333));
                menu.Items.Add(new HorizontalRow(headerItems));
                menu.Items.Add(new Line(UnityEngine.Color.black));

                List <ValueTuple <IItem, int> > items = new List <ValueTuple <IItem, int> >();
                items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Crate.MainMenu", new LabelData(_localizationHelper.GetLocalizationKey("Back"))), 250));
                items.Add(ValueTuple.Create <IItem, int>(new EmptySpace(), 250));
                items.Add(ValueTuple.Create <IItem, int>(new EmptySpace(), 250));

                bool selected = false;

                if (selectAll == true)
                {
                    selected = true;
                }
                else if (selectAll == false)
                {
                    selected = false;
                }

                if (selected)
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Crate.SelectNoneInCrate", new LabelData(_localizationHelper.GetLocalizationKey("SelectNone"))), 250));
                }
                else
                {
                    items.Add(ValueTuple.Create <IItem, int>(new ButtonCallback("Crate.SelectAllInCrate", new LabelData(_localizationHelper.GetLocalizationKey("SelectAll"))), 250));
                }

                menu.Items.Add(new HorizontalRow(items));
                menu.Items.Add(new Line(UnityEngine.Color.black));

                foreach (var itemKvp in data.Player.ActiveColony.Stockpile.Items)
                {
                    items = new List <ValueTuple <IItem, int> >();
                    items.Add(ValueTuple.Create <IItem, int>(new ItemIcon(itemKvp.Key), 250));
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(ItemId.GetItemId(itemKvp.Key), UnityEngine.TextAnchor.MiddleLeft, 18, LabelData.ELocalizationType.Type)), 250));
                    items.Add(ValueTuple.Create <IItem, int>(new Label(new LabelData(_localizationHelper.LocalizeOrDefault("Crate", data.Player) + ": " + itemKvp.Value.ToString())), 250));
                    items.Add(ValueTuple.Create <IItem, int>(new Toggle(new LabelData(_localizationHelper.LocalizeOrDefault("Select", data.Player)), "Crate." + itemKvp.Key + ".ItemSelected"), 250));

                    if (selectAll == null)
                    {
                        menu.LocalStorage.TryGetAs("Crate." + itemKvp.Key + ".ItemSelected", out selected);
                    }

                    menu.LocalStorage.SetAs("Crate." + itemKvp.Key + ".ItemSelected", selected);
                    menu.Items.Add(new HorizontalRow(items));
                }
            }
            catch (Exception ex)
            {
                CivLogger.LogError(ex);
            }

            return(menu);
        }