コード例 #1
0
        private void RenderScreen(NamelessGame game, Screen screen, GameSettings settings)
        {
            effect.Parameters["tileAtlas"].SetValue(tileAtlas);
            var projectionMatrix = //Matrix.CreateOrthographic(game.getActualWidth(),game.getActualHeight(),0,1);
                                   Matrix.CreateOrthographicOffCenter(0, game.GetActualWidth(), game.GetActualHeight(), 0, 0, 2);

            effect.Parameters["xViewProjection"].SetValue(projectionMatrix);

            effect.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
            effect.GraphicsDevice.BlendState       = BlendState.AlphaBlend;

            var       device = game.GraphicsDevice;
            Stopwatch s      = Stopwatch.StartNew();

            for (int y = 0; y < settings.GetHeightZoomed(); y++)
            {
                for (int x = 0; x < settings.GetWidthZoomed(); x++)
                {
                    DrawTile(game.GraphicsDevice, game, x, y,
                             x * settings.GetFontSizeZoomed(),
                             y * settings.GetFontSizeZoomed(),
                             characterToTileDictionary[screen.ScreenBuffer[y, x].Char],
                             screen.ScreenBuffer[y, x].CharColor,
                             screen.ScreenBuffer[y, x].BackGroundColor, foregroundModel, backgroundModel
                             );
                }
            }
            s.Stop();
            var tileModel = backgroundModel;

            effect.CurrentTechnique = effect.Techniques["Background"];
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, tileModel.Vertices, 0, tileModel.Vertices.Length,
                                                 tileModel.Indices.ToArray(), 0, 2, this.VertexDeclaration);
            }

            effect.CurrentTechnique = effect.Techniques["Point"];

            tileModel = foregroundModel;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, tileModel.Vertices, 0, tileModel.Vertices.Length,
                                                 tileModel.Indices.ToArray(), 0, tileModel.Indices.Count() / 3, this.VertexDeclaration);
            }
        }
