From ab957c790bdc9f2f33bb356e1046ee89f757b612 Mon Sep 17 00:00:00 2001 From: amevarashi Date: Sun, 2 Nov 2025 16:10:06 +0500 Subject: [PATCH] Replace GUI.Label with Widgets.Label and add dynamic label rect height --- .../RJW_Menstruation/UI/Dialog_WombStatus.cs | 79 +++++++++++-------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/1.6/source/RJW_Menstruation/RJW_Menstruation/UI/Dialog_WombStatus.cs b/1.6/source/RJW_Menstruation/RJW_Menstruation/UI/Dialog_WombStatus.cs index 72706ef..5f46350 100644 --- a/1.6/source/RJW_Menstruation/RJW_Menstruation/UI/Dialog_WombStatus.cs +++ b/1.6/source/RJW_Menstruation/RJW_Menstruation/UI/Dialog_WombStatus.cs @@ -32,9 +32,6 @@ namespace RJW_Menstruation private Texture2D anal; private Color cumcolor; - private static GUIStyle fontstylecenter = null; - private static GUIStyle fontstyleright = null; - private static GUIStyle fontstyleleft = null; private static GUIStyle boxstyle = null; private static GUIStyle buttonstyle = null; @@ -140,9 +137,6 @@ namespace RJW_Menstruation public override void PreOpen() { base.PreOpen(); - if (fontstylecenter == null) fontstylecenter = new GUIStyle() { alignment = TextAnchor.MiddleCenter }; - if (fontstyleright == null) fontstyleright = new GUIStyle() { alignment = TextAnchor.MiddleRight }; - if (fontstyleleft == null) fontstyleleft = new GUIStyle() { alignment = TextAnchor.MiddleLeft }; if (boxstyle == null) boxstyle = new GUIStyle(GUI.skin.textArea); if (buttonstyle == null) buttonstyle = new GUIStyle(GUI.skin.button); } @@ -158,8 +152,6 @@ namespace RJW_Menstruation buttonstyle.hover = buttonstyle.normal; boxstyle.border.left = 4; boxstyle.border.right = 4; boxstyle.border.bottom = 4; boxstyle.border.top = 4; - fontstyleleft.normal.textColor = Color.white; - float preginfoheight = 0f; Hediff hediff = comp.Pregnancy; if (hediff != null && Utility.ShowFetusImage(hediff)) @@ -174,22 +166,24 @@ namespace RJW_Menstruation { string feinfo = PregnancyCommon.GetBabyInfo(m.babies); string fainfo = PregnancyCommon.GetFatherInfo(m.babies, m.pawn, m.is_parent_known) + " "; + TextAnchor faAnchor; if (feinfo.Length + fainfo.Length > 45) { preginfoheight = fontheight + 2; buttonstyle.alignment = TextAnchor.UpperLeft; - fontstyleright.alignment = TextAnchor.LowerRight; + faAnchor = TextAnchor.LowerRight; } else { preginfoheight = fontheight; buttonstyle.alignment = TextAnchor.MiddleLeft; - + faAnchor = TextAnchor.MiddleRight; } Rect preginfo = new Rect(0f, mainRect.yMax - wombRectHeight - 2, wombRectWidth, preginfoheight); - fontstyleright.normal.textColor = Color.white; GUI.Box(preginfo, feinfo, buttonstyle); - GUI.Label(preginfo, fainfo, fontstyleright); + Text.Anchor = faAnchor; + Widgets.Label(preginfo, fainfo); + GenUI.ResetLabelAlign(); } } @@ -202,8 +196,6 @@ namespace RJW_Menstruation { preginfoheight = fontheight; Rect preginfo = new Rect(0f, mainRect.yMax - wombRectHeight - 2, wombRectWidth, preginfoheight); - fontstyleright.normal.textColor = Color.white; - fontstyleright.alignment = TextAnchor.MiddleRight; buttonstyle.alignment = TextAnchor.MiddleLeft; string father; @@ -214,7 +206,9 @@ namespace RJW_Menstruation father = b.father.LabelShort; GUI.Box(preginfo, b.babies.Count + " " + fetus.def.label + " " + Translations.Dialog_WombInfo02, buttonstyle); - GUI.Label(preginfo, Translations.Dialog_WombInfo03 + ": " + father + " ", fontstyleright); + Text.Anchor = TextAnchor.MiddleRight; + Widgets.Label(preginfo, Translations.Dialog_WombInfo03 + ": " + father + " "); + GenUI.ResetLabelAlign(); } } else if (hediff is HediffWithParents p) @@ -234,23 +228,26 @@ namespace RJW_Menstruation fainfo = Translations.Dialog_WombInfo03 + ": " + father + " "; } + TextAnchor faAnchor; + if (feinfo.Length + fainfo.Length > 45) { preginfoheight = fontheight + 2; buttonstyle.alignment = TextAnchor.UpperLeft; - fontstyleright.alignment = TextAnchor.LowerRight; + faAnchor = TextAnchor.LowerRight; } else { preginfoheight = fontheight; buttonstyle.alignment = TextAnchor.MiddleLeft; - + faAnchor = TextAnchor.MiddleRight; } Rect preginfo = new Rect(0f, mainRect.yMax - wombRectHeight - 2, wombRectWidth, preginfoheight); - fontstyleright.normal.textColor = Color.white; GUI.Box(preginfo, feinfo, buttonstyle); - GUI.Label(preginfo, fainfo, fontstyleright); + Text.Anchor = faAnchor; + Widgets.Label(preginfo, fainfo); + GenUI.ResetLabelAlign(); } } else cum = ContentFinder.Get(("Womb/Empty"), true); @@ -268,11 +265,13 @@ namespace RJW_Menstruation { naked = !naked; } - Rect pawnLabelRect = new Rect(0, pawnRectHeight, pawnRectWidth, fontheight - 10); - Rect pawnLabel2Rect = new Rect(0, pawnRectHeight + fontheight - 10, pawnRectWidth, fontheight - 10); - fontstylecenter.normal.textColor = pawn.DrawColor; - GUI.Label(pawnLabelRect, pawn.Name?.ToStringFull ?? pawn.Label, fontstylecenter); - if (pawn.story != null) GUI.Label(pawnLabel2Rect, pawn.ageTracker.AgeBiologicalYears + ", " + pawn.story.Title, fontstylecenter); + string pawnLabel = pawn.Name?.ToStringFull ?? pawn.Label; + if (pawn.story != null) pawnLabel += "\n" + pawn.ageTracker.AgeBiologicalYears + ", " + pawn.story.Title; + Rect pawnLabelRect = new Rect(0, pawnRectHeight, pawnRectWidth, Text.CalcHeight(pawnLabel, pawnRectWidth)); + GUI.color = pawn.DrawColor; + Text.Anchor = TextAnchor.UpperCenter; + Widgets.Label(pawnLabelRect, pawnLabel); + GenUI.ResetLabelAlign(); GUI.color = Color.white; @@ -305,12 +304,14 @@ namespace RJW_Menstruation TooltipHandler.TipRegion(wombInfoRect, comp.GetCurStageDesc); - fontstyleright.normal.textColor = Color.red; - fontstyleright.alignment = TextAnchor.MiddleRight; + GUI.color = Color.red; + Text.Anchor = TextAnchor.MiddleRight; //if (comp.GetFertilization) GUI.Label(wombInfoRect, Translations.Dialog_WombInfo05 + " ", fontstyleright); //else if (comp.GetEggFertilizing) GUI.Label(wombInfoRect, Translations.Dialog_WombInfo06 + " ", fontstyleright); //else if (comp.GetEgg) GUI.Label(wombInfoRect, Translations.Dialog_WombInfo07 + " ", fontstyleright); - GUI.Label(wombInfoRect, comp.GetFertilizingInfo + " ", fontstyleright); + Widgets.Label(wombInfoRect, comp.GetFertilizingInfo + " "); + GenUI.ResetLabelAlign(); + GUI.color = Color.white; //Widgets.Label(wombInfoRect,Translations.Dialog_WombInfo01 + ": " + comp.GetCurStageLabel); @@ -385,9 +386,11 @@ namespace RJW_Menstruation private void DrawVagina(Rect rect, HediffComp_Menstruation comp) { + string vaginaLabel = pawn.GetVaginaLabel(); + string anusLabel = pawn.GetAnusLabel(); Rect genitalIconRect = new Rect(rect.x, rect.y + fontheight, genitalRectWidth, genitalRectHeight); - Rect genitalVaginaLabelRect = new Rect(rect.x, rect.y + 10f, genitalRectWidth, fontheight); - Rect genitalAnusLabelRect = new Rect(rect.x, rect.y + fontheight + genitalRectHeight, genitalRectWidth, fontheight); + Rect genitalVaginaLabelRect = rect.TopPartPixels(Text.CalcHeight(vaginaLabel, genitalRectWidth)); + Rect genitalAnusLabelRect = rect.BottomPartPixels(Text.CalcHeight(anusLabel, genitalRectWidth)); vagina = pawn.GetGenitalIcon(comp); anal = pawn.GetAnalIcon(); @@ -400,14 +403,18 @@ namespace RJW_Menstruation GUI.DrawTexture(genitalIconRect, vagina, ScaleMode.ScaleToFit); GUI.color = Color.white; - GUI.Label(genitalVaginaLabelRect, pawn.GetVaginaLabel(), fontstylecenter); - GUI.Label(genitalAnusLabelRect, pawn.GetAnusLabel(), fontstylecenter); + Text.Anchor = TextAnchor.MiddleCenter; + Widgets.Label(genitalVaginaLabelRect, vaginaLabel); + Text.Anchor = TextAnchor.LowerCenter; + Widgets.Label(genitalAnusLabelRect, anusLabel); + GenUI.ResetLabelAlign(); } private void DrawBreast(Rect rect) { + string breastLabel = pawn.GetBreastLabel(); Rect BreastIconRect = new Rect(rect.x, rect.y + fontheight, breastRectWidth, breastRectHeight); - Rect BreastLabelRect = new Rect(rect.x, rect.y, breastRectWidth, fontheight); + Rect BreastLabelRect = rect.TopPartPixels(Text.CalcHeight(breastLabel, breastRectWidth)); Rect MilkGaugeRect = new Rect(rect.x, rect.yMax, breastRectWidth, 20f); GUI.color = new Color(1.00f, 0.47f, 0.47f, 1); @@ -419,7 +426,9 @@ namespace RJW_Menstruation GUI.color = Color.white; - GUI.Label(BreastLabelRect, pawn.GetBreastLabel(), fontstylecenter); + Text.Anchor = TextAnchor.MiddleCenter; + Widgets.Label(BreastLabelRect, breastLabel); + GenUI.ResetLabelAlign(); pawn.DrawMilkBars(MilkGaugeRect); @@ -469,7 +478,9 @@ namespace RJW_Menstruation private void FillableBarLabeled(Rect rect, string label, float fillPercent, Texture2D filltexture, Texture2D bgtexture, string tooltip = null) { Widgets.FillableBar(rect, Math.Min(fillPercent, 1.0f), filltexture, bgtexture, true); - GUI.Label(rect, label, fontstyleleft); + Text.Anchor = TextAnchor.MiddleLeft; + Widgets.Label(rect, label); + GenUI.ResetLabelAlign(); Widgets.DrawHighlightIfMouseover(rect); if (tooltip != null) TooltipHandler.TipRegion(rect, tooltip); }