Exemple #1
0
 public void StartConstructing()
 {
     if (observingHangar.constructing)
     {
         observingHangar.StopConstruction();
         PrepareHangarWindow();
     }
     else
     {
         if (GameMaster.colonyController.energyCrystalsCount >= Shuttle.STANDART_COST)
         {
             ColonyController colony = GameMaster.colonyController;
             colony.GetEnergyCrystals(Shuttle.STANDART_COST);
             if (colony.storage.CheckBuildPossibilityAndCollectIfPossible(ResourcesCost.GetCost(ResourcesCost.SHUTTLE_BUILD_COST_ID)))
             {
                 observingHangar.StartConstruction();
                 PrepareHangarWindow();
             }
             else
             {
                 UIController.current.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.NotEnoughResources));
             }
         }
         else
         {
             UIController.current.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.NotEnoughEnergyCrystals));
             constructButton.GetComponent <Image>().overrideSprite = null;
         }
     }
 }
Exemple #2
0
    /// <summary>
    /// use only from hangar.deconstructShuttle
    /// </summary>
    public void Deconstruct()
    {
        float pc = GameMaster.demolitionLossesPercent;

        if (pc != 1)
        {
            ResourceContainer[] compensation = ResourcesCost.GetCost(ResourcesCost.SHUTTLE_BUILD_COST_ID);
            Storage             s            = GameMaster.colonyController.storage;
            for (int i = 0; i < compensation.Length; i++)
            {
                s.AddResource(compensation[i].type, compensation[i].volume * GameMaster.demolitionLossesPercent);
            }
            GameMaster.colonyController.AddEnergyCrystals(cost * pc);
        }
        if (status == ShipStatus.InPort)
        {
            shuttlesList.Remove(this);
        }
        if (crew != null)
        {
            Crew c = crew;
            crew = null;
            c.Dismiss();
        }
    }
    public void CostPanel_Build()
    {
        switch (costPanelMode)
        {
        case CostPanelMode.SurfaceMaterialChanging:
            ResourceType rt = ResourceType.GetResourceTypeById(costPanel_selectedButton.y);
            if (colony.storage.CheckBuildPossibilityAndCollectIfPossible(new ResourceContainer[] { new ResourceContainer(rt, PlaneExtension.INNER_RESOLUTION * PlaneExtension.INNER_RESOLUTION) }))
            {
                observingSurface.ChangeMaterial(rt.ID, true);
                costPanel.transform.GetChild(0).GetChild(costPanel_selectedButton.x).GetComponent <Image>().overrideSprite = null;
            }
            else
            {
                GameLogUI.NotEnoughResourcesAnnounce();
            }
            break;

        case CostPanelMode.ColumnBuilding:
        {
            if (colony.storage.CheckBuildPossibilityAndCollectIfPossible(ResourcesCost.GetCost(Structure.COLUMN_ID)))
            {
                // float supportPoints = observingSurface.myChunk.CalculateSupportPoints(observingSurface.pos.x, observingSurface.pos.y, observingSurface.pos.z);
                // if (supportPoints <= 1)
                // {
                Structure s = Structure.GetStructureByID(Structure.COLUMN_ID);
                s.SetBasement(observingSurface, new PixelPosByte(7, 7));
                PoolMaster.current.BuildSplash(s.transform.position);
                SetCostPanelMode(CostPanelMode.Disabled);

                Plane p;
                if ((s as IPlanable).TryGetPlane(observingSurface.faceIndex, out p) && !p.isTerminate)
                {
                    UIController.current.Select(p);
                }
                else
                {
                    ReturnButton();
                }
                // }
                //   else
                //  {
                //    observingSurface.myChunk.ReplaceBlock(observingSurface.pos, BlockType.Cave, observingSurface.material_id, ResourceType.CONCRETE_ID, false);
                // }
            }
            else
            {
                GameLogUI.NotEnoughResourcesAnnounce();
            }
        }
        break;

        case CostPanelMode.BlockBuilding:
            BlockBuildingSite bbs = new BlockBuildingSite(observingSurface, ResourceType.GetResourceTypeById(costPanel_selectedButton.y));
            SetCostPanelMode(CostPanelMode.Disabled);
            UIController.current.ShowWorksite(bbs);
            break;
        }
    }
