Ejemplo n.º 1
0
    protected virtual void ChangeHull(ShipHullData data)
    {
        selectedShipHull = data;

        if (selectedShipHull != null)
        {
            BuildShipDesigns(selectedShipHull);

            ShipSlotLayout slotLayout = ResourceManager.instance.GetShipSlotLayout(selectedShipHull.Name);

            if (slotLayout != null)
            {
                FormatSlotLayout(slotLayout);
            }
        }
    }
Ejemplo n.º 2
0
 public ShipSlotLayout(ShipSlotLayout slotLayout)
 {
     foreach (Rect slot in slotLayout.ForeSlots)
     {
         ForeSlots.Add(new Rect(slot));
     }
     foreach (Rect slot in slotLayout.AftSlots)
     {
         AftSlots.Add(new Rect(slot));
     }
     foreach (Rect slot in slotLayout.PortSlots)
     {
         PortSlots.Add(new Rect(slot));
     }
     foreach (Rect slot in slotLayout.StarboardSlots)
     {
         StarboardSlots.Add(new Rect(slot));
     }
     foreach (Rect slot in slotLayout.CenterSlots)
     {
         CenterSlots.Add(new Rect(slot));
     }
 }
Ejemplo n.º 3
0
    public ShipDesignData(ShipDesign design)
    {
        Design = design;
        Hull   = Design.GetHull();

        float EngineFTL             = 0;
        float Power                 = 0;
        int   CommandPointReduction = 0;
        float PowerEffiency         = 0;
        float CloakingPowerPerMass  = 0;

        int            ForeSlotCount      = 0;
        int            AftSlotCount       = 0;
        int            PortSlotCount      = 0;
        int            StarboardSlotCount = 0;
        int            CenterSlotCount    = 0;
        ShipSlotLayout slotLayout         = Hull.GetSlotLayout();

        if (slotLayout != null)
        {
            ForeSlotCount      = slotLayout.ForeSlots.Count;
            AftSlotCount       = slotLayout.AftSlots.Count;
            PortSlotCount      = slotLayout.PortSlots.Count;
            StarboardSlotCount = slotLayout.StarboardSlots.Count;
            CenterSlotCount    = slotLayout.CenterSlots.Count;
        }

        //Set base stats from hulldata
        CommandPoints                 = Hull.BaseCommandPoints;
        Research                      = Hull.BaseResearch;
        Repair                        = Hull.BaseRepair;
        Sensor                        = Hull.BaseSensor;
        LongRangeSensor               = Hull.BaseLongRangeSensor;
        AdvancedSensor                = Hull.BaseAdvancedSensor;
        Fuel                          = Hull.BaseFuel;
        Crew                          = Hull.BaseCrew;
        Supplies                      = Hull.BaseSupply;
        FTLSpeed                      = Hull.BaseFTL;
        ForeQuadrant.Health           = Hull.BaseHealthPerSlot * ForeSlotCount;
        ForeQuadrant.ArmorHealth      = Hull.BaseArmorPerSlot * ForeSlotCount;
        AftQuadrant.Health            = Hull.BaseHealthPerSlot * AftSlotCount;
        AftQuadrant.ArmorHealth       = Hull.BaseArmorPerSlot * AftSlotCount;
        PortQuadrant.Health           = Hull.BaseHealthPerSlot * PortSlotCount;
        PortQuadrant.ArmorHealth      = Hull.BaseArmorPerSlot * PortSlotCount;
        StarboardQuadrant.Health      = Hull.BaseHealthPerSlot * StarboardSlotCount;
        StarboardQuadrant.ArmorHealth = Hull.BaseArmorPerSlot * StarboardSlotCount;
        CenterQuadrant.Health         = Hull.BaseHealthPerSlot * CenterSlotCount;
        CenterQuadrant.ArmorHealth    = Hull.BaseArmorPerSlot * CenterSlotCount;

        //Get stats from each module
        AddQuadModuleStats(ForeQuadrant, Design.ForeModules, ref Power, ref CloakingPowerPerMass, ref CommandPointReduction, ref PowerEffiency, ref EngineFTL);
        AddQuadModuleStats(AftQuadrant, Design.AftModules, ref Power, ref CloakingPowerPerMass, ref CommandPointReduction, ref PowerEffiency, ref EngineFTL);
        AddQuadModuleStats(PortQuadrant, Design.PortModules, ref Power, ref CloakingPowerPerMass, ref CommandPointReduction, ref PowerEffiency, ref EngineFTL);
        AddQuadModuleStats(StarboardQuadrant, Design.StarboardModules, ref Power, ref CloakingPowerPerMass, ref CommandPointReduction, ref PowerEffiency, ref EngineFTL);
        AddQuadModuleStats(CenterQuadrant, Design.CenterModules, ref Power, ref CloakingPowerPerMass, ref CommandPointReduction, ref PowerEffiency, ref EngineFTL);

        //Last stat calcs
        CommandPoints  -= CommandPointReduction;
        FTLSpeed       += EngineFTL / Mass;
        PowerGenerated -= Power * (1 - PowerEffiency);
        CloakingPower   = CloakingPowerPerMass * Mass;
        MinCrew         = (int)(Crew * ResourceManager.gameConstants.MinCrewPercent);

        maxRange = CalculateMaxRange();
        BuildDamageGraph();
    }
