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
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".
-
The Yarn line presenter gets a new line.
-
It puts the speaker's Yarn name (example:
Dyno) intoCharacterLabel. If the line has no speaker, it hidesNameTag. -
It fires
line_started.dialogue_box.gdis listening and callsPortraitObject.show_character("Dyno"). -
show_characterlooks through itscharacterslist for the one whoseyarn_nameisDyno. -
If it finds one:
Portraitshows that character's portrait (the default expression for now).CharacterLabelis changed to the character's display name (PlaceholderLeanna).
-
If it doesn't find one,
Portraitis hidden and the name tag keeps the Yarn name. -
The line presenter types the text into
TextLabeland showsContinueIndicator. -
For choices, the options presenter fills
OptionsContainerwith 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
Shapes are drawn in this order: shadow -> then outline -> then fill
Editing the curve in the editor
- Open
portrait_object.tscn. - Make sure the style's box (or name tag) has a
curveset. - Select
BoxShapeEditor(orTagShapeEditor) in the scene tree. - Use the Path2D tools in the top bar of the 2D view to move, add or delete points and drag their handles.
- The box redraws as you edit. The change is saved in the curve's
.tresfile, because the editor node and the style share the same curve.
Making a new style
- In
styles/, duplicate an existing style, box and curve file (or create new ones with New Resource). - In the new style, set
boxandname_tagto the new shapes. - 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.
- Select
PortraitObjectand set itsstyleto 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
- Right-click
dialogue/characters/→ New Resource →CharacterData. Name the file after the character. - Set
yarn_nameto exactly what you write in Yarn. - Set
display_nameif the name on screen should be different. - Add at least one portrait with the key
neutral(or whateverdefault_expressionis set to). - Open
portrait_object.tscn, selectPortraitObjectand add the new file to thecharacterslist.
If you skip step 5, the character's lines still play, but with no portrait and with the Yarn name in the name tag.