Exemple #1
0
        /// Load all plant definitions
        public static void LoadMenuOrdersFromCode()
        {
            Defs.orders = new Dictionary <string, MenuOrderDef>();

            Defs.AddMenuOrder(
                new MenuOrderDef {
                uid        = "cancel",
                name       = "Cancel orders",
                shortDesc  = "Cancel all orders is a designated area",
                selector   = SelectorType.AreaTile,
                layer      = Layer.Orders,
                sprite     = Res.sprites["order_to_cancel"],
                actionArea = (RectI rect) => {
                    foreach (Vector2Int position in rect)
                    {
                        foreach (Tilable tilable in Loki.map.GetAllTilablesAt(position))
                        {
                            tilable.ClearOrder();
                        }
                    }
                },
                keyCode = KeyCode.C,
            }
                );

            Defs.AddMenuOrder(
                new MenuOrderDef {
                uid        = "cut_wood",
                name       = "Cut Wood",
                shortDesc  = "Cut all trees in a designated area.",
                selector   = SelectorType.AreaTile,
                layer      = Layer.Orders,
                sprite     = Res.sprites["order_to_cut"],
                actionArea = (RectI rect) => {
                    foreach (Vector2Int position in rect)
                    {
                        Plant plant = (Plant)Loki.map.grids[Layer.Plant].GetTilableAt(position);
                        if (plant != null && plant.def.cuttable && plant.def.type == TilableType.Tree)
                        {
                            //plant.OrderToCut();
                            plant.AddOrder(Defs.orders["cut_wood"]);
                        }
                    }
                },
                graphics = new GraphicDef {
                    textureName = "order_to_cut"
                },
                keyCode = KeyCode.W,
            }
                );
            Defs.AddMenuOrder(
                new MenuOrderDef {
                uid        = "cut_plants",
                name       = "Cut Plants",
                layer      = Layer.Orders,
                shortDesc  = "Cut all plants in a designated area.",
                selector   = SelectorType.AreaTile,
                sprite     = Res.sprites["order_to_cut_plant"],
                actionArea = (RectI rect) => {
                    foreach (Vector2Int position in rect)
                    {
                        Plant plant = (Plant)Loki.map.grids[Layer.Plant].GetTilableAt(position);
                        if (plant != null && plant.def.cuttable)
                        {
                            plant.AddOrder(Defs.orders["cut_plants"]);
                        }
                    }
                },
                graphics = new GraphicDef {
                    textureName = "order_to_cut_plant"
                },
                keyCode = KeyCode.D,
            }
                );
            Defs.AddMenuOrder(
                new MenuOrderDef {
                uid        = "harvest_plants",
                name       = "Haverst Plants",
                layer      = Layer.Orders,
                shortDesc  = "Harvest all plants in a designated area.",
                selector   = SelectorType.AreaTile,
                sprite     = Res.sprites["order_harvest"],
                actionArea = (RectI rect) => {
                    foreach (Vector2Int position in rect)
                    {
                        Plant plant = (Plant)Loki.map.grids[Layer.Plant].GetTilableAt(position);
                        if (plant != null && plant.def.cuttable && plant.def.type == TilableType.Plant)
                        {
                            plant.AddOrder(Defs.orders["harvest_plants"]);
                        }
                    }
                },
                graphics = new GraphicDef {
                    textureName = "order_harvest"
                },
                keyCode = KeyCode.H,
            }
                );
        }