Skip to content

Commit

Permalink
Merge pull request #114 from Meorge/feat/testimony-indicator
Browse files Browse the repository at this point in the history
"Testimony" flashing label
  • Loading branch information
LuisMayo authored Jul 18, 2023
2 parents 2bf46eb + 513f73d commit d3b1215
Show file tree
Hide file tree
Showing 5 changed files with 461 additions and 1 deletion.
60 changes: 60 additions & 0 deletions docs/UsingTestimonyIndicatorEffect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Using the Testimony Indicator Effect
To indicate that a specific type of dialogue is playing out, you can place
a flashing text label in the top-left corner of the screen. In the original
games, this label would read "Testimony" during a witness's testimony in
court. With *Objection*, you can set this label to anything you want, as well
as change its colors as you please.

![Testimony indicator effect in action](img/testimony-indicator.gif)

See `example_testimony_indicator.py` for example usage.

## Setting up the effect
Only a few commands are necessary to set up the label effect:
```py
[
# Set the text for the label
DialogueAction("testimony set 'Testimony'", 0),

# (Optional) Set the fill color of the text.
# The arguments following "fillcolor" are RGB values in the range 0-255.
DialogueAction("testimony fillcolor 230 255 230", 0),

# (Optional) Set the stroke color of the text.
# The arguments following "strokecolor" are RGB values in the range 0-255.
DialogueAction("testimony strokecolor 20 150 80", 0),

# Start flashing the label
DialogueAction("testimony show", 0)
]
```
Just add those commands to your list of `BaseDialogueItem` objects and you'll
have your label!

### Resetting the colors
If you don't set the fill or stroke colors, they'll default to `(255, 255, 255)`
(white) and `(0, 192, 56)` (the green color used in the original games'
"Testimony" label), respectively.

If you'd like to return the colors to their defaults, you can pass a single
parameter, `default`, to `testimony fillcolor` and `testimony strokecolor`,
like so:
```py
[
# Reset the fill color of the label to white
DialogueAction("testimony fillcolor default", 0),

# Reset the stroke color of the label to the green color used in the
# original games
DialogueAction("testimony strokecolor default", 0)
]
```

### Turning off the label
Disabling the label is as easy as issuing a single command:
```py
[
DialogueAction("testimony hide", 0)
]
```
That's it!
Binary file added docs/img/testimony-indicator.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
252 changes: 252 additions & 0 deletions examples/example_testimony_indicator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
from objection_engine.ace_attorney_scene import AceAttorneyDirector
from objection_engine.parse_tags import (
DialoguePage,
DialogueAction,
DialogueTextChunk,
DialogueTextLineBreak,
)

