/// <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 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> /// 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> /// 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); }