View Issue Details

IDProjectCategoryLast Update
0022286AI War 2Bug - GameplayNov 30, 2019 4:47 pm
ReporterAstilious Assigned ToBadgerBadger  
Status resolvedResolutionfixed 
Product Version1.010 Extracting Those Archives 
Fixed in Version1.011 SuperCat Swats Back 
Summary0022286: Suppress Tooltips doesn't Suppress
DescriptionThe bug is in the external code. Basically there is an early exit return before the CalculateShouldTooltipsBeSuppressed() call in GetShouldBeHidden() in Window_InGameHoverPlanetInfo.cs. Fixed by replacing lines 76 through 79 with:
if( Planet.CurrentlyHoveredOver == null && GalaxyMapPlanetLinkBase.CurrentlyHoveredOver == null )
    return true;
And changing line 82 to return false;

I've attached a fixed version of the file.
TagsGUI

Activities

Astilious

Nov 28, 2019 5:32 am

reporter  

Window_InGameHoverPlanetInfo.cs (38,163 bytes)   
using Arcen.Universal;
using Arcen.AIW2.Core;
using System;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

namespace Arcen.AIW2.External
{
    public class Window_InGameHoverPlanetInfo : WindowControllerAbstractBase
    {
        public static Window_InGameHoverPlanetInfo Instance;
        public Window_InGameHoverPlanetInfo()
        {
            this.OnlyShowInGame = true;
            Instance = this;
        }

        public static bool IsDrawing = false;

        public class bPanel : ImageButtonAbstractBase
        {
            public static bPanel Instance;
            public bPanel() { Instance = this; }

            public ArcenUI_ImageButton MyElement;
            private SubTextGroup SubTexts;
            private string NextTextToShow = string.Empty;
            private string WrappedNextTextToShow = string.Empty;
            private string LastTextToShow = string.Empty;
            private bool NeedsToResize = true;
            private float LastRequestedWidth;
            private float LastRequestedHeight;
            private bool hasSetCanvasOffset = false;

            public void ClearMyself()
            {
                this.LastTextToShow = string.Empty;
                this.NextTextToShow = string.Empty;
                this.NeedsToResize = true;
            }

            private ArcenDoubleCharacterBuffer textBuffer = new ArcenDoubleCharacterBuffer();

            public override void UpdateContentFromVolatile( ArcenUIWrapperedUnityImage Image, ArcenUI_Image.SubImageGroup _SubImages, SubTextGroup _SubTexts )
            {
                if ( !this.GetShouldBeHidden() )
                {
                    textBuffer.EnsureResetForNextUpdate();
                    this.GetTextToRender( textBuffer );
                    string newText = textBuffer.GetStringAndResetForNextUpdate();

                    if ( newText == null )
                        newText = string.Empty;
                    if ( newText != this.LastTextToShow )
                    {
                        this.NextTextToShow = newText;
                        this.NeedsToResize = true;
                    }
                }

                Window_InGameHoverPlanetInfo.Instance.myXPositionScale = GameSettings.Current.GetFloatBySetting( "SidebarScale" );

                this.SubTexts = _SubTexts;
                this.DoResizeIfNeeded();
            }

            public override bool GetShouldBeHidden()
            {
                if ( Engine_AIW2.Instance.CurrentGameViewMode != GameViewMode.GalaxyMapView )
                    return true;
                if ( GameEntityTypeData.CurrentlyHoveredOver != null )
                    return true;
                if ( GameEntity_Base.CurrentlyHoveredOver != null )
                    return true;
                if ( Planet.CurrentlyHoveredOver == null && GalaxyMapPlanetLinkBase.CurrentlyHoveredOver == null )
                    return true;
                if ( InputCaching.CalculateShouldTooltipsBeSuppressed() )
                    return true;
                return false;
            }

            public void UpdateTextIfNeeded()
            {
                string nextText = this.WrappedNextTextToShow;
                if ( this.LastTextToShow.Length <= 0 && nextText.Length <= 0 )
                {
                    this.ClearMyself();
                    return;
                }

                try
                {
                    if ( this.LastTextToShow != nextText )
                    {
                        this.LastTextToShow = nextText;
                        ArcenDoubleCharacterBuffer buffer = this.SubTexts[0].Text.StartWritingToBuffer();
                        buffer.Add( this.LastTextToShow );
                        this.SubTexts[0].Text.FinishWritingToBuffer();
                        this.NeedsToResize = true;
                        this.DoResizeIfNeeded();
                    }
                }
                catch ( Exception e )
                {
                    ArcenDebugging.ArcenDebugLog( "Exception in UpdateContentFromVolatile for the single text element:" + e.ToString(), Verbosity.ShowAsError );
                }
            }

