void DrawTile(GraphicsDevice device, NamelessGame game, int positionX, int positionY, AtlasTileData atlasTileData, Color color, Color backGroundColor) { if (atlasTileData == null) { atlasTileData = new AtlasTileData(1, 1); } var fontsize = game.GetSettings().GetFontSizeZoomed(); var tilesize = tileAtlas.Width / 16; if (fontsize < 4) { _spriteBatch.Draw(whiteRectangle, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), null, color.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 0); } else { _spriteBatch.Draw(whiteRectangle, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), null, backGroundColor.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 0); _spriteBatch.Draw(tileAtlas, new Rectangle(positionX, game.GetActualCharacterHeight() - positionY, fontsize, fontsize), new Rectangle(atlasTileData.X * tilesize, atlasTileData.Y * tilesize, tilesize, tilesize), color.ToXnaColor(), 0, default(Vector2), SpriteEffects.None, 1); } }
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); }; }
public WorldBoardScreen(NamelessGame game) { Panel = new Panel() { Width = (int)game.GetSettings().HudWidth(), Height = game.GetActualCharacterHeight(), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top }; var vPanel = new VerticalStackPanel(); ReturnToGame = CreateButton("Back", game.GetSettings().HudWidth() - 50); ReturnToGame.Click += ReturnToGameOnClick; ModeTerrain = CreateButton("Terrain", game.GetSettings().HudWidth() - 50); ModeTerrain.Click += OnClickModeTerrain; ModeRegions = CreateButton("Regions", game.GetSettings().HudWidth() - 50); ModeRegions.Click += OnClickLandmasses; ModePolitical = CreateButton("Political", game.GetSettings().HudWidth() - 50); ModePolitical.Click += OnClickPolitical; ModeArtifacts = CreateButton("Artifacts", game.GetSettings().HudWidth() - 50); ModeArtifacts.Click += OnClickArtifacts; var grid = new Grid() { VerticalAlignment = VerticalAlignment.Top, ColumnSpacing = 3, Width = (int)game.GetSettings().HudWidth() - 50, HorizontalAlignment = HorizontalAlignment.Center }; LocalMap = new ImageTextButton(); LocalMap.Text = "Local"; LocalMap.GridColumn = 0; LocalMap.Width = (int)game.GetSettings().HudWidth() / 2 - 50; LocalMap.Height = 50; LocalMap.Click += OnLocalMap; LocalMap.HorizontalAlignment = HorizontalAlignment.Left; LocalMap.VerticalAlignment = VerticalAlignment.Top; LocalMap.ContentHorizontalAlignment = HorizontalAlignment.Center; LocalMap.ContentVerticalAlignment = VerticalAlignment.Center; WorldMap = new ImageTextButton(); WorldMap.Text = "World"; WorldMap.GridColumn = 2; WorldMap.Width = (int)game.GetSettings().HudWidth() / 2 - 50; WorldMap.Height = 50; WorldMap.Click += OnWorldMap; WorldMap.HorizontalAlignment = HorizontalAlignment.Left; WorldMap.VerticalAlignment = VerticalAlignment.Top; WorldMap.ContentHorizontalAlignment = HorizontalAlignment.Center; WorldMap.ContentVerticalAlignment = VerticalAlignment.Center; grid.Widgets.Add(LocalMap); grid.Widgets.Add(WorldMap); TextBox list = new TextBox(); list.Width = (int)game.GetSettings().HudWidth() - 50; list.Height = 100; list.Readonly = true; DescriptionLog = list; vPanel.Widgets.Add(grid); vPanel.Widgets.Add(new HorizontalSeparator()); vPanel.Widgets.Add(DescriptionLog); vPanel.Widgets.Add(new HorizontalSeparator()); vPanel.Widgets.Add(ModeTerrain); vPanel.Widgets.Add(ModeRegions); vPanel.Widgets.Add(ModePolitical); vPanel.Widgets.Add(ModeArtifacts); vPanel.Widgets.Add(ReturnToGame); Panel.Widgets.Add(vPanel); game.Desktop.Widgets.Add(Panel); }
public Hud(NamelessGame game) { Panel = new Panel() { Width = (int)game.GetSettings().HudWidth(), Height = game.GetActualCharacterHeight(), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top }; var vPanel = new VerticalStackPanel(); HealthBar = new HorizontalProgressBar(); HealthBar.Width = (int)game.GetSettings().HudWidth(); HealthBar.Height = 10; HealthBar.Maximum = 100; HealthBar.Minimum = 0; HealthBar.Value = 0.5f; HealthBar.VerticalAlignment = VerticalAlignment.Stretch; HealthBar.HorizontalAlignment = HorizontalAlignment.Left; HealthBar.SetColor(game.GraphicsDevice, Color.Red); StaminaBar = new HorizontalProgressBar(); StaminaBar.Width = (int)game.GetSettings().HudWidth(); StaminaBar.Height = 10; StaminaBar.Maximum = 100; StaminaBar.Minimum = 0; StaminaBar.VerticalAlignment = VerticalAlignment.Stretch; StaminaBar.HorizontalAlignment = HorizontalAlignment.Left; StaminaBar.SetColor(game.GraphicsDevice, Color.Green); StrLabel = new Label() { Text = "Str" }; PerLabel = new Label() { Text = "Per" }; RefLabel = new Label() { Text = "Ref" }; ImgLabel = new Label() { Text = "Img" }; WillLabel = new Label() { Text = "Wil" }; WitLabel = new Label() { Text = "Wit" }; TurnLabel = new Label() { Text = "Turn" }; var separator1 = new HorizontalSeparator(); var separator2 = new HorizontalSeparator(); ScrollableListBox list = new ScrollableListBox(); list.Width = (int)game.GetSettings().HudWidth(); list.Height = 300; EventLog = list; WorldMapButton = new ImageTextButton() { GridColumn = 2, ContentHorizontalAlignment = HorizontalAlignment.Center, ContentVerticalAlignment = VerticalAlignment.Center, Text = "Map", VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, Width = 200, Height = 50 }; WorldMapButton.Click += OnClickWorldMap; InventoryButton = new ImageTextButton() { GridColumn = 0, Text = "Inventory", ContentHorizontalAlignment = HorizontalAlignment.Center, ContentVerticalAlignment = VerticalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Left, Width = 200, Height = 50 }; InventoryButton.Click += (sender, args) => { ActionsThisTick.Add(HudAction.OpenInventory); }; vPanel.Widgets.Add(TurnLabel); vPanel.Widgets.Add(HealthBar); vPanel.Widgets.Add(StaminaBar); vPanel.Widgets.Add(StrLabel); vPanel.Widgets.Add(PerLabel); vPanel.Widgets.Add(RefLabel); vPanel.Widgets.Add(ImgLabel); vPanel.Widgets.Add(WillLabel); vPanel.Widgets.Add(WitLabel); vPanel.Widgets.Add(separator1); vPanel.Widgets.Add(EventLog); vPanel.Widgets.Add(separator2); var grid = new Grid() { VerticalAlignment = VerticalAlignment.Bottom, ColumnSpacing = 3 }; grid.Widgets.Add(InventoryButton); grid.Widgets.Add(WorldMapButton); Panel.Widgets.Add(vPanel); Panel.Widgets.Add(grid); game.Desktop.Widgets.Add(Panel); }
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(); }); }; }