コード例 #1
0
        public override void UpdateContent(ArcenUIWrapperedUnityImage Image, ArcenUI_Image.SubImageGroup SubImages, SubTextGroup SubTexts)
        {
            GameEntityTypeData typeData = this.TypeToBuild;

            if (typeData == null)
            {
                return;
            }

            WorldSide  localSide       = World_AIW2.Instance.GetLocalPlayerSide();
            Planet     planet          = Engine_AIW2.Instance.NonSim_GetPlanetBeingCurrentlyViewed();
            CombatSide localCombatSide = planet.Combat.GetSideForWorldSide(localSide);

            int debugStage = -1;

            try
            {
                debugStage = 1;

                debugStage = 2;
                SubImages[INDEX_ICON_NO_FLAIR].WrapperedImage.UpdateWith(null, true);
                SubImages[INDEX_ICON_FLAIR_ONLY].WrapperedImage.UpdateWith(typeData.GUISprite_Icon_White, true);

                // uncomment if you want a crazy experiment with icons varying in size over time
                //float size = ( World_AIW2.Instance.GameSecond * 10 ) % 100;
                //if ( size < 1 )
                //    size = 1;
                //SubImages[INDEX_ICON_FLAIR_ONLY].WrapperedImage.SetSize( size, size / 2 );

                // uncomment if you want to try vertically centering non-flair icons instead of leaving the gap at the bottom
                //if ( typeData.GUISprite_Flair == null )
                //    SubImages[INDEX_ICON_FLAIR_ONLY].WrapperedImage.SetOffset( 0, 5 );

                debugStage = 4;
                SubImages[INDEX_FLAIR].WrapperedImage.UpdateWith(typeData.GUISprite_Flair, true);

                debugStage = 5;
                bool showFuel = typeData.BalanceStats.SquadFuelConsumption > 0 && localSide.NetFuel < typeData.BalanceStats.SquadFuelConsumption;
                SubImages[INDEX_FUEL].WrapperedImage.UpdateToShowOrHide(showFuel);

                debugStage = 6;
                bool showPower = typeData.BalanceStats.SquadPowerConsumption > 0 && localCombatSide.NetPower < typeData.BalanceStats.SquadPowerConsumption;
                SubImages[INDEX_POWER].WrapperedImage.UpdateToShowOrHide(showPower);

                debugStage = 7;
                bool showScience  = false;
                bool showLocked   = false;
                bool showUnlocked = false;

                if (this.ButtonMode == Mode.Tech)
                {
                    if (typeData.TechPrereq == null)
                    {
                        // shouldn't really be on the tech menu anyway
                    }
                    else
                    {
                        if (localSide.GetHasResearched(typeData.TechPrereq))
                        {
                            showUnlocked = true;
                        }
                        else if (localSide.GetCanResearch(typeData.TechPrereq, true, false) != ArcenRejectionReason.Unknown)
                        {
                            showLocked = true;
                        }
                        else if (localSide.GetCanResearch(typeData.TechPrereq, false, false) != ArcenRejectionReason.Unknown)
                        {
                            showScience = true;
                        }
                    }
                }

                SubImages[INDEX_SCIENCE].WrapperedImage.UpdateToShowOrHide(showScience);

                //uncomment if you want a crazy experiemnt replacing this icon with a fuel icon
                //SubImages[INDEX_SCIENCE].WrapperedImage.SetBundleAndPathInBundle( "arcenui", "assets/icons/officialgui/resources/fuel.png" );

                SubImages[INDEX_LOCKED].WrapperedImage.UpdateToShowOrHide(showLocked);
                Image.SetColor(showLocked ? ColorMath.LightGray : ColorMath.White);
                SubImages[INDEX_UNLOCKED].WrapperedImage.UpdateToShowOrHide(showUnlocked);

                debugStage = 8;
                bool showActiveKeyboardColumnIndicator = false;
                if (this.ButtonMode == Mode.Build)
                {
                    showActiveKeyboardColumnIndicator = this.ColumnIndex == Window_InGameBuildTypeIconMenu.Instance.CurrentTypeIndex;
                }
                else if (this.ButtonMode == Mode.Tech)
                {
                    showActiveKeyboardColumnIndicator = this.ColumnIndex == Window_InGameTechTypeIconMenu.Instance.CurrentTypeIndex;
                }
                SubImages[INDEX_ACTIVE_KEYBOARD_COLUMN].WrapperedImage.UpdateToShowOrHide(showActiveKeyboardColumnIndicator);

                debugStage = 15;
                int markLevel = typeData.Balance_MarkLevel.Ordinal;
                if (markLevel < 0 || markLevel > 5)
                {
                    markLevel = 0;
                }
                SubImages[INDEX_MARK_LEVEL].WrapperedImage.UpdateWith(markLevel <= 0 ? null : Window_InGameOutlineSidebar.Sprite_MarkLevels[markLevel], true);
            }
            catch (Exception e)
            {
                ArcenDebugging.ArcenDebugLog("Exception in UpdateContent (image) at stage " + debugStage + ":" + e.ToString(), Verbosity.ShowAsError);
            }

            debugStage = -1;
            try
            {
                debugStage = 1;
                ArcenUIWrapperedTMProText text = SubTexts[TEXT_INDEX_UPPER_LEFT].Text;

                debugStage = 2;
                ArcenDoubleCharacterBuffer buffer = text.StartWritingToBuffer();

                if (typeData != null)
                {
                    switch (this.ButtonMode)
                    {
                    case Mode.Build:
                    case Mode.Queue:
                        if (planet != null)
                        {
                            int remainingCap = localCombatSide.GetRemainingCap(typeData);

                            text.SetFontSize(12);
                            buffer.Add(remainingCap);

                            if (remainingCap <= 0)
                            {
                                text.SetColor(ColorMath.LightRed);
                            }
                            else
                            {
                                text.SetColor(ColorMath.White);
                            }
                        }
                        break;

                    case Mode.Tech:
                        if (typeData.TechPrereq == null)
                        {
                            break;
                        }
                        if (localSide.GetHasResearched(typeData.TechPrereq))
                        {
                            break;
                        }
                        int cost = typeData.TechPrereq.ScienceCost;
                        buffer.Add(cost);
                        if (cost > localSide.StoredScience)
                        {
                            text.SetColor(ColorMath.LightRed);
                        }
                        else
                        {
                            text.SetColor(ColorMath.White);
                        }
                        break;
                    }
                }

                text.FinishWritingToBuffer();

                debugStage = 3;
                text       = SubTexts[TEXT_INDEX_ABOVE_BUTTON].Text;

                debugStage = 4;
                buffer     = text.StartWritingToBuffer();

                if (this.ButtonMode == Mode.Queue)
                {
                    GameEntity builder = null;
                    Engine_AIW2.Instance.DoForSelected(SelectionCommandScope.CurrentPlanet_UnlessViewingGalaxy, delegate(GameEntity selected)
                    {
                        if (selected.TypeData != this.TypeDoingTheBuilding)
                        {
                            return(DelReturn.Continue);
                        }
                        if (builder != null)
                        {
                            // only show time display when there's only one builder, otherwise it's not clear what should be shown
                            builder = null;
                            return(DelReturn.Break);
                        }
                        builder = selected;
                        return(DelReturn.Continue);
                    });
                    debugStage = 5;
                    if (builder != null && builder.BuildQueue != null)
                    {
                        BuildQueueItem item = builder.BuildQueue.GetQueueItemFor(typeData);
                        if (item != null)
                        {
                            bool showTimer = item.MetalSpentOnCurrentIteration > 0 && item.NumberBuiltThisLoop < item.NumberToBuildEachLoop;
                            if (showTimer)
                            {
                                FInt metalLeft = typeData.BalanceStats.SquadMetalCost - item.MetalSpentOnCurrentIteration;
                                FInt metalRate = builder.TypeData.MetalFlows[MetalFlowPurpose.BuildingShipsInternally].EffectiveThroughput;
                                if (metalLeft > 0 && metalRate > 0)
                                {
                                    FInt secondsLeft = metalLeft / metalRate;
                                    buffer.Add(Engine_Universal.ToHoursAndMinutesString(secondsLeft.IntValue));
                                }
                            }
                        }
                    }
                }

                debugStage = 6;
                text.FinishWritingToBuffer();
            }
            catch (Exception e)
            {
                ArcenDebugging.ArcenDebugLog("Exception in UpdateContent (text) at stage " + debugStage + ":" + e.ToString(), Verbosity.ShowAsError);
            }
        }