Exemple #4
0
    override public ResourceContainer[] GetUpgradeCost()
    {
        ResourceContainer[] cost = ResourcesCost.GetCost(MINE_ID);
        float discount           = GameMaster.upgradeCostIncrease + level - 1;

        for (int i = 0; i < cost.Length; i++)
        {
            cost[i] = new ResourceContainer(cost[i].type, cost[i].volume * discount);
        }
        return(cost);
    }
    public void SetStartResources()
    {
        //start resources
        switch (difficulty)
        {
        case Difficulty.Utopia:
            colonyController.AddCitizens(100, true);
            colonyController.storage.AddResource(ResourceType.metal_K, 100);
            colonyController.storage.AddResource(ResourceType.metal_M, 100);
            colonyController.storage.AddResource(ResourceType.metal_E, 50);
            colonyController.storage.AddResource(ResourceType.metal_N, 1);
            colonyController.storage.AddResource(ResourceType.Plastics, 200);
            colonyController.storage.AddResource(ResourceType.Food, colonyController.citizenCount * 1.5f * DAYS_IN_MONTH);
            break;

        case Difficulty.Easy:
            colonyController.AddCitizens(70, true);
            colonyController.storage.AddResource(ResourceType.metal_K, 100);
            colonyController.storage.AddResource(ResourceType.metal_M, 60);
            colonyController.storage.AddResource(ResourceType.metal_E, 30);
            colonyController.storage.AddResource(ResourceType.Plastics, 150);
            colonyController.storage.AddResource(ResourceType.Food, colonyController.citizenCount * DAYS_IN_MONTH);
            break;

        case Difficulty.Normal:
            colonyController.AddCitizens(50, true);
            colonyController.storage.AddResource(ResourceType.metal_K, 100);
            colonyController.storage.AddResource(ResourceType.metal_M, 50);
            colonyController.storage.AddResource(ResourceType.metal_E, 20);
            colonyController.storage.AddResource(ResourceType.Plastics, 100);
            colonyController.storage.AddResource(ResourceType.Food, colonyController.citizenCount * DAYS_IN_MONTH * 0.75f);
            break;

        case Difficulty.Hard:
            colonyController.AddCitizens(40, true);
            colonyController.storage.AddResource(ResourceType.metal_K, 50);
            colonyController.storage.AddResource(ResourceType.metal_M, 20);
            colonyController.storage.AddResource(ResourceType.metal_E, 2);
            colonyController.storage.AddResource(ResourceType.Plastics, 10);
            colonyController.storage.AddResource(ResourceType.Food, colonyController.citizenCount * DAYS_IN_MONTH * 0.55f);
            break;

        case Difficulty.Torture:
            colonyController.AddCitizens(30, true);
            colonyController.storage.AddResource(ResourceType.metal_K, 40);
            colonyController.storage.AddResource(ResourceType.metal_M, 20);
            colonyController.storage.AddResource(ResourceType.metal_E, 10);
            colonyController.storage.AddResource(ResourceType.Food, colonyController.citizenCount * DAYS_IN_MONTH * 0.45f);
            break;
        }
        colonyController.storage.AddResources(ResourcesCost.GetCost(Structure.SETTLEMENT_CENTER_ID));
    }
Exemple #6
0
    public virtual ResourceContainer[] GetUpgradeCost()
    {
        if (upgradedIndex == -1)
        {
            return(null);
        }
        ResourceContainer[] cost = ResourcesCost.GetCost(upgradedIndex);
        float discount           = GameMaster.realMaster.upgradeDiscount;

        for (int i = 0; i < cost.Length; i++)
        {
            cost[i] = new ResourceContainer(cost[i].type, cost[i].volume * (1 - discount));
        }
        return(cost);
    }
Exemple #7
0
    override public ResourceContainer[] GetUpgradeCost()
    {
        int costId = HEADQUARTERS_ID;

        switch (level)
        {
        case 1: costId = ResourcesCost.HQ_LVL2_COST_ID; break;

        case 2: costId = ResourcesCost.HQ_LVL3_COST_ID; break;

        case 3: costId = ResourcesCost.HQ_LVL4_COST_ID; break;

        case 4: costId = ResourcesCost.HQ_LVL5_COST_ID; break;

        case 5: costId = ResourcesCost.HQ_LVL6_COST_ID; break;
        }
        ResourceContainer[] cost = ResourcesCost.GetCost(costId);
        return(cost);
    }
 public void CreateSelectedBuilding(byte x, byte z)
 {
     ResourceContainer[] cost = ResourcesCost.GetCost(chosenStructure.id);
     if (GameMaster.colonyController.storage.CheckSpendPossibility(cost))
     {
         GameMaster.colonyController.storage.GetResources(cost);
         Structure s = Structure.GetStructureByID(chosenStructure.id);
         s.SetBasement(observingSurface, new PixelPosByte(x, z));
         PoolMaster.current.BuildSplash(observingSurface.transform.position);
         if (constructionPlane.activeSelf)
         {
             PrepareConstructionPlane();
         }
     }
     else
     {
         UIController.current.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.NotEnoughResources));
     }
 }
