public int CompareTo(NuyenString strOther) { if (_blnUseDecimal) { if (strOther.UseDecimal) { return(_decValue.CompareTo(strOther.Value)); } return(-1); } if (strOther.UseDecimal) { return(1); } return(string.Compare(_strBaseString, strOther.BaseString, false, GlobalOptions.CultureInfo)); }
private async ValueTask BuildVehicleList(XPathNodeIterator objXmlVehicleList) { await this.DoThreadSafeAsync(x => x.SuspendLayout()); try { int intOverLimit = 0; bool blnHideOverAvailLimit = await chkHideOverAvailLimit.DoThreadSafeFuncAsync(x => x.Checked); bool blnFreeItem = await chkFreeItem.DoThreadSafeFuncAsync(x => x.Checked); bool blnShowOnlyAffordItems = await chkShowOnlyAffordItems.DoThreadSafeFuncAsync(x => x.Checked); bool blnBlackMarketDiscount = await chkBlackMarketDiscount.DoThreadSafeFuncAsync(x => x.Checked); decimal decBaseCostMultiplier = 1.0m; if (await chkUsedVehicle.DoThreadSafeFuncAsync(x => x.Checked)) { decBaseCostMultiplier -= (await nudUsedVehicleDiscount.DoThreadSafeFuncAsync(x => x.Value) / 100.0m); } decBaseCostMultiplier *= 1 + (await nudMarkup.DoThreadSafeFuncAsync(x => x.Value) / 100.0m); bool blnHasSearch = await txtSearch.DoThreadSafeFuncAsync(x => x.TextLength != 0); if (await tabViews.DoThreadSafeFuncAsync(x => x.SelectedIndex) == 1) { XmlDocument dummy = new XmlDocument { XmlResolver = null }; DataTable tabVehicles = new DataTable("vehicles"); tabVehicles.Columns.Add("VehicleGuid"); tabVehicles.Columns.Add("VehicleName"); tabVehicles.Columns.Add("Accel"); tabVehicles.Columns.Add("Armor"); tabVehicles.Columns.Add("Body"); tabVehicles.Columns.Add("Handling"); tabVehicles.Columns.Add("Pilot"); tabVehicles.Columns.Add("Sensor"); tabVehicles.Columns.Add("Speed"); tabVehicles.Columns.Add("Seats"); tabVehicles.Columns.Add("Gear"); tabVehicles.Columns.Add("Mods"); tabVehicles.Columns.Add("Weapons"); tabVehicles.Columns.Add("WeaponMounts"); tabVehicles.Columns.Add("Avail", typeof(AvailabilityValue)); tabVehicles.Columns.Add("Source", typeof(SourceString)); tabVehicles.Columns.Add("Cost", typeof(NuyenString)); foreach (XPathNavigator objXmlVehicle in objXmlVehicleList) { if (blnHideOverAvailLimit && !objXmlVehicle.CheckAvailRestriction(_objCharacter)) { ++intOverLimit; continue; } if (!blnFreeItem && blnShowOnlyAffordItems) { decimal decCostMultiplier = decBaseCostMultiplier; if (blnBlackMarketDiscount && _setBlackMarketMaps.Contains((await objXmlVehicle .SelectSingleNodeAndCacheExpressionAsync( "category")) ?.Value)) { decCostMultiplier *= 0.9m; } if (Vehicle.DoesDealerConnectionApply(_setDealerConnectionMaps, (await objXmlVehicle .SelectSingleNodeAndCacheExpressionAsync( "category")) ?.Value)) { decCostMultiplier *= 0.9m; } if (!objXmlVehicle.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier)) { ++intOverLimit; continue; } } using (Vehicle objVehicle = new Vehicle(_objCharacter)) { objVehicle.Create(objXmlVehicle.ToXmlNode(dummy), true, true, false, true); string strID = objVehicle.SourceIDString; string strVehicleName = objVehicle.CurrentDisplayName; string strAccel = objVehicle.TotalAccel; string strArmor = objVehicle.TotalArmor.ToString(GlobalSettings.CultureInfo); string strBody = objVehicle.TotalBody.ToString(GlobalSettings.CultureInfo); string strHandling = objVehicle.TotalHandling; string strPilot = objVehicle.Pilot.ToString(GlobalSettings.CultureInfo); string strSensor = objVehicle.CalculatedSensor.ToString(GlobalSettings.CultureInfo); string strSpeed = objVehicle.TotalSpeed; string strSeats = objVehicle.TotalSeats.ToString(GlobalSettings.CultureInfo); using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdGear)) { foreach (Gear objGear in objVehicle.GearChildren) { sbdGear.AppendLine(objGear.CurrentDisplayName); } if (sbdGear.Length > 0) { sbdGear.Length -= Environment.NewLine.Length; } using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdMods)) { foreach (VehicleMod objMod in objVehicle.Mods) { sbdMods.AppendLine(objMod.CurrentDisplayName); } if (sbdMods.Length > 0) { sbdMods.Length -= Environment.NewLine.Length; } using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdWeapons)) { if (sbdWeapons.Length > 0) { sbdWeapons.Length -= Environment.NewLine.Length; } foreach (Weapon objWeapon in objVehicle.Weapons) { sbdWeapons.AppendLine(objWeapon.CurrentDisplayName); } using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdWeaponMounts)) { foreach (WeaponMount objWeaponMount in objVehicle.WeaponMounts) { sbdWeaponMounts.AppendLine(objWeaponMount.CurrentDisplayName); } if (sbdWeaponMounts.Length > 0) { sbdWeaponMounts.Length -= Environment.NewLine.Length; } AvailabilityValue objAvail = objVehicle.TotalAvailTuple(); SourceString strSource = await SourceString.GetSourceStringAsync( objVehicle.Source, objVehicle.DisplayPage(GlobalSettings.Language), GlobalSettings.Language, GlobalSettings.CultureInfo, _objCharacter); NuyenString strCost = new NuyenString( objVehicle.TotalCost.ToString(GlobalSettings.CultureInfo)); tabVehicles.Rows.Add(strID, strVehicleName, strAccel, strArmor, strBody, strHandling, strPilot, strSensor, strSpeed, strSeats, sbdGear.ToString(), sbdMods.ToString(), sbdWeapons.ToString(), sbdWeaponMounts.ToString(), objAvail, strSource, strCost); } } } } } } await dgvVehicles.DoThreadSafeAsync(x => { x.Columns[0].Visible = false; x.Columns[13].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopRight; x.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; DataSet set = new DataSet("vehicles"); set.Tables.Add(tabVehicles); x.DataSource = set; x.DataMember = "vehicles"; }); } else { string strSpace = await LanguageManager.GetStringAsync("String_Space"); using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool, out List <ListItem> lstVehicles)) { foreach (XPathNavigator objXmlVehicle in objXmlVehicleList) { if (blnHideOverAvailLimit && !objXmlVehicle.CheckAvailRestriction(_objCharacter)) { ++intOverLimit; continue; } if (!blnFreeItem && blnShowOnlyAffordItems) { decimal decCostMultiplier = decBaseCostMultiplier; if (blnBlackMarketDiscount && _setBlackMarketMaps.Contains((await objXmlVehicle .SelectSingleNodeAndCacheExpressionAsync( "category")) ?.Value)) { decCostMultiplier *= 0.9m; } if (Vehicle.DoesDealerConnectionApply(_setDealerConnectionMaps, (await objXmlVehicle .SelectSingleNodeAndCacheExpressionAsync( "category")) ?.Value)) { decCostMultiplier *= 0.9m; } if (!objXmlVehicle.CheckNuyenRestriction(_objCharacter.Nuyen, decCostMultiplier)) { ++intOverLimit; continue; } } string strDisplayname = (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("translate"))?.Value ?? (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("name"))?.Value ?? await LanguageManager.GetStringAsync("String_Unknown"); if (!GlobalSettings.SearchInCategoryOnly && blnHasSearch) { string strCategory = (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("category"))?.Value; if (!string.IsNullOrEmpty(strCategory)) { ListItem objFoundItem = _lstCategory.Find(objFind => objFind.Value.ToString() == strCategory); if (!string.IsNullOrEmpty(objFoundItem.Name)) { strDisplayname += strSpace + '[' + objFoundItem.Name + ']'; } } } lstVehicles.Add(new ListItem( (await objXmlVehicle.SelectSingleNodeAndCacheExpressionAsync("id")) ?.Value ?? string.Empty, strDisplayname)); } lstVehicles.Sort(CompareListItems.CompareNames); if (intOverLimit > 0) { // Add after sort so that it's always at the end lstVehicles.Add(new ListItem(string.Empty, string.Format(GlobalSettings.CultureInfo, await LanguageManager.GetStringAsync( "String_RestrictedItemsHidden"), intOverLimit))); } string strOldSelected = await lstVehicle.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()); _blnLoading = true; await lstVehicle.PopulateWithListItemsAsync(lstVehicles); _blnLoading = false; await lstVehicle.DoThreadSafeAsync(x => { if (string.IsNullOrEmpty(strOldSelected)) { x.SelectedIndex = -1; } else { x.SelectedValue = strOldSelected; } }); } } } finally { await this.DoThreadSafeAsync(x => x.ResumeLayout()); } }