コード例 #2
0
        public InventoryScreen(NamelessGame game)
        {
            this.game = game;

            Panel = new Panel()
            {
                Width  = game.GetActualWidth(),
                Height = game.GetActualCharacterHeight(),
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Top
            };
            ReturnToGame = new ImageTextButton()
            {
                GridRow    = 1,
                GridColumn = 1,
                ContentHorizontalAlignment = HorizontalAlignment.Center,
                ContentVerticalAlignment   = VerticalAlignment.Center,
                Text = "Back",
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Right,
                Width  = 200,
                Height = 50
            };
            ReturnToGame.Click += OnClickReturnToGame;

            var grid = new Grid()
            {
                VerticalAlignment = VerticalAlignment.Stretch, ColumnSpacing = 3, RowSpacing = 2
            };

            grid.RowsProportions.Add(new Proportion(ProportionType.Fill));
            grid.RowsProportions.Add(new Proportion(ProportionType.Pixels, 50));

            EquipmentBox = new Table()
            {
                GridColumn        = 0, GridRow = 0, HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                BorderThickness   = new Thickness(1),
                Border            = new SolidBrush(Color.White)
            };
            ItemBox = new Table()
            {
                GridColumn        = 1, GridRow = 0, HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                BorderThickness   = new Thickness(1),
                Border            = new SolidBrush(Color.White)
            };


            //FillItems(game);


            grid.Widgets.Add(EquipmentBox);
            grid.Widgets.Add(ItemBox);
            grid.Widgets.Add(ReturnToGame);
            Panel.Widgets.Add(grid);

            game.Desktop.Widgets.Add(Panel);

            SelectedTable = ItemBox;

            ItemChoiceDialog = new ChoiceDialog(
                new ChoiceOption()
            {
                Id = ItemDialogActions.Equip, Text = "Equip"
            },
                new ChoiceOption()
            {
                Id = ItemDialogActions.Drop, Text = "Drop"
            },
                new ChoiceOption()
            {
                Id = ItemDialogActions.Cancel, Text = "Cancel"
            }
                );
            ItemChoiceDialog.Title = "Item commands";


            EquipmentChoiceDialog = new ChoiceDialog(
                new ChoiceOption()
            {
                Id = EquipmentDialogActions.Unequip, Text = "Unequip"
            },
                new ChoiceOption()
            {
                Id = EquipmentDialogActions.Drop, Text = "Drop"
            },
                new ChoiceOption()
            {
                Id = EquipmentDialogActions.Cancel, Text = "Cancel"
            }
                );
            EquipmentChoiceDialog.Title = "Equipment commands";

            ItemBox.OnItemClick += (TableItem selectedItem) =>
            {
                int selectedIndex = ItemBox.Items.IndexOf(selectedItem);
                if (selectedIndex > 0)
                {
                    this.SelectedItem = selectedItem;

                    var itemEntity = (IEntity)selectedItem.Tag;
                    FillItemChoiceDialog(itemEntity);
                    OpenDialog(ItemChoiceDialog, game);
                }
            };

            EquipmentBox.OnItemClick += (TableItem selectedItem) =>
            {
                int selectedIndex = EquipmentBox.Items.IndexOf(selectedItem);
                if (selectedIndex > 0)
                {
                    this.SelectedItem = selectedItem;
                    OpenDialog(EquipmentChoiceDialog, game);
                }
            };

            EquipmentChoiceDialog.OptionsTable.OnItemClick += (TableItem selectedItemOptions) =>
            {
                if (SelectedItem.Tag == null)
                {
                    Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                    {
                        CloseDialog(EquipmentChoiceDialog);
                    });
                    return;
                }

                var playerEntity = game.PlayerEntity;
                var slot         = (Slot)SelectedItem.Tag;
                var itemsHolder  = playerEntity.GetComponentOfType <ItemsHolder>();
                var equipment    = playerEntity.GetComponentOfType <EquipmentSlots>();

                var equipmentItem = equipment.Slots.First(x => x.Item1 == slot).Item2.Equipment;

                if (equipmentItem == null)
                {
                    Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                    {
                        CloseDialog(EquipmentChoiceDialog);
                    });
                    return;
                }

                var chosenItem    = (ChoiceOption)selectedItemOptions.Tag;
                var dialogActions = (EquipmentDialogActions)chosenItem.Id;
                switch (dialogActions)
                {
                case EquipmentDialogActions.Drop:

                    Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                    {
                        equipment.TakeOff(equipmentItem);
                        var position = playerEntity.GetComponentOfType <Position>();
                        var command  = new DropItemCommand(new List <IEntity>()
                        {
                            game.GetEntity(equipment.ParentEntityId)
                        }, itemsHolder, position.Point);
                        namelessGame.Commander.EnqueueCommand(command);
                        invScreenSystem.ScheduleUpdate();
                    });


                    break;

                case EquipmentDialogActions.Unequip:
                    Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                    {
                        equipment.TakeOff(equipmentItem);
                        invScreenSystem.ScheduleUpdate();
                    });
                    break;

                case EquipmentDialogActions.Cancel:
                    break;

                default:
                    break;
                }

                Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                {
                    CloseDialog(EquipmentChoiceDialog);
                });
            };

            ItemChoiceDialog.Closed += (sender, args) => { SelectTable(ItemBox); dialogOpened = false; };

            ItemChoiceDialog.OptionsTable.OnItemClick += (TableItem selectedItemOptions) =>
            {
                var playerEntity = game.PlayerEntity;
                var itemEntity   = (IEntity)SelectedItem.Tag;
                var itemsHolder  = playerEntity.GetComponentOfType <ItemsHolder>();
                var equipment    = playerEntity.GetComponentOfType <EquipmentSlots>();

                var equipmentItem = itemEntity.GetComponentOfType <Equipment>();

                var chosenItem = (ChoiceOption)selectedItemOptions.Tag;


                ItemDialogActions itemDialogActions = (ItemDialogActions)chosenItem.Id;
                switch (itemDialogActions)
                {
                case ItemDialogActions.DropAmount:
                {
                    AmountDialog = new AmountDialog();
                    AmountDialog.ShowModal(game.Desktop);
                    AmountDialog.Amount.OnTouchDown();
                    AmountDialog.Closed += (sender, args) =>
                    {
                        if (AmountDialog.Result)
                        {
                            var position      = playerEntity.GetComponentOfType <Position>();
                            var amount        = AmountDialog.Amount.Text == null ? 0 : int.Parse(AmountDialog.Amount.Text);
                            var itemComponent = itemEntity.GetComponentOfType <Item>();
                            if (amount >= itemComponent.Amount)
                            {
                                CloseDialog(ItemChoiceDialog);
                                Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                                    {
                                        var command = new DropItemCommand(new List <IEntity>()
                                        {
                                            itemEntity
                                        }, itemsHolder,
                                                                          position.Point);
                                        namelessGame.Commander.EnqueueCommand(command);
                                        invScreenSystem.ScheduleUpdate();
                                    });
                            }
                            else if (amount < 1)
                            {
                            }
                            else
                            {
                                var clonedEntity = itemEntity.CloneEntity();

                                //game.EntitiesToAdd.Add(clonedEntity);

                                var clonedItemComponent = clonedEntity.GetComponentOfType <Item>();

                                itemComponent.Amount      -= amount;
                                clonedItemComponent.Amount = amount;



                                Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                                    {
                                        CloseDialog(ItemChoiceDialog);
                                        var command = new DropItemCommand(new List <IEntity>()
                                        {
                                            clonedEntity
                                        }, itemsHolder,
                                                                          position.Point);
                                        namelessGame.Commander.EnqueueCommand(command);

                                        invScreenSystem.ScheduleUpdate();
                                    });
                            }
                        }
                        AmountDialog = null;
                    };
                }
                break;

                case ItemDialogActions.Drop:
                {
                    Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                        {
                            var position = playerEntity.GetComponentOfType <Position>();
                            var command  = new DropItemCommand(new List <IEntity>()
                            {
                                itemEntity
                            }, itemsHolder,
                                                               position.Point);
                            namelessGame.Commander.EnqueueCommand(command);
                            invScreenSystem.ScheduleUpdate();
                            CloseDialog(ItemChoiceDialog);
                        });
                }
                break;

                case ItemDialogActions.Equip:
                    Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                    {
                        List <Slot> slotsEquipTo;
                        slotsEquipTo = (List <Slot>)chosenItem.Data;
                        equipment.Equip(equipmentItem, slotsEquipTo);
                        invScreenSystem.ScheduleUpdate();
                        CloseDialog(ItemChoiceDialog);
                    });

                    break;

                case ItemDialogActions.Cancel:
                    Actions.Add((InventoryScreenSystem invScreenSystem, NamelessGame namelessGame) =>
                    {
                        CloseDialog(ItemChoiceDialog);
                    });
                    break;

                default:
                    break;
                }
            };

            EquipmentChoiceDialog.Closed += (sender, args) => { SelectTable(EquipmentBox);
                                                                dialogOpened = false; };

            OnCloseDialog += () => { FillItems(this.game); };
        }
