/// <summary> /// Handles changing of vehicle's name (realname / model / version) /// </summary> /// <param name="isModelChange">true for model change, else version change</param> /// <returns>true if changes were applied, else false</returns> private bool _ChangeModelOrVersion(bool isModelChange) { // Preparing name list SortedStringCollection sortedNameList = new SortedStringCollection(); Dictionary <string, string> index = new Dictionary <string, string>(); foreach (DBResource.Entry anotherEntry in _PhysicsResource.EntryList) { // 60 first entries and comments are ignored if (!anotherEntry.isComment && anotherEntry.index > 63) { string currentRef = anotherEntry.id.Id; string currentName = anotherEntry.value; if (currentName != null && !sortedNameList.Contains(currentName)) { // Empty symbol is allowed if (SharedConstants.ERROR_DB_RESVAL.Equals(currentName) && DatabaseConstants.NOT_AVAILABLE_NAME_PHYSICS_DB_RESID.Equals(currentRef) || !SharedConstants.ERROR_DB_RESVAL.Equals(currentName)) { sortedNameList.Add(currentName); index.Add(currentName, currentRef); } } } } // Displaying browse dialog TableBrowsingDialog dialog = new TableBrowsingDialog(_MESSAGE_BROWSE_PHYSICS_NAMES, sortedNameList, index) { IsAddButtonEnabled = true }; DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { // Applying changes if (_IsVehicleWithRealName) { // RealName used only DatabaseHelper.UpdateCellFromTopicWherePrimaryKey(_PhysicsTable, SharedConstants.REAL_NAME_PHYSICS_DB_COLUMN, _CurrentVehicle, dialog.SelectedIndex); } else { // Model or version name if (isModelChange) { DatabaseHelper.UpdateCellFromTopicWherePrimaryKey(_PhysicsTable, SharedConstants.MODEL_NAME_PHYSICS_DB_COLUMN, _CurrentVehicle, dialog.SelectedIndex); } else { DatabaseHelper.UpdateCellFromTopicWherePrimaryKey(_PhysicsTable, SharedConstants.VERSION_NAME_PHYSICS_DB_COLUMN, _CurrentVehicle, dialog.SelectedIndex); } } return(true); } return(false); }
/// <summary> /// Returns a couple of set code/name /// </summary> /// <returns></returns> private Couple <string> _PickSetManufacturer() { // Preparing manufacturer list Couple <string> returnedCodeName = null; SortedStringCollection sortedNameList = new SortedStringCollection(); Dictionary <string, string> index = new Dictionary <string, string>(); List <DB.Cell[]> brandCells = DatabaseHelper.SelectCellsFromTopic(_BrandsTable, SharedConstants.ID_BRANDS_DB_COLUMN); foreach (DB.Cell[] cells in brandCells) { DB.Cell currentCell = cells[0]; string brandCode = DatabaseHelper.GetResourceValueFromCell(currentCell, _BrandsResource); if (!index.ContainsKey(brandCode)) { sortedNameList.Add(brandCode); index.Add(brandCode, currentCell.value); } } // Displaying browse dialog TableBrowsingDialog dialog = new TableBrowsingDialog(_MESSAGE_BROWSE_MANUFACTURERS, sortedNameList, index); DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { returnedCodeName = new Couple <string>(dialog.SelectedIndex, dialog.SelectedValue); } return(returnedCodeName); }
/// <summary> /// Handles changing of vehicle's manufacturer /// </summary> /// <returns>true if changes were applied, else false</returns> private bool _ChangeManufacturer() { bool returnedValue = false; // Preparing manufacturer list SortedStringCollection sortedManufList = new SortedStringCollection(); List <DB.Cell[]> allBrandRefAndNames = DatabaseHelper.SelectCellsFromTopic(_BrandsTable, DatabaseConstants.REF_DB_COLUMN, SharedConstants.ID_BRANDS_DB_COLUMN, SharedConstants.NAME_BRANDS_DB_COLUMN, SharedConstants.BITFIELD_DB_COLUMN); Dictionary <string, string> index = new Dictionary <string, string>(); foreach (DB.Cell[] anotherEntry in allBrandRefAndNames) { // Bitfield // * b0 active brand if true // * b1 clothes if true bool[] currentBitField = DatabaseHelper.ParseBitField(anotherEntry[3]); // Inactive and clothes brands are ignored if (currentBitField[0] && !currentBitField[1]) { string currentRef = DatabaseHelper.GetResourceValueFromCell(anotherEntry[0], _BrandsResource); string brandId = DatabaseHelper.GetResourceValueFromCell(anotherEntry[1], _BrandsResource); string brandName = DatabaseHelper.GetResourceValueFromCell(anotherEntry[2], _BrandsResource); string currentName = string.Format(_FORMAT_BRAND_NAME, brandName, brandId); // ?? Names are not included if (!SharedConstants.ERROR_DB_RESVAL.Equals(currentName) && !DatabaseConstants.NOT_AVAILABLE_NAME_BRANDS_DB_RESID.Equals(anotherEntry[2].value) && !sortedManufList.Contains(currentName)) { sortedManufList.Add(currentName); index.Add(currentName, currentRef); } } } // Displaying browse dialog TableBrowsingDialog dialog = new TableBrowsingDialog(_MESSAGE_BROWSE_BRANDS, sortedManufList, index); DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { // Applying changes DatabaseHelper.UpdateCellFromTopicWherePrimaryKey(_PhysicsTable, SharedConstants.BRAND_PHYSICS_DB_COLUMN, _CurrentVehicle, dialog.SelectedIndex); returnedValue = true; } return(returnedValue); }
/// <summary> /// Handles interior color set adding /// </summary> /// <returns></returns> private bool _AddInteriorSet() { bool returnedResult = false; // Preparing name list SortedStringCollection sortedNameList = new SortedStringCollection(); Dictionary <string, string> index = new Dictionary <string, string>(); foreach (DBResource.Entry anotherEntry in _InteriorResource.EntryList) { if (anotherEntry.isValid && !anotherEntry.isComment) { if (anotherEntry.id.Id.EndsWith(SharedConstants.NAME_INTERIOR_CATEGORY)) { string colorName = anotherEntry.value; if (!sortedNameList.Contains(colorName)) { sortedNameList.Add(colorName); index.Add(colorName, anotherEntry.id.Id); } } } } // Displaying browse dialog TableBrowsingDialog dialog = new TableBrowsingDialog(_MESSAGE_BROWSE_SET_NAMES, sortedNameList, index); DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { // Applying changes string value = DatabaseHelper.BuildFullLineValue(_InteriorTable, "", SharedConstants.AC_MANUFACTURER_ID_BRANDS_DB_VAL, dialog.SelectedIndex, SharedConstants.NOT_AVAILABLE_INTERIOR_COLOR_DB_RESID, SharedConstants.NOT_AVAILABLE_INTERIOR_COLOR_DB_RESID, SharedConstants.NOT_AVAILABLE_INTERIOR_COLOR_DB_RESID, "0"); _InteriorSetId = DatabaseHelper.InsertAllCellsIntoTopic(_InteriorTable, 0, value); returnedResult = true; } return(returnedResult); }
/// <summary> /// Allows to change brake characteristics /// </summary> /// <param name="isFrontBrakes"></param> private void _ChangeBrakesCharacteristics(bool isFrontBrakes) { // Preparing type list SortedStringCollection sortedBrakesList = new SortedStringCollection(); Dictionary <string, string> index = new Dictionary <string, string>(); // Browsing all physics resource values foreach (DBResource.Entry entry in _PhysicsResource.EntryList) { if (entry.isValid && !entry.isComment) { // Filter over physics resource if (entry.id.Id.EndsWith(DBResource.SUFFIX_PHYSICS_BRAKES_CHAR) && !sortedBrakesList.Contains(entry.value)) { sortedBrakesList.Add(entry.value); index.Add(entry.value, entry.id.Id); } } } // Displaying browse dialog string message = (isFrontBrakes ? _MESSAGE_BROWSE_FRONT_BRAKES : _MESSAGE_BROWSE_REAR_BRAKES); TableBrowsingDialog dialog = new TableBrowsingDialog(message, sortedBrakesList, index); DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { Cursor = Cursors.WaitCursor; // Applying changes string columnName = (isFrontBrakes ? SharedConstants.BRAKES_CHAR_FRONT_PHYSICS_DB_COLUMN : SharedConstants.BRAKES_CHAR_REAR_PHYSICS_DB_COLUMN); DatabaseHelper.UpdateCellFromTopicWherePrimaryKey(_PhysicsTable, columnName, _CurrentVehicle, dialog.SelectedIndex); // Reloading _InitializeDatasheetContents(); // Modification flag _IsDatabaseModified = true; StatusBarLogManager.ShowEvent(this, _STATUS_CHANGING_BRAKE_CHAR_OK); Cursor = Cursors.Default; } }
private void resourceBrowseButton_Click(object sender, EventArgs e) { // Click on browse button try { Cursor = Cursors.WaitCursor; // Preparing value list SortedStringCollection sortedValueList = new SortedStringCollection(); Dictionary <string, string> index = new Dictionary <string, string>(); foreach (DBResource.Entry anotherEntry in _DbResource.EntryList) { if (anotherEntry.isValid && !anotherEntry.isComment) { string value = anotherEntry.value; if (!sortedValueList.Contains(value)) { sortedValueList.Add(value); index.Add(value, anotherEntry.id.Id); } } } // Displaying browse dialog TableBrowsingDialog dialog = new TableBrowsingDialog(_MESSAGE_BROWSE_RES_VALUES, sortedValueList, index); DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { // Resource update _ResourceId = dialog.SelectedIndex; _UpdateInfoLabel(); } } catch (Exception ex) { MessageBoxes.ShowError(this, ex); } finally { Cursor = Cursors.Default; } }
/// <summary> /// Allows to pick an interior color/material /// </summary> /// <returns></returns> private static string _PickInteriorColor(bool isForMaterial) { // Preparing color list string returnedColor = null; SortedStringCollection sortedColorList = new SortedStringCollection(); Dictionary <string, string> index = new Dictionary <string, string>(); Dictionary <string, string> currentReference; string currentMessage; if (isForMaterial) { currentReference = ColorsHelper.MaterialsReference; currentMessage = _MESSAGE_BROWSE_MATERIALS; } else { currentReference = ColorsHelper.InteriorReference; currentMessage = _MESSAGE_BROWSE_COLORS; } foreach (KeyValuePair <string, string> pair in currentReference) { string colorName = string.Format(_FORMAT_COLOR_NAME_LABEL, pair.Value, pair.Key); if (ColorsHelper.IdByCodeReference.ContainsKey(pair.Key)) { string colorId = ColorsHelper.IdByCodeReference[pair.Key]; sortedColorList.Add(colorName); index.Add(colorName, colorId); } } // Displaying browse dialog TableBrowsingDialog dialog = new TableBrowsingDialog(currentMessage, sortedColorList, index); DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { returnedColor = dialog.SelectedIndex; } return(returnedColor); }
/// <summary> /// Allow to choose a brand reference /// </summary> /// <returns></returns> private string _GetBrandReference() { string returnedRef = null; // Preparing manufacturer list SortedStringCollection sortedManufList = new SortedStringCollection(); List <DB.Cell[]> allBrandRefAndNames = DatabaseHelper.SelectCellsFromTopic(_BrandsTable, DatabaseConstants.REF_DB_COLUMN, SharedConstants.NAME_BRANDS_DB_COLUMN, SharedConstants.BITFIELD_DB_COLUMN); Dictionary <string, string> index = new Dictionary <string, string>(); foreach (DB.Cell[] anotherEntry in allBrandRefAndNames) { // Bitfield // * b0 active brand if true // * b1 clothes if true bool[] currentBitField = DatabaseHelper.ParseBitField(anotherEntry[2]); // Inactive and clothes brands are ignored if (currentBitField[0] && !currentBitField[1]) { string currentRef = DatabaseHelper.GetResourceValueFromCell(anotherEntry[0], _BrandsResource); string currentName = DatabaseHelper.GetResourceValueFromCell(anotherEntry[1], _BrandsResource); if (currentName != null && !SharedConstants.ERROR_DB_RESVAL.Equals(currentName) && !sortedManufList.Contains(currentName)) { sortedManufList.Add(currentName); index.Add(currentName, currentRef); } } } // Displaying browse dialog TableBrowsingDialog dialog = new TableBrowsingDialog(_MESSAGE_BROWSE_TUNING_BRANDS, sortedManufList, index); DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { returnedRef = dialog.SelectedIndex; } return(returnedRef); }
private void browseSlotsButton_Click(object sender, EventArgs e) { // Click on '...' button for slots try { Cursor = Cursors.WaitCursor; // Preparing slot list SortedStringCollection sortedSlotList = new SortedStringCollection(); Dictionary <string, string> index = new Dictionary <string, string>(); // Misc slot sortedSlotList.Add(Tools.NAME_MISC_SLOT); index.Add(Tools.NAME_MISC_SLOT, Tools.KEY_MISC_SLOT); // Vehicle slots VehicleSlotsHelper.InitReference(Tools.WorkingPath + LibraryConstants.FOLDER_XML); foreach (KeyValuePair <string, string> pair in VehicleSlotsHelper.SlotReference) { sortedSlotList.Add(pair.Key); index.Add(pair.Key, pair.Value); } Cursor = Cursors.Default; // Displaying browse dialog TableBrowsingDialog dialog = new TableBrowsingDialog(_MESSAGE_BROWSE_SLOTS, sortedSlotList, index); DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { slotRefTextBox.Text = dialog.SelectedIndex; } } catch (Exception ex) { MessageBoxes.ShowError(this, ex); } }
/// <summary> /// Populates a collection with a string version of each business /// object in the collection provided /// </summary> /// <param name="col">The business object collection</param> /// <returns>Returns an ICollection object</returns> private ICollection CreateValueList(IBusinessObjectCollection col) { if (this.OrderCriteria == null) { //IF there is no order criteria then order by bo.ToString. var valueList = new SortedStringCollection(); foreach (IBusinessObject bo in col) { valueList.Add(bo.ToString()); } return(valueList); } else { var valueList = new ArrayList(); foreach (IBusinessObject bo in col) { valueList.Add(bo.ToString()); } return(valueList); } }
/// <summary> /// Handles changing of vehicle's tires (no effect in game ?) /// </summary> /// <returns></returns> private bool _ChangeTires() { bool returnedValue = false; // Preparing type list SortedStringCollection sortedTireList = new SortedStringCollection(); Dictionary <string, string> index = new Dictionary <string, string>(); // Browsing all physics resource values foreach (DBResource.Entry entry in _PhysicsResource.EntryList) { if (entry.isValid && !entry.isComment) { // Filter over physics resource if (entry.id.Id.EndsWith(DBResource.SUFFIX_PHYSICS_TIRES) && !sortedTireList.Contains(entry.value)) { sortedTireList.Add(entry.value); index.Add(entry.value, entry.id.Id); } } } // Displaying browse dialog TableBrowsingDialog dialog = new TableBrowsingDialog(_MESSAGE_BROWSE_TIRES, sortedTireList, index); DialogResult dr = dialog.ShowDialog(); if (dr == DialogResult.OK && dialog.SelectedIndex != null) { // Applying changes DatabaseHelper.UpdateCellFromTopicWherePrimaryKey(_PhysicsTable, SharedConstants.TYRES_TYPE_PHYSICS_DB_COLUMN, _CurrentVehicle, dialog.SelectedIndex); returnedValue = true; } return(returnedValue); }
/// <summary> /// Updates vehicle list according to slots reference /// </summary> private void _RefreshVehicleList() { Cursor = Cursors.WaitCursor; vehicleListView.Items.Clear(); vehicleListView.Groups.Clear(); // Taking list mode into account (original/modded names) Dictionary <string, string> originalNamesByModdedNames = null; SortedStringCollection vehicleNames = new SortedStringCollection(); if (_IsShowOriginalNames) { foreach (string vehicleName in VehicleSlotsHelper.SlotReference.Keys) { vehicleNames.Add(vehicleName); } } else { // Loading database for read-only DB.Culture currentCulture = Program.ApplicationSettings.GetCurrentCulture(); // Physics TduFile[] loadedFiles = DatabaseHelper.LoadTopicForReadOnly(DB.Topic.CarPhysicsData, currentCulture); DB physics = loadedFiles[0] as DB; DBResource rPhysics = loadedFiles[1] as DBResource; // Brands loadedFiles = DatabaseHelper.LoadTopicForReadOnly(DB.Topic.Brands, currentCulture); DB brands = loadedFiles[0] as DB; DBResource rBrands = loadedFiles[1] as DBResource; originalNamesByModdedNames = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> anotherPair in VehicleSlotsHelper.SlotReference) { // Brand name string brandName = NamesHelper.GetVehicleBrandName(anotherPair.Value, physics, brands, rBrands); // Vehicle name string vehicleName = NamesHelper.GetVehicleFullName(anotherPair.Value, false, physics, rPhysics, brands, rBrands); string moddedName = (brandName.ToUpper() + " " + vehicleName).Trim(); // To maintain 2 identical names while (originalNamesByModdedNames.ContainsKey(moddedName)) { moddedName += _SYMBOL_PRIME; } originalNamesByModdedNames.Add(moddedName, anotherPair.Key); vehicleNames.Add(moddedName); } } // Reference browsing foreach (string vehicleName in vehicleNames) { ListViewItem li = new ListViewItem(vehicleName); // Group by brand (first word in fact) string currentBrand = vehicleName.Split(' ')[0]; ListViewGroup currentGroup = new ListViewGroup(currentBrand, currentBrand); if (!vehicleListView.Groups.Contains(currentGroup)) { vehicleListView.Groups.Add(currentGroup); } li.Group = vehicleListView.Groups[currentBrand]; // Computing vehicle name string slotName = null; if (_IsShowOriginalNames) { slotName = vehicleName; } else if (originalNamesByModdedNames != null && originalNamesByModdedNames.ContainsKey(vehicleName)) { slotName = originalNamesByModdedNames[vehicleName]; } if (slotName != null && VehicleSlotsHelper.SlotReference.ContainsKey(slotName)) { string vehicleRef = VehicleSlotsHelper.SlotReference[slotName]; // Tag li.Tag = vehicleRef; VehicleSlotsHelper.VehicleInfo currentInfo = VehicleSlotsHelper.VehicleInformation[vehicleRef]; // Non-moddable vehicles are faded // Image depending on car or bike type if (currentInfo.isBike) { if (currentInfo.isModdable) { li.ImageIndex = (int)_ImageIndex.Bike; } else { li.ImageIndex = (int)_ImageIndex.NonModdableBike; } } else { if (currentInfo.isModdable) { li.ImageIndex = (int)_ImageIndex.Car; } else { li.ImageIndex = (int)_ImageIndex.NonModdableCar; } } vehicleListView.Items.Add(li); } } Cursor = Cursors.Default; }
public void TestSorting() { SortedStringCollection col = new SortedStringCollection(); Assert.AreEqual(col.Count, 0); Assert.IsFalse(col.IsSynchronized); Assert.AreEqual(new ArrayList().GetEnumerator().GetType(), col.GetEnumerator().GetType()); Assert.AreEqual("System.Object", col.SyncRoot.ToString()); col.Add("c"); Assert.AreEqual(col.Count, 1); Assert.AreEqual(col[0], "c"); col.Add("a"); Assert.AreEqual(col.Count, 2); Assert.AreEqual(col[0], "a"); Assert.AreEqual(col[1], "c"); col.Add("b"); Assert.AreEqual(col.Count, 3); Assert.AreEqual(col[0], "a"); Assert.AreEqual(col[1], "b"); Assert.AreEqual(col[2], "c"); col.Add("e"); Assert.AreEqual(col.Count, 4); Assert.AreEqual(col[0], "a"); Assert.AreEqual(col[1], "b"); Assert.AreEqual(col[2], "c"); Assert.AreEqual(col[3], "e"); col.Add("b"); Assert.AreEqual(col.Count, 5); Assert.AreEqual(col[0], "a"); Assert.AreEqual(col[1], "b"); Assert.AreEqual(col[2], "b"); Assert.AreEqual(col[3], "c"); Assert.AreEqual(col[4], "e"); col.Add("d"); Assert.AreEqual(col.Count, 6); Assert.AreEqual(col[0], "a"); Assert.AreEqual(col[1], "b"); Assert.AreEqual(col[2], "b"); Assert.AreEqual(col[3], "c"); Assert.AreEqual(col[4], "d"); Assert.AreEqual(col[5], "e"); string[] exactCopy = new string[8]; col.CopyTo(exactCopy, 0); Assert.AreEqual(col[0], exactCopy[0]); Assert.AreEqual(col[1], exactCopy[1]); Assert.AreEqual(col[2], exactCopy[2]); Assert.AreEqual(col[3], exactCopy[3]); Assert.AreEqual(col[4], exactCopy[4]); Assert.AreEqual(col[5], exactCopy[5]); Assert.AreEqual(null, exactCopy[6]); Assert.AreEqual(null, exactCopy[7]); string[] offsetCopy = new string[8]; col.CopyTo(offsetCopy, 1); Assert.AreEqual(null, offsetCopy[0]); Assert.AreEqual(col[0], offsetCopy[1]); Assert.AreEqual(col[1], offsetCopy[2]); Assert.AreEqual(col[2], offsetCopy[3]); Assert.AreEqual(col[3], offsetCopy[4]); Assert.AreEqual(col[4], offsetCopy[5]); Assert.AreEqual(col[5], offsetCopy[6]); Assert.AreEqual(null, offsetCopy[7]); }