private void SaveWIP(object sender, EventArgs e)
 {
     ShipData savedShip = new ShipData()
     {
         Animated = this.ActiveHull.Animated,
         CombatState = this.ActiveHull.CombatState,
         Hull = this.ActiveHull.Hull,
         IconPath = this.ActiveHull.IconPath,
         ModelPath = this.ActiveHull.ModelPath,
         Name = this.ActiveHull.Name,
         Role = this.ActiveHull.Role,
         ShipStyle = this.ActiveHull.ShipStyle,
         ThrusterList = this.ActiveHull.ThrusterList,
         ModuleSlotList = new List<ModuleSlotData>()
     };
     foreach (SlotStruct slot in this.Slots)
     {
         if (!slot.isDummy)
         {
             ModuleSlotData data = new ModuleSlotData()
             {
                 InstalledModuleUID = slot.ModuleUID,
                 Position = slot.slotReference.Position,
                 Restrictions = slot.Restrictions
             };
             if (slot.module != null)
             {
                 data.facing = slot.module.facing;
                 data.state = slot.state;
             }
             savedShip.ModuleSlotList.Add(data);
             if (slot.module == null || slot.module.ModuleType != ShipModuleType.Hangar)
             {
                 continue;
             }
             data.SlotOptions = slot.module.hangarShipUID;
         }
         else if (!slot.isDummy)
         {
             ModuleSlotData data = new ModuleSlotData()
             {
                 Position = slot.slotReference.Position,
                 Restrictions = slot.Restrictions,
                 InstalledModuleUID = ""
             };
             savedShip.ModuleSlotList.Add(data);
         }
         else
         {
             ModuleSlotData data = new ModuleSlotData()
             {
                 Position = slot.slotReference.Position,
                 Restrictions = slot.Restrictions,
                 InstalledModuleUID = "Dummy"
             };
             savedShip.ModuleSlotList.Add(data);
         }
     }
     string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
     Ship_Game.Gameplay.CombatState defaultstate = this.ActiveHull.CombatState;
     savedShip.CombatState = this.CombatState;
     string filename = string.Format("{0:yyyy-MM-dd}__{1}", DateTime.Now, this.ActiveHull.Name);
     savedShip.Name = filename;
     XmlSerializer Serializer = new XmlSerializer(typeof(ShipData));
     TextWriter WriteFileStream = new StreamWriter(string.Concat(path, "/StarDrive/WIP/", filename, ".xml"));
     Serializer.Serialize(WriteFileStream, savedShip);
     WriteFileStream.Close();
     savedShip.CombatState = defaultstate;
     this.ShipSaved = true;
 }
        public void SaveShipDesign(string name)
        {
            this.ActiveHull.ModuleSlotList.Clear();
            this.ActiveHull.Name = name;
            ShipData toSave = this.ActiveHull.GetClone();
            foreach (SlotStruct slot in this.Slots)
            {
                if (slot.isDummy)
                {
                    ModuleSlotData data = new ModuleSlotData()
                    {
                        Position = slot.slotReference.Position,
                        Restrictions = slot.Restrictions,
                        InstalledModuleUID = "Dummy"
                    };
                    toSave.ModuleSlotList.Add(data);
                }
                else
                {
                    ModuleSlotData data = new ModuleSlotData()
                    {
                        InstalledModuleUID = slot.ModuleUID,
                        Position = slot.slotReference.Position,
                        Restrictions = slot.Restrictions
                    };
                    if (slot.module != null)
                    {
                        data.facing = slot.module.facing;
                    }
                    toSave.ModuleSlotList.Add(data);
                    if (slot.module != null && slot.module.ModuleType == ShipModuleType.Hangar)
                    {
                        data.SlotOptions = slot.module.hangarShipUID;
                    }
                    data.state = slot.state;
                }
            }
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            Ship_Game.Gameplay.CombatState combatState = toSave.CombatState;
            toSave.CombatState = this.CombatState;
            toSave.Name = name;

            //Cases correspond to the 5 options in the drop-down menu; default exists for... Propriety, mainly. The option selected when saving will always be the Category saved, pretty straightforward.
            switch (this.CategoryList.Options[this.CategoryList.ActiveIndex].@value)
            {
                case 1:
                    {
                        this.ActiveHull.ShipCategory = ShipData.Category.Unclassified;
                        break;
                    }
                case 2:
                    {
                        this.ActiveHull.ShipCategory = ShipData.Category.Civilian;
                        break;
                    }
                case 3:
                    {
                        this.ActiveHull.ShipCategory = ShipData.Category.Recon;
                        break;
                    }
                case 4:
                    {
                        this.ActiveHull.ShipCategory = ShipData.Category.Fighter;
                        break;
                    }
                case 5:
                    {
                        this.ActiveHull.ShipCategory = ShipData.Category.Bomber;
                        break;
                    }
                default:
                    {
                        this.ActiveHull.ShipCategory = ShipData.Category.Unclassified;
                        break;
                    }
            }

            //Adds the category determined by the case from the dropdown to the 'toSave' ShipData.
            toSave.ShipCategory = this.ActiveHull.ShipCategory;

            //Adds the boolean derived from the checkbox boolean (CarrierOnly) to the ShipData. Defaults to 'false'.
            toSave.CarrierShip = this.CarrierOnly;

            XmlSerializer Serializer = new XmlSerializer(typeof(ShipData));
            TextWriter WriteFileStream = new StreamWriter(string.Concat(path, "/StarDrive/Saved Designs/", name, ".xml"));
            Serializer.Serialize(WriteFileStream, toSave);
            WriteFileStream.Close();
            this.ShipSaved = true;
            if (Ship_Game.ResourceManager.ShipsDict.ContainsKey(name))
            {
                Ship newShip = Ship.CreateShipFromShipData(toSave);
                newShip.SetShipData(toSave);
                newShip.InitForLoad();
                newShip.InitializeStatus();
                Ship_Game.ResourceManager.ShipsDict[name] = newShip;
                Ship_Game.ResourceManager.ShipsDict[name].IsPlayerDesign = true;
            }
            else
            {
                Ship newShip = Ship.CreateShipFromShipData(toSave);
                newShip.SetShipData(toSave);
                newShip.InitForLoad();
                newShip.InitializeStatus();
                Ship_Game.ResourceManager.ShipsDict.Add(name, newShip);
                Ship_Game.ResourceManager.ShipsDict[name].IsPlayerDesign = true;
            }
            EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).UpdateShipsWeCanBuild();
            this.ActiveHull.CombatState = this.CombatState;
            this.ChangeHull(this.ActiveHull);
        }
 public void SaveShipData(string name)
 {
     ShipData data = new ShipData()
     {
         Name = this.HullName,
         ModelPath = Path.GetFileNameWithoutExtension(this.ModelPath),
         Role = "carrier",
         Hull = this.HullName,
         IconPath = "ShipIcons/hunter"
     };
     List<ModuleSlotData> slotDataList = new List<ModuleSlotData>();
     foreach (SlotStruct slot in this.SlotList)
     {
         if (!slot.pq.isFilled)
         {
             continue;
         }
         Vector2 Position = new Vector2((float)(slot.pq.X + slot.pq.W / 2 - this.border.X), (float)(slot.pq.Y + slot.pq.H / 2 - this.border.Y));
         ModuleSlotData newData = new ModuleSlotData()
         {
             Position = Position,
             InstalledModuleUID = slot.ModuleUID,
             Restrictions = slot.Restrictions
         };
         slotDataList.Add(newData);
     }
     data.ModuleSlotList = slotDataList;
     data.DefaultAIState = AIState.AwaitingOrders;
     data.ThrusterList = this.TList;
     XmlSerializer Serializer = new XmlSerializer(typeof(ShipData));
     TextWriter WriteFileStream = new StreamWriter(string.Concat("Ship Tool/", this.HullName, ".xml"));
     Serializer.Serialize(WriteFileStream, data);
     WriteFileStream.Close();
 }
 public void ChangeHull(ShipData hull)
 {
     this.Reset = true;
     this.DesignStack.Clear();
     lock (GlobalStats.ObjectManagerLocker)
     {
         if (this.shipSO != null)
         {
             base.ScreenManager.inter.ObjectManager.Remove(this.shipSO);
         }
     }
     this.ActiveHull = new ShipData()
     {
         Animated = hull.Animated,
         CombatState = hull.CombatState,
         Hull = hull.Hull,
         IconPath = hull.IconPath,
         ModelPath = hull.ModelPath,
         Name = hull.Name,
         Role = hull.Role,
         ShipStyle = hull.ShipStyle,
         ThrusterList = hull.ThrusterList,
         ShipCategory = hull.ShipCategory,
         CarrierShip = hull.CarrierShip,
         ModuleSlotList = new List<ModuleSlotData>(),
     };
     this.CarrierOnly = hull.CarrierShip;
     this.LoadCategory = hull.ShipCategory;
     this.fml = true;
     this.fmlevenmore = true;
     foreach (ModuleSlotData slot in hull.ModuleSlotList)
     {
         ModuleSlotData data = new ModuleSlotData()
         {
             Position = slot.Position,
             Restrictions = slot.Restrictions,
             facing = slot.facing,
             InstalledModuleUID = slot.InstalledModuleUID
         };
         this.ActiveHull.ModuleSlotList.Add(slot);
     }
     this.CombatState = hull.CombatState;
     if (!hull.Animated)
     {
         this.ActiveModel = Ship_Game.ResourceManager.GetModel(this.ActiveHull.ModelPath);
         ModelMesh mesh = this.ActiveModel.Meshes[0];
         this.shipSO = new SceneObject(mesh)
         {
             ObjectType = ObjectType.Dynamic,
             World = this.worldMatrix
         };
         lock (GlobalStats.ObjectManagerLocker)
         {
             base.ScreenManager.inter.ObjectManager.Submit(this.shipSO);
         }
     }
     else
     {
         SkinnedModel sm = Ship_Game.ResourceManager.GetSkinnedModel(this.ActiveHull.ModelPath);
         this.shipSO = new SceneObject(sm.Model)
         {
             ObjectType = ObjectType.Dynamic,
             World = this.worldMatrix
         };
         lock (GlobalStats.ObjectManagerLocker)
         {
             base.ScreenManager.inter.ObjectManager.Submit(this.shipSO);
         }
     }
     foreach (ToggleButton button in this.CombatStatusButtons)
     {
         string action = button.Action;
         string str = action;
         if (action == null)
         {
             continue;
         }
         if (str == "attack")
         {
             if (this.CombatState != Ship_Game.Gameplay.CombatState.AttackRuns)
             {
                 button.Active = false;
             }
             else
             {
                 button.Active = true;
             }
         }
         else if (str == "arty")
         {
             if (this.CombatState != Ship_Game.Gameplay.CombatState.Artillery)
             {
                 button.Active = false;
             }
             else
             {
                 button.Active = true;
             }
         }
         else if (str == "hold")
         {
             if (this.CombatState != Ship_Game.Gameplay.CombatState.HoldPosition)
             {
                 button.Active = false;
             }
             else
             {
                 button.Active = true;
             }
         }
         else if (str == "orbit_left")
         {
             if (this.CombatState != Ship_Game.Gameplay.CombatState.OrbitLeft)
             {
                 button.Active = false;
             }
             else
             {
                 button.Active = true;
             }
         }
         else if (str == "broadside_left")
         {
             if (this.CombatState != Ship_Game.Gameplay.CombatState.BroadsideLeft)
             {
                 button.Active = false;
             }
             else
             {
                 button.Active = true;
             }
         }
         else if (str != "orbit_right")
         {
             if (str == "evade")
             {
                 if (this.CombatState != Ship_Game.Gameplay.CombatState.Evade)
                 {
                     button.Active = false;
                 }
                 else
                 {
                     button.Active = true;
                 }
             }
         }
         else if (str == "broadside_right")
         {
             if (this.CombatState != Ship_Game.Gameplay.CombatState.BroadsideRight)
             {
                 button.Active = false;
             }
             else
             {
                 button.Active = true;
             }
         }
         else if (this.CombatState != Ship_Game.Gameplay.CombatState.OrbitRight)
         {
             button.Active = false;
         }
         else
         {
             button.Active = true;
         }
     }
     this.SetupSlots();
 }
 private List<ModuleSlotData> ConvertToData(LinkedList<ModuleSlot> slotList)
 {
     List<ModuleSlotData> list = new List<ModuleSlotData>();
     foreach (ModuleSlot moduleSlot in slotList)
     {
         ModuleSlotData moduleSlotData = new ModuleSlotData();
         moduleSlotData.Position = moduleSlot.Position;
         moduleSlotData.InstalledModuleUID = moduleSlot.InstalledModuleUID;
         if (moduleSlot.HangarshipGuid != Guid.Empty)
             moduleSlotData.HangarshipGuid = moduleSlot.HangarshipGuid;
         moduleSlotData.Restrictions = moduleSlot.Restrictions;
         if (moduleSlot.module.ModuleType == ShipModuleType.Hangar)
             moduleSlotData.SlotOptions = moduleSlot.module.hangarShipUID;
         moduleSlotData.facing = moduleSlot.module.facing;
         moduleSlotData.Health = moduleSlot.module.Health;
         moduleSlotData.Shield_Power = moduleSlot.module.shield_power;
         moduleSlotData.state = moduleSlot.state;
         list.Add(moduleSlotData);
     }
     return list;
 }