Ejemplo n.º 1
0
        // Methods
        /// <summary>
        /// Initializes MainUnitFile with the given file name.
        /// </summary>
        /// <param name="fName">The name of the file</param>
        public void InitUnitFile(string filePath)
        {
            /// We're wrapping most of this method in a try-catch block to catch file exceptions.
            /// This will allow the app to quickly recover from incorrect file selections
            try
            {
                // First things first, initialize MainUnitFile
                MainUnitFile = new UnitFile(filePath);
                MainUnitFile.init();

                // Now that we've initialized the file, pull out the names for each unit
                UnitName tempUName;
                foreach (UnitFileNode node in MainUnitFile.UnitDir.TheUnits)
                {
                    tempUName = new UnitName(node.TheUnit, node.Index);
                    // Toss it on the NameList..
                    UnitEditor.NameList.Add(tempUName);

                    // ...and on the Armies
                    Armies.AddUnit(tempUName);
                }

                // Finally, set UnitEditor to the first unit in the list
                UnitEditor.changeSelection(UnitEditor.NameList[0]);
            }
            catch (SUE_InvalidFileException ivfe)
            {
                // Send message to user, redo file open.
                throw ivfe;
            }
        }
        // Methods
        public void AddUnit(UnitName uName)
        {
            // Add the unit to the collection
            ArmyNode tempANode = new ArmyNode(uName.TheUnit);

            startingArmies.Add(tempANode);

            // Listen to changes in the Display Name
            uName.PropertyChanged += tempANode.OnNameChange;

            // Listen to changes in the ArmyNode
            tempANode.PropertyChanged += OnArmyNodeChanged;
        }
Ejemplo n.º 3
0
        // Methods
        public void changeSelection(UnitName uName)
        {
            // Make it easy to access the unit
            Unit tempy = uName.TheUnit;

            // Mark all following actions as an initial load
            IsInitialLoad = true;

            // Unsubscribe old UnitName
            if (curUnitName != null)
            {
                PropertyChanged -= curUnitName.OnNameChange;
            }

            // And slap all the values where they belong
            CurUnitName = uName;
            DispName    = tempy.DisplayName.Value;
            Health      = tempy.HitPoints.Value;
            Def         = tempy.Defense.Value;
            Movement    = tempy.Speed.Value;
            AirAtt      = tempy.AirAttack.Value;
            InfAtt      = tempy.InfAttack.Value;
            VehAtt      = tempy.ArmorAttack.Value;
            SightRange  = tempy.Vision.Value;
            AttRange    = tempy.AttackRange.Value;

            // Multiply by 1000 so that we're showing the "real", in-game value
            Cost = tempy.Cost.Value * 1000;

            // New additions!
            Fuel       = tempy.GasTank.Value;
            CollDamage = tempy.CollateralDamage.Value;

            IsIndirect  = tempy.IsIndirect;
            IsSingleUse = tempy.IsSingleUse;
            IsNotKept   = tempy.IsNotKept;
            CanBuy      = tempy.CanBuyFlag;

            // Final additions!
            MoveType  = tempy.MoveCat;
            ArmorType = tempy.UnitCat;

            // We have to convert UnitFaction to VMFact
            UFaction = tempy.Faction;

            // Subscribe new UnitName
            PropertyChanged += curUnitName.OnNameChange;

            // Ok, we can respond to events normally
            IsInitialLoad = false;
        }
        // Event listeners
        public void OnNameChange(object sender, PropertyChangedEventArgs args)
        {
            // First, we'll listening to when our UnitName changes
            UnitName tempUN = sender as UnitName;

            if (tempUN == null)
            {
                // Ignore
                return;
            }

            if (args.PropertyName == "ViewName")
            {
                DispName = tempUN.ViewName;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds a new unit to the unit file
        /// </summary>
        /// <param name="unInd">The index of the unit to be cloned</param>
        /// <param name="newName">The name of the unit</param>
        public void AddUnit(int unInd, string newName)
        {
            // First, find the unit to be cloned
            Unit tempy = UnitEditor.NameList[unInd].TheUnit;

            // Pass the info to MainUnitFile
            long tempInd = MainUnitFile.UnitDir.CloneUnit(tempy, newName);

            // Now set tempy to the newly formed unit
            tempy = MainUnitFile.UnitDir.TheUnits.Find(x => x.Index == tempInd).TheUnit;

            // Now, if everything went right, we should have a new unit in UnitDir
            UnitName tempUN = new UnitName(tempy, tempInd);

            // Add it to UnitEditorVM
            UnitEditor.NameList.Add(tempUN);
            // Add it to StartingArmies
            Armies.AddUnit(tempUN);
        }