コード例 #1
0
        public UiInventory(ContentManager Content, Player player)
            : base(Content, new string[0])
        {
            this.Content = Content;
            this.player  = player;

            resetMenu();

            this.addCallback(element =>
            {
                if (this.selected != -1)
                {
                    if (this.unformatted.Length == 0)
                    {
                        return;                               // "you have no items" placeholder
                    }
                    Item selectedItem = Inventory.getItem(unformatted[this.selected]);
                    this.finished     = false;

                    system.pushElement(new UiList(Content, COMMANDS).addCallback(command =>
                    {
                        UiList commandList = (UiList)command;
                        switch (commandList.selected)
                        {
                        case 0: break; // TODO Use item

                        case 1:        // Examine
                            {
                                system.pushElement(new UiTextBox(selectedItem.description, false), Vector2.Zero);
                                break;
                            }

                        case 2:     // Discard
                            {
                                system.pushElement(new UiOptionBox(Content, "Really discard this?", "No", "Yes").addCallback(o =>
                                {
                                    UiOptionBox option = (UiOptionBox)o;
                                    if (option.selected == 1)
                                    {
                                        player.setItemCount(selectedItem.name, 0);
                                        this.resetMenu();
                                    }
                                }), Vector2.Zero);
                                break;
                            }
                        }
                    }), COMMAND_LOCATION);
                }
            });
        }
コード例 #2
0
        public UiPauseMenu(Game1 game, ContentManager Content, Player player, string map, bool overworld)
            : base(Content, new string[4] {
            "Items", "Save", "Options", "Quit"
        })
        {
            this.game    = game;
            this.Content = Content;
            this.player  = player;

            addCallback(element =>
            {
                UiList list = (UiList)element;
                switch (list.selected)
                {
                case 0:     // inventory
                    {
                        element.finished = false;
                        system.pushElement(new UiInventory(Content, player),
                                           new Vector2(Tile.TILE_SIZE, Tile.TILE_SIZE));
                        break;
                    }

                case 1:                           // save
                    {
                        element.finished = false; // don't close the menu yet
                        system.pushElement(new UiSavePicker(Content, true).addCallback(element2 =>
                        {
                            UiSavePicker savePicker = (UiSavePicker)element2;
                            string filename         = savePicker.selectedString;
                            if (filename == null)
                            {
                                return;
                            }
                            else if (filename == UiSavePicker.CREATE_NEW_FILE)
                            {
                                filename = "save" + savePicker.GetHashCode();     // create new file name
                            }
                            SaveGame.Save(filename + ".json", player, map, overworld);
                            element.finished = true;     // actually, do the close menu
                        }), new Vector2(Tile.TILE_SIZE * 10, Tile.TILE_SIZE));
                        break;
                    }

                case 2:     // TODO options
                    {
                        element.finished = false;
                        system.pushElement(new UiOptionsMenu(game, Content),
                                           new Vector2(
                                               Game1.INTERNAL_WIDTH / 2 - UiOptionsMenu.WIDTH / 2,
                                               Game1.INTERNAL_HEIGHT / 2 - UiOptionsMenu.HEIGHT / 2)
                                           );
                        break;
                    }

                case 3:     // TODO quit
                    {
                        system.pushElement(new UiOptionBox(Content, "Quit? Unsaved progress will be lost.", "No", "Yes")
                                           .addCallback(element =>
                        {
                            UiOptionBox option = (UiOptionBox)element;
                            if (option.selected == 1)
                            {
                                game.goToTitle();
                            }
                        }), Vector2.Zero);
                        break;
                    }
                }
            });
        }