OBJ PortraitObject

-signed Macha-latte

Summary

PortraitObject is everything the player sees during dialogue i.e. the text box, the name tag, the character portrait, the continue arrow and the choices. It sits inside the DialogueBox scene. How dialogue is started, run and closed is covered in OBJ DialogueSystem.

The goal is a look that's easy to change without touching code:

  • The text box and name tag are drawn in code from a list of points or a curve, so they can be any shape. No images needed.
  • All the look settings (shapes, colors, outline, shadow) are stored in style files. Swapping the style file changes the whole look.
  • Each character has a character file with their display name and portraits.
  • Everything updates live in the editor, so you can see changes without running the game.

Files

All the files are for PortraitObject are in dialogue/portrait_object/ unless specified otherwise

File What it is
portrait_object.tscn / .gd The PortraitObject scene. Hands the style to the parts that draw it, and swaps portrait and name for each speaker.
portrait_box.gd Draws one box shape. Used by both the text box (Box) and the name tag (NameTag).
portrait_style.gd PortraitStyle resource. Holds the box shape and the name tag shape.
box_shape.gd BoxShape resource. One drawable shape: points or curve, colors, outline, shadow.
character_data.gd CharacterData resource. One character's names and portraits.
styles/ Saved styles, shapes and curves. All the current ones are test files.
dialogue/characters/ One CharacterData file per character.
dialogue/dialogue_box.gd Not part of PortraitObject, but it's what tells PortraitObject who is speaking (see Flow).

Structure

PortraitObject (Control)
|--Portrait (TextureRect)
|--Box (Control)
|	|--TextLabel (RichTextLable)
|   |--BoxShapeEditor (Path2D)
|	|--ContinueIndicator (Label)
|	|__OptionsContainer (VBoxContainer)
|__NameTag (Control)
	|--CharacterLabel (Label)
	|__TagShapeEditor (Path2D)

| Node | What it does | | --------------------- | ------------------------------------------------------------------------------------------------------ | | PortraitObject | The root. Fills the whole screen. Holds the style and characters settings. | | Portrait | The character picture. Hidden when the speaker has no portrait. | | Box | The main text box. Draws the box shape from the style. Anchored to the bottom of the screen. | | TextLabel | The dialogue text. The Yarn line presenter types into this. | | BoxShapeEditor | Editor helper for changing the box's curve (see Styles). Does nothing in game. | | ContinueIndicator | The V arrow. Shown while a line is on screen. | | OptionsContainer | Where the choice buttons appear. It's in the same spot as TextLabel, because choices replace the text. | | NameTag | The name box. Draws the name tag shape from the style. Hidden for lines with no speaker. | | CharacterLabel | The speaker's name. | | TagShapeEditor | Editor helper for changing the name tag's curve. Does nothing in game. | All of these are scene-unique nodes (%Name), so scripts can find them even if they're moved around in the tree. The Yarn presenters in DialogueBox point at TextLabel, CharacterLabel, NameTag, ContinueIndicator and OptionsContainer by path, so renaming or moving those breaks the dialogue box. If you do, update the paths on the presenters (see OBJ DialogueSystem -> Structure).

Flow

This starts where the Flow in OBJ DialogueSystem reaches "the runner sends a line".

  1. The Yarn line presenter gets a new line.

  2. It puts the speaker's Yarn name (example:Dyno) into CharacterLabel. If the line has no speaker, it hides NameTag.

  3. It fires line_started. dialogue_box.gd is listening and calls PortraitObject.show_character("Dyno").

  4. show_character looks through its characters list for the one whose yarn_name is Dyno.

  5. If it finds one:

    • Portrait shows that character's portrait (the default expression for now).
    • CharacterLabel is changed to the character's display name (Placeholder Leanna).
  6. If it doesn't find one, Portrait is hidden and the name tag keeps the Yarn name.

  7. The line presenter types the text into TextLabel and shows ContinueIndicator.

  8. For choices, the options presenter fills OptionsContainer with buttons instead.

Styles

The look is stored in resources nested inside each other:

PortraitObject
|__style: PortraitStyle
	|--box: BoxShape      -> drawn by the box
	|__curve: Curve2D     -> (optional) make the box curvy
	|__name_tag: BoxShape -> drawn by NameTag
		|__curve: Curve2D

When you set or change the style on PortraitObject, it passes each shape down to the node that draws it. Every resource tells its parent when something changes, so editing a color or point redraws the box right away, even in the editor.

BoxShape settings

Setting What it does
points Corners of the shape, in order. Joined with straight lines. Used when there's no curve.
curve A Curve2D for a curved shape. Used instead of points when it has 3 or more points.
curve_smoothness How finely the curve is cut into straight pieces when drawn (1–10). Higher is smoother but slower.
fill_color Inside color.
outline_color Border color.
outline_width Border thickness (0–30). The border is drawn outside the shape, so it doesn't cover the text area.
shadow_color Shadow color. Set alpha to 0 for no shadow.
shadow_offset How far the shadow is moved from the box. The shadow uses the shape including its border.
antialiased Smooths the jagged edges.

Shapes are drawn in this order: shadow -> then outline -> then fill

Editing the curve in the editor

  1. Open portrait_object.tscn.
  2. Make sure the style's box (or name tag) has a curve set.
  3. Select BoxShapeEditor (or TagShapeEditor) in the scene tree.
  4. Use the Path2D tools in the top bar of the 2D view to move, add or delete points and drag their handles.
  5. The box redraws as you edit. The change is saved in the curve's .tres file, because the editor node and the style share the same curve.

Making a new style

  1. In styles/, duplicate an existing style, box and curve file (or create new ones with New Resource).
  2. In the new style, set box and name_tag to the new shapes.
  3. Make the curves unique in the new shapes (right-click the curve → Make Unique, or point at the new curve file). Otherwise editing one style also changes the other.
  4. Select PortraitObject and set its style to the new style.

Character

Each character has a CharacterData file in dialogue/characters/.

|Setting|What it does| |---|---| |yarn_name|The name used in .yarn files before the colon. Must match exactly, including capital letters.| |display_name|The name shown in the name tag. If empty, yarn_name is shown.| |portraits|A list of expression name → image, like neutral → leanna.png.| |default_expression|Which portrait to use when no expression is given or the expression doesn't exist. Defaults to neutral.| Example: dyno.tres has yarn_name = Dyno and display_name = Leanna. In Yarn the line is written Dyno: Wazzap?!, and the name tag shows Leanna.

Adding a character

  1. Right-click dialogue/characters/ → New Resource → CharacterData. Name the file after the character.
  2. Set yarn_name to exactly what you write in Yarn.
  3. Set display_name if the name on screen should be different.
  4. Add at least one portrait with the key neutral (or whatever default_expression is set to).
  5. Open portrait_object.tscn, select PortraitObject and add the new file to the characters list.

If you skip step 5, the character's lines still play, but with no portrait and with the Yarn name in the name tag.