コード例 #3
0
        public PickUpItemsScreen(NamelessGame game)
        {
            this.game = game;
            Panel     = new Panel()
            {
                Width  = game.GetActualWidth(),
                Height = game.GetActualCharacterHeight(),
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Top
            };
            ReturnToGame = new ImageTextButton()
            {
                GridRow    = 1,
                GridColumn = 0,
                ContentHorizontalAlignment = HorizontalAlignment.Center,
                ContentVerticalAlignment   = VerticalAlignment.Center,
                Text = "Back",
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Right,
                Width  = 200,
                Height = 50
            };
            ReturnToGame.Click += OnClickReturnToGame;

            var grid = new Grid()
            {
                VerticalAlignment = VerticalAlignment.Stretch, RowSpacing = 2
            };

            grid.RowsProportions.Add(new Proportion(ProportionType.Fill));
            grid.RowsProportions.Add(new Proportion(ProportionType.Pixels, 50));

            ItemsTable = new Table()
            {
                GridColumn          = 0,
                GridRow             = 0,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            grid.Widgets.Add(ItemsTable);
            grid.Widgets.Add(ReturnToGame);
            Panel.Widgets.Add(grid);

            game.Desktop.Widgets.Add(Panel);

            SelectTable(ItemsTable);

            ItemsTable.OnItemClick += (item) =>
            {
                if (item == null)
                {
                    return;
                }

                var playerEntity = game.PlayerEntity;
                var itemsHolder  = playerEntity.GetComponentOfType <ItemsHolder>();
                var position     = playerEntity.GetComponentOfType <Position>();

                var itemEntity = item.Tag as IEntity;

                if (itemEntity == null)
                {
                    return;
                }

                int selectedIndex = ItemsTable.Items.IndexOf(item);
                if (selectedIndex > 0)
                {
                    this.SelectedItem = item;
                }

                Actions.Add((PickUpItemScreenSystem pickupScreenSystem, NamelessGame namelessGame) =>
                {
                    var command = new PickUpItemCommand(new List <IEntity>()
                    {
                        itemEntity
                    }, itemsHolder, position.Point);
                    namelessGame.Commander.EnqueueCommand(command);
                    if (ItemsTable.Items.Count == 2)
                    {
                        pickupScreenSystem.BackToGame(game);
                    }
                    pickupScreenSystem.ScheduleUpdate();
                });
            };
        }