Exemple #9
0
    }                                                         // для структур, имеющих влияние на другие блоки; сообщает, что одна секция отвалилась

    // в финальном виде копипастить в потомков
    protected bool PrepareStructureForDestruction(bool forced)
    {
        if (forced)
        {
            UnsetBasement();
        }
        else
        {
            ResourceContainer[] resourcesLeft = ResourcesCost.GetCost(id);
            if (resourcesLeft.Length > 0 & GameMaster.demolitionLossesPercent != 1)
            {
                for (int i = 0; i < resourcesLeft.Length; i++)
                {
                    resourcesLeft[i] = new ResourceContainer(resourcesLeft[i].type, resourcesLeft[i].volume * (1 - GameMaster.demolitionLossesPercent));
                }
                GameMaster.colonyController.storage.AddResources(resourcesLeft);
            }
        }
        if (!forced & (basement != null))
        {
            basement.RemoveStructure(this);
            if (subscribedToChunkUpdate)
            {
                basement.myChunk.ChunkUpdateEvent -= ChunkUpdated;
                subscribedToChunkUpdate            = false;
            }
            SurfaceBlock lastBasement = basement;
            if (isBasement)
            {
                Block upperBlock = lastBasement.myChunk.GetBlock(lastBasement.pos.x, lastBasement.pos.y + 1, lastBasement.pos.z);
                if (upperBlock != null)
                {
                    lastBasement.myChunk.DeleteBlock(upperBlock.pos);
                }
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #10
0
 public void StopConstruction()
 {
     if (status == HangarStatus.ConstructingShuttle)
     {
         status = HangarStatus.NoShuttle;
         var   cost = ResourcesCost.GetCost(ResourcesCost.SHUTTLE_BUILD_COST_ID);
         float pc   = workflow / workComplexityCoefficient;
         for (int i = 0; i < cost.Length; i++)
         {
             cost[i] = cost[i].ChangeVolumeToPercent(1f - pc);
         }
         colony.storage.AddResources(cost);
         workflow = 0f;
         if (subscribedToUpdate)
         {
             GameMaster.realMaster.labourUpdateEvent -= LabourUpdate;
             subscribedToUpdate = false;
         }
     }
 }
 public void StartConstructing()
 {
     if (observingHangar.status == Hangar.HangarStatus.ConstructingShuttle)
     {
         observingHangar.StopConstruction();
         PrepareHangarWindow();
     }
     else
     {
         ColonyController colony = GameMaster.realMaster.colonyController;
         if (colony.storage.CheckBuildPossibilityAndCollectIfPossible(ResourcesCost.GetCost(ResourcesCost.SHUTTLE_BUILD_COST_ID)))
         {
             observingHangar.StartConstruction();
             PrepareHangarWindow();
         }
         else
         {
             AnnouncementCanvasController.NotEnoughResourcesAnnounce();
         }
     }
 }
 override public ResourceContainer[] GetUpgradeCost()
 {
     if (level < 4)
     {
         ResourceContainer[] cost = ResourcesCost.GetCost(upgradedIndex);
         float discount           = GameMaster.upgradeDiscount;
         for (int i = 0; i < cost.Length; i++)
         {
             cost[i] = new ResourceContainer(cost[i].type, cost[i].volume * discount);
         }
         return(cost);
     }
     else
     {
         ResourceContainer[] cost = ResourcesCost.GetCost(HQ_4_ID);
         float discount           = GameMaster.upgradeCostIncrease + level - 4;
         for (int i = 0; i < cost.Length; i++)
         {
             cost[i] = new ResourceContainer(cost[i].type, cost[i].volume * discount);
         }
         return(cost);
     }
 }
Exemple #13
0
    public void PrepareHangarWindow()
    {
        Shuttle shuttle     = observingHangar.shuttle;
        bool    haveShuttle = (shuttle != null);


        shuttleNameTextField.gameObject.SetActive(haveShuttle);
        repairButton.gameObject.SetActive(haveShuttle);
        disassembleButton.gameObject.SetActive(haveShuttle);

        bool showProgressBar = false;

        if (haveShuttle)
        {
            shuttleNameTextField.text = shuttle.name;
            savedProgressBarValue     = (int)(shuttle.condition * 100);
            mainShuttleIcon.uvRect    = UIController.GetTextureUV(shuttle.condition > 0.85 ? Icons.ShuttleGoodIcon : (shuttle.condition < 0.5 ? Icons.ShuttleBadIcon : Icons.ShuttleNormalIcon));
            showProgressBar           = true;
            resourceCostContainer.gameObject.SetActive(false);
            mode = HangarObserverMode.ShuttleInside;
        }
        else
        {
            savedProgressBarValue  = (int)(observingHangar.workflow / observingHangar.workflowToProcess * 100);
            mainShuttleIcon.uvRect = Rect.zero;
            showProgressBar        = observingHangar.constructing;
            constructButton.GetComponent <Image>().overrideSprite = showProgressBar ? PoolMaster.gui_overridingSprite : null;
            resourceCostContainer.gameObject.SetActive(!showProgressBar);
            if (!showProgressBar)
            {
                mode = HangarObserverMode.NoShuttle;
                ResourceContainer[] rc = ResourcesCost.GetCost(ResourcesCost.SHUTTLE_BUILD_COST_ID);
                int l = rc.Length;
                for (int i = 0; i < resourceCostContainer.transform.childCount; i++)
                {
                    Transform t = resourceCostContainer.GetChild(i);
                    if (i < rc.Length)
                    {
                        int rid = rc[i].type.ID;
                        t.GetComponent <RawImage>().uvRect = ResourceType.GetTextureRect(rid);
                        Text tx = t.GetChild(0).GetComponent <Text>();
                        tx.text = Localization.GetResourceName(rid) + " : " + rc[i].volume.ToString();
                        float[] storageResources = GameMaster.colonyController.storage.standartResources;
                        showingResourcesCount[i] = new Vector2(rid, rc[i].volume);
                        if (storageResources[rid] < rc[i].volume)
                        {
                            tx.color = Color.red;
                        }
                        else
                        {
                            tx.color = Color.white;
                        }
                        t.gameObject.SetActive(true);
                    }
                    else
                    {
                        t.gameObject.SetActive(false);
                    }
                }
                constructButton.transform.GetChild(0).GetComponent <Text>().text = Localization.GetPhrase(LocalizedPhrase.ConstructShuttle) + " (" + Shuttle.STANDART_COST.ToString() + ')';
            }
            else
            {
                mode = HangarObserverMode.BuildingShuttle;
            }
        }
        constructButton.gameObject.SetActive(!showProgressBar);
        progressBar.transform.parent.gameObject.SetActive(showProgressBar);
        if (showProgressBar)
        {
            shuttleStatusText.text = savedProgressBarValue.ToString() + '%';
            progressBar.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, startOffset, savedProgressBarValue / 100f * fullProgressBarLength);
            shuttleStatusText.text = savedProgressBarValue.ToString() + '%';
        }
    }
    public void SelectBuildingForConstruction(Structure building, int buttonIndex)
    {
        chosenStructure = building;
        buildingButtonsContainer.GetChild(buttonIndex).GetComponent <Image>().overrideSprite = PoolMaster.gui_overridingSprite;
        if (selectedBuildingButton >= 0)
        {
            buildingButtonsContainer.GetChild(selectedBuildingButton).GetComponent <Image>().overrideSprite = null;
        }
        selectedBuildingButton = buttonIndex;

        infoPanel.SetActive(true);
        nameField.text     = Localization.GetStructureName(chosenStructure.id);
        gridTextField.text = chosenStructure.innerPosition.size.ToString() + " x " + chosenStructure.innerPosition.size.ToString();
        Building b = chosenStructure as Building;

        if (b != null)
        {
            if (b.energySurplus != 0)
            {
                energyIcon.SetActive(true);
                energyTextField.gameObject.SetActive(true);
                energyTextField.text = b.energySurplus > 0 ? '+' + b.energySurplus.ToString() :  b.energySurplus.ToString();
            }
            else
            {
                energyIcon.SetActive(false);
                energyTextField.gameObject.SetActive(false);
            }
            if (b is House)
            {
                housingIcon.SetActive(true);
                housingTextField.gameObject.SetActive(true);
                housingTextField.text = (b as House).housing.ToString();
            }
            else
            {
                housingIcon.SetActive(false);
                housingTextField.gameObject.SetActive(false);
            }
        }
        else
        {
            energyIcon.SetActive(false);
            energyTextField.gameObject.SetActive(false);
            housingIcon.SetActive(false);
            housingTextField.gameObject.SetActive(false);
        }
        description.text = Localization.GetStructureDescription(chosenStructure.id);

        resourcesCostImage[0].transform.parent.gameObject.SetActive(true);
        Text t = resourcesCostImage[0].transform.GetChild(0).GetComponent <Text>();

        Building bd = chosenStructure as Building;

        // material check :
        if (bd != null & bd.requiredBasementMaterialId != -1 & bd.requiredBasementMaterialId != observingSurface.material_id)
        {
            t.text  = Localization.GetRestrictionPhrase(RestrictionKey.UnacceptableSurfaceMaterial);
            t.color = Color.yellow;
            resourcesCostImage[0].uvRect = ResourceType.GetTextureRect(0);
            resourcesCostImage[0].gameObject.SetActive(true);
            for (int i = 1; i < resourcesCostImage.Length - 1; i++)
            {
                resourcesCostImage[i].gameObject.SetActive(false);
            }
            int n = resourcesCostImage.Length - 1;
            t      = resourcesCostImage[n].transform.GetChild(0).GetComponent <Text>();
            t.text = Localization.GetPhrase(LocalizedPhrase.RequiredSurface) + " : " + Localization.GetResourceName(bd.requiredBasementMaterialId);
            resourcesCostImage[n].uvRect = ResourceType.GetTextureRect(bd.requiredBasementMaterialId);
            resourcesCostImage[n].gameObject.SetActive(true);
            t.color            = Color.yellow;
            buildingCreateMode = BuildingCreateInfoMode.Unacceptable_Material;
            innerBuildButton.gameObject.SetActive(false);
        }
        else
        {
            // all conditions met
            ResourceContainer[] cost = ResourcesCost.GetCost(chosenStructure.id);
            //resource cost drawing
            float[] storageResources = GameMaster.colonyController.storage.standartResources;
            for (int i = 0; i < resourcesCostImage.Length; i++)
            {
                if (i < cost.Length)
                {
                    resourcesCostImage[i].uvRect = ResourceType.GetTextureRect(cost[i].type.ID);
                    t      = resourcesCostImage[i].transform.GetChild(0).GetComponent <Text>();
                    t.text = Localization.GetResourceName(cost[i].type.ID) + " : " + string.Format("{0:0.##}", cost[i].volume);
                    showingResourcesCount[i] = new Vector2(cost[i].type.ID, cost[i].volume);
                    if (storageResources[cost[i].type.ID] < cost[i].volume)
                    {
                        t.color = Color.red;
                    }
                    else
                    {
                        t.color = Color.white;
                    }
                    resourcesCostImage[i].gameObject.SetActive(true);
                }
                else
                {
                    resourcesCostImage[i].gameObject.SetActive(false);
                }
            }
            lastStorageStatus  = GameMaster.colonyController.storage.operationsDone;
            buildingCreateMode = BuildingCreateInfoMode.Acceptable;
            innerBuildButton.gameObject.SetActive(true);
        }
    }
    public void CostPanel_Build()
    {
        switch (costPanelMode)
        {
        case CostPanelMode.SurfaceMaterialChanging:
            ResourceType rt = ResourceType.GetResourceTypeById(costPanel_selectedButton.y);
            if (GameMaster.colonyController.storage.CheckBuildPossibilityAndCollectIfPossible(new ResourceContainer[] { new ResourceContainer(rt, GameMaster.SURFACE_MATERIAL_REPLACE_COUNT) }))
            {
                observingSurface.ReplaceMaterial(rt.ID);
                costPanel.transform.GetChild(0).GetChild(costPanel_selectedButton.x).GetComponent <Image>().overrideSprite = null;
            }
            else
            {
                UIController.current.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.NotEnoughResources));
            }
            break;

        case CostPanelMode.ColumnBuilding:
        {
            if (GameMaster.colonyController.storage.CheckBuildPossibilityAndCollectIfPossible(ResourcesCost.GetCost(Structure.COLUMN_ID)))
            {
                // float supportPoints = observingSurface.myChunk.CalculateSupportPoints(observingSurface.pos.x, observingSurface.pos.y, observingSurface.pos.z);
                // if (supportPoints <= 1)
                // {
                Structure s = Structure.GetStructureByID(Structure.COLUMN_ID);
                s.SetBasement(observingSurface, new PixelPosByte(7, 7));
                PoolMaster.current.BuildSplash(observingSurface.transform.position);
                SetCostPanelMode(CostPanelMode.Disabled);
                // }
                //   else
                //  {
                //    observingSurface.myChunk.ReplaceBlock(observingSurface.pos, BlockType.Cave, observingSurface.material_id, ResourceType.CONCRETE_ID, false);
                // }
            }
            else
            {
                UIController.current.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.NotEnoughResources));
            }
        }
        break;

        case CostPanelMode.BlockBuilding:
            BlockBuildingSite bbs = observingSurface.gameObject.AddComponent <BlockBuildingSite>();
            bbs.Set(observingSurface, ResourceType.GetResourceTypeById(costPanel_selectedButton.y));
            SetCostPanelMode(CostPanelMode.Disabled);
            UIController.current.ShowWorksite(bbs);
            break;
        }
    }
    void SetCostPanelMode(CostPanelMode m)
    {
        if (m != CostPanelMode.Disabled)
        {
            costPanel.gameObject.SetActive(true);
        }
        else
        {
            costPanel.transform.GetChild(0).gameObject.SetActive(false);
            costPanel.transform.GetChild(1).gameObject.SetActive(false);
            costPanel.transform.GetChild(2).gameObject.SetActive(false);
            changeMaterialButton.GetComponent <Image>().overrideSprite = null;
            columnCreateButton.GetComponent <Image>().overrideSprite   = null;
            blockCreateButton.GetComponent <Image>().overrideSprite    = null;
            costPanel.SetActive(false);
            costPanelMode = CostPanelMode.Disabled;
            return;
        }
        Transform t;

        switch (m)
        {
        case CostPanelMode.SurfaceMaterialChanging:
            if (costPanelMode == CostPanelMode.SurfaceMaterialChanging)
            {
                SetCostPanelMode(CostPanelMode.Disabled);
                return;
            }
            else
            {
                changeMaterialButton.GetComponent <Image>().overrideSprite = PoolMaster.gui_overridingSprite;
                columnCreateButton.GetComponent <Image>().overrideSprite   = null;
                blockCreateButton.GetComponent <Image>().overrideSprite    = null;
                Transform buttonsKeeper = costPanel.transform.GetChild(0);
                buttonsKeeper.gameObject.SetActive(true);
                costPanel.transform.GetChild(1).gameObject.SetActive(false);
                costPanel.transform.GetChild(2).gameObject.SetActive(false);
                int lastUsedIndex = 0;
                foreach (ResourceType rt in ResourceType.materialsForCovering)
                {
                    if (rt.ID == observingSurface.material_id)
                    {
                        continue;
                    }
                    t = buttonsKeeper.GetChild(lastUsedIndex);
                    t.gameObject.SetActive(true);
                    RawImage ri = t.GetChild(0).GetComponent <RawImage>();
                    ri.texture = UIController.current.resourcesTexture;
                    ri.uvRect  = ResourceType.GetTextureRect(rt.ID);
                    t.GetChild(1).GetComponent <Text>().text = Localization.GetResourceName(rt.ID);
                    Button b = t.GetComponent <Button>();
                    b.onClick.RemoveAllListeners();
                    Vector2Int indxs = new Vector2Int(lastUsedIndex, rt.ID);
                    b.onClick.AddListener(() =>
                    {
                        this.CostPanel_SelectResource(indxs);
                    });
                    b.GetComponent <Image>().overrideSprite = null;
                    lastUsedIndex++;
                }
                if (lastUsedIndex < buttonsKeeper.childCount)
                {
                    for (; lastUsedIndex < buttonsKeeper.childCount; lastUsedIndex++)
                    {
                        buttonsKeeper.GetChild(lastUsedIndex).gameObject.SetActive(false);
                    }
                }
                costPanel.transform.GetChild(2).gameObject.SetActive(false);     // build button
            }
            break;

        case CostPanelMode.ColumnBuilding:
            if (costPanelMode != CostPanelMode.ColumnBuilding)
            {
                columnCreateButton.GetComponent <Image>().overrideSprite   = PoolMaster.gui_overridingSprite;
                changeMaterialButton.GetComponent <Image>().overrideSprite = null;
                blockCreateButton.GetComponent <Image>().overrideSprite    = null;

                t = costPanel.transform;
                t.GetChild(0).gameObject.SetActive(false); // buttons
                t.GetChild(2).gameObject.SetActive(true);  // build button
                t = t.GetChild(1);                         // resource cost
                t.gameObject.SetActive(true);
                ResourceContainer[] rc = ResourcesCost.GetCost(Structure.COLUMN_ID);
                for (int i = 0; i < t.childCount; i++)
                {
                    Transform r = t.GetChild(i);
                    if (i < rc.Length)
                    {
                        r.gameObject.SetActive(true);
                        int id = rc[i].type.ID;
                        r.GetComponent <RawImage>().uvRect = ResourceType.GetTextureRect(id);
                        Text tx = r.GetChild(0).GetComponent <Text>();
                        tx.text = Localization.GetResourceName(id) + " : " + rc[i].volume.ToString();
                        float[] storageResource = GameMaster.colonyController.storage.standartResources;
                        tx.color = (rc[i].volume > storageResource[rc[i].type.ID]) ? Color.red : Color.white;
                    }
                    else
                    {
                        r.gameObject.SetActive(false);
                    }
                }
            }
            else
            {
                SetCostPanelMode(CostPanelMode.Disabled);
                return;
            }
            break;

        case CostPanelMode.BlockBuilding:
            if (costPanelMode != CostPanelMode.BlockBuilding)
            {
                blockCreateButton.GetComponent <Image>().overrideSprite    = PoolMaster.gui_overridingSprite;
                changeMaterialButton.GetComponent <Image>().overrideSprite = null;
                columnCreateButton.GetComponent <Image>().overrideSprite   = null;

                t = costPanel.transform;
                t.GetChild(2).gameObject.SetActive(false);
                t.GetChild(1).gameObject.SetActive(false);
                t = t.GetChild(0);
                t.gameObject.SetActive(true);
                int i = 0;
                for (; i < ResourceType.blockMaterials.Length; i++)
                {
                    Transform c = t.GetChild(i);
                    c.gameObject.SetActive(true);
                    int id = ResourceType.blockMaterials[i].ID;
                    c.GetChild(0).GetComponent <RawImage>().uvRect = ResourceType.GetTextureRect(id);
                    c.GetChild(1).GetComponent <Text>().text       = Localization.GetResourceName(id);
                    Button b = c.GetComponent <Button>();
                    b.onClick.RemoveAllListeners();
                    Vector2Int indxs = new Vector2Int(i, id);
                    b.onClick.AddListener(() =>
                    {
                        this.CostPanel_SelectResource(indxs);
                    });
                    b.GetComponent <Image>().overrideSprite = null;
                }
                if (i < t.childCount)
                {
                    for (; i < t.childCount; i++)
                    {
                        t.GetChild(i).gameObject.SetActive(false);
                    }
                }
            }
            else
            {
                SetCostPanelMode(CostPanelMode.Disabled);
                return;
            }
            break;
        }
        costPanelMode = m;
    }
    public void SelectBuildingForConstruction(int i_structureID, int buttonIndex)
    {
        selectedStructureID = i_structureID;
        buildingButtonsContainer.GetChild(buttonIndex).GetComponent <Image>().overrideSprite = PoolMaster.gui_overridingSprite;
        if (selectedBuildingButton >= 0)
        {
            buildingButtonsContainer.GetChild(selectedBuildingButton).GetComponent <Image>().overrideSprite = null;
        }
        selectedBuildingButton = buttonIndex;

        infoPanel.SetActive(true);
        nameField.text = Localization.GetStructureName(selectedStructureID);
        var sts = Structure.GetStructureSize(selectedStructureID).ToString();

        gridTextField.text = sts + " x " + sts;

        var stype = Structure.GetTypeByID(selectedStructureID);
        var btype = typeof(Building);

        if (stype == btype || stype.IsSubclassOf(btype))
        {
            var energySurplus = Building.GetEnergySurplus(selectedStructureID);
            if (energySurplus != 0)
            {
                energyIcon.SetActive(true);
                energyTextField.gameObject.SetActive(true);
                energyTextField.text = energySurplus > 0 ? '+' + energySurplus.ToString() :  energySurplus.ToString();
            }
            else
            {
                energyIcon.SetActive(false);
                energyTextField.gameObject.SetActive(false);
            }
            var htype = typeof(House);
            if (stype == htype || stype.IsSubclassOf(htype))
            {
                housingIcon.SetActive(true);
                housingTextField.gameObject.SetActive(true);
                housingTextField.text = House.GetHousingValue(selectedStructureID).ToString();
            }
            else
            {
                housingIcon.SetActive(false);
                housingTextField.gameObject.SetActive(false);
            }
        }
        else
        {
            energyIcon.SetActive(false);
            energyTextField.gameObject.SetActive(false);
            housingIcon.SetActive(false);
            housingTextField.gameObject.SetActive(false);
        }
        description.text = Localization.GetStructureDescription(selectedStructureID);
        (description.transform.parent as RectTransform).SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, description.rectTransform.rect.height);

        resourcesCostImage[0].transform.parent.gameObject.SetActive(true);
        Text t = resourcesCostImage[0].transform.GetChild(0).GetComponent <Text>();

        string reason     = "UNACCEPTABLE!";
        bool   acceptable = Structure.CheckSpecialBuildingConditions(selectedStructureID, observingSurface, ref reason);

        if (!acceptable)
        {
            t.text  = reason;
            t.color = Color.yellow;
            resourcesCostImage[0].uvRect = ResourceType.GetResourceIconRect(0);
            resourcesCostImage[0].gameObject.SetActive(true);
            for (int i = 1; i < resourcesCostImage.Length; i++)
            {
                resourcesCostImage[i].gameObject.SetActive(false);
            }
            buildingCreateMode = BuildingCreateInfoMode.Unacceptable_Material;
            innerBuildButton.gameObject.SetActive(false);
        }
        else
        {
            // all conditions met
            ResourceContainer[] cost;
            if (selectedStructureID != Structure.SETTLEMENT_CENTER_ID)
            {
                cost = ResourcesCost.GetCost(selectedStructureID);
            }
            else
            {
                cost = ResourcesCost.GetSettlementUpgradeCost(constructingLevel);
            }
            //resource cost drawing
            float[] storageResources = colony.storage.standartResources;
            for (int i = 0; i < resourcesCostImage.Length; i++)
            {
                if (i < cost.Length)
                {
                    resourcesCostImage[i].uvRect = ResourceType.GetResourceIconRect(cost[i].type.ID);
                    t      = resourcesCostImage[i].transform.GetChild(0).GetComponent <Text>();
                    t.text = Localization.GetResourceName(cost[i].type.ID) + " : " + string.Format("{0:0.##}", cost[i].volume);
                    showingResourcesCount[i] = new Vector2(cost[i].type.ID, cost[i].volume);
                    if (storageResources[cost[i].type.ID] < cost[i].volume)
                    {
                        t.color = Color.red;
                    }
                    else
                    {
                        t.color = Color.white;
                    }
                    resourcesCostImage[i].gameObject.SetActive(true);
                }
                else
                {
                    resourcesCostImage[i].gameObject.SetActive(false);
                }
            }
            lastStorageStatus  = colony.storage.operationsDone;
            buildingCreateMode = BuildingCreateInfoMode.Acceptable;
            innerBuildButton.gameObject.SetActive(true);
        }
    }
 // end build request
 public void CreateSelectedBuilding(byte x, byte z, bool checkForIntersections)
 {
     if (observingSurface == null || observingSurface.destroyed)
     {
         SelfShutOff();
         return;
     }
     ResourceContainer[] cost;
     if (selectedStructureID != Structure.SETTLEMENT_CENTER_ID)
     {
         cost = ResourcesCost.GetCost(selectedStructureID);
     }
     else
     {
         cost = ResourcesCost.GetSettlementUpgradeCost(constructingLevel);
     }
     if (colony.storage.CheckSpendPossibility(cost))
     {
         byte strSize = Structure.GetStructureSize(selectedStructureID), res = PlaneExtension.INNER_RESOLUTION;
         if (x + strSize > res)
         {
             x = (byte)(res - strSize);
         }
         if (z + strSize > res)
         {
             z = (byte)(res - strSize);
         }
         if (checkForIntersections && observingSurface.IsAnyBuildingInArea(new SurfaceRect(x, z, strSize)))
         {
             constructingPlaneTouchPos = new Vector2Int(x, z);
             buildIntersectionSubmit.SetActive(true);
             return;
         }
         else
         {
             colony.storage.GetResources(cost);
             Structure s  = Structure.GetStructureByID(selectedStructureID);
             byte      rt = 0;
             if (s.rotate90only)
             {
                 rt  = (byte)(Random.value * 3);
                 rt *= 2;
             }
             else
             {
                 rt = (byte)(Random.value * 7);
             }
             if (s.ID == Structure.SETTLEMENT_CENTER_ID)
             {
                 (s as Settlement).SetLevel(constructingLevel);
             }
             s.SetBasement(observingSurface, new PixelPosByte(x, z));
             //if (!(s is Dock) & !(s is Hangar)) s.SetModelRotation(rt);
             PoolMaster.current.BuildSplash(s.transform.position);
             GameMaster.realMaster.eventTracker?.BuildingConstructed(s);
             if (observingSurface.fulfillStatus != FullfillStatus.Empty)
             {
                 if (constructionPlane.activeSelf)
                 {
                     PrepareConstructionPlane();
                 }
                 if (strSize == res | Structure.PlaceInCenter(selectedStructureID))
                 {
                     if (s is IPlanable)
                     {
                         var   ip = s as IPlanable;
                         Plane p;
                         if (ip.TryGetPlane(observingSurface.faceIndex, out p) && !p.isTerminate)
                         {
                             var sbb = selectedBuildingButton;
                             UIController.current.Select(p);
                         }
                     }
                 }
                 ReturnButton();
             }
             else
             {
                 ReturnButton();
             }
         }
     }
     else
     {
         GameLogUI.NotEnoughResourcesAnnounce();
     }
 }
    public void PrepareHangarWindow()
    {
        showingStatus = observingHangar.status;
        switch (showingStatus)
        {
        case Hangar.HangarStatus.ShuttleOnMission:
        {
            if (buildWindow.activeSelf)
            {
                buildWindow.SetActive(false);
            }
            if (mycanvas.progressPanelMode == ProgressPanelMode.Hangar)
            {
                mycanvas.DeactivateProgressPanel(ProgressPanelMode.Hangar);
            }
            shuttleLabel.GetChild(0).GetComponent <RawImage>().uvRect = UIController.GetIconUVRect(Icons.GuidingStar);
            shuttleLabel.GetChild(1).GetComponent <Text>().text       = Localization.GetPhrase(LocalizedPhrase.ShuttleOnMission);
            if (!shuttleLabel.gameObject.activeSelf)
            {
                shuttleLabel.gameObject.SetActive(true);
            }
            break;
        }

        case Hangar.HangarStatus.ShuttleInside:
        {
            if (buildWindow.activeSelf)
            {
                buildWindow.SetActive(false);
            }
            if (mycanvas.progressPanelMode == ProgressPanelMode.Hangar)
            {
                mycanvas.DeactivateProgressPanel(ProgressPanelMode.Hangar);
            }
            shuttleLabel.GetChild(0).GetComponent <RawImage>().uvRect = UIController.GetIconUVRect(Icons.ShuttleGoodIcon);
            shuttleLabel.GetChild(1).GetComponent <Text>().text       = Localization.GetPhrase(LocalizedPhrase.ShuttleReady);
            if (!shuttleLabel.gameObject.activeSelf)
            {
                shuttleLabel.gameObject.SetActive(true);
            }
            break;
        }

        case Hangar.HangarStatus.ConstructingShuttle:
        {
            if (buildWindow.activeSelf)
            {
                buildWindow.SetActive(false);
            }
            mycanvas.ActivateProgressPanel(ProgressPanelMode.Hangar);
            if (shuttleLabel.gameObject.activeSelf)
            {
                shuttleLabel.gameObject.SetActive(false);
            }
            break;
        }

        case Hangar.HangarStatus.NoShuttle:
        default:
        {
            if (!buildWindow.activeSelf)
            {
                buildWindow.SetActive(true);
            }
            if (mycanvas.progressPanelMode == ProgressPanelMode.Hangar)
            {
                mycanvas.DeactivateProgressPanel(ProgressPanelMode.Hangar);
            }
            if (shuttleLabel.gameObject.activeSelf)
            {
                shuttleLabel.gameObject.SetActive(false);
            }

            displayingCost = ResourcesCost.GetCost(ResourcesCost.SHUTTLE_BUILD_COST_ID);
            costLength     = displayingCost?.Length ?? 0;
            var storage = GameMaster.realMaster.colonyController.storage;
            int rid;
            for (int i = 0; i < resourceCostContainer.transform.childCount; i++)
            {
                Transform t = resourceCostContainer.GetChild(i);
                if (i < costLength)
                {
                    rid = displayingCost[i].type.ID;
                    t.GetComponent <RawImage>().uvRect = ResourceType.GetResourceIconRect(rid);
                    Text tx = t.GetChild(0).GetComponent <Text>();
                    tx.text = Localization.GetResourceName(rid) + " : " + displayingCost[i].volume.ToString();
                    if (storage.GetResourceCount(rid) < displayingCost[i].volume)
                    {
                        tx.color = Color.red;
                    }
                    else
                    {
                        tx.color = Color.white;
                    }
                    t.gameObject.SetActive(true);
                }
                else
                {
                    t.gameObject.SetActive(false);
                }
            }
            lastStorageDrawnValue = storage.operationsDone;
            break;
        }
        }
    }