            #region GetTextToRender
            public void GetTextToRender( ArcenDoubleCharacterBuffer buffer )
            {
                if ( InputCaching.CalculateShouldTooltipsBeSuppressed() )
                    return;

                int debugStage = 0;
                try
                {
                    IsDrawing = false;
                    debugStage = 1;
                    if ( Engine_AIW2.Instance.CurrentGameViewMode != GameViewMode.GalaxyMapView )
                        return;
                    if ( Planet.CurrentlyHoveredOver == null && GalaxyMapPlanetLinkBase.CurrentlyHoveredOver == null )
                        return;
                    if ( GameEntityTypeData.CurrentlyHoveredOver != null )
                        return;
                    if ( GameEntity_Base.CurrentlyHoveredOver != null )
                        return;
                    debugStage = 2;
                    Planet relatedPlanet = Planet.CurrentlyHoveredOver;
                    GalaxyMapPlanetLinkBase link = GalaxyMapPlanetLinkBase.CurrentlyHoveredOver;
                    if ( relatedPlanet == null )
                    {
                        if ( link != null )
                        {
                            GetTextForPlanetLink( buffer, link );
                            return;
                        }
                        else
                        {
                            return;
                        }
                    }

                    bool isShowingAbbreviatedVersion = !GameSettings.Current.GetBoolBySetting( "ShowShipAndPlanetDetailModeByDefault" );
                    if ( InputCaching.CalculateShouldToggleShipAndPlanetTooltipDetailMode() )
                        isShowingAbbreviatedVersion = !isShowingAbbreviatedVersion;

                    IsDrawing = true;
                    debugStage = 3;
                    buffer.Add( "Planet <b>" );

                    debugStage = 4;
                    buffer.Add( relatedPlanet.Name );
                    buffer.Add( "<b>" );

                    debugStage = 41;
                    if ( relatedPlanet.IntelLevel <= PlanetIntelLevel.Unexplored )
                    {
                        buffer.Add( ", Unexplored" );
                        buffer.Add( "\nWe have no vision of this planet. Either capture nearby planets or Hack this planet to gain vision. " );
                        buffer.Add(relatedPlanet.IntelLevel.ToString());
                    }
                    else
                    {
                        if ( relatedPlanet.IntelLevel == PlanetIntelLevel.ExploredByNaturalMeans )
                        {
                            int lastVisionTime = World_AIW2.Instance.GameSecond - relatedPlanet.GetGameSecondLastHadVision(); //Chris notes: hmm, if GetDoHumansHaveVision() gives true then this might be odd.  We shall see.
                            buffer.Add( "\nExplored: We are seeing old data for this planet; it was last viewed " );
                            buffer.Add( lastVisionTime );
                            buffer.Add( " seconds ago.");
                        }
                        else if ( relatedPlanet.IntelLevel == PlanetIntelLevel.ExploredByDistantHacking )
                        {
                            int lastVisionTime = World_AIW2.Instance.GameSecond - relatedPlanet.GetGameSecondLastHadVision(); //Chris notes: hmm, if GetDoHumansHaveVision() gives true then this might be odd.  We shall see.
                            buffer.Add( "\nExplored By Spy Nanites: We are seeing old data for this planet; it was last explored by hacking " );
                            buffer.Add( lastVisionTime );
                            buffer.Add( " seconds ago." );
                        }
                        if ( relatedPlanet.IntelLevel == PlanetIntelLevel.CurrentlyWatched)
                        {
                            buffer.Add( "\nWatched: We are seeing current data for this planet. " );
                        }
                        if ( relatedPlanet.IntelLevel == PlanetIntelLevel.WatchedUntilReconquered)
                        {
                            if ( relatedPlanet.GetControllingFaction().Type == FactionType.AI )
                                buffer.Add( "\nWatched: We will see current data unless the loses and then reconquers this planet. " );
                            else
                                buffer.Add( "\nWatched: We will see current data unless the AI reconquers this planet. " );
                        }
                        if ( relatedPlanet.IntelLevel == PlanetIntelLevel.PermanentlyWatched)
                        {
                            buffer.Add( "\nPermanently Watched: We will always see current data for this planet. " );
                        }
                        debugStage = 5;
                        Faction owner = relatedPlanet.GetControllingFaction();
                        if ( owner.Type == FactionType.AI )
                        {
                            buffer.Add( " (" );
                            relatedPlanet.MarkLevelForAIOnly.WriteStartColorHexTo( buffer );
                            buffer.Add( relatedPlanet.MarkLevelForAIOnly.Abbreviation );
                            relatedPlanet.MarkLevelForAIOnly.WriteEndColorHexTo( buffer );
                            buffer.Add( ")" );
                        }
                        debugStage = 6;
                        if ( owner.Type == FactionType.NaturalObject )
                        {
                            if ( relatedPlanet.UnderInfluenceOfFactionIndex == -1 )
                                buffer.Add( " Neutral Territory" );
                            else
                            {
                                Faction influencer = World_AIW2.Instance.GetFactionByIndex(relatedPlanet.UnderInfluenceOfFactionIndex);
                                buffer.Add(" Owned by ");
                                buffer.Add( "<color=#" ).Add(influencer.TeamCenterColor.ColorHexBrighter ).Add(">");
                                buffer.Add( influencer.GetDisplayName() );
                                buffer.Add( "</color>." );
                            }

                        }
                        else
                        {
                            buffer.Add( " Owned By " );
                            if ( owner.SpecialFactionData != null )
                            {
                                buffer.Add( "<color=#" ).Add( owner.TeamCenterColor.ColorHexBrighter ).Add( ">" );
                                buffer.Add( owner.GetDisplayName() );
                                buffer.Add( "</color>." );
                            }
                        }

                        debugStage = 7;
                        Faction playerFaction = World_AIW2.Instance.GetLocalPlayerFaction();
                        PlanetFaction playerPlanetFaction = relatedPlanet.GetPlanetFactionForFaction( playerFaction );
                        if( playerPlanetFaction.AIPLeftFromControlling > FInt.Zero)
                            buffer.Add(" Capturing this planet would cost ").Add( playerPlanetFaction.AIPLeftFromControlling.ToString(), "FF0000").Add( " AIP.");
                        int threatStrengthInt, hostileStrengthMinusThreatInt, myTotalStrength, myMobileStrength, myAndAlliedTotalStrength, myAndAlliedMobileStrength;
                        Faction hostileFaction;
                        string myOrAlliedColor;
                        string alliedColor;
                        Window_InGameHoverPlanetInfo.GetPlanetFactionalData( relatedPlanet, out threatStrengthInt, out hostileStrengthMinusThreatInt, out myTotalStrength, out myMobileStrength,
                                                                             out myAndAlliedTotalStrength, out myAndAlliedMobileStrength, out myOrAlliedColor, out alliedColor, out hostileFaction, true );
                        //Player strength
                        if ( myTotalStrength > 0 )
                        {
                            buffer.StartColor( myOrAlliedColor );
                            buffer.Add( "\nYour Mobile Strength: " );
                            buffer.Add( ArcenExternalUIUtilities.StrengthTextIcon );
                            ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, myMobileStrength, true, true );
                            buffer.Add( "<pos=250>Your Immobile Strength: " ).Add( ArcenExternalUIUtilities.StrengthTextIcon );
                            ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, myTotalStrength - myMobileStrength, true, true );
                            buffer.EndColor();
                        }

                        int alliedTotalStrength = myAndAlliedTotalStrength - myTotalStrength;
                        int alliedMobileStrength = myAndAlliedMobileStrength - myMobileStrength;

                        //Allied strength
                        if ( alliedTotalStrength > 0 )
                        {
                            buffer.StartColor( alliedColor );
                            buffer.Add( "\nAllied Mobile Strength: " );
                            buffer.Add( ArcenExternalUIUtilities.StrengthTextIcon );
                            ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, alliedMobileStrength, true, true );
                            buffer.Add( "<pos=250>Allied Immobile Strength: " ).Add( ArcenExternalUIUtilities.StrengthTextIcon );
                            ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, alliedTotalStrength - alliedMobileStrength, true, true );
                            buffer.EndColor();
                        }

