17 private const int SpeakerHeight = 30;
18 private const int ContinueIndicatorWidth = 28;
19 private const int ContinueIndicatorHeight = 22;
20 private const int ContentInset = 10;
22 private string _speaker;
24 private bool _continueIndicatorVisible =
true;
45 string? nickname =
null)
48 ArgumentNullException.ThrowIfNull(view);
50 _speaker = speaker ??
string.Empty;
51 _text = text ??
string.Empty;
53 Panel = CreatePanel(renderSurfaceHost, view, bounds);
54 SpeakerText = CreateSpeakerText(renderSurfaceHost, view, GetSpeakerBounds(bounds), _speaker);
55 BodyText = CreateBodyText(renderSurfaceHost, view, GetBodyBounds(bounds), _text);
56 ContinueIndicator = CreateContinueIndicator(renderSurfaceHost, view, GetContinueBounds(bounds));
63 CompleteInitialization();
80 string? nickname =
null)
83 ArgumentNullException.ThrowIfNull(sceneLayer);
85 _speaker = speaker ??
string.Empty;
86 _text = text ??
string.Empty;
88 Panel = CreatePanel(renderSurfaceHost, sceneLayer, bounds);
89 SpeakerText = CreateSpeakerText(renderSurfaceHost, sceneLayer, GetSpeakerBounds(bounds), _speaker);
90 BodyText = CreateBodyText(renderSurfaceHost, sceneLayer, GetBodyBounds(bounds), _text);
91 ContinueIndicator = CreateContinueIndicator(renderSurfaceHost, sceneLayer, GetContinueBounds(bounds));
98 CompleteInitialization();
170 _speaker = speaker ??
string.Empty;
182 _text = text ??
string.Empty;
194 _continueIndicatorVisible = visible;
195 ContinueIndicator.Visible = visible;
207 SpeakerText.SetColors(speakerColor, SKColors.Transparent);
208 BodyText.SetColors(bodyColor, SKColors.Transparent);
221 .SetBorderColor(border);
233 Panel.ZOrder = zOrder;
234 SpeakerText.ZOrder = zOrder + 1;
235 BodyText.ZOrder = zOrder + 1;
236 ContinueIndicator.ZOrder = zOrder + 2;
255 ContinueIndicator.Visible = _continueIndicatorVisible;
261 base.OnPointerClick(args);
273 base.OnKeyboardInput(args);
285 private void CompleteInitialization()
296 return ConfigurePanel(
new DirectRectangle(Color.FromArgb(238, 24, 25, 32), host, view, bounds));
303 return ConfigurePanel(
new DirectRectangle(Color.FromArgb(238, 24, 25, 32), host, layer, bounds));
314 private static TextBlock CreateSpeakerText(RenderSurfaceHostBase host,
319 return ConfigureSpeakerText(
new TextBlock(host, view, bounds), speaker);
322 private static TextBlock CreateSpeakerText(RenderSurfaceHostBase host,
327 return ConfigureSpeakerText(
new TextBlock(host, layer, view:
null, worldBounds: bounds), speaker);
330 private static TextBlock ConfigureSpeakerText(TextBlock textBlock,
string speaker)
332 return textBlock.
SetText(speaker)
333 .
SetFont(SKTypeface.Default, 17f, minSize: 11f)
334 .
SetColors(
new SKColor(255, 224, 145), SKColors.Transparent)
335 .
SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Center)
340 private static TextBlock CreateBodyText(RenderSurfaceHostBase host,
345 return ConfigureBodyText(
new TextBlock(host, view, bounds), text);
348 private static TextBlock CreateBodyText(RenderSurfaceHostBase host,
353 return ConfigureBodyText(
new TextBlock(host, layer, view:
null, worldBounds: bounds), text);
356 private static TextBlock ConfigureBodyText(TextBlock textBlock,
string text)
359 .
SetFont(SKTypeface.Default, 16f, minSize: 10f)
360 .
SetColors(SKColors.White, SKColors.Transparent)
361 .
SetAlignment(SKTextAlign.Left, TextBlock.VerticalAlign.Top)
366 private static TextBlock CreateContinueIndicator(RenderSurfaceHostBase host,
370 return ConfigureContinueIndicator(
new TextBlock(host, view, bounds));
373 private static TextBlock CreateContinueIndicator(RenderSurfaceHostBase host,
377 return ConfigureContinueIndicator(
new TextBlock(host, layer, view:
null, worldBounds: bounds));
380 private static TextBlock ConfigureContinueIndicator(TextBlock textBlock)
383 .
SetFont(SKTypeface.Default, 14f, minSize: 9f)
384 .
SetColors(SKColors.White, SKColors.Transparent)
385 .
SetAlignment(SKTextAlign.Center, TextBlock.VerticalAlign.Center)
389 private static Rectangle GetSpeakerBounds(Rectangle bounds)
391 return new Rectangle(bounds.X + ContentInset,
393 Math.Max(1, bounds.Width - ContentInset * 2),
397 private static Rectangle GetBodyBounds(Rectangle bounds)
399 int top = bounds.Y + SpeakerHeight + 4;
400 int bottom = bounds.Bottom - ContinueIndicatorHeight - 4;
401 return new Rectangle(bounds.X + ContentInset,
403 Math.Max(1, bounds.Width - ContentInset * 2),
404 Math.Max(1, bottom - top));
407 private static Rectangle GetContinueBounds(Rectangle bounds)
409 return new Rectangle(bounds.Right - ContentInset - ContinueIndicatorWidth,
410 bounds.Bottom - ContinueIndicatorHeight - 4,
411 ContinueIndicatorWidth,
412 ContinueIndicatorHeight);
415 private static Rectangle ValidateBounds(Rectangle bounds)
417 if (bounds.Width < 120 || bounds.Height < SpeakerHeight + ContinueIndicatorHeight + 24)
418 throw new ArgumentOutOfRangeException(nameof(bounds), bounds,
"Conversation-box bounds are too small.");
SceneLayer? SceneLayer
Gets the scene layer shared by all children in scene-layer mode.
View? View
Gets the view shared by all children in view mode.
virtual DirectComposite Add(IDirectCompositeChild child, bool keepCurrentOffset=true, Vector2? explicitLocalOffsetPx=null)
Adds a composite-compatible direct drawable as a child.
DirectDrawingMode Mode
Gets the coordinate mode shared by the composite and its children.
Renders a configurable rectangle with support for fill, border, rounded corners, dash patterns,...
DirectRectangle SetFilled(bool isFilled)
Sets whether the rectangle interior is filled with the base color (or pattern).
DirectRectangle SetBorderColor(Color color)
Sets a distinct border (stroke) color, independent of the fill color.
DirectRectangle SetStrokeWidth(float width)
Sets the width (thickness) of the rectangle's stroke (outline) in pixels.
DirectRectangle SetCornerRadius(float radius)
Sets the radius for rounded corners in pixels.
A retained-mode text drawable with wrapping, multi-line ( ) support, horizontal/vertical alignment,...
TextBlock SetFont(SKTypeface typeface, float size, float? minSize=null)
Sets the font face and size (and optional minimum size for auto-shrink).
TextBlock EnableWrapping(bool enable=true)
Enables or disables word wrapping when laying out paragraphs.
TextBlock SetAlignment(SKTextAlign h, VerticalAlign v)
Sets the horizontal and vertical alignment used when drawing the laid-out lines within the bounds.
TextBlock SetPadding(float horizontal, float vertical)
Sets symmetric horizontal and vertical padding and invalidates cached layout.
TextBlock SetColors(SKColor fg, SKColor bg)
Sets the foreground (text) and background colors using Skia colors.
TextBlock SetText(string text)
Sets the current text content and rebuilds layout as needed. If no reveal animation is active,...
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
Represents a rendered view of a scene, combining a camera position with a viewport configuration to c...
Represents a single layer within a Scene, containing a grid of tiles and supporting various coordinat...
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.
@ View
Performs direct drawing at the view level using screen-space coordinates.