public LoadDesigns(ShipDesignScreen screen)
 {
     this.screen = screen;
     base.IsPopup = true;
     base.TransitionOnTime = TimeSpan.FromSeconds(0.25);
     base.TransitionOffTime = TimeSpan.FromSeconds(0.25);
 }
 public DesignManager(ShipDesignScreen screen, string txt)
 {
     this.ShipName = txt;
     this.screen = screen;
     base.IsPopup = true;
     base.TransitionOnTime = TimeSpan.FromSeconds(0.25);
     base.TransitionOffTime = TimeSpan.FromSeconds(0.25);
 }
 private void DebugAlterSlot(Vector2 SlotPos, ShipDesignScreen.SlotModOperation op)
 {
     ModuleSlotData toRemove;
     switch (op)
     {
         case ShipDesignScreen.SlotModOperation.Delete:
         {
             toRemove = null;
             foreach (ModuleSlotData slotdata in this.ActiveHull.ModuleSlotList)
             {
                 if (slotdata.Position != SlotPos)
                 {
                     continue;
                 }
                 toRemove = slotdata;
                 break;
             }
             if (toRemove == null)
             {
                 return;
             }
             this.ActiveHull.ModuleSlotList.Remove(toRemove);
             this.ChangeHull(this.ActiveHull);
             return;
         }
         case ShipDesignScreen.SlotModOperation.I:
         {
             toRemove = null;
             foreach (ModuleSlotData slotdata in this.ActiveHull.ModuleSlotList)
             {
                 if (slotdata.Position != SlotPos)
                 {
                     continue;
                 }
                 toRemove = slotdata;
                 break;
             }
             if (toRemove == null)
             {
                 return;
             }
             toRemove.Restrictions = Restrictions.I;
             this.ChangeHull(this.ActiveHull);
             return;
         }
         case ShipDesignScreen.SlotModOperation.IO:
         {
             toRemove = null;
             foreach (ModuleSlotData slotdata in this.ActiveHull.ModuleSlotList)
             {
                 if (slotdata.Position != SlotPos)
                 {
                     continue;
                 }
                 toRemove = slotdata;
                 break;
             }
             if (toRemove == null)
             {
                 return;
             }
             toRemove.Restrictions = Restrictions.IO;
             this.ChangeHull(this.ActiveHull);
             return;
         }
         case ShipDesignScreen.SlotModOperation.O:
         {
             toRemove = null;
             foreach (ModuleSlotData slotdata in this.ActiveHull.ModuleSlotList)
             {
                 if (slotdata.Position != SlotPos)
                 {
                     continue;
                 }
                 toRemove = slotdata;
                 break;
             }
             if (toRemove == null)
             {
                 return;
             }
             toRemove.Restrictions = Restrictions.O;
             this.ChangeHull(this.ActiveHull);
             return;
         }
         case ShipDesignScreen.SlotModOperation.Add:
         {
             return;
         }
         case ShipDesignScreen.SlotModOperation.E:
         {
             toRemove = null;
             foreach (ModuleSlotData slotdata in this.ActiveHull.ModuleSlotList)
             {
                 if (slotdata.Position != SlotPos)
                 {
                     continue;
                 }
                 toRemove = slotdata;
                 break;
             }
             if (toRemove == null)
             {
                 return;
             }
             toRemove.Restrictions = Restrictions.E;
             this.ChangeHull(this.ActiveHull);
             return;
         }
         default:
         {
             return;
         }
     }
 }
 private void ChangeModuleState(ShipDesignScreen.ActiveModuleState state)
 {
     if (this.ActiveModule == null)
     {
         return;
     }
     byte x = Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].XSIZE;
     byte y = Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].YSIZE;
     switch (state)
     {
         case ShipDesignScreen.ActiveModuleState.Normal:
         {
             this.ActiveModule.XSIZE = Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].XSIZE;
             this.ActiveModule.YSIZE = Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].YSIZE;
             this.ActiveModState = ShipDesignScreen.ActiveModuleState.Normal;
             return;
         }
         case ShipDesignScreen.ActiveModuleState.Left:
         {
             this.ActiveModule.XSIZE = y;
             this.ActiveModule.YSIZE = x;
             this.ActiveModState = ShipDesignScreen.ActiveModuleState.Left;
             this.ActiveModule.facing = 270f;
             return;
         }
         case ShipDesignScreen.ActiveModuleState.Right:
         {
             this.ActiveModule.XSIZE = y;
             this.ActiveModule.YSIZE = x;
             this.ActiveModState = ShipDesignScreen.ActiveModuleState.Right;
             this.ActiveModule.facing = 90f;
             return;
         }
         case ShipDesignScreen.ActiveModuleState.Rear:
         {
             this.ActiveModule.XSIZE = Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].XSIZE;
             this.ActiveModule.YSIZE = Ship_Game.ResourceManager.ShipModulesDict[this.ActiveModule.UID].YSIZE;
             this.ActiveModState = ShipDesignScreen.ActiveModuleState.Rear;
             this.ActiveModule.facing = 180f;
             return;
         }
         default:
         {
             return;
         }
     }
 }
        public override void HandleInput(InputState input)
        {
            this.pFacilities.HandleInputNoReset(this);
            if (HelperFunctions.CheckIntersection(this.RightColony.r, input.CursorPosition))
            {
                ToolTip.CreateTooltip(Localizer.Token(2279), this.ScreenManager);
            }
            if (HelperFunctions.CheckIntersection(this.LeftColony.r, input.CursorPosition))
            {
                ToolTip.CreateTooltip(Localizer.Token(2280), this.ScreenManager);
            }
            if ((input.Right || this.RightColony.HandleInput(input)) && (PlanetScreen.screen.Debug || this.p.Owner == EmpireManager.GetEmpireByName(PlanetScreen.screen.PlayerLoyalty)))
            {

                try
                {
                    this.p.Owner.GetPlanets().thisLock.EnterReadLock();
                    int thisindex = this.p.Owner.GetPlanets().IndexOf(this.p);
                    thisindex = (thisindex >= this.p.Owner.GetPlanets().Count - 1 ? 0 : thisindex + 1);
                    if (this.p.Owner.GetPlanets()[thisindex] != this.p)
                    {
                        this.p = this.p.Owner.GetPlanets()[thisindex];
                        PlanetScreen.screen.workersPanel = new ColonyScreen(this.p, this.ScreenManager, this.eui);
                    }
                    this.p.Owner.GetPlanets().thisLock.ExitReadLock();
                }
                catch
                {

                    System.Diagnostics.Debug.WriteLine("Colony Screen Handle Inpu. Likely null reference.");
                }
                if (input.CurrentMouseState.RightButton != ButtonState.Released || this.previousMouse.RightButton != ButtonState.Released)
                {
                    this.eui.screen.ShipsInCombat.Active = true;
                    this.eui.screen.PlanetsInCombat.Active = true;
                }
                return;
            }
            if ((input.Left || this.LeftColony.HandleInput(input)) && (PlanetScreen.screen.Debug || this.p.Owner == EmpireManager.GetEmpireByName(PlanetScreen.screen.PlayerLoyalty)))
            {
                int thisindex = this.p.Owner.GetPlanets().IndexOf(this.p);
                thisindex = (thisindex <= 0 ? this.p.Owner.GetPlanets().Count - 1 : thisindex - 1);
                if (this.p.Owner.GetPlanets()[thisindex] != this.p)
                {
                    this.p = this.p.Owner.GetPlanets()[thisindex];
                    PlanetScreen.screen.workersPanel = new ColonyScreen(this.p, this.ScreenManager, this.eui);
                }
                if (input.CurrentMouseState.RightButton != ButtonState.Released || this.previousMouse.RightButton != ButtonState.Released)
                {
                    this.eui.screen.ShipsInCombat.Active = true;
                    this.eui.screen.PlanetsInCombat.Active = true;
                }
                return;
            }
            this.p.UpdateIncomes();
            this.HandleDetailInfo(input);
            this.currentMouse = Mouse.GetState();
            Vector2 MousePos = new Vector2((float)this.currentMouse.X, (float)this.currentMouse.Y);
            this.buildSL.HandleInput(input);
            this.buildSL.Update();
            this.build.HandleInput(this);
            if (this.p.Owner != EmpireManager.GetEmpireByName(PlanetScreen.screen.PlayerLoyalty))
            {
                this.HandleDetailInfo(input);
                if (input.CurrentMouseState.RightButton != ButtonState.Released || this.previousMouse.RightButton != ButtonState.Released)
                {
                    this.eui.screen.ShipsInCombat.Active = true;
                    this.eui.screen.PlanetsInCombat.Active = true;
                }
                return;
            }
            if (!HelperFunctions.CheckIntersection(this.launchTroops.Rect, input.CursorPosition))
            {
                this.launchTroops.State = UIButton.PressState.Normal;
            }
            else
            {
                this.launchTroops.State = UIButton.PressState.Hover;
                if (input.InGameSelect)
                {
                    bool play = false;
                    foreach (PlanetGridSquare pgs in this.p.TilesList)
                    {
                        if (pgs.TroopsHere.Count <= 0 || pgs.TroopsHere[0].GetOwner() != EmpireManager.GetEmpireByName(PlanetScreen.screen.PlayerLoyalty))
                        {
                            continue;
                        }

                        play = true;

                        ResourceManager.CreateTroopShipAtPoint((this.p.Owner.data.DefaultTroopShip != null) ? this.p.Owner.data.DefaultTroopShip : this.p.Owner.data.DefaultSmallTransport, this.p.Owner, this.p.Position, pgs.TroopsHere[0]);
                        this.p.TroopsHere.Remove(pgs.TroopsHere[0]);
                        pgs.TroopsHere[0].SetPlanet(null);
                        pgs.TroopsHere.Clear();
                        this.ClickedTroop = true;
                        this.detailInfo = null;
                    }
                    if (play)
                    {

                        AudioManager.PlayCue("sd_troop_takeoff");
                    }
                }
            }
            //fbedard: Click button to send troops
            if (!HelperFunctions.CheckIntersection(this.SendTroops.Rect, input.CursorPosition))
            {
                this.SendTroops.State = UIButton.PressState.Normal;
            }
            else
            {
                this.SendTroops.State = UIButton.PressState.Hover;
                if (input.InGameSelect)
                {
                    this.eui.empire.GetShips().thisLock.EnterReadLock();
                    List<Ship> troopShips = new List<Ship>(this.eui.empire.GetShips()
                        .Where(troop => troop.TroopList.Count > 0
                            && troop.GetAI().State == AIState.AwaitingOrders
                            && troop.fleet == null && !troop.InCombat).OrderBy(distance => Vector2.Distance(distance.Center, this.p.Position)));
                    this.eui.empire.GetShips().thisLock.ExitReadLock();
                    this.eui.empire.GetPlanets().thisLock.EnterReadLock();
                    List<Planet> planetTroops = new List<Planet>(this.eui.empire.GetPlanets()
                        .Where(troops => troops.TroopsHere.Count > 1).OrderBy(distance => Vector2.Distance(distance.Position, this.p.Position))
                        .Where(Name => Name.Name != this.p.Name));
                    this.eui.empire.GetPlanets().thisLock.ExitReadLock();
                    if (troopShips.Count > 0)
                    {
                        AudioManager.PlayCue("echo_affirm");
                        troopShips.First().GetAI().OrderRebase(this.p,true);
                    }
                    else
                        if (planetTroops.Count > 0)
                        {
                            {
                                planetTroops.First().TroopsHere.thisLock.EnterWriteLock();
                                Ship troop = planetTroops.First().TroopsHere.First().Launch();
                                if (troop != null)
                                {
                                    AudioManager.PlayCue("echo_affirm");
                                    troop.GetAI().OrderRebase(this.p,true);
                                }
                                planetTroops.First().TroopsHere.thisLock.ExitWriteLock();
                            }
                        }
                        else
                        {
                            AudioManager.PlayCue("blip_click");
                        }
                }
            }
            if (!HelperFunctions.CheckIntersection(this.edit_name_button, MousePos))
            {
                this.editHoverState = 0;
            }
            else
            {
                this.editHoverState = 1;
                if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                {
                    this.PlanetName.HandlingInput = true;
                }
            }
            if (!this.PlanetName.HandlingInput)
            {
                GlobalStats.TakingInput = false;
                bool empty = true;
                string text = this.PlanetName.Text;
                int num = 0;
                while (num < text.Length)
                {
                    if (text[num] == ' ')
                    {
                        num++;
                    }
                    else
                    {
                        empty = false;
                        break;
                    }
                }
                if (empty)
                {
                    int ringnum = 1;
                    foreach (SolarSystem.Ring ring in this.p.system.RingList)
                    {
                        if (ring.planet == this.p)
                        {
                            this.PlanetName.Text = string.Concat(this.p.system.Name, " ", NumberToRomanConvertor.NumberToRoman(ringnum));
                        }
                        ringnum++;
                    }
                }
            }
            else
            {
                GlobalStats.TakingInput = true;
                this.PlanetName.HandleTextInput(ref this.PlanetName.Text, input);
            }
            this.GovernorDropdown.HandleInput(input);
            if (this.GovernorDropdown.Options[this.GovernorDropdown.ActiveIndex].@value != (int)this.p.colonyType)
            {
                this.p.colonyType = (Planet.ColonyType)this.GovernorDropdown.Options[this.GovernorDropdown.ActiveIndex].@value;
                if (this.p.colonyType != Planet.ColonyType.Colony)
                {
                    this.p.FoodLocked = true;
                    this.p.ProdLocked = true;
                    this.p.ResLocked = true;
                    this.p.GovernorOn = true;
                }
                else
                {
                    this.p.GovernorOn = false;
                    this.p.FoodLocked = false;
                    this.p.ProdLocked = false;
                    this.p.ResLocked = false;
                }
            }
            this.HandleSlider();
            if (this.p.HasShipyard && this.build.Tabs.Count > 1 && this.build.Tabs[1].Selected)
            {
                if (HelperFunctions.CheckIntersection(this.playerDesignsToggle.r, input.CursorPosition))
                {
                    ToolTip.CreateTooltip(Localizer.Token(2225), this.ScreenManager);
                }
                if (this.playerDesignsToggle.HandleInput(input))
                {
                    AudioManager.PlayCue("sd_ui_accept_alt3");
                    GlobalStats.ShowAllDesigns = !GlobalStats.ShowAllDesigns;
                    if (GlobalStats.ShowAllDesigns)
                    {
                        this.playerDesignsToggle.Active = true;
                    }
                    else
                    {
                        this.playerDesignsToggle.Active = false;
                    }
                    this.Reset = true;
                }
            }
            if (this.p.colonyType != Planet.ColonyType.Colony)
            {
                this.FoodLock.Locked = true;
                this.ProdLock.Locked = true;
                this.ResLock.Locked = true;
            }
            else
            {
                if (!HelperFunctions.CheckIntersection(this.FoodLock.LockRect, MousePos) || this.p.Owner == null || this.p.Owner.data.Traits.Cybernetic != 0)
                {
                    this.FoodLock.Hover = false;
                }
                else
                {
                    if (this.FoodLock.Locked)
                    {
                        this.FoodLock.Hover = false;
                        if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                        {
                            this.p.FoodLocked = false;
                            this.FoodLock.Locked = false;
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                        }
                    }
                    else
                    {
                        this.FoodLock.Hover = true;
                        if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                        {
                            this.p.FoodLocked = true;
                            this.FoodLock.Locked = true;
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                        }
                    }
                    ToolTip.CreateTooltip(69, this.ScreenManager);
                }
                if (!HelperFunctions.CheckIntersection(this.ProdLock.LockRect, MousePos))
                {
                    this.ProdLock.Hover = false;
                }
                else
                {
                    if (this.ProdLock.Locked)
                    {
                        this.ProdLock.Hover = false;
                        if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                        {
                            this.p.ProdLocked = false;
                            this.ProdLock.Locked = false;
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                        }
                    }
                    else
                    {
                        this.ProdLock.Hover = true;
                        if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                        {
                            this.p.ProdLocked = true;
                            this.ProdLock.Locked = true;
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                        }
                    }
                    ToolTip.CreateTooltip(69, this.ScreenManager);
                }
                if (!HelperFunctions.CheckIntersection(this.ResLock.LockRect, MousePos))
                {
                    this.ResLock.Hover = false;
                }
                else
                {
                    if (this.ResLock.Locked)
                    {
                        this.ResLock.Hover = false;
                        if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                        {
                            this.p.ResLocked = false;
                            this.ResLock.Locked = false;
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                        }
                    }
                    else
                    {
                        this.ResLock.Hover = true;
                        if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                        {
                            this.p.ResLocked = true;
                            this.ResLock.Locked = true;
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                        }
                    }
                    ToolTip.CreateTooltip(69, this.ScreenManager);
                }
            }
            this.selector = null;
            this.ClickedTroop = false;
            foreach (PlanetGridSquare pgs in this.p.TilesList)
            {
                if (!HelperFunctions.CheckIntersection(pgs.ClickRect, MousePos))
                {
                    pgs.highlighted = false;
                }
                else
                {
                    if (!pgs.highlighted)
                    {
                        AudioManager.PlayCue("sd_ui_mouseover");
                    }
                    pgs.highlighted = true;
                }
                if (pgs.TroopsHere.Count <= 0 || !HelperFunctions.CheckIntersection(pgs.TroopClickRect, MousePos))
                {
                    continue;
                }
                this.detailInfo = pgs.TroopsHere[0];
                if (input.RightMouseClick && pgs.TroopsHere[0].GetOwner() == EmpireManager.GetEmpireByName(PlanetScreen.screen.PlayerLoyalty))
                {
                    AudioManager.PlayCue("sd_troop_takeoff");
                    ResourceManager.CreateTroopShipAtPoint((this.p.Owner.data.DefaultTroopShip != null) ? this.p.Owner.data.DefaultTroopShip : this.p.Owner.data.DefaultSmallTransport, this.p.Owner, this.p.Position, pgs.TroopsHere[0]);
                    this.p.TroopsHere.Remove(pgs.TroopsHere[0]);
                    pgs.TroopsHere[0].SetPlanet(null);
                    pgs.TroopsHere.Clear();
                    this.ClickedTroop = true;
                    this.detailInfo = null;
                    rmouse = true;
                }
                return;
            }
            if (!this.ClickedTroop)
            {
                foreach (PlanetGridSquare pgs in this.p.TilesList)
                {
                    if (HelperFunctions.CheckIntersection(pgs.ClickRect, input.CursorPosition))
                    {
                        this.detailInfo = pgs;
                        Rectangle bRect = new Rectangle(pgs.ClickRect.X + pgs.ClickRect.Width / 2 - 32, pgs.ClickRect.Y + pgs.ClickRect.Height / 2 - 32, 64, 64);
                        if (pgs.building != null && pgs.building.Scrappable && HelperFunctions.CheckIntersection(bRect, input.CursorPosition) && input.RightMouseClick)
                        {
                            this.toScrap = pgs.building;
                            string message = string.Concat("Do you wish to scrap ", Localizer.Token(pgs.building.NameTranslationIndex), "? Half of the building's construction cost will be recovered to your storage.");
                            MessageBoxScreen messageBox = new MessageBoxScreen(message);
                            messageBox.Accepted += new EventHandler<EventArgs>(this.ScrapAccepted);
                            this.ScreenManager.AddScreen(messageBox);
                            this.ClickedTroop = true;
                            rmouse = true;
                            return;
                        }
                    }
                    if (pgs.TroopsHere.Count <= 0 || !HelperFunctions.CheckIntersection(pgs.TroopClickRect, input.CursorPosition))
                    {
                        continue;
                    }
                    this.detailInfo = pgs.TroopsHere;
                }
            }
            if (!GlobalStats.HardcoreRuleset)
            {
                if (HelperFunctions.CheckIntersection(this.foodDropDown.r, MousePos) && this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                {
                    this.foodDropDown.Toggle();
                    Planet planet = this.p;
                    planet.fs = (Planet.GoodState)((int)planet.fs + (int)Planet.GoodState.IMPORT);
                    if (this.p.fs > Planet.GoodState.EXPORT)
                    {
                        this.p.fs = Planet.GoodState.STORE;
                    }
                    AudioManager.PlayCue("sd_ui_accept_alt3");
                }
                if (HelperFunctions.CheckIntersection(this.prodDropDown.r, MousePos) && this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                {
                    this.prodDropDown.Toggle();
                    AudioManager.PlayCue("sd_ui_accept_alt3");
                    Planet planet1 = this.p;
                    planet1.ps = (Planet.GoodState)((int)planet1.ps + (int)Planet.GoodState.IMPORT);
                    if (this.p.ps > Planet.GoodState.EXPORT)
                    {
                        this.p.ps = Planet.GoodState.STORE;
                    }
                }
            }
            else
            {
                foreach (ThreeStateButton b in this.ResourceButtons)
                {
                    b.HandleInput(input, this.ScreenManager);
                }
            }
            for (int i = this.QSL.indexAtTop; i < this.QSL.Copied.Count && i < this.QSL.indexAtTop + this.QSL.entriesToDisplay; i++)
            {
                try
                {
                    ScrollList.Entry e = this.QSL.Copied[i];
                    if (!HelperFunctions.CheckIntersection(e.clickRect, MousePos))
                    {
                        e.clickRectHover = 0;
                    }
                    else
                    {
                        this.selector = new Selector(this.ScreenManager, e.clickRect);
                        if (e.clickRectHover == 0)
                        {
                            AudioManager.PlayCue("sd_ui_mouseover");
                        }
                        e.clickRectHover = 1;
                    }
                    if (HelperFunctions.CheckIntersection(e.up, MousePos))
                    {
                        ToolTip.CreateTooltip(63, PlanetScreen.screen.ScreenManager);
                        if (!input.CurrentKeyboardState.IsKeyDown(Keys.RightControl) && !input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl) || this.currentMouse.LeftButton != ButtonState.Pressed || this.previousMouse.LeftButton != ButtonState.Released)
                        {
                            if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released && i > 0)
                            {
                                object tmp = this.p.ConstructionQueue[i - 1];
                                this.p.ConstructionQueue[i - 1] = this.p.ConstructionQueue[i];
                                this.p.ConstructionQueue[i] = tmp as QueueItem;
                                AudioManager.PlayCue("sd_ui_accept_alt3");
                            }
                        }
                        else if (i > 0)
                        {
                            LinkedList<QueueItem> copied = new LinkedList<QueueItem>();
                            foreach (QueueItem qi in this.p.ConstructionQueue)
                            {
                                copied.AddLast(qi);
                            }
                            copied.Remove(this.p.ConstructionQueue[i]);
                            copied.AddFirst(this.p.ConstructionQueue[i]);
                            this.p.ConstructionQueue.Clear();
                            foreach (QueueItem qi in copied)
                            {
                                this.p.ConstructionQueue.Add(qi);
                            }
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                            break;
                        }
                    }
                    if (HelperFunctions.CheckIntersection(e.down, MousePos))
                    {
                        ToolTip.CreateTooltip(64, PlanetScreen.screen.ScreenManager);
                        if (!input.CurrentKeyboardState.IsKeyDown(Keys.RightControl) && !input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl) || this.currentMouse.LeftButton != ButtonState.Pressed || this.previousMouse.LeftButton != ButtonState.Released)
                        {
                            if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released && i + 1 < this.QSL.Copied.Count)
                            {
                                object tmp = this.p.ConstructionQueue[i + 1];
                                this.p.ConstructionQueue[i + 1] = this.p.ConstructionQueue[i];
                                this.p.ConstructionQueue[i] = tmp as QueueItem;
                                AudioManager.PlayCue("sd_ui_accept_alt3");
                            }
                        }
                        else if (i + 1 < this.QSL.Copied.Count)
                        {
                            LinkedList<QueueItem> copied = new LinkedList<QueueItem>();
                            foreach (QueueItem qi in this.p.ConstructionQueue)
                            {
                                copied.AddLast(qi);
                            }
                            copied.Remove(this.p.ConstructionQueue[i]);
                            copied.AddLast(this.p.ConstructionQueue[i]);
                            this.p.ConstructionQueue.Clear();
                            foreach (QueueItem qi in copied)
                            {
                                this.p.ConstructionQueue.Add(qi);
                            }
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                            break;
                        }
                    }
                    if (HelperFunctions.CheckIntersection(e.apply, MousePos) && !this.p.RecentCombat && this.p.Crippled_Turns <= 0)
                    {
                        if (!input.CurrentKeyboardState.IsKeyDown(Keys.RightControl) && !input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl) || this.currentMouse.LeftButton != ButtonState.Pressed || this.previousMouse.LeftButton != ButtonState.Released)
                        {
                            if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                            {

                                if (this.p.ApplyStoredProduction(i))
                                {
                                    AudioManager.PlayCue("sd_ui_accept_alt3");
                                }
                                else
                                {
                                    AudioManager.PlayCue("UI_Misc20");
                                }
                            }
                        }
                        //else if (PlanetScreen.screen.Debug)
                        //{
                        //    this.p.ApplyProductiontoQueue(this.p.ConstructionQueue[i].Cost - this.p.ConstructionQueue[i].productionTowards, i);
                        //}
                        else if (this.p.ProductionHere == 0f)
                        {
                            AudioManager.PlayCue("UI_Misc20");
                        }
                        else
                        {
                            this.p.ApplyAllStoredProduction(i);
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                        }
                    }
                    if (HelperFunctions.CheckIntersection(e.cancel, MousePos) && this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                    {
                        Planet productionHere2 = this.p;
                        productionHere2.ProductionHere = productionHere2.ProductionHere + (e.item as QueueItem).productionTowards;
                        if (this.p.ProductionHere > this.p.MAX_STORAGE)
                        {
                            this.p.ProductionHere = this.p.MAX_STORAGE;
                        }
                        QueueItem item = (e.item as QueueItem);
                        if (item.pgs != null)
                        {
                            (e.item as QueueItem).pgs.QItem = null;
                        }
                        if(item.Goal !=null)
                        {
                            if(item.Goal.GoalName=="BuildConstructionShip")
                            {
                                p.Owner.GetGSAI().Goals.Remove(item.Goal);

                            }
                            if(item.Goal.GetFleet() !=null)
                                p.Owner.GetGSAI().Goals.Remove(item.Goal);

                        }
                        this.p.ConstructionQueue.Remove(e.item as QueueItem);
                        AudioManager.PlayCue("sd_ui_accept_alt3");
                    }
                }
                catch
                {
                }
            }
            this.QSL.HandleInput(input, this.p);
            if (this.ActiveBuildingEntry != null)
            {
                foreach (PlanetGridSquare pgs in this.p.TilesList)
                {
                    if (!HelperFunctions.CheckIntersection(pgs.ClickRect, MousePos) || this.currentMouse.LeftButton != ButtonState.Released || this.previousMouse.LeftButton != ButtonState.Pressed)
                    {
                        continue;
                    }
                    if (pgs.Habitable && pgs.building == null && pgs.QItem == null && (this.ActiveBuildingEntry.item as Building).Name != "Biospheres")
                    {
                        QueueItem qi = new QueueItem();
                        //{
                        qi.isBuilding = true;
                        qi.Building = this.ActiveBuildingEntry.item as Building;
                        qi.Cost = ResourceManager.BuildingsDict[qi.Building.Name].Cost * UniverseScreen.GamePaceStatic;
                        qi.productionTowards = 0f;
                        qi.pgs = pgs;
                        //};
                        pgs.QItem = qi;
                        this.p.ConstructionQueue.Add(qi);
                        this.ActiveBuildingEntry = null;
                        break;
                    }
                    else if (pgs.Habitable || pgs.Biosphere || pgs.QItem != null || !(this.ActiveBuildingEntry.item as Building).CanBuildAnywhere)
                    {
                        AudioManager.PlayCue("UI_Misc20");
                        this.ActiveBuildingEntry = null;
                        break;
                    }
                    else
                    {
                        QueueItem qi = new QueueItem();
                        //{
                        qi.isBuilding = true;
                        qi.Building = this.ActiveBuildingEntry.item as Building;
                        qi.Cost = ResourceManager.BuildingsDict[qi.Building.Name].Cost * UniverseScreen.GamePaceStatic;
                        qi.productionTowards = 0f;
                        qi.pgs = pgs;
                        //};
                        pgs.QItem = qi;
                        this.p.ConstructionQueue.Add(qi);
                        this.ActiveBuildingEntry = null;
                        break;
                    }
                }
                if (this.ActiveBuildingEntry != null)
                {
                    foreach (QueueItem qi in this.p.ConstructionQueue)
                    {
                        if (!qi.isBuilding || !(qi.Building.Name == (this.ActiveBuildingEntry.item as Building).Name) || !(this.ActiveBuildingEntry.item as Building).Unique)
                        {
                            continue;
                        }
                        this.ActiveBuildingEntry = null;
                        break;
                    }
                }
                if (this.currentMouse.RightButton == ButtonState.Pressed && this.previousMouse.RightButton == ButtonState.Released)
                {
                    this.ClickedTroop = true;
                    this.ActiveBuildingEntry = null;
                }
                if (this.currentMouse.LeftButton == ButtonState.Released && this.previousMouse.LeftButton == ButtonState.Pressed)
                {
                    this.ClickedTroop = true;
                    this.ActiveBuildingEntry = null;
                }
            }
            for (int i = this.buildSL.indexAtTop; i < this.buildSL.Copied.Count && i < this.buildSL.indexAtTop + this.buildSL.entriesToDisplay; i++)
            {
                ScrollList.Entry e = this.buildSL.Copied[i];
                if (e.item is ModuleHeader)
                {
                    (e.item as ModuleHeader).HandleInput(input, e);
                }
                else if (!HelperFunctions.CheckIntersection(e.clickRect, MousePos))
                {
                    e.clickRectHover = 0;
                }
                else
                {
                    this.selector = new Selector(this.ScreenManager, e.clickRect);
                    if (e.clickRectHover == 0)
                    {
                        AudioManager.PlayCue("sd_ui_mouseover");
                    }
                    e.clickRectHover = 1;
                    if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Pressed && e.item is Building && this.ActiveBuildingEntry == null)
                    {
                        this.ActiveBuildingEntry = e;
                    }
                    if (this.currentMouse.LeftButton == ButtonState.Released && this.previousMouse.LeftButton == ButtonState.Pressed)
                    {
                        if (this.ClickTimer >= this.TimerDelay)
                        {
                            this.ClickTimer = 0f;
                        }
                        else
                        {
                            Rectangle rectangle = e.addRect;
                            if (!HelperFunctions.CheckIntersection(e.addRect, input.CursorPosition))
                            {
                                QueueItem qi = new QueueItem();
                                if (e.item is Ship)
                                {
                                    qi.isShip = true;
                                    qi.sData = (e.item as Ship).GetShipData();
                                    qi.Cost = (e.item as Ship).GetCost(this.p.Owner);
                                    qi.productionTowards = 0f;
                                    this.p.ConstructionQueue.Add(qi);
                                    AudioManager.PlayCue("sd_ui_mouseover");
                                }
                                else if (e.item is Troop)
                                {
                                    qi.isTroop = true;
                                    qi.troop = e.item as Troop;
                                    qi.Cost = (e.item as Troop).GetCost();
                                    qi.productionTowards = 0f;
                                    this.p.ConstructionQueue.Add(qi);
                                    AudioManager.PlayCue("sd_ui_mouseover");
                                }
                                else if (e.item is Building)
                                {
                                    this.p.AddBuildingToCQ(ResourceManager.GetBuilding((e.item as Building).Name));
                                    AudioManager.PlayCue("sd_ui_mouseover");
                                }
                            }
                        }
                    }
                }
                Rectangle rectangle1 = e.addRect;
                if (!HelperFunctions.CheckIntersection(e.addRect, MousePos))
                {
                    e.PlusHover = 0;
                }
                else
                {
                    e.PlusHover = 1;
                    ToolTip.CreateTooltip(51, this.ScreenManager);
                    if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                    {
                        QueueItem qi = new QueueItem();
                        if (e.item is Building)
                        {
                            this.p.AddBuildingToCQ(ResourceManager.GetBuilding((e.item as Building).Name));
                        }
                        else if (e.item is Ship)
                        {
                            qi.isShip = true;
                            qi.sData = (e.item as Ship).GetShipData();
                            qi.Cost = (e.item as Ship).GetCost(this.p.Owner);
                            qi.productionTowards = 0f;
                            this.p.ConstructionQueue.Add(qi);
                        }
                        else if (e.item is Troop)
                        {
                            qi.isTroop = true;
                            qi.troop = e.item as Troop;
                            qi.Cost = (e.item as Troop).GetCost();
                            qi.productionTowards = 0f;
                            this.p.ConstructionQueue.Add(qi);
                        }
                    }
                }
                Rectangle rectangle2 = e.editRect;
                if (!HelperFunctions.CheckIntersection(e.editRect, MousePos))
                {
                    e.EditHover = 0;
                }
                else
                {
                    e.EditHover = 1;
                    ToolTip.CreateTooltip(52, this.ScreenManager);
                    if (this.currentMouse.LeftButton == ButtonState.Pressed && this.previousMouse.LeftButton == ButtonState.Released)
                    {
                        ShipDesignScreen sdScreen = new ShipDesignScreen(this.eui);
                        this.ScreenManager.AddScreen(sdScreen);
                        sdScreen.ChangeHull((e.item as Ship).GetShipData());
                    }
                }
            }
            this.shipsCanBuildLast = this.p.Owner.ShipsWeCanBuild.Count;
            this.buildingsHereLast = this.p.BuildingList.Count;
            this.buildingsCanBuildLast = this.BuildingsCanBuild.Count;
            if (input.RightMouseClick && !this.ClickedTroop) rmouse = false;
            if (!rmouse && (input.CurrentMouseState.RightButton != ButtonState.Released || this.previousMouse.RightButton != ButtonState.Released))
            {
                this.eui.screen.ShipsInCombat.Active = true;
                this.eui.screen.PlanetsInCombat.Active = true;
            }
            this.previousMouse = this.currentMouse;
        }