コード例 #2
0
            public override void OnUpdate()
            {
                WorldSide localSide = World_AIW2.Instance.GetLocalSide();

                if (localSide == null)
                {
                    return;
                }
                ArcenUI_ButtonSet     elementAsType    = (ArcenUI_ButtonSet)Element;
                Window_InGameTechMenu windowController = (Window_InGameTechMenu)Element.Window.Controller;

                if (windowController.MenuIndexChangedSinceLastButtonSetUpdate)
                {
                    elementAsType.ClearButtons();

                    TechMenu menu = TechMenuTable.Instance.Rows[windowController.CurrentMenuIndex];
                    if (menu != null)
                    {
                        int shownColumnCount = 0;
                        for (int x = 0; x < menu.Columns.Count; x++)
                        {
                            bool haveShownAnythingInThisColumn = false;
                            List <TechTypeData> column         = menu.Columns[x];
                            for (int y = 0; y < column.Count; y++)
                            {
                                TechTypeData item = column[y];
                                if (item.NotOnMainTechMenu)
                                {
                                    continue;
                                }
                                if (item.Prerequisite != null)
                                {
                                    TechTypeData prereq   = item.Prerequisite;
                                    bool         foundOne = false;
                                    while (prereq != null)
                                    {
                                        if ((prereq.Prerequisite == null && !prereq.NotOnMainTechMenu) || localSide.GetHasResearched(prereq))
                                        {
                                            foundOne = true;
                                            break;
                                        }
                                        prereq = prereq.Prerequisite;
                                    }
                                    if (!foundOne)
                                    {
                                        continue;
                                    }
                                }
                                //if ( localSide.GetCanResearch( item ) != ArcenRejectionReason.Unknown &&
                                //     !localSide.UnlockedTechs.Contains( item ) )
                                //    continue;
                                haveShownAnythingInThisColumn = true;
                                bTechItem newButtonController = new bTechItem(item);
                                Vector2   offset;
                                offset.x = shownColumnCount * elementAsType.ButtonWidth;
                                offset.y = y * elementAsType.ButtonHeight;
                                Vector2 size;
                                size.x = elementAsType.ButtonWidth;
                                size.y = elementAsType.ButtonHeight;
                                elementAsType.AddButton(newButtonController, size, offset);
                            }
                            if (haveShownAnythingInThisColumn)
                            {
                                shownColumnCount++;
                            }
                        }
                    }

                    elementAsType.ActuallyPutItemsBackInPoolThatAreStillCleared();

                    windowController.MenuIndexChangedSinceLastButtonSetUpdate = false;
                }
            }
