using LibW4M.Data.WeaponFactory; using LibXom.Data; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace W4Gui.Components { public partial class WeaponsPanel : UserControl { public float ConvertToFloat(decimal value) { try { if (value.Equals(Decimal.MaxValue)) return Single.NaN; if (value.Equals(Decimal.MaxValue-1)) return Single.PositiveInfinity; if (value.Equals(Decimal.MaxValue - 2)) return Single.NegativeInfinity; return Convert.ToSingle(value); } catch (OverflowException) { return float.MaxValue; } } public decimal ConvertToDecimal(float value) { try { return Convert.ToDecimal(value); } catch (OverflowException) { if (float.IsNaN(value)) return Decimal.MaxValue; else if (float.IsPositiveInfinity(value)) return Decimal.MaxValue - 1; else if (float.IsNegativeInfinity(value)) return Decimal.MaxValue - 2; else return Decimal.MaxValue - 3; } } public void SaveWeaponData(ref WeaponData weapon) { // Save general settings weapon.Name = DataManager.SaveFile.LookupString(this.selName.Text); weapon.DetonationType = (DetonationType)this.selDetonation.SelectedIndex; weapon.ProjectileLaunchType = (ProjectileLaunchType)this.selType.SelectedIndex; weapon.RetreatTime = this.selRetreatTime.Value; weapon.FuseTime = this.selFuseTime.Value; // Save power settings weapon.WormDamageRadius = this.selWormDmgRad.Value; weapon.WormDamageMagnitude = this.selWormDmgMag.Value; weapon.LandDamageRadius = this.selLandDmgRad.Value; weapon.Push = this.selBlastDmgRad.Value; weapon.ProjectileMaxPower = this.selMaxThrowStr.Value; // Save clusters weapon.ProjectileNumClusters = this.selNumCluster.Value; weapon.ClusterSpread = this.selClusterSpread.Value; weapon.ClusterMaxSpeed = this.selClusterMaxSpeed.Value; // Save technical weapon.PayloadResourceId = this.selPayloadId.Value; weapon.ProjectileCollisionRadius = this.selCollisionRad.Value; weapon.LaunchFX = DataManager.SaveFile.LookupString(this.selLaunchFx.Text); weapon.ArielFX = DataManager.SaveFile.LookupString(this.selArielFx.Text); weapon.DetonationFX = DataManager.SaveFile.LookupString(this.selDetonationFx.Text); // Save graphical resources weapon.GraphicalResources = DataManager.SaveFile.StringArrayToXomStringArray(this.selGraphicalResoures.Items); weapon.GraphicalLocators = DataManager.SaveFile.StringArrayToXomStringArray(this.selGraphicalLocators.Items); // Save toggles weapon.Homing = this.selHoming.Checked; weapon.HomingAvoidLand = this.selAdvancedHoming.Checked; weapon.Poison = this.selPoison.Checked; weapon.EffectedByWind = this.selWindEffected.Checked; weapon.ProjectilePowersUp = this.selPowerUpLaunch.Checked; weapon.FireOnGround = this.selFireOnGround.Checked; } public void LoadWeaponData(WeaponData weapon) { // Read general settings this.selName.Text = weapon.Name.Value; this.selDetonation.SelectedIndex = (int)weapon.DetonationType; this.selType.SelectedIndex = (int)weapon.ProjectileLaunchType; this.selRetreatTime.Value = weapon.RetreatTime; this.selFuseTime.Value = weapon.FuseTime; // Read power settings this.selWormDmgRad.Value = weapon.WormDamageRadius; this.selWormDmgMag.Value = weapon.WormDamageMagnitude; this.selLandDmgRad.Value = weapon.LandDamageRadius; this.selBlastDmgRad.Value = weapon.Push; this.selMaxThrowStr.Value = weapon.ProjectileMaxPower; // Read clusters this.selNumCluster.Value = weapon.ProjectileNumClusters; this.selClusterSpread.Value = weapon.ClusterSpread; this.selClusterMaxSpeed.Value = weapon.ClusterMaxSpeed; // Read technical this.selPayloadId.Value = weapon.PayloadResourceId; this.selCollisionRad.Value = weapon.ProjectileCollisionRadius; this.selLaunchFx.Text = weapon.LaunchFX.Value; this.selArielFx.Text = weapon.ArielFX.Value; this.selDetonationFx.Text = weapon.DetonationFX.Value; this.selGraphicalResoures.LoadData(DataManager.SaveFile.XomStringArrayToStringArray(weapon.GraphicalResources)); this.selGraphicalLocators.LoadData(DataManager.SaveFile.XomStringArrayToStringArray(weapon.GraphicalLocators)); // Read toggles this.selHoming.Checked = weapon.Homing; this.selAdvancedHoming.Checked = weapon.HomingAvoidLand; this.selPoison.Checked = weapon.Poison; this.selWindEffected.Checked = weapon.EffectedByWind; this.selPowerUpLaunch.Checked = weapon.ProjectilePowersUp; this.selFireOnGround.Checked = weapon.FireOnGround; } public WeaponsPanel() { InitializeComponent(); } } }