Ejemplo n.º 1
0
        private static void Right_Click(Players.Player player)
        {
            int forester = last_forester.GetValueOrDefault(player.ID, 0);

            AreaJobTracker.CommandToolTypeData data = new AreaJobTracker.CommandToolTypeData();

            switch (forester)
            {
            default:
            case 0:
                data.LocaleEntry = "popup.tooljob.cherryforester";
                data.AreaType    = "Khanx.CherryForester";
                break;

            case 1:
                data.LocaleEntry = "popup.tooljob.taigaforester";
                data.AreaType    = "Khanx.TaigaForester";
                break;

            case 2:
                data.LocaleEntry = "popup.tooljob.oliveforester";
                data.AreaType    = "Khanx.OliveForester";
                break;

            case 3:
                data.LocaleEntry = "popup.tooljob.autumredforester";
                data.AreaType    = "Khanx.AutummRedForester";
                break;

            case 4:
                data.LocaleEntry = "popup.tooljob.autummorangeforester";
                data.AreaType    = "Khanx.AutummOrangeForester";
                break;

            case 5:
                data.LocaleEntry = "popup.tooljob.autumyellowforester";
                data.AreaType    = "Khanx.AutummYellowForester";
                break;

            case 6:
                data.LocaleEntry = "popup.tooljob.darktemperateforester";
                data.AreaType    = "Khanx.DarkTemperateForester";
                break;

            case 7:
                data.LocaleEntry = "popup.tooljob.temperateforester";
                data.AreaType    = "Khanx.TemperateForester";
                break;

            case 8:
                data.LocaleEntry = "popup.tooljob.lighttemperateforester";
                data.AreaType    = "Khanx.LightTemperateForester";
                break;
            }

            data.Minimum3DBlockCount = 36;
            data.Maximum3DBlockCount = 100;
            data.Minimum2DBlockCount = 36;
            data.Maximum2DBlockCount = 100;
            data.MinimumHeight       = 1;
            data.MaximumHeight       = 3;
            data.OneAreaOnly         = true;

            AreaJobTracker.StartCommandToolSelection(player, data);
        }
Ejemplo n.º 2
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;
            }
        }