public GameModel(Grid grMain, string levelsFolderName, string weaponFolderName) { isModelReady = false; isLoadTimerEnd = false; lvlName = levelsFolderName; grGame = (Grid)grMain.Children[0]; grPauseMenu = (PauseMenuGrid)grMain.Children[1]; dlgDefeat = (ChoiceDialog)grMain.Children[2]; dlgVictory = (ChoiceDialog)grMain.Children[3]; grStats = (StatsGrid)grMain.Children[4]; grLoadScreen = (Grid)grMain.Children[grMain.Children.Count - 1]; ClearGridGame(); mediaPlayers = new List <MediaPlayer>(); InitTimers(); camera = new Camera(GetImageFromGridGame(1), GetImageFromGridGame(2), GetImageFromGridGame(3), levelsFolderName, weaponFolderName); rifle = new Rifle(GetImageFromGridGame(0), weaponFolderName); scope = new Scope(GetImageFromGridGame(1), GetImageFromGridGame(2), GetImageFromGridGame(3), GetImageFromGridGame(0), weaponFolderName); listOfTargets = new ListOfTargets(GetImageFromGridGame(1), GetImageFromGridGame(2), GetImageFromGridGame(3), levelsFolderName); interfaceElements = new InterfaceElements(grGame, grStats, dlgDefeat, dlgVictory); PrepareModel(); isModelReady = true; loadTimer.Start(); InterfaceElements.timer.timer.Start(); }
public InterfaceElements(Grid grGame, StatsGrid grStats, ChoiceDialog dlgDefeat, ChoiceDialog dlgVictory) { InterfaceElements.grStats = grStats; InterfaceElements.dlgDefeat = dlgDefeat; InterfaceElements.dlgVictory = dlgVictory; bulletsCounter = new BulletsCounter() { Foreground = interfaceForeground }; timer = new Timer(START_REM_TIME) { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, Margin = new Thickness(25, 0, 25, 15), Foreground = interfaceForeground }; killsCounter = new KillsCounter() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(25, 25, 25, 0), Foreground = interfaceForeground }; InterfaceElContainer container = new InterfaceElContainer(bulletsCounter) { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom }; Grid.SetZIndex(container, 2); grGame.Children.Add(container); container = new InterfaceElContainer(killsCounter, timer) { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom, Height = 200 }; Grid.SetZIndex(container, 2); grGame.Children.Add(container); }
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); }; }
private void preparation(CancellationToken token) { bool yesToAll = false; ChoiceDialog dialog = new ChoiceDialog("Copy Items", "Replace &All", "&Replace This Item", "&Skip Item", "&Cancel"); foreach (string item in Items) { token.ThrowIfCancellationRequested(); string name = "", newItem = ""; bool isDir = false, exists = false, newItemFileExists = false, newItemDirectoryExists = false; if (File.Exists(item)) { exists = true; name = new FileInfo(item).Name; newItem = Path.Combine(Destination.FullName, name); isDir = false; } else if (Directory.Exists(item)) { exists = true; name = new DirectoryInfo(item).Name; newItem = Path.Combine(Destination.FullName, name); isDir = true; } if (!exists) { continue; } newItemFileExists = File.Exists(newItem); newItemDirectoryExists = Directory.Exists(newItem); if (!isDir && newItemDirectoryExists || isDir && newItemFileExists) { // Something went really wrong, do something! continue; } if (item == newItem) { continue; } if ((newItemFileExists || newItemDirectoryExists) && !yesToAll) { dialog.Owner = Host.MainForm; DialogResult result = dialog.ShowDialog( "There is already a " + (newItemFileExists ? "file" : "directory") + " named \"" + name + "\" at the destination." ); if (result == DialogResult.No) { continue; } else if (result == DialogResult.Cancel) { throw new OperationCanceledException(); } else if (result == DialogResult.OK) { yesToAll = true; } } enqueueItem(item, newItem, token); } }
/// <summary> /// Loads a dialog tree from a XML file (located in Resources/Dialogs/Trees/). /// </summary> /// <param name="filename">Filename (without extension).</param> public void loadFileOfDialogs(string filename) { filename = "Dialogs/Trees/" + filename; XmlDocument xmlDoc; try { xmlDoc = loadDocument(filename); } catch (XmlException e) { Debug.LogError("Unable to parse XML file. Error: " + e.Message); return; } catch (System.Exception e) { Debug.LogError("Unable to parse XML file (not a XmlException). Error: " + e.Message); return; } BaseDialog beginNode = null; Dictionary <string, BaseDialog> registeredNodes = new Dictionary <string, BaseDialog>(); // Parsowanie XMLi dla drzewek dialogowych. foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) { string type = node.Attributes.GetNamedItem("type").InnerText.ToLower(); switch (type) { case "showdialog": { string who = node.Attributes.GetNamedItem("who")?.InnerText; string whichNext = node.Attributes.GetNamedItem("next")?.InnerText; string text = node.InnerText, finalText; if (!dialogPairs.TryGetValue(text, out finalText)) { finalText = text; } ShowDialog workingNode = new ShowDialog(); //workingNode.nextNode = registeredNodes[whichNext]; workingNode.who = who; workingNode.dialog = text; registeredNodes.Add(node.Name, workingNode); if (beginNode == null) { beginNode = workingNode; } } break; case "choicedialog": { string who = node.Attributes.GetNamedItem("who")?.InnerText; string text = node.InnerText, finalText; if (!dialogPairs.TryGetValue(text, out finalText)) { finalText = text; } ChoiceDialog choiceDialog = new ChoiceDialog(); choiceDialog.who = who; choiceDialog.dialog = text; registeredNodes.Add(node.Name, choiceDialog); if (beginNode == null) { beginNode = choiceDialog; } } break; default: { Debug.LogWarning("Unknown dialog type: " + type); } break; } } foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) { string type = node.Attributes.GetNamedItem("type").InnerText.ToLower(); switch (type) { case "showdialog": { string whichNext = node.Attributes.GetNamedItem("next")?.InnerText; if (whichNext.Length > 0) { ShowDialog workingNode = (ShowDialog)registeredNodes[node.Name]; workingNode.nextNode = registeredNodes[whichNext]; } } break; case "choicedialog": { //int choices = int.Parse(node.Attributes.GetNamedItem("choices").InnerText); int choices = (node.Attributes.Count - 2) / 2; string[] choiceNodes = new string[choices], choiceStrs = new string[choices]; for (int x = 0; x < choices; ++x) { choiceStrs[x] = node.Attributes.GetNamedItem("choice_" + x).InnerText; choiceNodes[x] = node.Attributes.GetNamedItem("choiceNode_" + x).InnerText; } ChoiceDialog workingNode = (ChoiceDialog)registeredNodes[node.Name]; workingNode.choices = choiceStrs; workingNode.choiceNodes = new BaseDialog[choices]; for (int x = 0; x < choices; ++x) { workingNode.choiceNodes[x] = registeredNodes[choiceNodes[x]]; } } break; } } if (beginNode != null) { registeredDialogs.Add(filename, beginNode); } }