                        //hostile strength minus thread
                        if ( hostileStrengthMinusThreatInt > 0 || threatStrengthInt > 0 )
                        {
                            if ( hostileFaction != null )
                                buffer.StartColor( hostileFaction.TeamCenterColor.ColorHexBrighter );
                            else
                                buffer.StartColor( "ffffff" );

                            buffer.Add( "\nEnemy Guard Strength: " );
                            buffer.Add( ArcenExternalUIUtilities.StrengthTextIcon );
                            ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, hostileStrengthMinusThreatInt, true, true );
                            if (! GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" ) && relatedPlanet.IntelLevel < PlanetIntelLevel.CurrentlyWatched)
                            buffer.Add("?");
                            
                            buffer.Add( "<pos=250>Enemy Threat Strength: " ).Add( ArcenExternalUIUtilities.StrengthTextIcon );
                            ArcenExternalUIUtilities.WriteRoundedNumberWithSuffix( buffer, threatStrengthInt, true, true );
                            if (! GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" ) && relatedPlanet.IntelLevel < PlanetIntelLevel.CurrentlyWatched)
                                buffer.Add("?");
                            buffer.EndColor();
                        }

                        debugStage = 71;

                        if ( GameSettings.Current.GetBoolBySetting( "Debug_WriteCounterattackInfoInPlanetTooltips" ) )
                        {
                            buffer.Add( "\nCounterattack Debug Info:" )
                                .Add( "  <color=#999999>Unspent Budget:</color> " ).Add( relatedPlanet.AICounterattackUnspentBudget.ToFloatNonSim().ToString( "0.##" ) )
                                .Add( "  <color=#999999>Timer:</color> " ).Add( relatedPlanet.AICountdownTimerForCounterattack )
                                .Add( "  <color=#999999>Would Be Stalled By:</color> " ).Add( (relatedPlanet.AICounterattackToBeStalledByPlayerStrengthOf / 1000f).ToString( "0.000" ) )
                                .Add( "  <color=#999999>Player Strength Here:</color> " ).Add( (relatedPlanet.PlayerStrengthHereForBlockingAICounterAttacks / 1000f).ToString( "0.000" ) )
                                .Add( "  <color=#999999>Stalled:</color> " ).Add( relatedPlanet.AICounterAttacksCurrentlyStalled ? "yes" : "no" )
                                .Add( "  <color=#999999>Required To Send:</color> " ).Add( (relatedPlanet.AIStrengthRequiredToSend / 1000f).ToString( "0.000" ) )
                                .Add( "  <color=#999999>Insufficient To Send:</color> " ).Add( relatedPlanet.AICounterAttacksNotSufficientToTryToSend ? "yes" : "no" )
                                .Add( "  <color=#999999>Forces stored:</color> " ).Add( (relatedPlanet.PrecalculatedAICounterattackForcesStrength / 1000f).ToString( "0.000" ) )
                                .Add( "  <color=#999999>Wave Normal:</color> " ).Add( relatedPlanet.ShipGroup_WavesFromHere_Normal == null ? "null" : relatedPlanet.ShipGroup_WavesFromHere_Normal.InternalName )
                                .Add( "  <color=#999999>Wave Guardians:</color> " ).Add( relatedPlanet.ShipGroup_WavesFromHere_Guardians == null ? "null" : relatedPlanet.ShipGroup_WavesFromHere_Guardians.InternalName )
                                .Add( "  <color=#999999>Wave Dire Guardians:</color> " ).Add( relatedPlanet.ShipGroup_WavesFromHere_DireGuardians == null ? "null" : relatedPlanet.ShipGroup_WavesFromHere_DireGuardians.InternalName )
                                ;
                        }

                        debugStage = 8;
                        for ( ResourceType resource = ResourceType.None + 1; resource < ResourceType.Length; resource++ )
                        {
                            int resourceOutput = 0;
                            string colorAndIcon = "<color=#ffee8e>";
                            switch ( resource )
                            {
                                case ResourceType.Hacking:
                                    resourceOutput = relatedPlanet.GetHackingLeftForFaction( playerFaction.FactionIndex ).IntValue;
                                    if ( isShowingAbbreviatedVersion && resourceOutput <= 0 )
                                        continue;
                                    colorAndIcon = ArcenExternalUIUtilities.HackingTextColorAndIcon;
                                    break;
                                case ResourceType.Science:
                                    resourceOutput = relatedPlanet.GetScienceLeftForFaction( playerFaction.FactionIndex ).IntValue;
                                    if ( isShowingAbbreviatedVersion && resourceOutput <= 0 )
                                        continue;
                                    colorAndIcon = ArcenExternalUIUtilities.ScienceTextColorAndIcon;
                                    break;
                                case ResourceType.Energy:
                                    relatedPlanet.DoForEntities( EntityRollupType.EnergyProducers, delegate ( GameEntity_Squad entity )
                                    {
                                        resourceOutput += entity.DataForMark.ResourceProduction[ResourceType.Energy].IntValue;
                                        return DelReturn.Continue;
                                    } );
                                    if ( isShowingAbbreviatedVersion && ( playerPlanetFaction == relatedPlanet.GetControllingPlanetFaction() || resourceOutput <= 0 ) )
                                        continue;
                                    colorAndIcon = ArcenExternalUIUtilities.EnergyTextColorAndIcon;
                                    break;
                                case ResourceType.Metal:
                                    if ( isShowingAbbreviatedVersion && playerPlanetFaction == relatedPlanet.GetControllingPlanetFaction() )
                                        continue;
                                    relatedPlanet.DoForEntities( EntityRollupType.MetalProducers, delegate ( GameEntity_Squad entity )
                                    {
                                        resourceOutput += entity.DataForMark.ResourceProduction[ResourceType.Metal].IntValue;
                                        return DelReturn.Continue;
                                    } );
                                    colorAndIcon = ArcenExternalUIUtilities.MetalTextColorAndIcon;
                                    break;
                            }
                            buffer.Add( "\n" );
                            buffer.Add( colorAndIcon ).Add( "<pos=30>" ).Add( resource.ToString() ).Add( ":</color> " ).Add( "<pos=120>" ).Add( resourceOutput.ToString( "#,##0" ) );
                        }
                    }