Exemple #20
0
    public void PrepareHangarWindow()
    {
        var uc  = UIController.current;
        var rcc = resourceCostContainer.gameObject;

        showingStatus = observingHangar.status;
        switch (showingStatus)
        {
        case Hangar.HangarStatus.ShuttleOnMission:
        {
            if (rcc.activeSelf)
            {
                rcc.SetActive(false);
            }
            if (uc.progressPanelMode == ProgressPanelMode.Hangar)
            {
                uc.DeactivateProgressPanel(ProgressPanelMode.Hangar);
            }
            shuttleLabel.GetChild(0).GetComponent <RawImage>().uvRect = UIController.GetIconUVRect(Icons.GuidingStar);
            shuttleLabel.GetChild(1).GetComponent <Text>().text       = Localization.GetPhrase(LocalizedPhrase.ShuttleOnMission);
            if (!shuttleLabel.gameObject.activeSelf)
            {
                shuttleLabel.gameObject.SetActive(true);
            }
            break;
        }

        case Hangar.HangarStatus.ShuttleInside:
        {
            if (rcc.activeSelf)
            {
                rcc.SetActive(false);
            }
            if (uc.progressPanelMode == ProgressPanelMode.Hangar)
            {
                uc.DeactivateProgressPanel(ProgressPanelMode.Hangar);
            }
            shuttleLabel.GetChild(0).GetComponent <RawImage>().uvRect = UIController.GetIconUVRect(Icons.ShuttleGoodIcon);
            shuttleLabel.GetChild(1).GetComponent <Text>().text       = Localization.GetPhrase(LocalizedPhrase.ShuttleReady);
            if (!shuttleLabel.gameObject.activeSelf)
            {
                shuttleLabel.gameObject.SetActive(true);
            }
            break;
        }

        case Hangar.HangarStatus.ConstructingShuttle:
        {
            if (rcc.activeSelf)
            {
                rcc.SetActive(false);
            }
            UIController.current.ActivateProgressPanel(ProgressPanelMode.Hangar);
            if (shuttleLabel.gameObject.activeSelf)
            {
                shuttleLabel.gameObject.SetActive(false);
            }
            break;
        }

        case Hangar.HangarStatus.NoShuttle:
        default:
        {
            if (!rcc.activeSelf)
            {
                rcc.SetActive(true);
            }
            if (uc.progressPanelMode == ProgressPanelMode.Hangar)
            {
                uc.DeactivateProgressPanel(ProgressPanelMode.Hangar);
            }
            if (shuttleLabel.gameObject.activeSelf)
            {
                shuttleLabel.gameObject.SetActive(false);
            }

            ResourceContainer[] rc   = ResourcesCost.GetCost(ResourcesCost.SHUTTLE_BUILD_COST_ID);
            var     st               = GameMaster.realMaster.colonyController.storage;
            float[] storageResources = st.standartResources;
            for (int i = 1; i < resourceCostContainer.transform.childCount; i++)
            {
                Transform t = resourceCostContainer.GetChild(i);
                if (i < rc.Length)
                {
                    int rid = rc[i].type.ID;
                    t.GetComponent <RawImage>().uvRect = ResourceType.GetResourceIconRect(rid);
                    Text tx = t.GetChild(0).GetComponent <Text>();
                    tx.text = Localization.GetResourceName(rid) + " : " + rc[i].volume.ToString();
                    showingResourcesCount[i] = new Vector2(rid, rc[i].volume);
                    if (storageResources[rid] < rc[i].volume)
                    {
                        tx.color = Color.red;
                    }
                    else
                    {
                        tx.color = Color.white;
                    }
                    t.gameObject.SetActive(true);
                }
                else
                {
                    t.gameObject.SetActive(false);
                }
            }
            lastStorageDrawnValue = st.operationsDone;
            break;
        }
        }
    }