private void _addDuelButton_Click(object sender, RoutedEventArgs e) { // Check for selected items if (_duel1ComboBox.SelectedItem == null || _duel2ComboBox.SelectedItem == null) { return; } Duels.Add(new Duel(((KeyValuePair <short, string>)_duel1ComboBox.SelectedItem).Key, ((KeyValuePair <short, string>)_duel1ComboBox.SelectedItem).Value, ((KeyValuePair <short, string>)_duel2ComboBox.SelectedItem).Key, ((KeyValuePair <short, string>)_duel2ComboBox.SelectedItem).Value)); }
internal Duel(IntPtr pDuel) { m_buffer = Marshal.AllocHGlobal(4096); m_pDuel = pDuel; lock (Duels){ if (!Duels.ContainsKey(m_pDuel)) { Duels.Add(m_pDuel, this); } } }
internal Duel(IntPtr duelPtr) { _buffer = Marshal.AllocHGlobal(4096); _duelPtr = duelPtr; Duels.Add(_duelPtr, this); }
internal Duel(IntPtr pDuel) { m_buffer = Marshal.AllocHGlobal(4096); m_pDuel = pDuel; Duels.Add(m_pDuel, this); }
private void _loadSimulationButton_Click(object sender, RoutedEventArgs e) { // Show dialog OpenFileDialog dialog = new OpenFileDialog { Filter = "Simulation files (*.balancingsim)|*.balancingsim", Title = "Load simulation..." }; if (!(dialog.ShowDialog() ?? false)) { return; } // Catch errors occuring while reading try { // Load file into buffer RAMBuffer buffer = new RAMBuffer(dialog.FileName); // Check version int version = buffer.ReadInteger(); if (version > Version) { throw new ArgumentException("The given file was created with a newer version of this program, please consider updating."); } // Read civs _civ1ComboBox.SelectedValue = buffer.ReadShort(); _civ2ComboBox.SelectedValue = buffer.ReadShort(); // Merge tech lists int count1 = buffer.ReadInteger(); HashSet <short> res1 = new HashSet <short>(); for (int i = 0; i < count1; i++) { res1.Add(buffer.ReadShort()); } foreach (var res in Researches1) { res.Checked = res1.Contains(res.Id); } int count2 = buffer.ReadInteger(); HashSet <short> res2 = new HashSet <short>(); for (int i = 0; i < count2; i++) { res2.Add(buffer.ReadShort()); } foreach (var res in Researches2) { res.Checked = res2.Contains(res.Id); } // Read duels int count = buffer.ReadInteger(); Duels.Clear(); for (int i = 0; i < count; i++) { short id1 = buffer.ReadShort(); short id2 = buffer.ReadShort(); if (!Units.ContainsKey(id1) || !Units.ContainsKey(id2)) { continue; } Duels.Add(new Duel(id1, Units[id1], id2, Units[id2])); } } catch (Exception ex) { // Error MessageBox.Show($"Unable to load given file: {ex.Message}"); } }