                    debugStage = 30;
                    
                    {
                        buffer.Add( "\n" ).Add( FontSizes.MUCH_SMALLER_SIZE_PLUS_A_TAD_STRING).Add( "<color=#996f4c>Hold </color><color=#d18444>" ).Add( InputActionTypeDataTable.Instance.GetHumanReadableKeyComboForAction( "SuppressTooltips" ) ).Add( "</color> <color=#996f4c>to hide all tooltips.  " );

                        buffer.Add( "Hold </color><color=#d18444>" ).Add( InputActionTypeDataTable.Instance.GetHumanReadableKeyComboForAction( "ToggleShipAndPlanetTooltipDetailMode" ) );
                        if ( isShowingAbbreviatedVersion )
                            buffer.Add( "</color> <color=#996f4c>to see a more-detailed tooltip." );
                        else
                            buffer.Add( "</color> <color=#996f4c>to see a less-detailed tooltip." );
                    }
                }
                catch ( Exception e )
                {
                    ArcenDebugging.ArcenDebugLog( "Exception in planet tooltip text generation at stage " + debugStage + ":" + e.ToString(), Verbosity.ShowAsError );
                }
            }

            private void GetTextForPlanetLink( ArcenDoubleCharacterBuffer buffer, GalaxyMapPlanetLinkBase link )
            {
                Planet firstPlanet = link.PlanetOne;
                Planet secondPlanet = link.PlanetTwo;
                Planet aiPlanetOrNull;
                bool hasGate;
                GalaxyMapLinkUtils.DetectAiAndWarpGateAdjacencyToPlayer( firstPlanet, secondPlanet, out aiPlanetOrNull, out hasGate );

                if ( aiPlanetOrNull != null )
                {
                    Planet humanPlanet = aiPlanetOrNull == secondPlanet ? firstPlanet : secondPlanet;
                    Faction aiFaction = aiPlanetOrNull.GetControllingFaction();
                    string aiName = aiFaction.GetDisplayName();
                    var aiColor = aiFaction.TeamCenterColor.ColorHex;
                    if ( hasGate )
                    {
                        bool foundWavesAgainstThisPlanet = false;
                        WaveUtils.DoForKnownWavesAgainstHumanHomeworlds( wave =>
                        {
                            Planet targetPlanet = World_AIW2.Instance.GetPlanetByIndex( wave.targetPlanetIdx );
                            Planet sourcePlanet = World_AIW2.Instance.GetPlanetByIndex( wave.planetWithWarpGateIdx );
                            if ( targetPlanet == humanPlanet && sourcePlanet == aiPlanetOrNull )
                            {
                                if ( !foundWavesAgainstThisPlanet )
                                {
                                    buffer.StartColor( Color.red ).Add( $"Incoming wave!" ).EndColor().NewLine();
                                }

                                foundWavesAgainstThisPlanet = true;

                                buffer.Add( wave.ToString() ).NewLine();
                            }
                            return DelReturn.Continue;
                        } );

                        if ( !foundWavesAgainstThisPlanet )
                        {
                            buffer.StartColor( Color.yellow ).Add( $"Active <color=#{aiColor}>{aiName}</color> Warp Gate on {aiPlanetOrNull.Name}!" ).EndColor().NewLine();
                            buffer.Add( $"<size=80%>Possible {aiName} attack waves on planet {humanPlanet.Name} from wormhole {aiPlanetOrNull.Name}</size>" ).NewLine();
                        }
                    }
                    else
                    {
                        buffer.Add( $"Destroyed <color=#{aiColor}>{aiName}</color> Warp Gate on {aiPlanetOrNull.Name}." ).NewLine();
                        buffer.Add( $"<size=80%>Attack waves on planet {humanPlanet.Name} from wormhole {aiPlanetOrNull.Name} are suppressed.</size>" ).NewLine();
                    }

                    buffer.NewLine();
                }
                buffer.StartColor( "aaaaaa" ).Add( $"Wormhole between planets {firstPlanet.Name} and {secondPlanet.Name}" ).EndColor();
            }

            #endregion
            
            public override void OnMainThreadUpdate()
            {
                this.UpdatePositionAndSize();
            }

            public void UpdatePositionAndSize()
            {
                //if ( this.GetShouldBeHidden() )
                //    return;
                if ( !this.hasSetCanvasOffset )
                {
                    if ( this.MyElement != null && this.MyElement.Window != null && this.MyElement.Window.Canvas )
                    {
                        this.hasSetCanvasOffset = true;
                        this.MyElement.Window.Canvas.sortingOrder = 32767; //as high as it will go, so this is always on top!
                    }
                }

                try
                {
                    float screenXPixel = 230 * (Window_InGameHoverEntityInfo.Instance == null ? 1f : Window_InGameHoverEntityInfo.Instance.myXPositionScale);
                    float screenYPixel = 0;

                    if ( this.MyElement != null && this.MyElement.Window != null )
                        this.MyElement.Window.IsAutomaticPositioningDisabled = true;

                    Vector3 worldSpacePoint = ArcenUI.Instance.guiCamera.ScreenToWorldPoint( new Vector3( screenXPixel, screenYPixel, ArcenUI.POSITION_Z ) );
                    if ( Window_InGameSidebarShips.Instance != null )
                        worldSpacePoint.x = Window_InGameSidebarShips.Instance.GetWorldSpaceMaxX( 5f *
                            (Window_InGameHoverEntityInfo.Instance == null ? 1f : Window_InGameHoverEntityInfo.Instance.myXPositionScale), false );

                    SubText groupZero = this.SubTexts[0];
                    if ( groupZero == null || groupZero.Obj == null || groupZero.Obj.transform == null || groupZero.Obj.transform.parent == null )
                        return;

                    Vector2 sizeDelta = ((RectTransform)groupZero.Obj.transform.parent).GetWorldSpaceSize();
                    float width = sizeDelta.x;
                    float height = sizeDelta.y;

                    float maxXPixel = ArcenUI.Instance.world_BottomRight.x - width;
                    float maxYPixel = ArcenUI.Instance.world_BottomRight.y + height;

                    worldSpacePoint.x = Mathf.Min( worldSpacePoint.x, maxXPixel );
                    worldSpacePoint.y = Mathf.Max( worldSpacePoint.y, maxYPixel );

                    if ( this.MyElement != null && this.MyElement.Window != null && this.MyElement.Window.Canvas )
                        this.MyElement.Window.CanvasT.position = worldSpacePoint;
                }
                catch ( Exception ) { } //be silent on this, I guess

            }

            public override void SetElement( ArcenUI_Element Element )
            {
                this.MyElement = (ArcenUI_ImageButton)Element;
                this.MyElement.Window.MaxDeltaTimeBeforeUpdates = 0;
            }

            public override void OnUpdate()
            {
                this.DoResizeIfNeeded();
                base.OnUpdate();
            }

            private float lastGeneralTooltipScale = 1f;
            private const int BASE_TOOLTIP_WIDTH = 600;

            public void DoResizeIfNeeded()
            {
                float newGeneralTooltipScale = GameSettings.Current.GetFloatBySetting( "PlanetTooltipScale" );
                bool hasScaleMismatch = newGeneralTooltipScale != lastGeneralTooltipScale;
                if ( hasScaleMismatch )
                    this.NeedsToResize = true;

                if ( this.MyElement != null && this.NeedsToResize && this.SubTexts != null && this.SubTexts[1].Obj.activeInHierarchy &&
                    this.NextTextToShow != null && this.NextTextToShow.Length > 0 )
                {
                    this.NeedsToResize = false;
                    this.lastGeneralTooltipScale = newGeneralTooltipScale;
                    string text = this.NextTextToShow;

                    if ( hasScaleMismatch )
                    {
                        this.SubTexts[1].ReferenceText.rectTransform.UI_SetWidth( BASE_TOOLTIP_WIDTH / newGeneralTooltipScale );
                        this.SubTexts[0].Obj.transform.parent.localScale = new Vector3( newGeneralTooltipScale, newGeneralTooltipScale, newGeneralTooltipScale );
                    }

                    Vector2 messageSize = Mat.V2_Zero;
                    if ( text != null && text.Length > 0 )
                        messageSize = ArcenUI.Instance.CalculateSizeOfTextMeshProUGUIText( this.SubTexts[1].ReferenceText, ref text, 0f );
                    this.WrappedNextTextToShow = this.NextTextToShow;// text;

                    float textInset = 6 * newGeneralTooltipScale;

                    this.LastRequestedWidth = textInset + messageSize.x + textInset;
                    this.LastRequestedHeight = textInset + messageSize.y + textInset;

                    float referenceSideLength = 50 / newGeneralTooltipScale;
                    float xScale = this.LastRequestedWidth / referenceSideLength;
                    float yScale = this.LastRequestedHeight / referenceSideLength;

                    ArcenUI_Image.SubImage subImage = this.MyElement.SubImages[0];
                    subImage.Img.rectTransform.sizeDelta = new Vector2( referenceSideLength * xScale, referenceSideLength * yScale );
                    this.UpdateTextIfNeeded();
                    this.UpdatePositionAndSize();
                }
            }
        }

        #region GetPlanetFactionalData
        public static void GetPlanetFactionalData( Planet planet, out int threatStrengthInt, out int hostileStrengthMinusThreatInt, 
            out int myTotalStrength, out int myMobileStrength, out int myAndAlliedTotalStrength, out int myAndAlliedMobileStrength, out string myOrAlliedColor,
                                                   out string alliedColor, out Faction hostileFaction, bool IsForTooltips )
        {
            PlanetFaction localFaction = planet.GetLocalPlayerFaction();
            threatStrengthInt = 0;
            hostileStrengthMinusThreatInt = 0;
            hostileFaction = null;
            myOrAlliedColor = "ffffff";
            alliedColor = "ffffff";
            myTotalStrength = 0;
            myMobileStrength = 0;
            myAndAlliedTotalStrength = 0;
            myAndAlliedMobileStrength = 0;

            if ( planet.GetControllingFaction().Type == FactionType.Player )
                threatStrengthInt = localFaction.DataByStance[FactionStance.Hostile].TotalStrengthVisible; //you have vision here since you own the planet
            else
            {
                if ( planet.IntelLevel <= PlanetIntelLevel.Unexplored )
                    return;
                if ( GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" ))
                {
                    //Show more detailed information, even if you can't really see it according to the rules
                    threatStrengthInt = localFaction.DataByStance[FactionStance.Hostile].RelativeToHumanTeam_ThreatStrength;
                    hostileStrengthMinusThreatInt = localFaction.DataByStance[FactionStance.Hostile].TotalStrength;
                }
                else
                {
                    threatStrengthInt = localFaction.DataByStance[FactionStance.Hostile].RelativeToHumanTeam_ThreatStrengthVisible;
                    hostileStrengthMinusThreatInt = localFaction.DataByStance[FactionStance.Hostile].TotalStrengthVisible;

                }
                hostileStrengthMinusThreatInt -= threatStrengthInt;
            }

            myTotalStrength = localFaction.DataByStance[FactionStance.Self].TotalStrength;
            myMobileStrength = localFaction.DataByStance[FactionStance.Self].MobileStrength;
            myAndAlliedTotalStrength = myTotalStrength + localFaction.DataByStance[FactionStance.Friendly].TotalStrength;;
            myAndAlliedMobileStrength = myMobileStrength + localFaction.DataByStance[FactionStance.Friendly].MobileStrength;
            if ( threatStrengthInt <= 0 && hostileStrengthMinusThreatInt <= 0 && myAndAlliedTotalStrength <= 0 && threatStrengthInt <= 0 )
                return;

            if ( myTotalStrength > 0 )
                myOrAlliedColor = localFaction.Faction.TeamCenterColor.GetColorHexBrighter( IsForTooltips );
            if ( myAndAlliedTotalStrength > 0 )
            {
                //calculate the strongest ally's color; if we have no strength here, also use that for "my" color
                int strongestAlliedStrength = 0;
                PlanetFaction alliedFaction;
                for ( int j = 0; j < planet.Factions.Count; j++ )
                {
                    alliedFaction = planet.Factions[j];
                    if ( !alliedFaction.GetIsFriendlyTowards( localFaction ) || alliedFaction == localFaction ) //don't count ourselves as an allied faction
                        continue;
                    if ( alliedFaction.DataByStance[FactionStance.Self].TotalStrength <= 0 )
                        continue;
                    if ( alliedFaction.DataByStance[FactionStance.Self].TotalStrength >  strongestAlliedStrength )
                    {
                        alliedColor = alliedFaction.Faction.TeamCenterColor.GetColorHexBrighter( IsForTooltips );
                        strongestAlliedStrength = alliedFaction.DataByStance[FactionStance.Self].TotalStrength;

                        if ( myTotalStrength == 0 )
                            myOrAlliedColor = alliedFaction.Faction.TeamCenterColor.GetColorHexBrighter( IsForTooltips );
                    }
                }
            }

            if ( hostileStrengthMinusThreatInt > 0 || threatStrengthInt > 0 )
            {
                PlanetFaction enemyFaction;
                for ( int j = 0; j < planet.Factions.Count; j++ )
                {
                    enemyFaction = planet.Factions[j];
                    if ( !enemyFaction.GetIsHostileTowards( localFaction ) )
                        continue;

                    if ( GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" ))
                    {
                        if ( enemyFaction.DataByStance[FactionStance.Self].TotalStrength <= 0 )
                            continue;
                    }
                    else
                    {
                        if ( enemyFaction.DataByStance[FactionStance.Self].TotalStrengthVisible <= 0 )
                            continue;
                    }
                    if ( planet.GetControllingPlanetFaction() == enemyFaction )
                    {
                        hostileFaction = enemyFaction.Faction;
                        break;
                    }
                    if ( planet.UnderInfluenceOfFactionIndex != -1 )
                    {
                        Faction influencer = World_AIW2.Instance.GetFactionByIndex(planet.UnderInfluenceOfFactionIndex);
                        if ( planet.GetPlanetFactionForFaction(influencer) == enemyFaction )
                        {
                            hostileFaction = influencer;
                            break;
                        }
                    }
                }
                if ( hostileFaction == null )
                {
                    int strengthOfStrongestEnemy = 0;
                    for ( int j = 0; j < planet.Factions.Count; j++ )
                    {
                        enemyFaction = planet.Factions[j];
                        if ( !enemyFaction.GetIsHostileTowards( localFaction ) )
                            continue;
                        int strengthToCheck = enemyFaction.DataByStance[FactionStance.Self].TotalStrengthVisible;

                        if ( GameSettings.Current.GetBoolBySetting( "GalaxyMinimalFogOfWar" ))
                            strengthToCheck = enemyFaction.DataByStance[FactionStance.Self].TotalStrength;

                        if ( strengthToCheck < strengthOfStrongestEnemy )
                            continue;
                        hostileFaction = enemyFaction.Faction;
                        break;
                    }
                }

            }
        }
        #endregion
    }
}
Window_InGameHoverPlanetInfo.cs (38,163 bytes)   

