Skip to content

Commit 0aee313

Browse files
authored
2310 textbox should not apply localization on assignment (#2311)
* First pass at fixing localization on assignment Refactoring and XML docs * Added SetTextNoTranslate to TextRuntime Fixed initial assignment of text using localization for "" (potentially)
1 parent fc26efd commit 0aee313

File tree

13 files changed

+374
-172
lines changed

13 files changed

+374
-172
lines changed

.claude/code-style.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
* Do not use `(not, used)` in lambdas, even if you see it elsewhere in the code. Instead use `(_,_)`.
1111
* **Unit tests: always use explicit types, not `var`**. Every local variable declaration in a unit test method must use the concrete type (e.g., `ComponentSave button = new ComponentSave { ... }`, not `var button = new ComponentSave { ... }`).
1212
* **Unit tests: prefer `async Task` over blocking**. Test methods that call async code must be declared `async Task` and use `await`. Never use `.GetAwaiter().GetResult()`, `.Result`, or `.Wait()` in tests.
13+
* **XML documentation**: Always include `/// <summary>` on new publicly-facing types, methods, properties, and events. Do not doc private or internal members unless their behavior is non-obvious. Before writing a summary, check whether the member overrides or implements a base class or interface member — if so, use `/// <inheritdoc/>` instead. When a public member is primarily called internally (e.g., by a service or manager), say so in the summary and point to the preferred user-facing API.

Gum/Wireframe/CustomSetPropertyOnRenderable.cs

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
#endif
44
using Gum.Content.AnimationChain;
55
using Gum.DataTypes;
6-
using Gum.Graphics.Animation;
76
using Gum.RenderingLibrary;
87
using RenderingLibrary;
98
using RenderingLibrary.Content;
109
using RenderingLibrary.Graphics;
1110
using RenderingLibrary.Graphics.Fonts;
12-
using RenderingLibrary.Math.Geometry;
1311
using System;
1412
using System.Collections.Generic;
1513
using System.Drawing;
@@ -26,10 +24,10 @@
2624
using Gum.Localization;
2725
using System.Security.Policy;
2826
using Gum.Managers;
29-
using Microsoft.Xna.Framework.Graphics;
3027
using Gum.Converters;
28+
using Gum.Wireframe;
3129

32-
#if !FRB
30+
#if !FRB && !RAYLIB
3331
using MonoGameGum.GueDeriving;
3432
#endif
3533

@@ -41,15 +39,21 @@
4139

4240

4341
#if RAYLIB
42+
using Gum.Renderables;
43+
using Gum.GueDeriving;
44+
using Raylib_cs;
4445
namespace RaylibGum.Renderables;
4546
#else
47+
using Gum.Graphics.Animation;
48+
using RenderingLibrary.Math.Geometry;
49+
using Microsoft.Xna.Framework.Graphics;
4650
namespace Gum.Wireframe;
4751
#endif
4852

49-
5053
public class CustomSetPropertyOnRenderable
5154
{
5255
public static ILocalizationService? LocalizationService { get; set; }
56+
5357
#if GUM
5458
private static readonly FontManager _fontManager;
5559
#endif
@@ -64,7 +68,8 @@ static CustomSetPropertyOnRenderable()
6468
}
6569

6670
/// <summary>
67-
/// Additional logic to perform before falling back to reflection. This can be added by libraries adding additional runtime types
71+
/// Additional logic to perform before falling back to reflection.
72+
/// This can be added by libraries adding additional runtime types
6873
/// </summary>
6974
public static Func<IRenderableIpso, GraphicalUiElement, string, object, bool>? AdditionalPropertyOnRenderable = null;
7075

@@ -93,59 +98,10 @@ public static void SetPropertyOnRenderable(IRenderableIpso renderableIpso, Graph
9398
}
9499
else if (renderableIpso is SolidRectangle)
95100
{
96-
var solidRect = renderableIpso as SolidRectangle;
97-
98-
if (propertyName == "Blend")
99-
{
100-
var valueAsGumBlend = (RenderingLibrary.Blend)value;
101-
102-
var valueAsXnaBlend = valueAsGumBlend.ToBlendState();
103-
104-
solidRect.BlendState = valueAsXnaBlend;
105-
106-
handled = true;
107-
}
108-
else if (propertyName == "Alpha")
109-
{
110-
int valueAsInt = (int)value;
111-
solidRect.Alpha = valueAsInt;
112-
handled = true;
113-
}
114-
else if (propertyName == "Red")
115-
{
116-
int valueAsInt = (int)value;
117-
solidRect.Red = valueAsInt;
118-
handled = true;
119-
}
120-
else if (propertyName == "Green")
121-
{
122-
int valueAsInt = (int)value;
123-
solidRect.Green = valueAsInt;
124-
handled = true;
125-
}
126-
else if (propertyName == "Blue")
127-
{
128-
int valueAsInt = (int)value;
129-
solidRect.Blue = valueAsInt;
130-
handled = true;
131-
}
132-
else if (propertyName == "Color")
133-
{
134-
//var valueAsColor = (Color)value;
135-
if (value is System.Drawing.Color drawingColor)
136-
{
137-
solidRect.Color = drawingColor;
138-
}
139-
else if (value is Microsoft.Xna.Framework.Color xnaColor)
140-
{
141-
solidRect.Color = xnaColor.ToSystemDrawing();
142-
143-
}
144-
145-
handled = true;
146-
}
147-
101+
handled = TrySetPropertyOnSolidRectangle(renderableIpso, propertyName, value, handled);
148102
}
103+
#endif
104+
149105
else if (renderableIpso is Sprite renderableSprite)
150106
{
151107
handled = TrySetPropertyOnSprite(renderableSprite, graphicalUiElement, propertyName, value);
@@ -158,7 +114,6 @@ public static void SetPropertyOnRenderable(IRenderableIpso renderableIpso, Graph
158114
{
159115
handled = TrySetPropertyOnInvisbileRenderable(renderableIpso, propertyName, value, handled);
160116
}
161-
#endif
162117

163118
if(!handled && AdditionalPropertyOnRenderable != null)
164119
{
@@ -196,6 +151,63 @@ public static void SetPropertyOnRenderable(IRenderableIpso renderableIpso, Graph
196151
}
197152
}
198153

154+
private static bool TrySetPropertyOnSolidRectangle(IRenderableIpso renderableIpso, string propertyName, object value, bool handled)
155+
{
156+
var solidRect = renderableIpso as SolidRectangle;
157+
158+
if (propertyName == "Blend")
159+
{
160+
var valueAsGumBlend = (RenderingLibrary.Blend)value;
161+
162+
var valueAsXnaBlend = valueAsGumBlend.ToBlendState();
163+
164+
solidRect.BlendState = valueAsXnaBlend;
165+
166+
handled = true;
167+
}
168+
else if (propertyName == "Alpha")
169+
{
170+
int valueAsInt = (int)value;
171+
solidRect.Alpha = valueAsInt;
172+
handled = true;
173+
}
174+
else if (propertyName == "Red")
175+
{
176+
int valueAsInt = (int)value;
177+
solidRect.Red = valueAsInt;
178+
handled = true;
179+
}
180+
else if (propertyName == "Green")
181+
{
182+
int valueAsInt = (int)value;
183+
solidRect.Green = valueAsInt;
184+
handled = true;
185+
}
186+
else if (propertyName == "Blue")
187+
{
188+
int valueAsInt = (int)value;
189+
solidRect.Blue = valueAsInt;
190+
handled = true;
191+
}
192+
else if (propertyName == "Color")
193+
{
194+
//var valueAsColor = (Color)value;
195+
if (value is System.Drawing.Color drawingColor)
196+
{
197+
solidRect.Color = drawingColor;
198+
}
199+
else if (value is Microsoft.Xna.Framework.Color xnaColor)
200+
{
201+
solidRect.Color = xnaColor.ToSystemDrawing();
202+
203+
}
204+
205+
handled = true;
206+
}
207+
208+
return handled;
209+
}
210+
199211
private static bool TrySetPropertyOnInvisbileRenderable(IRenderableIpso renderableIpso, string propertyName, object value, bool handled)
200212
{
201213
bool didSet = false;

0 commit comments

Comments
 (0)