コード例 #3
0
            public override void UpdateContent(ArcenUIWrapperedUnityImage Image, ArcenUI_Image.SubImageGroup _SubImages, SubTextGroup _SubTexts)
            {
                this.SubImages = _SubImages;
                this.SubTexts  = _SubTexts;
                GameEntityTypeData typeData = this.TypeToBuild;

                if (typeData == null)
                {
                    return;
                }

                WorldSide localSide = World_AIW2.Instance.GetLocalPlayerSide();

                //Planet planet = Engine_AIW2.Instance.NonSim_GetPlanetBeingCurrentlyViewed();
                //CombatSide localCombatSide = planet.Combat.GetSideForWorldSide( localSide );

                if (GameEntity.CurrentlyHoveredOver != null)
                {
                    this.PanelMode = Mode.ActualUnit;
                }
                else if (Window_InGameTechTabMenu.Instance.IsOpen)
                {
                    this.PanelMode = Mode.Tech;
                }
                else if (Window_InGameBuildTabMenu.Instance.IsOpen)
                {
                    this.PanelMode = Mode.Build;
                }

                TextId.SubjectSummary.Set(typeData.Name, string.Empty);

                try
                {
                    int markLevel = typeData.Balance_MarkLevel == null ? 0 : typeData.Balance_MarkLevel.Ordinal;
                    if (markLevel <= 0)
                    {
                        ImageId.MarkLevel.Hide();
                    }
                    else
                    {
                        ImageId.MarkLevel.Set(Window_InGameOutlineSidebar.Sprite_MarkLevels[markLevel], string.Empty);
                    }

                    if (this.PanelMode == Mode.Tech && typeData.TechPrereq != null)
                    {
                        bool unlocked = localSide.GetHasResearched(typeData.TechPrereq);
                        ImageId.Locked.ChangeVisibility(!unlocked);
                        ImageId.Unlocked.ChangeVisibility(unlocked);
                        ImageId.Science.Show();
                        TextId.Science.Set(typeData.TechPrereq.ScienceCost, string.Empty);
                    }
                    else
                    {
                        ImageId.Locked.Hide();
                        ImageId.Unlocked.Hide();
                        ImageId.Science.Hide();
                        TextId.Science.Hide();
                    }

                    if (typeData.BalanceStats.SquadFuelConsumption > 0)
                    {
                        ImageId.Fuel.Show();
                        ImageId.Power.Hide();
                        TextId.FuelOrPower.Set(typeData.BalanceStats.SquadFuelConsumption, string.Empty);
                    }
                    else if (typeData.BalanceStats.SquadPowerConsumption > 0)
                    {
                        ImageId.Fuel.Hide();
                        ImageId.Power.Show();
                        TextId.FuelOrPower.Set(typeData.BalanceStats.SquadPowerConsumption, string.Empty);
                    }
                    else
                    {
                        ImageId.Fuel.Hide();
                        ImageId.Power.Hide();
                        TextId.FuelOrPower.Hide();
                    }

                    if (typeData.BalanceStats.SquadMetalCost > 0)
                    {
                        ImageId.Metal.Show();
                        TextId.Metal.Set(typeData.BalanceStats.SquadMetalCost, string.Empty);
                    }
                    else
                    {
                        ImageId.Metal.Hide();
                        TextId.Metal.Hide();
                    }

                    int cap = typeData.BalanceStats.SquadsPerCap;
                    if (cap <= 0)
                    {
                        ImageId.Cap.Hide();
                        TextId.Cap.Hide();
                    }
                    else
                    {
                        ImageId.Cap.Show();
                        TextId.Cap.Set(cap, string.Empty);
                    }

                    ImageId.Strength.Show();
                    TextId.Strength.Set(typeData.BalanceStats.StrengthPerSquad.IntValue, string.Empty);

                    SystemEntry.SubEntry mainOffensiveWeaponSystemSubEntry = null;
                    EntitySystemTypeData cloakSystem   = null;
                    EntitySystemTypeData tachyonSystem = null;
                    EntitySystemTypeData tractorSystem = null;
                    EntitySystemTypeData gravitySystem = null;
                    for (int i = 0; i < typeData.SystemEntries.Count; i++)
                    {
                        SystemEntry entry = typeData.SystemEntries[i];
                        if (entry.SubEntries.Count <= 0)
                        {
                            continue;
                        }
                        SystemEntry.SubEntry subEntry = entry.SubEntries[0];
                        if (mainOffensiveWeaponSystemSubEntry == null && subEntry.GetDPS() > 0)
                        {
                            mainOffensiveWeaponSystemSubEntry = subEntry;
                        }
                        EntitySystemTypeData systemData = subEntry.SystemData;
                        if (cloakSystem == null && subEntry.BalanceStats.SquadCloakingPoints > 0)
                        {
                            cloakSystem = systemData;
                        }
                        if (tachyonSystem == null && subEntry.BalanceStats.TachyonPoints > 0)
                        {
                            tachyonSystem = systemData;
                        }
                        if (tractorSystem == null && subEntry.BalanceStats.TractorPoints > 0)
                        {
                            tractorSystem = systemData;
                        }
                        if (gravitySystem == null && subEntry.BalanceStats.GravityPoints > 0)
                        {
                            gravitySystem = systemData;
                        }
                    }

                    if (mainOffensiveWeaponSystemSubEntry != null)
                    {
                        SystemEntry.SubEntry systemSubEntry = mainOffensiveWeaponSystemSubEntry;
                        EntitySystemTypeData systemData     = systemSubEntry.SystemData;
                        Balance_WeaponType   weaponData     = systemData.Balance_WeaponType;

                        ImageId.Attack.Set(systemData.Balance_WeaponType.CounterType);
                        TextId.Attack.Set(systemSubEntry.GetDPS().IntValue, systemData.Balance_WeaponType.CounterType.StatTooltip);
                        ImageId.Range.Set(weaponData.Range);
                        ImageId.EngineDamage.Set(weaponData.Balance_EngineDamageType);
                        ImageId.Paralysis.Set(weaponData.Balance_ParalysisClass);
                        ImageId.Ion.Set(weaponData.Balance_IonClass);
                        ImageId.Implosion.Set(weaponData.Balance_ImplosionClass);
                        ImageId.Nuclear.Set(systemData.Balance_NuclearClass);
                    }
                    else
                    {
                        ImageId.Attack.Hide();
                        TextId.Attack.Hide();
                        ImageId.Range.Hide();
                        ImageId.EngineDamage.Hide();
                        ImageId.Paralysis.Hide();
                        ImageId.Ion.Hide();
                        ImageId.Implosion.Hide();
                        ImageId.Nuclear.Hide();
                    }

                    ImageId.Defense.Set(typeData.Balance_Defense);

                    int        totalMaxHP = (typeData.BalanceStats.HullPoints + typeData.BalanceStats.ShieldPoints) * typeData.Balance_ShipsPerSquad;
                    GameEntity entity     = GameEntity.CurrentlyHoveredOver;
                    if (this.PanelMode == Mode.ActualUnit && entity != null && (entity.HullPointsLost > 0 || entity.ShieldPointsLost > 0 || entity.SquadShipsLost > 0 || entity.SelfBuildingMetalRemaining > 0))
                    {
                        float percent;
                        if (entity.SelfBuildingMetalRemaining <= 0)
                        {
                            int totalCurrentHP = (typeData.BalanceStats.HullPoints + typeData.BalanceStats.ShieldPoints) * (typeData.Balance_ShipsPerSquad - 1);
                            totalCurrentHP += (entity.GetCurrentHullPoints() + entity.GetCurrentShieldPoints());
                            percent         = ((float)totalCurrentHP / (float)totalMaxHP) * 100;
                        }
                        else
                        {
                            percent = (1f - ((float)entity.SelfBuildingMetalRemaining / (float)typeData.BalanceStats.SquadMetalCost)) * 100;
                        }
                        string percentMask;
                        if (entity.SelfBuildingMetalRemaining > 0 || entity.HasNotYetBeenFullyClaimed)
                        {
                            percentMask = "#,##0.0";
                        }
                        else
                        {
                            percentMask = "#,##0";
                        }
                        int    totalHPForDisplay        = totalMaxHP;
                        string suffix                   = ArcenExternalUIUtilities.GetRoundedNumberWithSuffix(ref totalHPForDisplay, true);
                        ArcenCharacterBuffer textBuffer = new ArcenCharacterBuffer();
                        textBuffer.Add(totalHPForDisplay.ToString("#,##0"));
                        textBuffer.Add(suffix);
                        textBuffer.Add(" (");
                        textBuffer.Add(percent.ToString(percentMask));
                        textBuffer.Add("%)");
                        string text = textBuffer.ToString();
                        TextId.Defense.Set(text, typeData.Balance_Defense.StatTooltip);
                    }
                    else
                    {
                        TextId.Defense.Set(totalMaxHP, typeData.Balance_Defense.StatTooltip);
                    }

                    ImageId.Speed.Set(typeData.Balance_Speed);
                    ImageId.EngineDamageResistance.Set(typeData.Balance_EngineHealthType);
                    ImageId.ParalysisResistance.Set(typeData.Balance_ParalysisResistance);
                    ImageId.IonResistance.Set(typeData.Balance_IonResistance);
                    ImageId.ImplosionResistance.Set(typeData.Balance_ImplosionResistance);
                    ImageId.NuclearResistance.Set(typeData.Balance_NuclearResistance);

                    ImageId.Cloak.Set(cloakSystem == null ? null : cloakSystem.Balance_CloakingType);
                    ImageId.Tachyon.Set(tachyonSystem == null ? null : tachyonSystem.Balance_TachyonType);
                    ImageId.Tractor.Set(tractorSystem == null ? null : tractorSystem.Balance_TractorType);
                    ImageId.TractorResistance.Set(typeData.Balance_TractorResistanceType);
                    ImageId.Gravity.Set(gravitySystem == null ? null : gravitySystem.Balance_GravityType);
                    ImageId.GravityResistance.Set(typeData.Balance_GravityResistanceType);

                    TextId.Description.Set(typeData.Description, string.Empty);
                }
                catch (Exception e)
                {
                    ArcenDebugging.ArcenDebugLog("Exception in UpdateContent after " + (LastWrittenWasImageInsteadOfText ? "image " + LastImageIDWritten : "text " + LastTextIDWritten) + ":" + e.ToString(), Verbosity.ShowAsError);
                }
            }