BadgerBadger

Nov 30, 2019 1:25 pm

manager   ~0054754

Can you give me a couple quick pictures showing what the problem is that you are fixing? I'm not really familiar with this code.

Astilious

Nov 30, 2019 4:36 pm

reporter   ~0054759

Ah, I can see how I was unclear about what the actual problem was now I'm looking at it, sorry. Screenshots aren't great for showing something not happening and the bug is easy to reproduce, so here are the steps.

Steps to reproduce:
1. Start or load any game.
2. Go to the galaxy map.
3. Hover mouse over any planet. Note the tooltip box on the bottom left.
4. Press the "Supress Tooltips" button (default shift).
5. The tooltip box on the bottom left is still present (despite including text stating it should be hidden!).

BadgerBadger

Nov 30, 2019 4:47 pm

manager   ~0054760

Thanks for the code!

Issue History

Date Modified Username Field Change
Nov 28, 2019 5:30 am Astilious New Issue
Nov 28, 2019 5:30 am Astilious File Added: Window_InGameSelectionInfo.cs
Nov 28, 2019 5:31 am Astilious File Deleted: Window_InGameSelectionInfo.cs
Nov 28, 2019 5:31 am Astilious File Added: Window_InGameHoverPlanetInfo.cs
Nov 28, 2019 5:32 am Astilious File Deleted: Window_InGameHoverPlanetInfo.cs
Nov 28, 2019 5:32 am Astilious File Added: Window_InGameHoverPlanetInfo.cs
Nov 28, 2019 5:47 am Astilious Tag Attached: GUI
Nov 30, 2019 1:25 pm BadgerBadger Note Added: 0054754
Nov 30, 2019 4:36 pm Astilious Note Added: 0054759
Nov 30, 2019 4:47 pm BadgerBadger Assigned To => BadgerBadger
Nov 30, 2019 4:47 pm BadgerBadger Status new => resolved
Nov 30, 2019 4:47 pm BadgerBadger Resolution open => fixed
Nov 30, 2019 4:47 pm BadgerBadger Fixed in Version => 1.011 SuperCat Swats Back
Nov 30, 2019 4:47 pm BadgerBadger Note Added: 0054760