public ShipQueueItem(ShipData data, Rectangle qRect, Color c) { this.ShipToBuild = data; this.IconColor = c; this.ListRect = qRect; string role = data.Role; string str = role; if (role != null) { switch (str) { case "fighter": { this.IconPath = "TacticalIcons/symbol_fighter"; return; } case "scout": { this.IconPath = "TacticalIcons/symbol_fighter"; return; } case "capital": { this.IconPath = "TacticalIcons/symbol_capital"; return; } case "frigate": { this.IconPath = "TacticalIcons/symbol_frigate"; return; } case "freighter": { this.IconPath = "TacticalIcons/symbol_freighter"; return; } case "station": { this.IconPath = "TacticalIcons/symbol_station"; return; } case "carrier": { this.IconPath = "TacticalIcons/symbol_carrier"; break; } default: { return; } } } }
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; }
private float GetMaintCostShipyardProportional(ShipData ship, float fCost, Empire empire) { float maint = 0f; float maintModReduction = 1; string role = ship.Role; // Calculate maintenance by proportion of ship cost, Duh. if (ship.Role == "fighter" || ship.Role == "scout") maint = fCost * GlobalStats.ActiveModInfo.UpkeepFighter; else if (ship.Role == "corvette") maint = fCost * GlobalStats.ActiveModInfo.UpkeepCorvette; else if (ship.Role == "frigate" || ship.Role == "destroyer") maint = fCost * GlobalStats.ActiveModInfo.UpkeepFrigate; else if (ship.Role == "cruiser") maint = fCost * GlobalStats.ActiveModInfo.UpkeepCruiser; else if (ship.Role == "carrier") maint = fCost * GlobalStats.ActiveModInfo.UpkeepCarrier; else if (ship.Role == "capital") maint = fCost * GlobalStats.ActiveModInfo.UpkeepCapital; else if (ship.Role == "freighter") maint = fCost * GlobalStats.ActiveModInfo.UpkeepFreighter; else if (ship.Role == "platform") maint = fCost * GlobalStats.ActiveModInfo.UpkeepPlatform; else if (ship.Role == "station") maint = fCost * GlobalStats.ActiveModInfo.UpkeepStation; else if (ship.Role == "drone" && GlobalStats.ActiveModInfo.useDrones) maint = fCost * GlobalStats.ActiveModInfo.UpkeepDrone; else maint = fCost * GlobalStats.ActiveModInfo.UpkeepBaseline; if (maint == 0f && GlobalStats.ActiveModInfo.UpkeepBaseline > 0) maint = fCost * GlobalStats.ActiveModInfo.UpkeepBaseline; else if (maint == 0f && GlobalStats.ActiveModInfo.UpkeepBaseline == 0) maint = fCost * 0.004f; // Modifiers below here if ((ship.Role == "freighter" || ship.Role == "platform") && empire != null && !empire.isFaction && empire.data.CivMaintMod != 1.0) { maint *= empire.data.CivMaintMod; } if ((ship.Role == "freighter" || ship.Role == "platform") && empire != null && !empire.isFaction && empire.data.Privatization) { maint *= 0.5f; } if (GlobalStats.OptionIncreaseShipMaintenance > 1) { maintModReduction = GlobalStats.OptionIncreaseShipMaintenance; maint *= (float)maintModReduction; } return maint; }
private float GetMaintCostShipyard(ShipData ship, float Size, Empire empire) { float maint = 0f; string role = ship.Role; string str = role; //bool nonCombat = false; //added by gremlin: Maintenance changes float maintModReduction = 1; //Get Maintanence of ship role bool foundMaint = false; if (ResourceManager.ShipRoles.ContainsKey(ship.Role)) { for (int i = 0; i < ResourceManager.ShipRoles[ship.Role].RaceList.Count; i++) { if (ResourceManager.ShipRoles[ship.Role].RaceList[i].ShipType == empire.data.Traits.ShipType) { maint = ResourceManager.ShipRoles[ship.Role].RaceList[i].Upkeep; foundMaint = true; break; } } if (!foundMaint) maint = ResourceManager.ShipRoles[ship.Role].Upkeep; } else return 0f; //Modify Maintanence by freighter size if (ship.Role == "freighter") { switch ((int)Size / 50) { case 0: { break; } case 1: { maint *= 1.5f; break; } case 2: case 3: case 4: { maint *= 2f; break; } default: { maint *= (int)Size / 50; break; } } } if ((ship.Role == "freighter" || ship.Role == "platform") && empire.data.CivMaintMod != 1.0) { maint *= empire.data.CivMaintMod; } //Apply Privatization if ((ship.Role == "freighter" || ship.Role == "platform") && empire.data.Privatization) { maint *= 0.5f; } //Subspace Projectors do not get any more modifiers if (ship.Name == "Subspace Projector") { return maint; } //Maintenance fluctuator //string configvalue1 = ConfigurationManager.AppSettings["countoffiles"]; float OptionIncreaseShipMaintenance = GlobalStats.OptionIncreaseShipMaintenance; if (OptionIncreaseShipMaintenance > 1) { maintModReduction = OptionIncreaseShipMaintenance; maint *= maintModReduction; } return maint; }
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(); }
public override void HandleInput(InputState input) { this.CategoryList.HandleInput(input); this.CarrierOnlyBox.HandleInput(input); if (this.ActiveModule != null && (this.ActiveModule.InstalledWeapon != null && this.ActiveModule.ModuleType != ShipModuleType.Turret || this.ActiveModule.XSIZE != this.ActiveModule.YSIZE)) { if (input.Left) this.ChangeModuleState(ShipDesignScreen.ActiveModuleState.Left); if (input.Right) this.ChangeModuleState(ShipDesignScreen.ActiveModuleState.Right); if (input.Down) this.ChangeModuleState(ShipDesignScreen.ActiveModuleState.Rear); if (input.Up) this.ChangeModuleState(ShipDesignScreen.ActiveModuleState.Normal); } if (input.CurrentKeyboardState.IsKeyDown(Keys.Y) && !input.LastKeyboardState.IsKeyDown(Keys.Y) && !GlobalStats.TakingInput) { AudioManager.PlayCue("echo_affirm"); this.ExitScreen(); } if (this.close.HandleInput(input)) this.ExitScreen(); else if (input.CurrentKeyboardState.IsKeyDown(Keys.Z) && input.LastKeyboardState.IsKeyUp(Keys.Z) && input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl)) { if (this.DesignStack.Count <= 0) return; ShipModule shipModule = this.ActiveModule; DesignAction designAction = this.DesignStack.Pop(); SlotStruct slot1 = new SlotStruct(); foreach (SlotStruct slot2 in this.Slots) { if (slot2.pq == designAction.clickedSS.pq) { this.ClearSlotNoStack(slot2); slot1 = slot2; slot1.facing = designAction.clickedSS.facing; } foreach (SlotStruct slotStruct in designAction.AlteredSlots) { if (slot2.pq == slotStruct.pq) { this.ClearSlotNoStack(slot2); break; } } } if (designAction.clickedSS.ModuleUID != null) { this.ActiveModule = ResourceManager.GetModule(designAction.clickedSS.ModuleUID); this.ResetModuleState(); this.InstallModuleNoStack(slot1); } foreach (SlotStruct slotStruct in designAction.AlteredSlots) { foreach (SlotStruct slot2 in this.Slots) { if (slot2.pq == slotStruct.pq && slotStruct.ModuleUID != null) { this.ActiveModule = ResourceManager.GetModule(slotStruct.ModuleUID); this.ResetModuleState(); this.InstallModuleNoStack(slot2); slot2.facing = slotStruct.facing; slot2.ModuleUID = slotStruct.ModuleUID; } } } this.ActiveModule = shipModule; this.ResetModuleState(); } else { if (!HelperFunctions.CheckIntersection(this.ModuleSelectionMenu.Menu, input.CursorPosition) && !HelperFunctions.CheckIntersection(this.HullSelectionRect, input.CursorPosition) && !HelperFunctions.CheckIntersection(this.ChooseFighterSub.Menu, input.CursorPosition)) { if (input.ScrollOut) { this.TransitionZoom -= 0.1f; if ((double)this.TransitionZoom < 0.300000011920929) this.TransitionZoom = 0.3f; if ((double)this.TransitionZoom > 2.65000009536743) this.TransitionZoom = 2.65f; } if (input.ScrollIn) { this.TransitionZoom += 0.1f; if ((double)this.TransitionZoom < 0.300000011920929) this.TransitionZoom = 0.3f; if ((double)this.TransitionZoom > 2.65000009536743) this.TransitionZoom = 2.65f; } } if (input.CurrentKeyboardState.IsKeyDown(Keys.OemTilde)) input.LastKeyboardState.IsKeyUp(Keys.OemTilde); if (this.Debug) { if (input.CurrentKeyboardState.IsKeyDown(Keys.Enter) && input.LastKeyboardState.IsKeyUp(Keys.Enter)) { foreach (ModuleSlotData moduleSlotData in this.ActiveHull.ModuleSlotList) moduleSlotData.InstalledModuleUID = (string)null; new XmlSerializer(typeof(ShipData)).Serialize((TextWriter)new StreamWriter("Content/Hulls/" + this.ActiveHull.ShipStyle + "/" + this.ActiveHull.Name + ".xml"), (object)this.ActiveHull); } if (input.Right) ++this.operation; if (this.operation > (ShipDesignScreen.SlotModOperation)6) this.operation = ShipDesignScreen.SlotModOperation.Delete; } this.HoveredModule = (ShipModule)null; this.mouseStateCurrent = Mouse.GetState(); Vector2 vector2 = new Vector2((float)this.mouseStateCurrent.X, (float)this.mouseStateCurrent.Y); this.selector = (Selector)null; this.EmpireUI.HandleInput(input, (GameScreen)this); this.activeModSubMenu.HandleInputNoReset((object)this); this.hullSL.HandleInput(input); for (int index = this.hullSL.indexAtTop; index < this.hullSL.Copied.Count && index < this.hullSL.indexAtTop + this.hullSL.entriesToDisplay; ++index) { ScrollList.Entry e = this.hullSL.Copied[index]; if (e.item is ModuleHeader) { if ((e.item as ModuleHeader).HandleInput(input, e)) return; } else if (HelperFunctions.CheckIntersection(e.clickRect, vector2)) { this.selector = new Selector(this.ScreenManager, e.clickRect); e.clickRectHover = 1; this.selector = new Selector(this.ScreenManager, e.clickRect); if (input.InGameSelect) { AudioManager.PlayCue("sd_ui_accept_alt3"); if (!this.ShipSaved && !this.CheckDesign()) { MessageBoxScreen messageBoxScreen = new MessageBoxScreen(Localizer.Token(2121), "Save", "No"); messageBoxScreen.Accepted += new EventHandler<EventArgs>(this.SaveWIPThenChangeHull); messageBoxScreen.Cancelled += new EventHandler<EventArgs>(this.JustChangeHull); this.changeto = e.item as ShipData; this.ScreenManager.AddScreen((GameScreen)messageBoxScreen); return; } else { this.ChangeHull(e.item as ShipData); return; } } } else e.clickRectHover = 0; } this.modSel.HandleInput((object)this); if (this.ActiveModule != null) { if (this.ActiveModule.ModuleType == ShipModuleType.Hangar && !this.ActiveModule.IsTroopBay && !this.ActiveModule.IsSupplyBay) { this.UpdateHangarOptions(this.ActiveModule); this.ChooseFighterSL.HandleInput(input); for (int index = this.ChooseFighterSL.indexAtTop; index < this.ChooseFighterSL.Copied.Count && index < this.ChooseFighterSL.indexAtTop + this.ChooseFighterSL.entriesToDisplay; ++index) { ScrollList.Entry entry = this.ChooseFighterSL.Copied[index]; if (HelperFunctions.CheckIntersection(entry.clickRect, vector2)) { this.selector = new Selector(this.ScreenManager, entry.clickRect); entry.clickRectHover = 1; this.selector = new Selector(this.ScreenManager, entry.clickRect); if (input.InGameSelect) { this.ActiveModule.hangarShipUID = (entry.item as Ship).Name; this.HangarShipUIDLast = (entry.item as Ship).Name; AudioManager.PlayCue("sd_ui_accept_alt3"); return; } } } } } else if (this.HighlightedModule != null && this.HighlightedModule.ModuleType == ShipModuleType.Hangar && (!this.HighlightedModule.IsTroopBay && !this.HighlightedModule.IsSupplyBay)) { this.ChooseFighterSL.HandleInput(input); for (int index = this.ChooseFighterSL.indexAtTop; index < this.ChooseFighterSL.Copied.Count && index < this.ChooseFighterSL.indexAtTop + this.ChooseFighterSL.entriesToDisplay; ++index) { ScrollList.Entry entry = this.ChooseFighterSL.Copied[index]; if (HelperFunctions.CheckIntersection(entry.clickRect, vector2)) { this.selector = new Selector(this.ScreenManager, entry.clickRect); entry.clickRectHover = 1; this.selector = new Selector(this.ScreenManager, entry.clickRect); if (input.InGameSelect) { this.HighlightedModule.hangarShipUID = (entry.item as Ship).Name; this.HangarShipUIDLast = (entry.item as Ship).Name; AudioManager.PlayCue("sd_ui_accept_alt3"); return; } } } } for (int index = this.weaponSL.indexAtTop; index < this.weaponSL.Copied.Count && index < this.weaponSL.indexAtTop + this.weaponSL.entriesToDisplay; ++index) { ScrollList.Entry e = this.weaponSL.Copied[index]; if (e.item is ModuleHeader) { if ((e.item as ModuleHeader).HandleInput(input, e)) return; } else if (HelperFunctions.CheckIntersection(e.clickRect, vector2)) { this.selector = new Selector(this.ScreenManager, e.clickRect); e.clickRectHover = 1; this.selector = new Selector(this.ScreenManager, e.clickRect); if (input.InGameSelect) { this.SetActiveModule(ResourceManager.GetModule((e.item as ShipModule).UID)); this.ResetModuleState(); return; } } else e.clickRectHover = 0; } this.weaponSL.HandleInput(input); if (HelperFunctions.CheckIntersection(this.HullSelectionRect, input.CursorPosition) && input.CurrentMouseState.LeftButton == ButtonState.Pressed || HelperFunctions.CheckIntersection(this.modSel.Menu, input.CursorPosition) && input.CurrentMouseState.LeftButton == ButtonState.Pressed || HelperFunctions.CheckIntersection(this.activeModSubMenu.Menu, input.CursorPosition) && input.CurrentMouseState.LeftButton == ButtonState.Pressed) return; if (HelperFunctions.CheckIntersection(this.modSel.Menu, vector2)) { if (this.mouseStateCurrent.ScrollWheelValue > this.mouseStatePrevious.ScrollWheelValue && this.weaponSL.indexAtTop > 0) --this.weaponSL.indexAtTop; if (this.mouseStateCurrent.ScrollWheelValue < this.mouseStatePrevious.ScrollWheelValue && this.weaponSL.indexAtTop + this.weaponSL.entriesToDisplay < this.weaponSL.Entries.Count) ++this.weaponSL.indexAtTop; } if (HelperFunctions.CheckIntersection(this.ArcsButton.R, input.CursorPosition)) ToolTip.CreateTooltip(134, this.ScreenManager); if (this.ArcsButton.HandleInput(input)) { this.ArcsButton.ToggleOn = !this.ArcsButton.ToggleOn; this.ShowAllArcs = this.ArcsButton.ToggleOn; } if (input.Tab) { this.ShowAllArcs = !this.ShowAllArcs; this.ArcsButton.ToggleOn = this.ShowAllArcs; } if (input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Released) { this.StartDragPos = input.CursorPosition; this.cameraVelocity.X = 0.0f; this.cameraVelocity.Y = 0.0f; } if (input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Pressed) { float num1 = input.CursorPosition.X - this.StartDragPos.X; float num2 = input.CursorPosition.Y - this.StartDragPos.Y; this.camera._pos += new Vector2(-num1, -num2); this.StartDragPos = input.CursorPosition; this.cameraPosition.X += -num1; this.cameraPosition.Y += -num2; } else { this.cameraVelocity.X = 0.0f; this.cameraVelocity.Y = 0.0f; } this.cameraVelocity.X = MathHelper.Clamp(this.cameraVelocity.X, -10f, 10f); this.cameraVelocity.Y = MathHelper.Clamp(this.cameraVelocity.Y, -10f, 10f); if (input.Escaped) this.ExitScreen(); if (this.ToggleOverlay) { foreach (SlotStruct slotStruct in this.Slots) { Vector2 spaceFromWorldSpace = this.camera.GetScreenSpaceFromWorldSpace(new Vector2((float)slotStruct.pq.enclosingRect.X, (float)slotStruct.pq.enclosingRect.Y)); if (HelperFunctions.CheckIntersection(new Rectangle((int)spaceFromWorldSpace.X, (int)spaceFromWorldSpace.Y, (int)(16.0 * (double)this.camera.Zoom), (int)(16.0 * (double)this.camera.Zoom)), vector2)) { if (slotStruct.isDummy && slotStruct.parent.module != null) this.HoveredModule = slotStruct.parent.module; else if (slotStruct.module != null) this.HoveredModule = slotStruct.module; if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released) { AudioManager.GetCue("simple_beep").Play(); if (this.Debug) { this.DebugAlterSlot(slotStruct.slotReference.Position, this.operation); return; } else if (slotStruct.isDummy && slotStruct.parent.module != null) this.HighlightedModule = slotStruct.parent.module; else if (slotStruct.module != null) this.HighlightedModule = slotStruct.module; } } } } if (HelperFunctions.CheckIntersection(this.upArrow, vector2) && this.mouseStateCurrent.LeftButton == ButtonState.Released && (this.mouseStatePrevious.LeftButton == ButtonState.Pressed && this.scrollPosition > 0)) { --this.scrollPosition; AudioManager.GetCue("blip_click").Play(); foreach (ModuleButton moduleButton in this.ModuleButtons) moduleButton.moduleRect.Y += 128; } if (HelperFunctions.CheckIntersection(this.downArrow, vector2) && this.mouseStateCurrent.LeftButton == ButtonState.Released && this.mouseStatePrevious.LeftButton == ButtonState.Pressed) { ++this.scrollPosition; AudioManager.GetCue("blip_click").Play(); foreach (ModuleButton moduleButton in this.ModuleButtons) moduleButton.moduleRect.Y -= 128; } if (HelperFunctions.CheckIntersection(this.ModuleSelectionArea, vector2)) { if (input.ScrollIn && this.scrollPosition > 0) { --this.scrollPosition; AudioManager.GetCue("blip_click").Play(); foreach (ModuleButton moduleButton in this.ModuleButtons) moduleButton.moduleRect.Y += 128; } if (input.ScrollOut) { ++this.scrollPosition; AudioManager.GetCue("blip_click").Play(); foreach (ModuleButton moduleButton in this.ModuleButtons) moduleButton.moduleRect.Y -= 128; } } if (this.mouseStateCurrent.RightButton == ButtonState.Released && this.mouseStatePrevious.RightButton == ButtonState.Pressed) { //this should actually clear slots this.ActiveModule = (ShipModule)null; foreach (SlotStruct parent in this.Slots) { parent.ShowInvalid = false; parent.ShowValid = false; Vector2 spaceFromWorldSpace = this.camera.GetScreenSpaceFromWorldSpace(new Vector2((float)parent.pq.enclosingRect.X, (float)parent.pq.enclosingRect.Y)); Rectangle rect = new Rectangle((int)spaceFromWorldSpace.X, (int)spaceFromWorldSpace.Y, (int)(16.0 * (double)this.camera.Zoom), (int)(16.0 * (double)this.camera.Zoom)); if ((parent.module != null || parent.isDummy) && HelperFunctions.CheckIntersection(rect, vector2)) //if clicked at this slot { DesignAction designAction = new DesignAction(); designAction.clickedSS = new SlotStruct(); designAction.clickedSS.pq = parent.isDummy ? parent.parent.pq : parent.pq; designAction.clickedSS.Restrictions = parent.Restrictions; designAction.clickedSS.facing = parent.module != null ? parent.module.facing : 0.0f; designAction.clickedSS.ModuleUID = parent.isDummy ? parent.parent.ModuleUID : parent.ModuleUID; designAction.clickedSS.module = parent.module; designAction.clickedSS.slotReference = parent.isDummy ? parent.parent.slotReference : parent.slotReference; this.DesignStack.Push(designAction); AudioManager.GetCue("sub_bass_whoosh").Play(); if (parent.isDummy) this.ClearParentSlot(parent.parent); else this.ClearParentSlot(parent); this.RecalculatePower(); } } } foreach (ModuleButton moduleButton in this.ModuleButtons) { if (HelperFunctions.CheckIntersection(this.ModuleSelectionArea, new Vector2((float)(moduleButton.moduleRect.X + 30), (float)(moduleButton.moduleRect.Y + 30)))) { if (HelperFunctions.CheckIntersection(moduleButton.moduleRect, vector2)) { if (input.InGameSelect) this.SetActiveModule(ResourceManager.GetModule(moduleButton.ModuleUID)); moduleButton.isHighlighted = true; } else moduleButton.isHighlighted = false; } } if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && this.ActiveModule != null) { foreach (SlotStruct slot in this.Slots) { Vector2 spaceFromWorldSpace = this.camera.GetScreenSpaceFromWorldSpace(new Vector2((float)slot.pq.enclosingRect.X, (float)slot.pq.enclosingRect.Y)); if (HelperFunctions.CheckIntersection(new Rectangle((int)spaceFromWorldSpace.X, (int)spaceFromWorldSpace.Y, (int)(16.0 * (double)this.camera.Zoom), (int)(16.0 * (double)this.camera.Zoom)), vector2)) { AudioManager.GetCue("sub_bass_mouseover").Play(); this.InstallModule(slot); } } } else if (this.mouseStateCurrent.LeftButton == ButtonState.Pressed && this.mouseStatePrevious.LeftButton == ButtonState.Pressed) this.HoldTimer -= .01666f; else this.HoldTimer = 0.50f; foreach (SlotStruct slotStruct in this.Slots) { if (slotStruct.ModuleUID != null && this.HighlightedModule != null && (slotStruct.module == this.HighlightedModule && (double)slotStruct.module.FieldOfFire != 0.0) && slotStruct.module.ModuleType == ShipModuleType.Turret) { float num1 = slotStruct.module.FieldOfFire / 2f; Vector2 spaceFromWorldSpace = this.camera.GetScreenSpaceFromWorldSpace(new Vector2((float)(slotStruct.pq.enclosingRect.X + 16 * (int)slotStruct.module.XSIZE / 2), (float)(slotStruct.pq.enclosingRect.Y + 16 * (int)slotStruct.module.YSIZE / 2))); float num2 = Math.Abs(this.findAngleToTarget(spaceFromWorldSpace, vector2)); float num3 = this.HighlightedModule.facing; float num4 = Math.Abs(num2 - num3); if ((double)num4 > (double)num1) { if ((double)num2 > 180.0) num2 = (float)(-1.0 * (360.0 - (double)num2)); if ((double)num3 > 180.0) num3 = (float)(-1.0 * (360.0 - (double)num3)); num4 = Math.Abs(num2 - num3); } if (GlobalStats.AltArcControl) { //The Doctor: ALT (either) + LEFT CLICK to pick and move arcs. This way, it's impossible to accidentally pick the wrong arc, while it's just as responsive and smooth as the original method when you are trying to. if ((double)num4 < (double)num1 && (this.mouseStateCurrent.LeftButton == ButtonState.Pressed && this.mouseStatePrevious.LeftButton == ButtonState.Pressed && ((input.CurrentKeyboardState.IsKeyDown(Keys.LeftAlt) || input.LastKeyboardState.IsKeyDown(Keys.LeftAlt)) || (input.CurrentKeyboardState.IsKeyDown(Keys.RightAlt) || input.LastKeyboardState.IsKeyDown(Keys.RightAlt))))) { this.HighlightedModule.facing = Math.Abs(this.findAngleToTarget(spaceFromWorldSpace, vector2)); } } else { //Delay method if ((double)num4 < (double)num1 && (this.mouseStateCurrent.LeftButton == ButtonState.Pressed && this.mouseStatePrevious.LeftButton == ButtonState.Pressed && this.HoldTimer < 0)) { this.HighlightedModule.facing = Math.Abs(this.findAngleToTarget(spaceFromWorldSpace, vector2)); } } } } foreach (UIButton uiButton in this.Buttons) { if (HelperFunctions.CheckIntersection(uiButton.Rect, vector2)) { uiButton.State = UIButton.PressState.Hover; if (this.mouseStateCurrent.LeftButton == ButtonState.Pressed && this.mouseStatePrevious.LeftButton == ButtonState.Pressed) uiButton.State = UIButton.PressState.Pressed; if (this.mouseStateCurrent.LeftButton == ButtonState.Released && this.mouseStatePrevious.LeftButton == ButtonState.Pressed) { switch (uiButton.Launches) { case "Toggle Overlay": AudioManager.PlayCue("blip_click"); this.ToggleOverlay = !this.ToggleOverlay; continue; case "Save As...": if (this.CheckDesign()) { this.ScreenManager.AddScreen((GameScreen)new DesignManager(this, this.ActiveHull.Name)); continue; } else { AudioManager.PlayCue("UI_Misc20"); this.ScreenManager.AddScreen((GameScreen)new MessageBoxScreen(Localizer.Token(2049))); continue; } case "Load": this.ScreenManager.AddScreen((GameScreen)new LoadDesigns(this)); continue; default: continue; } } } else uiButton.State = UIButton.PressState.Normal; } if (this.ActiveHull != null) { foreach (ToggleButton toggleButton in this.CombatStatusButtons) { if (HelperFunctions.CheckIntersection(toggleButton.r, input.CursorPosition)) { if (toggleButton.HasToolTip) ToolTip.CreateTooltip(toggleButton.WhichToolTip, this.ScreenManager); if (input.InGameSelect) { AudioManager.PlayCue("sd_ui_accept_alt3"); switch (toggleButton.Action) { case "attack": this.CombatState = CombatState.AttackRuns; break; case "arty": this.CombatState = CombatState.Artillery; break; case "hold": this.CombatState = CombatState.HoldPosition; break; case "orbit_left": this.CombatState = CombatState.OrbitLeft; break; case "broadside_left": this.CombatState = CombatState.BroadsideLeft; break; case "orbit_right": this.CombatState = CombatState.OrbitRight; break; case "broadside_right": this.CombatState = CombatState.BroadsideRight; break; case "evade": this.CombatState = CombatState.Evade; break; } } } else toggleButton.Hover = false; switch (toggleButton.Action) { case "attack": toggleButton.Active = this.CombatState == CombatState.AttackRuns; continue; case "arty": toggleButton.Active = this.CombatState == CombatState.Artillery; continue; case "hold": toggleButton.Active = this.CombatState == CombatState.HoldPosition; continue; case "orbit_left": toggleButton.Active = this.CombatState == CombatState.OrbitLeft; continue; case "broadside_left": toggleButton.Active = this.CombatState == CombatState.BroadsideLeft; continue; case "orbit_right": toggleButton.Active = this.CombatState == CombatState.OrbitRight; continue; case "broadside_right": toggleButton.Active = this.CombatState == CombatState.BroadsideRight; continue; case "evade": toggleButton.Active = this.CombatState == CombatState.Evade; continue; default: continue; } } } this.mouseStatePrevious = this.mouseStateCurrent; base.HandleInput(input); } }
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 override void HandleInput(InputState input) { this.currentMouse = input.CurrentMouseState; Vector2 MousePos = new Vector2((float)this.currentMouse.X, (float)this.currentMouse.Y); this.ShipDesigns.HandleInput(input); if (input.Escaped || input.RightMouseClick) { this.ExitScreen(); } foreach (UIButton b in this.Buttons) { if (!HelperFunctions.CheckIntersection(b.Rect, MousePos)) { b.State = UIButton.PressState.Normal; } else { b.State = UIButton.PressState.Hover; if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Pressed) { b.State = UIButton.PressState.Pressed; } if (this.currentMouse.LeftButton != ButtonState.Released || this.previousMouse.LeftButton != ButtonState.Pressed) { continue; } string launches = b.Launches; if (launches == null || !(launches == "Load")) { continue; } this.LoadShipToScreen(); } } this.selector = null; for (int i = this.ShipDesigns.indexAtTop; i < this.ShipDesigns.Copied.Count && i < this.ShipDesigns.indexAtTop + this.ShipDesigns.entriesToDisplay; i++) { ScrollList.Entry e = this.ShipDesigns.Copied[i]; if (e.item is ModuleHeader) { (e.item as ModuleHeader).HandleInput(input, e); } else if (e.item is ShipData) { if (!HelperFunctions.CheckIntersection(e.clickRect, MousePos)) { e.clickRectHover = 0; } else { if (HelperFunctions.CheckIntersection(e.cancel, MousePos) && input.InGameSelect) { this.ShipToDelete = (e.item as ShipData).Name; MessageBoxScreen messageBox = new MessageBoxScreen("Confirm Delete:"); messageBox.Accepted += new EventHandler<EventArgs>(this.DeleteDataAccepted); base.ScreenManager.AddScreen(messageBox); } this.selector = new Selector(base.ScreenManager, e.clickRect); if (e.clickRectHover == 0) { AudioManager.PlayCue("sd_ui_mouseover"); } e.clickRectHover = 1; if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released) { this.EnterNameArea.Text = (e.item as ShipData).Name; this.selectedWIP = e.item as ShipData; AudioManager.PlayCue("sd_ui_accept_alt3"); } } } else if (!HelperFunctions.CheckIntersection(e.clickRect, MousePos)) { e.clickRectHover = 0; } else { if (HelperFunctions.CheckIntersection(e.cancel, MousePos) && !(e.item as Ship).reserved && !(e.item as Ship).FromSave && input.InGameSelect) { this.ShipToDelete = (e.item as Ship).Name; MessageBoxScreen messageBox = new MessageBoxScreen("Confirm Delete:"); messageBox.Accepted += new EventHandler<EventArgs>(this.DeleteAccepted); base.ScreenManager.AddScreen(messageBox); } this.selector = new Selector(base.ScreenManager, e.clickRect); if (e.clickRectHover == 0) { AudioManager.PlayCue("sd_ui_mouseover"); } e.clickRectHover = 1; if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released) { this.EnterNameArea.Text = (e.item as Ship).Name; AudioManager.PlayCue("sd_ui_accept_alt3"); } } } if (this.playerDesignsToggle.HandleInput(input)) { AudioManager.PlayCue("sd_ui_accept_alt3"); this.ShowAllDesigns = !this.ShowAllDesigns; if (this.ShowAllDesigns) { this.playerDesignsToggle.Active = true; } else { this.playerDesignsToggle.Active = false; } this.ResetSL(); } if (HelperFunctions.CheckIntersection(this.playerDesignsToggle.r, input.CursorPosition)) { ToolTip.CreateTooltip(Localizer.Token(2225), base.ScreenManager); } this.previousMouse = input.LastMouseState; base.HandleInput(input); }
public static Ship LoadSavedShip(ShipData data) { Ship parent = new Ship(); if (data.Name == "Left Right Test") parent.Position = new Vector2(200f, 200f); parent.Position = new Vector2(200f, 200f); parent.Name = data.Name; parent.Level = (int)data.Level; parent.Role = data.Role; parent.ModelPath = data.ModelPath; parent.ModuleSlotList = Ship.LoadSlotDataListToSlotList(data.ModuleSlotList, parent); foreach (ShipToolScreen.ThrusterZone thrusterZone in data.ThrusterList) parent.ThrusterList.Add(new Thruster() { tscale = thrusterZone.scale, XMLPos = thrusterZone.Position, Parent = parent }); return parent; }
public static Ship CreateShipFromShipData(ShipData data) { Ship parent = new Ship(); parent.Position = new Vector2(200f, 200f); parent.Name = data.Name; parent.Level = (int)data.Level; parent.experience = (int)data.experience; parent.Role = data.Role; parent.ModelPath = data.ModelPath; parent.ModuleSlotList = Ship.SlotDataListToSlotList(data.ModuleSlotList, parent); foreach (ShipToolScreen.ThrusterZone thrusterZone in data.ThrusterList) parent.ThrusterList.Add(new Thruster() { tscale = thrusterZone.scale, XMLPos = thrusterZone.Position, Parent = parent }); return parent; }
public ShipData ToShipData() { ShipData shipData = new ShipData(); shipData.BaseCanWarp = this.shipData.BaseCanWarp; shipData.BaseStrength = this.BaseStrength; shipData.techsNeeded = this.shipData.techsNeeded; shipData.TechScore = this.shipData.TechScore; shipData.ShipCategory = this.shipData.ShipCategory; shipData.Name = this.Name; shipData.Level = (byte)this.Level; shipData.experience = (byte)this.experience; shipData.Role = this.Role; shipData.IsShipyard = this.GetShipData().IsShipyard; shipData.IsOrbitalDefense = this.GetShipData().IsOrbitalDefense; shipData.Animated = this.GetShipData().Animated; shipData.CombatState = this.GetAI().CombatState; shipData.ModelPath = this.GetShipData().ModelPath; shipData.ModuleSlotList = this.ConvertToData(this.ModuleSlotList); shipData.ThrusterList = new List<ShipToolScreen.ThrusterZone>(); shipData.MechanicalBoardingDefense = this.MechanicalBoardingDefense; foreach (Thruster thruster in this.ThrusterList) shipData.ThrusterList.Add(new ShipToolScreen.ThrusterZone() { scale = thruster.tscale, Position = thruster.XMLPos }); return shipData; }
public void SetShipData(ShipData data) { this.shipData = data; }