pages = [
DialoguePage(
[
DialogueAction("music start pwr/cross-moderato", 0),
DialogueAction(
"testimony set 'Discussion'", 0
), # Set testimony indicator text with default colors
DialogueAction("testimony show", 0), # Show testimony indicator
]
),
DialoguePage(
[
DialogueAction("wait 0.03", 0),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-normal-idle.gif", 0
),
DialogueAction("cut left", 0),
DialogueAction('nametag "Phoenix"', 0),
DialogueAction("showbox", 0),
DialogueAction("evidence clear", 0),
DialogueAction("startblip male", 0),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-normal-talk.gif", 0
),
DialogueTextChunk("Hello", []),
DialogueTextChunk(".", []),
DialogueAction("stopblip", 0),
DialogueTextChunk(" ", []),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-normal-idle.gif", 0
),
DialogueAction("wait 0.6", 0),
DialogueAction("startblip male", 0),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-talk.gif",
0,
),
DialogueTextChunk("My", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("name", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("is", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("Phoenix", []),
DialogueTextChunk(".", []),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-idle.gif",
0,
),
DialogueAction("stopblip", 0),
DialogueAction("showarrow", 0),
DialogueAction("wait 2", 0),
DialogueAction("hidearrow", 0),
DialogueAction("sound pichoop", 0),
DialogueAction("wait 0.3", 0),
]
),
DialoguePage(
[
DialogueAction("wait 0.03", 0),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-idle.gif",
0,
),
DialogueAction("cut left", 0),
DialogueAction('nametag "Phoenix"', 0),
DialogueAction("showbox", 0),
DialogueAction("startblip male", 0),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-talk.gif",
0,
),
DialogueTextChunk("I", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("am", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("a", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("defense", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("attorney", []),
DialogueTextChunk(".", []),
DialogueAction("stopblip", 0),
DialogueTextChunk(" ", []),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-idle.gif",
0,
),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-idle.gif",
0,
),
DialogueAction("stopblip", 0),
DialogueAction("showarrow", 0),
DialogueAction("wait 2", 0),
DialogueAction("hidearrow", 0),
DialogueAction("sound pichoop", 0),
DialogueAction("wait 0.3", 0),
]
),
DialoguePage(
[
DialogueAction("wait 0.03", 0),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-idle.gif",
0,
),
DialogueAction("cut left", 0),
DialogueAction('nametag "Phoenix"', 0),
DialogueAction("showbox", 0),
DialogueAction("evidence clear", 0),
DialogueAction("startblip male", 0),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-talk.gif",
0,
),
DialogueTextChunk("Here", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("is", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("another", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("line", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("of", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("dialogue", []),
DialogueTextChunk(".", []),
DialogueAction("stopblip", 0),
DialogueTextChunk(" ", []),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-idle.gif",
0,
),
DialogueAction(
"sprite left assets/characters/phoenix/phoenix-handsondesk-idle.gif",
0,
),
DialogueAction("stopblip", 0),
DialogueAction("showarrow", 0),
DialogueAction("wait 2", 0),
DialogueAction("hidearrow", 0),
DialogueAction("sound pichoop", 0),
DialogueAction("wait 0.3", 0),
]
),
DialoguePage(
[
DialogueAction("wait 0.03", 0),
DialogueAction("hidebox", 0),
DialogueAction("testimony hide", 0), # Hide testimony indicator
DialogueAction(
"testimony set 'Counterargument'", 0
), # Set a new testimony indicator
DialogueAction("testimony fillcolor 56 200 200", 0), # Set the fill color
DialogueAction("testimony strokecolor 128 0 56", 0), # Set the stroke color
DialogueAction("wait 0.5", 0),
DialogueAction("pan right", 0),
DialogueAction(
"sprite right assets/characters/edgeworth/edgeworth-document-idle.gif",
0,
),
DialogueAction("wait 1.0", 0),
DialogueAction('nametag "Edgeworth"', 0),
DialogueAction("showbox", 0),
DialogueAction("testimony show", 0), # Start showing new indicator
DialogueAction("evidence clear", 0),
DialogueAction("startblip male", 0),
DialogueAction(
"sprite right assets/characters/edgeworth/edgeworth-document-talk.gif",
0,
),
DialogueTextChunk("I", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("am", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("Edgeworth", []),
DialogueTextChunk(",", []),
DialogueAction("stopblip", 0),
DialogueAction(
"sprite right assets/characters/edgeworth/edgeworth-document-idle.gif",
0,
),
DialogueAction("wait 0.3", 0),
DialogueAction("startblip male", 0),
DialogueAction(
"sprite right assets/characters/edgeworth/edgeworth-document-talk.gif",
0,
),
DialogueAction("testimony fillcolor default", 0), # Reset the fill color
DialogueAction(
"testimony strokecolor default", 0
), # Reset the stroke color
DialogueTextChunk(" ", []),
DialogueTextChunk("because", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("I", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("have", []),
DialogueTextChunk(" ", []),
DialogueTextLineBreak(),
DialogueTextChunk("the", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("second", []),
DialogueTextChunk("-", []),
DialogueAction("stopblip", 0),
DialogueAction(
"sprite right assets/characters/edgeworth/edgeworth-document-idle.gif",
0,
),
DialogueAction("wait 0.3", 0),
DialogueAction("startblip male", 0),
DialogueAction(
"sprite right assets/characters/edgeworth/edgeworth-document-talk.gif",
0,
),
DialogueTextChunk(" ", []),
DialogueTextChunk("most", []),
DialogueTextChunk(" ", []),
DialogueTextChunk("lines", []),
DialogueTextChunk(".", []),
DialogueAction("stopblip", 0),
DialogueTextChunk(" ", []),
DialogueAction(
"sprite right assets/characters/edgeworth/edgeworth-document-idle.gif",
0,
),
DialogueAction(
"sprite right assets/characters/edgeworth/edgeworth-document-idle.gif",
0,
),
DialogueAction("stopblip", 0),
DialogueAction("showarrow", 0),
DialogueAction("wait 2", 0),
DialogueAction("hidearrow", 0),
DialogueAction("sound pichoop", 0),
DialogueAction("wait 0.3", 0),
]
),
]

director = AceAttorneyDirector()
director.set_current_pages(pages)
director.render_movie()
37 changes: 36 additions & 1 deletion objection_engine/ace_attorney_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from os import environ, getenv
from turtle import pos

from objection_engine.testimony_indicator import TestimonyIndicatorTextObject

environ["TOKENIZERS_PARALLELISM"] = "false" # to make HF Transformers happy

from transformers import pipeline
Expand Down Expand Up @@ -596,7 +598,13 @@ def __init__(self, callbacks: dict = None, fps: float = 30):

self.evidence = EvidenceObject(parent=self.textbox_shaker, director=self)

self.judge_verdict = JudgeVerdictTextObject(parent=self.root, name="Judge Verdict")
self.judge_verdict = JudgeVerdictTextObject(
parent=self.root, name="Judge Verdict"
)

self.testimony_indicator = TestimonyIndicatorTextObject(
parent=self.root, name="Testimony Indicator"
)

self.scene = Scene(width=256, height=192, root=self.root)

Expand Down Expand Up @@ -830,6 +838,33 @@ def update(self, delta: float):

current_dialogue_obj.completed = True

elif c == "testimony":
command = action_split[1]
if command == "set":
new_text = action_split[2]
self.testimony_indicator.set_text(new_text)
elif command == "fillcolor":
if len(action_split) == 3 and action_split[2] == "default":
self.testimony_indicator.set_fill_color(None)
else:
r = int(action_split[2])
g = int(action_split[3])
b = int(action_split[4])
self.testimony_indicator.set_fill_color((r, g, b))
elif command == "strokecolor":
if len(action_split) == 3 and action_split[2] == "default":
self.testimony_indicator.set_stroke_color(None)
else:
r = int(action_split[2])
g = int(action_split[3])
b = int(action_split[4])
self.testimony_indicator.set_stroke_color((r, g, b))
elif command == "show":
self.testimony_indicator.make_visible()
elif command == "hide":
self.testimony_indicator.make_invisible()

current_dialogue_obj.completed = True
elif c == "nop":
current_dialogue_obj.completed = True

Expand Down
Loading

0 comments on commit d3b1215

Please sign in to comment.