private void btnAddRule_Click(object sender, EventArgs e) { var formSelectionList = _serviceProvider.GetRequiredService <formSelectionList>(); formSelectionList.selectionType = SelectionType.ScenarioRules; var result = formSelectionList.ShowDialog(this); if (result == DialogResult.OK) { if (selectedScenario.ScenarioRules.Any(x => x.Id == formSelectionList.selectionItem.Id)) { MessageBox.Show("Scenario already has that rule"); } else { var scenarioRule = _context.ScenarioRules.SingleOrDefault(x => x.Id == formSelectionList.selectionItem.Id); var scenarionRuleData = new ScenarioRuleData() { Id = scenarioRule.Id, Name = scenarioRule.Name, Description = scenarioRule.Description, }; selectedScenario.ScenarioRules.Add(scenarionRuleData); RefreshRuleList(); lstScenarioRules.SelectedIndex = lstScenarioRules.Items.Count - 1; LoadRuleData(); } } }
private void btnAddNewRule_Click(object sender, EventArgs e) { var newRule = new ScenarioRuleData() { Name = "New Rule", }; selectedScenario.ScenarioRules.Add(newRule); RefreshRuleList(); lstScenarioRules.SelectedIndex = lstScenarioRules.Items.Count - 1; LoadRuleData(); }
private void LoadScenarioData() { foreach (var scenario in map.Scenarios) { var scenarioData = new ScenarioData() { Id = scenario.Id, Name = scenario.Name, Description = scenario.Description, IsDefault = scenario.IsDefault, EnemyDeckId = scenario.EnemyDeckId, }; if (scenario.EnemyDeckId.HasValue) { scenarioData.EnemyDeckName = scenario.EnemyDeck.Name; } foreach (var objective in scenario.ObjectiveMap.Where(x => x.ObjectiveId.HasValue).Select(x => x.Objective).Distinct()) { var objectiveData = new ObjectiveData() { Id = objective.Id, Name = objective.Name, Color = Color.FromArgb(objective.Red, objective.Green, objective.Blue), }; scenarioData.Objectives.Add(objectiveData); } foreach (var scenarioRule in scenario.ScenarioRuleSet) { var scenarioRuleData = new ScenarioRuleData() { Id = scenarioRule.RuleId, Name = scenarioRule.Rule.Name, Description = scenarioRule.Rule.Description, }; scenarioData.ScenarioRules.Add(scenarioRuleData); } scenarioData.DeploymentMap = new List <List <int?> >(); scenarioData.ObjectiveMap = new List <List <int?> >(); for (int y = 0; y < GRID_SIZE; y++) { var deploymentRow = new List <int?>(); var objectiveRow = new List <int?>(); scenarioData.DeploymentMap.Add(deploymentRow); scenarioData.ObjectiveMap.Add(objectiveRow); for (int x = 0; x < GRID_SIZE; x++) { var deploymentCell = scenario.DeploymentMap.Single(cell => cell.RowId == y && cell.ColumnId == x); var objectiveCell = scenario.ObjectiveMap.Single(cell => cell.RowId == y && cell.ColumnId == x); deploymentRow.Add(deploymentCell.PlayerId); int?objectiveIndex = scenarioData.Objectives.FindIndex(x => x.Id == objectiveCell.ObjectiveId); if (objectiveIndex == -1) { objectiveIndex = null; } objectiveRow.Add(objectiveIndex); } } scenarioList.Add(scenarioData); } scenarioList = scenarioList.OrderByDescending(x => x.IsDefault).ThenBy(x => x.Name).ToList(); }