Skip to content

Instantly share code, notes, and snippets.

@methanoliver
Last active September 20, 2022 17:35
Show Gist options
  • Save methanoliver/7671cbcabe46bcc8a0f757ba195bb1a4 to your computer and use it in GitHub Desktop.
Save methanoliver/7671cbcabe46bcc8a0f757ba195bb1a4 to your computer and use it in GitHub Desktop.
Renpy: A ctc indicator that appears in a position fixed to the say window, wherever the say window may be.
### This here is mostly just example code to demonstrate the trick,
### the relevant parts are marked specially.
init:
default preferences.text_cps = 30
define CTCDisplayable = Text("Click To Continue")
### Defining the character object.
define nvl_ctc = NVLCharacter(
ctc = CTCDisplayable,
ctc_pause = CTCDisplayable,
ctc_timedpause = Null(),
# The point of this is that it's neither 'fixed'
# nor 'nestled', so while the displayables are part of the.
# Character object, they are not rendered by it at all.
ctc_position = "none",
clear=False,
kind=nvl
)
define gui.nvl_height = None
define gui.nvl_text_xpos = 0.0
define gui.nvl_text_ypos = 0
define gui.nvl_text_width = 512
define gui.nvl_text_xalign = 0
style nvl_window:
margin (10, 10)
padding (20, 16, 20, 16)
background Solid("#000")
xpos -500
style nvl_dialogue:
xpos gui.nvl_text_xpos
xanchor gui.nvl_text_xalign
ypos gui.nvl_text_ypos
xfill True
text_align gui.nvl_text_xalign
style nvl_entry:
xfill True
ysize gui.nvl_height
style nvl_window_right is nvl_window
style nvl_window_right:
xalign 1.0
xsize 512
yfill True
style nvl_window_left is nvl_window
style nvl_window_left:
xalign 0.0
xsize 512
yfill True
define l = NVLCharacter(kind=nvl_ctc, show_base = "nvl_window_left")
define r = NVLCharacter(kind=nvl_ctc, show_base = "nvl_window_right")
screen nvl(dialogue, items=None, base = "nvl_window", box = None):
window:
# This way, we can use the character object
# to explicitly pick which nvl window style we want.
style base
# And this way, we can override window position per-line.
if box:
if box.get("xfill"):
xfill box.get("xfill")
if box.get("yfill"):
yfill box.get("yfill")
if box.get("pos"):
pos box.get("pos")
if box.get("anchor"):
anchor box.get("anchor")
if box.get("align"):
align box.get("align")
if box.get("xysize"):
xysize box.get("xysize")
if box.get("area"):
area box.get("area")
vbox:
spacing gui.nvl_spacing
use nvl_dialogue(dialogue)
for i in items:
textbutton i.caption:
action i.action
style "nvl_button"
#### The critical part:
# A displayable given by the variable 'current_ctc'
# is part of the NVL screen itself.
# The same way would work for the regular say screen.
add current_ctc:
align (1.0, 1.0)
#### CTC trickery itself.
init -1 python:
# Yes, we use a store variable to keep the current CTC displayable.
# Yes, it's all about the side effects.
# No, that's the only reasonable way I have discovered so far to
# get at the SlowDone callback.
store.current_ctc = Null()
class UpdateCTC(Action):
def __init__(self, value, *args, **kwargs):
self.value = value
def __call__(self):
store.current_ctc = self.value
renpy.restart_interaction()
return None
### The CTC screen is invoked by the CTC machinery when it is defined.
### and is the other critical part of the trick.
screen ctc(arg=Null()):
# The screen itself doesn't do anything.
# SlowDone passes it the arg containing the appropriate displayable,
# so whenever the screen is rendered or re-rendered, we just stuff this
# argument into our store variable and force a refresh of the screens,
# which gets NVL screen to display it.
#
# I suspect this does not actually
# involve side effects of the screen itself.
on ["show", "replace"] action UpdateCTC(arg)
on ["hide", "replaced"] action UpdateCTC(Null())
label start:
scene bg white
l """I needed this because my nvl window is meant to be in different
screen locations, depending on the situation.{p}Here, the window can move.{w}
Notice the fun part:{w}
if you don't clear it, the lines carry over too."""
r """Observe!{p}Different NVL windows still have the CTC in the same place."""
r """I still find this a very crude hack, however.{w} Is there a legitimate day to do it?"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment