示例#1
0
        public UiLayerEditor(ContentManager Content, Overworld o)
        {
            this.o      = o;
            this.layers = o.meta.layers;
            layerList   = new UiList(Content, layers.ToArray());
            commandList = new UiList(Content, new string[4] {
                "Add", "Delete", "Set Base", "Exit"
            });
            commandList.addCallback(element =>
            {
                commandList.finished = false;
                switch (commandList.selected)
                {
                case 0: mode = Mode.Adding; genLayerStrings(); layerList.selected = 0; break;

                case 1: mode = Mode.Deleting; genLayerStrings(); layerList.selected = 0; break;

                case 2: mode = Mode.SetBase; genLayerStrings(); layerList.selected = o.meta.baseLayer; break;

                case 3: finished = true; break;
                }
            });
            layerList.addCallback(element =>
            {
                layerList.finished = false;
                if (layerList.selected != -1)
                {
                    if (mode == Mode.Adding)
                    {
                        system.pushElement(new UiTextInput("Filename: ").addCallback(input =>
                        {
                            UiTextInput textInput = (UiTextInput)input;
                            if (textInput.text != null)
                            {
                                layers.Insert(layerList.selected, textInput.text);
                                if (layerList.selected >= o.meta.baseLayer)
                                {
                                    o.meta.baseLayer++;
                                }
                                layerList.setStrings(layers.ToArray());
                                o.reloadLayers();
                            }
                        }), Vector2.Zero);
                    }
                    else if (mode == Mode.Deleting)
                    {
                        layers.RemoveAt(layerList.selected);
                        if (layerList.selected <= o.meta.baseLayer)
                        {
                            o.meta.baseLayer--;
                        }
                        layerList.setStrings(layers.ToArray());
                        o.reloadLayers();
                    }
                    else if (mode == Mode.SetBase)
                    {
                        o.meta.baseLayer = layerList.selected;
                        o.reloadLayers();
                    }
                    mode = Mode.Inactive;
                }
            });
        }
示例#2
0
        public TitleScreen(Game1 game, ContentManager Content)
        {
            this.game    = game;
            this.Content = Content;
            bg           = Content.Load <Texture2D>(GameInfo.titleBackground);
            ui           = new UiSystem(false);

            mainList = new UiList(Content, new string[4] {
                "New Game", "Load Game", "Options", "Quit"
            });
            mainList.addCallback(element =>
            {
                element.finished = false; // cancel removing the main list
                UiList list      = (UiList)element;
                int selected     = list.selected;
                switch (selected)
                {
                case -1:     // thwart attempt to close the main menu
                    {
                        list.selected = 0;
                        break;
                    }

                case 0:     // new game
                    {
                        TimeOfDay.restart();
                        Flags.reset();
                        if (GameInfo.startOverworld)
                        {
                            game.goToOverworld(new Player(Content, null, null), GameInfo.startMap);
                        }
                        else
                        {
                            game.goToWorld(new Player(Content, null, null), GameInfo.startMap);
                        }
                        break;
                    }

                case 1:     // load game
                    {
                        ui.pushElement(new UiSavePicker(Content, false).addCallback(element =>
                        {
                            UiSavePicker saves = (UiSavePicker)element;
                            string chosen      = saves.selectedString;
                            if (chosen == UiSavePicker.NO_FILES || chosen == null)
                            {
                                return;
                            }
                            SaveGame game = SaveGame.Load(Content, chosen);
                            TimeOfDay.restart();
                            Flags.reset();

                            // restore data from save
                            Player player = new Player(Content, null, null);
                            foreach (string s in game.inventory.Keys)
                            {
                                player.addItem(s, game.inventory[s]);
                            }
                            Flags.setAllFlags(game.flags, game.strings);
                            TimeOfDay.addMillis(game.time);
                            player.setTileLocation(game.location);

                            // go to overworld or map
                            if (game.overworld)
                            {
                                this.game.goToOverworld(player, game.map);
                            }
                            else
                            {
                                this.game.goToWorld(player, game.map, false);
                            }
                        }), new Vector2(Tile.TILE_SIZE, Tile.TILE_SIZE));
                        break;
                    }

                case 2:     // options
                    {
                        ui.pushElement(new UiOptionsMenu(game, Content),
                                       new Vector2(
                                           Game1.INTERNAL_WIDTH / 2 - UiOptionsMenu.WIDTH / 2,
                                           Game1.INTERNAL_HEIGHT / 2 - UiOptionsMenu.HEIGHT / 2)
                                       );
                        break;
                    }

                case 3:     // quit
                    {
                        game.Exit();
                        break;
                    }
                }
            });

            Vector2 center = Vector2.Round(new Vector2(
                                               Game1.INTERNAL_WIDTH / 2 - mainList.size.X / 2,
                                               (Game1.INTERNAL_HEIGHT / 2 - mainList.size.Y / 2) + 20));

            ui.pushElement(mainList, center);
        }