Ejemplo n.º 4
0
    public void SetDesign(ShipDesign design)
    {
        Clear();

        List <Rect> ForeSlots      = new List <Rect>();
        List <Rect> AftSlots       = new List <Rect>();
        List <Rect> PortSlots      = new List <Rect>();
        List <Rect> StarboardSlots = new List <Rect>();
        List <Rect> CenterSlots    = new List <Rect>();

        DesignName = design.Name;

        ShipSlotLayout shipLayout = ResourceManager.instance.GetShipHull(design.Hull).GetSlotLayout();

        if (shipLayout != null)
        {
            Vector2 ForePosition, AftPosition, PortPosition, StarboardPosition, CenterPosition;
            Vector2 ForeSize, AftSize, PortSize, StarboardSize, CenterSize;
            float   MinX, MaxX, MinY, MaxY, moduleScale = 16f;
            Vector2 ForeMin, AftMin, PortMin, StarboardMin, CenterMin;

            //Get size of center quadrant
            if (shipLayout.CenterSlots.Count > 0)
            {
                Rect CenterOuterRect = shipLayout.GetCenterOuterRect();
                CenterSize = new Vector2(CenterOuterRect.width / 16, CenterOuterRect.height / 16);
                CenterMin  = CenterOuterRect.position;
            }
            else
            {
                CenterSize = Vector2.zero;
                CenterMin  = Vector2.zero;
            }

            //Get size of port quadrant
            if (shipLayout.PortSlots.Count > 0)
            {
                Rect PortOuterRect = shipLayout.GetPortOuterRect();

                PortSize = new Vector2(PortOuterRect.width / 16, PortOuterRect.height / 16);
                PortMin  = PortOuterRect.position;
            }
            else
            {
                PortSize = Vector2.zero;
                PortMin  = Vector2.zero;
            }

            //Get size of starboard quadrant
            if (shipLayout.StarboardSlots.Count > 0)
            {
                Rect StarboardOuterRect = shipLayout.GetStarboardOuterRect();

                StarboardSize = new Vector2(StarboardOuterRect.width / 16, StarboardOuterRect.height / 16);
                StarboardMin  = StarboardOuterRect.position;
            }
            else
            {
                StarboardSize = Vector2.zero;
                StarboardMin  = Vector2.zero;
            }

            //Get size of fore quadrant
            if (shipLayout.ForeSlots.Count > 0)
            {
                Rect ForeOuterRect = shipLayout.GetForeOuterRect();

                ForeSize = new Vector2(ForeOuterRect.width / 16, ForeOuterRect.height / 16);
                ForeMin  = ForeOuterRect.position;
            }
            else
            {
                ForeSize = Vector2.zero;
                ForeMin  = Vector2.zero;
            }

            //Get size of aft quadrant
            if (shipLayout.AftSlots.Count > 0)
            {
                Rect AftOuterRect = shipLayout.GetAftOuterRect();

                AftSize = new Vector2(AftOuterRect.width / 16, AftOuterRect.height / 16);
                AftMin  = AftOuterRect.position;
            }
            else
            {
                AftSize = Vector2.zero;
                AftMin  = Vector2.zero;
            }

            //Determine scale of modules
            float MaxSlotsVertical   = 1 + ForeSize.y + AftSize.y + Mathf.Max(CenterSize.y, PortSize.y, StarboardSize.y);
            float MaxSlotsHorizontal = Mathf.Max(ForeSize.x, AftSize.x, 1 + CenterSize.x + PortSize.x + StarboardSize.x);
            if (MaxSlotsVertical * moduleScale > baseRect.height * 0.9f)
            {
                moduleScale = baseRect.height * 0.9f / MaxSlotsVertical;
            }
            if (MaxSlotsHorizontal * moduleScale > baseRect.width * 0.9f)
            {
                moduleScale = baseRect.width * 0.9f / MaxSlotsHorizontal;
            }

            //Apply scale
            ForeSize           *= moduleScale;
            AftSize            *= moduleScale;
            PortSize           *= moduleScale;
            StarboardSize      *= moduleScale;
            CenterSize         *= moduleScale;
            MaxSlotsVertical   *= moduleScale;
            MaxSlotsHorizontal *= moduleScale;

            //Determine the center of the layout
            //float centerY = (Screen.height - MaxSlotsVertical) / 2 + ForeSize.y + (MaxSlotsVertical - ForeSize.y - AftSize.y) / 2;
            //float centerX = Screen.width * 0.25f + (Screen.width - MaxSlotsHorizontal) / 2 + PortSize.x + moduleScale;
            float centerY = (Screen.height - MaxSlotsVertical) / 2 + ForeSize.y + moduleScale / 2 + (Mathf.Max(CenterSize.y, PortSize.y, StarboardSize.y) - CenterSize.y) / 2;
            float centerX = Screen.width * 0.25f + (Screen.width * 0.5f - MaxSlotsHorizontal) / 2 + PortSize.x + moduleScale / 2;

            CenterPosition    = new Vector2(centerX, centerY);
            StarboardPosition = new Vector2(CenterPosition.x + CenterSize.x + moduleScale / 2, CenterPosition.y + CenterSize.y / 2 - StarboardSize.y / 2);
            PortPosition      = new Vector2(CenterPosition.x - PortSize.x - moduleScale / 2, CenterPosition.y + CenterSize.y / 2 - PortSize.y / 2);
            ForePosition      = new Vector2(CenterPosition.x + CenterSize.x / 2 - ForeSize.x / 2, Mathf.Min(CenterPosition.y, StarboardPosition.y, PortPosition.y) - moduleScale / 2 - ForeSize.y);
            AftPosition       = new Vector2(CenterPosition.x + CenterSize.x / 2 - AftSize.x / 2, Mathf.Max(CenterPosition.y + CenterSize.y, StarboardPosition.y + StarboardSize.y, PortPosition.y + PortSize.y) + moduleScale / 2);

            MinX = Screen.width;
            MaxX = 0;
            MinY = Screen.height;
            MaxY = 0;

            float CenterMinX = Screen.width;
            float CenterMaxX = 0;
            float CenterMinY = Screen.height;
            float CenterMaxY = 0;

            //Build new slots
            foreach (Rect slot in shipLayout.CenterSlots)
            {
                Rect newSlot = new Rect((slot.x - CenterMin.x) / 16f * moduleScale + CenterPosition.x, (slot.y - CenterMin.y) / 16f * moduleScale + CenterPosition.y, moduleScale, moduleScale);
                if (newSlot.x < MinX)
                {
                    MinX = newSlot.x;
                }
                if (newSlot.xMax > MaxX)
                {
                    MaxX = newSlot.xMax;
                }
                if (newSlot.y < MinY)
                {
                    MinY = newSlot.y;
                }
                if (newSlot.yMax > MaxY)
                {
                    MaxY = newSlot.yMax;
                }

                if (newSlot.x < CenterMinX)
                {
                    CenterMinX = newSlot.x;
                }
                if (newSlot.xMax > CenterMaxX)
                {
                    CenterMaxX = newSlot.xMax;
                }
                if (newSlot.y < CenterMinY)
                {
                    CenterMinY = newSlot.y;
                }
                if (newSlot.yMax > CenterMaxY)
                {
                    CenterMaxY = newSlot.yMax;
                }
                CenterSlots.Add(newSlot);
            }
            float StarboardMinX = Screen.width;
            float StarboardMaxX = 0;
            float StarboardMinY = Screen.height;
            float StarboardMaxY = 0;

            foreach (Rect slot in shipLayout.StarboardSlots)
            {
                Rect newSlot = new Rect((slot.x - StarboardMin.x) / 16f * moduleScale + StarboardPosition.x, (slot.y - StarboardMin.y) / 16f * moduleScale + StarboardPosition.y, moduleScale, moduleScale);
                if (newSlot.x < MinX)
                {
                    MinX = newSlot.x;
                }
                if (newSlot.xMax > MaxX)
                {
                    MaxX = newSlot.xMax;
                }
                if (newSlot.y < MinY)
                {
                    MinY = newSlot.y;
                }
                if (newSlot.yMax > MaxY)
                {
                    MaxY = newSlot.yMax;
                }

                if (newSlot.x < StarboardMinX)
                {
                    StarboardMinX = newSlot.x;
                }
                if (newSlot.xMax > StarboardMaxX)
                {
                    StarboardMaxX = newSlot.xMax;
                }
                if (newSlot.y < StarboardMinY)
                {
                    StarboardMinY = newSlot.y;
                }
                if (newSlot.yMax > StarboardMaxY)
                {
                    StarboardMaxY = newSlot.yMax;
                }
                StarboardSlots.Add(newSlot);
            }
            float PortMinX = Screen.width;
            float PortMaxX = 0;
            float PortMinY = Screen.height;
            float PortMaxY = 0;

            foreach (Rect slot in shipLayout.PortSlots)
            {
                Rect newSlot = new Rect((slot.x - PortMin.x) / 16f * moduleScale + PortPosition.x, (slot.y - PortMin.y) / 16f * moduleScale + PortPosition.y, moduleScale, moduleScale);
                if (newSlot.x < MinX)
                {
                    MinX = newSlot.x;
                }
                if (newSlot.xMax > MaxX)
                {
                    MaxX = newSlot.xMax;
                }
                if (newSlot.y < MinY)
                {
                    MinY = newSlot.y;
                }
                if (newSlot.yMax > MaxY)
                {
                    MaxY = newSlot.yMax;
                }

                if (newSlot.x < PortMinX)
                {
                    PortMinX = newSlot.x;
                }
                if (newSlot.xMax > PortMaxX)
                {
                    PortMaxX = newSlot.xMax;
                }
                if (newSlot.y < PortMinY)
                {
                    PortMinY = newSlot.y;
                }
                if (newSlot.yMax > PortMaxY)
                {
                    PortMaxY = newSlot.yMax;
                }
                PortSlots.Add(newSlot);
            }
            float ForeMinX = Screen.width;
            float ForeMaxX = 0;
            float ForeMinY = Screen.height;
            float ForeMaxY = 0;

            foreach (Rect slot in shipLayout.ForeSlots)
            {
                Rect newSlot = new Rect((slot.x - ForeMin.x) / 16f * moduleScale + ForePosition.x, (slot.y - ForeMin.y) / 16f * moduleScale + ForePosition.y, moduleScale, moduleScale);
                if (newSlot.x < MinX)
                {
                    MinX = newSlot.x;
                }
                if (newSlot.xMax > MaxX)
                {
                    MaxX = newSlot.xMax;
                }
                if (newSlot.y < MinY)
                {
                    MinY = newSlot.y;
                }
                if (newSlot.yMax > MaxY)
                {
                    MaxY = newSlot.yMax;
                }

                if (newSlot.x < ForeMinX)
                {
                    ForeMinX = newSlot.x;
                }
                if (newSlot.xMax > ForeMaxX)
                {
                    ForeMaxX = newSlot.xMax;
                }
                if (newSlot.y < ForeMinY)
                {
                    ForeMinY = newSlot.y;
                }
                if (newSlot.yMax > ForeMaxY)
                {
                    ForeMaxY = newSlot.yMax;
                }
                ForeSlots.Add(newSlot);
            }
            float AftMinX = Screen.width;
            float AftMaxX = 0;
            float AftMinY = Screen.height;
            float AftMaxY = 0;

            foreach (Rect slot in shipLayout.AftSlots)
            {
                Rect newSlot = new Rect((slot.x - AftMin.x) / 16f * moduleScale + AftPosition.x, (slot.y - AftMin.y) / 16f * moduleScale + AftPosition.y, moduleScale, moduleScale);
                if (newSlot.x < MinX)
                {
                    MinX = newSlot.x;
                }
                if (newSlot.xMax > MaxX)
                {
                    MaxX = newSlot.xMax;
                }
                if (newSlot.y < MinY)
                {
                    MinY = newSlot.y;
                }
                if (newSlot.yMax > MaxY)
                {
                    MaxY = newSlot.yMax;
                }

                if (newSlot.x < AftMinX)
                {
                    AftMinX = newSlot.x;
                }
                if (newSlot.xMax > AftMaxX)
                {
                    AftMaxX = newSlot.xMax;
                }
                if (newSlot.y < AftMinY)
                {
                    AftMinY = newSlot.y;
                }
                if (newSlot.yMax > AftMaxY)
                {
                    AftMaxY = newSlot.yMax;
                }
                AftSlots.Add(newSlot);
            }

            //Add all slots to same list
            foreach (Rect slot in ForeSlots)
            {
                SlotRects.Add(slot);
            }
            foreach (Rect slot in AftSlots)
            {
                SlotRects.Add(slot);
            }
            foreach (Rect slot in PortSlots)
            {
                SlotRects.Add(slot);
            }
            foreach (Rect slot in StarboardSlots)
            {
                SlotRects.Add(slot);
            }
            foreach (Rect slot in CenterSlots)
            {
                SlotRects.Add(slot);
            }

            //Add sloted modules
            foreach (DesignModule designMod in design.ForeModules)
            {
                if (designMod.Position < ForeSlots.Count)
                {
                    SlotedModule slotedModule = SlotedModule.CreateSlotedModule(designMod, ForeSlots[designMod.Position]);
                    if (slotedModule != null)
                    {
                        SlotedModules.Add(slotedModule);
                    }
                }
            }
            foreach (DesignModule designMod in design.AftModules)
            {
                if (designMod.Position < AftSlots.Count)
                {
                    SlotedModule slotedModule = SlotedModule.CreateSlotedModule(designMod, AftSlots[designMod.Position]);
                    if (slotedModule != null)
                    {
                        SlotedModules.Add(slotedModule);
                    }
                }
            }
            foreach (DesignModule designMod in design.PortModules)
            {
                if (designMod.Position < PortSlots.Count)
                {
                    SlotedModule slotedModule = SlotedModule.CreateSlotedModule(designMod, PortSlots[designMod.Position]);
                    if (slotedModule != null)
                    {
                        SlotedModules.Add(slotedModule);
                    }
                }
            }
            foreach (DesignModule designMod in design.StarboardModules)
            {
                if (designMod.Position < StarboardSlots.Count)
                {
                    SlotedModule slotedModule = SlotedModule.CreateSlotedModule(designMod, StarboardSlots[designMod.Position]);
                    if (slotedModule != null)
                    {
                        SlotedModules.Add(slotedModule);
                    }
                }
            }
            foreach (DesignModule designMod in design.CenterModules)
            {
                if (designMod.Position < CenterSlots.Count)
                {
                    SlotedModule slotedModule = SlotedModule.CreateSlotedModule(designMod, CenterSlots[designMod.Position]);
                    if (slotedModule != null)
                    {
                        SlotedModules.Add(slotedModule);
                    }
                }
            }
        }
    }
Ejemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        //Force Camera to correct position
        Camera.main.transform.position = new Vector3(0f, 5f, 0f);
        Camera.main.transform.rotation = Quaternion.Euler(90, 0, 0);

        Indent = Screen.width * 0.15f;
        //Build all of the rectangles for slots
        Slots.Clear();
        for (int x = (int)Indent; x < Screen.width - 16; x += 16)
        {
            for (int y = 0; y < Screen.height - 16; y += 16)
            {
                Slots.Add(new Slot(new Rect(x, y, 16, 16)));
            }
        }

        if (loadLayout != null)
        {
            LayoutName = loadLayout.name;
            ShipSlotLayout loadedLayout = (ShipSlotLayout) new XmlSerializer(typeof(ShipSlotLayout)).Deserialize(new StringReader(loadLayout.text));

            foreach (Rect foreslot in loadedLayout.ForeSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Fore;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
            foreach (Rect foreslot in loadedLayout.AftSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Aft;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
            foreach (Rect foreslot in loadedLayout.PortSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Port;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
            foreach (Rect foreslot in loadedLayout.StarboardSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Starboard;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
            foreach (Rect foreslot in loadedLayout.CenterSlots)
            {
                foreach (Slot slot in Slots)
                {
                    if (foreslot == slot.rect)
                    {
                        slot.Quadrant = QuadrantTypes.Center;
                        slot.Active   = true;
                        ChangeCount(slot.Quadrant, 1);
                    }
                }
            }
        }

        selectedQuadrantType   = QuadrantTypes.Fore;
        QuadrantTypeButtonRect = new Rect(Screen.width * 0.05f, 0f, 100f, 40f);
        ResestButtonRect       = new Rect(QuadrantTypeButtonRect.x, QuadrantTypeButtonRect.y + 60f, 100f, 40f);
        SaveButtonRect         = new Rect(ResestButtonRect.x, ResestButtonRect.y + 60f, 100f, 40f);

        NameFieldRect = new Rect(Screen.width * 0.01f, SaveButtonRect.y + 60f, Screen.width * 0.13f, 30f);

        ForeCountRect      = new Rect(ResestButtonRect.x, NameFieldRect.y + 60f, 100f, 40f);
        AftCountRect       = new Rect(ResestButtonRect.x, ForeCountRect.y + 60f, 100f, 40f);
        PortCountRect      = new Rect(ResestButtonRect.x, AftCountRect.y + 60f, 100f, 40f);
        StarboardCountRect = new Rect(ResestButtonRect.x, PortCountRect.y + 60f, 100f, 40f);
        CenterCountRect    = new Rect(ResestButtonRect.x, StarboardCountRect.y + 60f, 100f, 40f);
        TotalCountRect     = new Rect(ResestButtonRect.x, CenterCountRect.y + 60f, 100f, 40f);
    }
Ejemplo n.º 6
0
    void OnGUI()
    {
        //Draw slots to screen
        foreach (Slot slot in Slots)
        {
            if (slot.Active)
            {
                switch (slot.Quadrant)
                {
                case QuadrantTypes.Fore:
                {
                    GUI.DrawTexture(slot.rect, Tex_Fore);
                    break;
                }

                case QuadrantTypes.Aft:
                {
                    GUI.DrawTexture(slot.rect, Tex_Aft);
                    break;
                }

                case QuadrantTypes.Port:
                {
                    GUI.DrawTexture(slot.rect, Tex_Port);
                    break;
                }

                case QuadrantTypes.Starboard:
                {
                    GUI.DrawTexture(slot.rect, Tex_Starboard);
                    break;
                }

                case QuadrantTypes.Center:
                {
                    GUI.DrawTexture(slot.rect, Tex_Center);
                    break;
                }
                }
            }
            else
            {
                GUI.Box(slot.rect, "");
            }
        }

        //Draw slot counts
        GUI.Label(ForeCountRect, "Fore: " + CountFore.ToString());
        GUI.Label(AftCountRect, "Aft: " + CountAft.ToString());
        GUI.Label(PortCountRect, "Port: " + CountPort.ToString());
        GUI.Label(StarboardCountRect, "Starboard: " + CountStarboard.ToString());
        GUI.Label(CenterCountRect, "Center: " + CountCenter.ToString());
        GUI.Label(TotalCountRect, "Total: " + (CountFore + CountAft + CountPort + CountStarboard + CountCenter).ToString());

        //Quadrant change button
        if (GUI.Button(QuadrantTypeButtonRect, selectedQuadrantType.ToString()))
        {
            if (selectedQuadrantType == QuadrantTypes.Center)
            {
                selectedQuadrantType = QuadrantTypes.Fore;
            }
            else
            {
                selectedQuadrantType++;
            }
        }
        //Reset Button
        if (GUI.Button(ResestButtonRect, "Reset"))
        {
            foreach (Slot slot in Slots)
            {
                slot.Active = false;
            }
            CountFore      = 0;
            CountAft       = 0;
            CountPort      = 0;
            CountStarboard = 0;
            CountCenter    = 0;
        }
        //Save button
        if (GUI.Button(SaveButtonRect, "Save"))
        {
            ShipSlotLayout shipSlotLayout = new ShipSlotLayout();

            foreach (Slot slot in Slots)
            {
                if (slot.Active)
                {
                    switch (slot.Quadrant)
                    {
                    case QuadrantTypes.Fore:
                    {
                        shipSlotLayout.ForeSlots.Add(slot.rect);
                        break;
                    }

                    case QuadrantTypes.Aft:
                    {
                        shipSlotLayout.AftSlots.Add(slot.rect);
                        break;
                    }

                    case QuadrantTypes.Port:
                    {
                        shipSlotLayout.PortSlots.Add(slot.rect);
                        break;
                    }

                    case QuadrantTypes.Starboard:
                    {
                        shipSlotLayout.StarboardSlots.Add(slot.rect);
                        break;
                    }

                    case QuadrantTypes.Center:
                    {
                        shipSlotLayout.CenterSlots.Add(slot.rect);
                        break;
                    }
                    }
                }
            }

            Directory.CreateDirectory(Application.dataPath + "/ShipSlotLayouts");

            string        path   = Application.dataPath + "/ShipSlotLayouts/" + LayoutName + ".xml";
            XmlSerializer Writer = new XmlSerializer(typeof(ShipSlotLayout));
            FileStream    file   = File.Create(path);
            Writer.Serialize(file, shipSlotLayout);
            file.Close();
        }

        LayoutName = GUI.TextField(NameFieldRect, LayoutName);
    }
Ejemplo n.º 7
0
    protected void FormatSlotLayout(ShipSlotLayout sourceLayout)
    {
        float moduleScale = ModulePanel.GetModuleScale();

        ClearFormatedSlots();
        ClearSlottedModules();

        Vector2 ForePosition, AftPosition, PortPosition, StarboardPosition, CenterPosition;
        Vector2 ForeSize, AftSize, PortSize, StarboardSize, CenterSize;
        float   MinX, MaxX, MinY, MaxY;
        Vector2 ForeMin, AftMin, PortMin, StarboardMin, CenterMin;

        //Get size of center quadrant
        if (sourceLayout.CenterSlots.Count > 0)
        {
            Rect CenterOuterRect = sourceLayout.GetCenterOuterRect();
            CenterSize = new Vector2(CenterOuterRect.width / 16, CenterOuterRect.height / 16);
            CenterMin  = CenterOuterRect.position;
        }
        else
        {
            CenterSize = Vector2.zero;
            CenterMin  = Vector2.zero;
        }

        //Get size of port quadrant
        if (sourceLayout.PortSlots.Count > 0)
        {
            Rect PortOuterRect = sourceLayout.GetPortOuterRect();

            PortSize = new Vector2(PortOuterRect.width / 16, PortOuterRect.height / 16);
            PortMin  = PortOuterRect.position;
        }
        else
        {
            PortSize = Vector2.zero;
            PortMin  = Vector2.zero;
        }

        //Get size of starboard quadrant
        if (sourceLayout.StarboardSlots.Count > 0)
        {
            Rect StarboardOuterRect = sourceLayout.GetStarboardOuterRect();

            StarboardSize = new Vector2(StarboardOuterRect.width / 16, StarboardOuterRect.height / 16);
            StarboardMin  = StarboardOuterRect.position;
        }
        else
        {
            StarboardSize = Vector2.zero;
            StarboardMin  = Vector2.zero;
        }

        //Get size of fore quadrant
        if (sourceLayout.ForeSlots.Count > 0)
        {
            Rect ForeOuterRect = sourceLayout.GetForeOuterRect();

            ForeSize = new Vector2(ForeOuterRect.width / 16, ForeOuterRect.height / 16);
            ForeMin  = ForeOuterRect.position;
        }
        else
        {
            ForeSize = Vector2.zero;
            ForeMin  = Vector2.zero;
        }

        //Get size of aft quadrant
        if (sourceLayout.AftSlots.Count > 0)
        {
            Rect AftOuterRect = sourceLayout.GetAftOuterRect();

            AftSize = new Vector2(AftOuterRect.width / 16, AftOuterRect.height / 16);
            AftMin  = AftOuterRect.position;
        }
        else
        {
            AftSize = Vector2.zero;
            AftMin  = Vector2.zero;
        }

        //Determine scale of modules
        float MaxSlotsVertical   = 1 + ForeSize.y + AftSize.y + Mathf.Max(CenterSize.y, PortSize.y, StarboardSize.y);
        float MaxSlotsHorizontal = Mathf.Max(ForeSize.x, AftSize.x, 1 + CenterSize.x + PortSize.x + StarboardSize.x);

        if (MaxSlotsVertical * moduleScale > Screen.height * 0.9f)
        {
            moduleScale = Screen.height * 0.9f / MaxSlotsVertical;
        }
        if (MaxSlotsHorizontal * moduleScale > Screen.width * 0.45f)
        {
            moduleScale = Screen.width * 0.45f / MaxSlotsHorizontal;
        }

        //Apply scale
        ForeSize           *= moduleScale;
        AftSize            *= moduleScale;
        PortSize           *= moduleScale;
        StarboardSize      *= moduleScale;
        CenterSize         *= moduleScale;
        MaxSlotsVertical   *= moduleScale;
        MaxSlotsHorizontal *= moduleScale;
        if (GetSelectedModule() != null)
        {
            SelectedModuleRect = new Rect(0, 0, GetSelectedModule().SizeX *moduleScale, GetSelectedModule().SizeY *moduleScale);
        }

        //Determine the center of the layout
        //float centerY = (Screen.height - MaxSlotsVertical) / 2 + ForeSize.y + (MaxSlotsVertical - ForeSize.y - AftSize.y) / 2;
        //float centerX = Screen.width * 0.25f + (Screen.width - MaxSlotsHorizontal) / 2 + PortSize.x + moduleScale;
        float centerY = (Screen.height - MaxSlotsVertical) / 2 + ForeSize.y + moduleScale / 2 + (Mathf.Max(CenterSize.y, PortSize.y, StarboardSize.y) - CenterSize.y) / 2;
        float centerX = Screen.width * 0.25f + (Screen.width * 0.5f - MaxSlotsHorizontal) / 2 + PortSize.x + moduleScale / 2;

        CenterPosition    = new Vector2(centerX, centerY);
        StarboardPosition = new Vector2(CenterPosition.x + CenterSize.x + moduleScale / 2, CenterPosition.y + CenterSize.y / 2 - StarboardSize.y / 2);
        PortPosition      = new Vector2(CenterPosition.x - PortSize.x - moduleScale / 2, CenterPosition.y + CenterSize.y / 2 - PortSize.y / 2);
        ForePosition      = new Vector2(CenterPosition.x + CenterSize.x / 2 - ForeSize.x / 2, Mathf.Min(CenterPosition.y, StarboardPosition.y, PortPosition.y) - moduleScale / 2 - ForeSize.y);
        AftPosition       = new Vector2(CenterPosition.x + CenterSize.x / 2 - AftSize.x / 2, Mathf.Max(CenterPosition.y + CenterSize.y, StarboardPosition.y + StarboardSize.y, PortPosition.y + PortSize.y) + moduleScale / 2);

        MinX = Screen.width;
        MaxX = 0;
        MinY = Screen.height;
        MaxY = 0;

        float CenterMinX = Screen.width;
        float CenterMaxX = 0;
        float CenterMinY = Screen.height;
        float CenterMaxY = 0;

        //Build new slots
        foreach (Rect slot in sourceLayout.CenterSlots)
        {
            Rect newSlot = new Rect((slot.x - CenterMin.x) / 16f * moduleScale + CenterPosition.x, (slot.y - CenterMin.y) / 16f * moduleScale + CenterPosition.y, moduleScale, moduleScale);
            if (newSlot.x < MinX)
            {
                MinX = newSlot.x;
            }
            if (newSlot.xMax > MaxX)
            {
                MaxX = newSlot.xMax;
            }
            if (newSlot.y < MinY)
            {
                MinY = newSlot.y;
            }
            if (newSlot.yMax > MaxY)
            {
                MaxY = newSlot.yMax;
            }

            if (newSlot.x < CenterMinX)
            {
                CenterMinX = newSlot.x;
            }
            if (newSlot.xMax > CenterMaxX)
            {
                CenterMaxX = newSlot.xMax;
            }
            if (newSlot.y < CenterMinY)
            {
                CenterMinY = newSlot.y;
            }
            if (newSlot.yMax > CenterMaxY)
            {
                CenterMaxY = newSlot.yMax;
            }
            CenterSlots.Add(newSlot);
        }
        CenterSlotsAreaRect = new Rect(CenterMinX, CenterMinY, CenterMaxX - CenterMinX, CenterMaxY - CenterMinY);
        float StarboardMinX = Screen.width;
        float StarboardMaxX = 0;
        float StarboardMinY = Screen.height;
        float StarboardMaxY = 0;

        foreach (Rect slot in sourceLayout.StarboardSlots)
        {
            Rect newSlot = new Rect((slot.x - StarboardMin.x) / 16f * moduleScale + StarboardPosition.x, (slot.y - StarboardMin.y) / 16f * moduleScale + StarboardPosition.y, moduleScale, moduleScale);
            if (newSlot.x < MinX)
            {
                MinX = newSlot.x;
            }
            if (newSlot.xMax > MaxX)
            {
                MaxX = newSlot.xMax;
            }
            if (newSlot.y < MinY)
            {
                MinY = newSlot.y;
            }
            if (newSlot.yMax > MaxY)
            {
                MaxY = newSlot.yMax;
            }

            if (newSlot.x < StarboardMinX)
            {
                StarboardMinX = newSlot.x;
            }
            if (newSlot.xMax > StarboardMaxX)
            {
                StarboardMaxX = newSlot.xMax;
            }
            if (newSlot.y < StarboardMinY)
            {
                StarboardMinY = newSlot.y;
            }
            if (newSlot.yMax > StarboardMaxY)
            {
                StarboardMaxY = newSlot.yMax;
            }
            StarboardSlots.Add(newSlot);
        }
        StarboardSlotsAreaRect = new Rect(StarboardMinX, StarboardMinY, StarboardMaxX - StarboardMinX, StarboardMaxY - StarboardMinY);
        float PortMinX = Screen.width;
        float PortMaxX = 0;
        float PortMinY = Screen.height;
        float PortMaxY = 0;

        foreach (Rect slot in sourceLayout.PortSlots)
        {
            Rect newSlot = new Rect((slot.x - PortMin.x) / 16f * moduleScale + PortPosition.x, (slot.y - PortMin.y) / 16f * moduleScale + PortPosition.y, moduleScale, moduleScale);
            if (newSlot.x < MinX)
            {
                MinX = newSlot.x;
            }
            if (newSlot.xMax > MaxX)
            {
                MaxX = newSlot.xMax;
            }
            if (newSlot.y < MinY)
            {
                MinY = newSlot.y;
            }
            if (newSlot.yMax > MaxY)
            {
                MaxY = newSlot.yMax;
            }

            if (newSlot.x < PortMinX)
            {
                PortMinX = newSlot.x;
            }
            if (newSlot.xMax > PortMaxX)
            {
                PortMaxX = newSlot.xMax;
            }
            if (newSlot.y < PortMinY)
            {
                PortMinY = newSlot.y;
            }
            if (newSlot.yMax > PortMaxY)
            {
                PortMaxY = newSlot.yMax;
            }
            PortSlots.Add(newSlot);
        }
        PortSlotsAreaRect = new Rect(PortMinX, PortMinY, PortMaxX - PortMinX, PortMaxY - PortMinY);
        float ForeMinX = Screen.width;
        float ForeMaxX = 0;
        float ForeMinY = Screen.height;
        float ForeMaxY = 0;

        foreach (Rect slot in sourceLayout.ForeSlots)
        {
            Rect newSlot = new Rect((slot.x - ForeMin.x) / 16f * moduleScale + ForePosition.x, (slot.y - ForeMin.y) / 16f * moduleScale + ForePosition.y, moduleScale, moduleScale);
            if (newSlot.x < MinX)
            {
                MinX = newSlot.x;
            }
            if (newSlot.xMax > MaxX)
            {
                MaxX = newSlot.xMax;
            }
            if (newSlot.y < MinY)
            {
                MinY = newSlot.y;
            }
            if (newSlot.yMax > MaxY)
            {
                MaxY = newSlot.yMax;
            }

            if (newSlot.x < ForeMinX)
            {
                ForeMinX = newSlot.x;
            }
            if (newSlot.xMax > ForeMaxX)
            {
                ForeMaxX = newSlot.xMax;
            }
            if (newSlot.y < ForeMinY)
            {
                ForeMinY = newSlot.y;
            }
            if (newSlot.yMax > ForeMaxY)
            {
                ForeMaxY = newSlot.yMax;
            }
            ForeSlots.Add(newSlot);
        }
        ForeSlotsAreaRect = new Rect(ForeMinX, ForeMinY, ForeMaxX - ForeMinX, ForeMaxY - ForeMinY);
        float AftMinX = Screen.width;
        float AftMaxX = 0;
        float AftMinY = Screen.height;
        float AftMaxY = 0;

        foreach (Rect slot in sourceLayout.AftSlots)
        {
            Rect newSlot = new Rect((slot.x - AftMin.x) / 16f * moduleScale + AftPosition.x, (slot.y - AftMin.y) / 16f * moduleScale + AftPosition.y, moduleScale, moduleScale);
            if (newSlot.x < MinX)
            {
                MinX = newSlot.x;
            }
            if (newSlot.xMax > MaxX)
            {
                MaxX = newSlot.xMax;
            }
            if (newSlot.y < MinY)
            {
                MinY = newSlot.y;
            }
            if (newSlot.yMax > MaxY)
            {
                MaxY = newSlot.yMax;
            }

            if (newSlot.x < AftMinX)
            {
                AftMinX = newSlot.x;
            }
            if (newSlot.xMax > AftMaxX)
            {
                AftMaxX = newSlot.xMax;
            }
            if (newSlot.y < AftMinY)
            {
                AftMinY = newSlot.y;
            }
            if (newSlot.yMax > AftMaxY)
            {
                AftMaxY = newSlot.yMax;
            }
            AftSlots.Add(newSlot);
        }
        AftSlotsAreaRect = new Rect(AftMinX, AftMinY, AftMaxX - AftMinX, AftMaxY - AftMinY);
        SlotsAreaRect    = new Rect(MinX, MinY, MaxX - MinX, MaxY - MinY);

        ModulePanel.SetModuleScale(moduleScale);
    }