UnitEngine and Overlay displayables

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
DesertFox
Regular
Posts: 196
Joined: Sun Jul 28, 2013 1:29 pm
Completed: Over The Hills And Far Away
Projects: My Little Dictator
Organization: WarGirl Games
Contact:

UnitEngine and Overlay displayables

#1 Post by DesertFox »

Another question on the UnitEngine. It's a known bug (I know, it's old coding) but returning to the main menu from the unitengine and then going to label start leaves the overlays running. I've been trying my best but can't crack it.

Is there a way to turn off the overlay layer so that all overlay displayables disappear?

Something I can slip into my script or mainmenu screen.

The buttons on the right hand side...

Code: Select all

    def overlay_ShowButtons(self):
      if self.mode>0:
        self.ShowButtons()

    def ShowButtons(self):

      if self.menu_items:
        # Don't show the normal buttons if we've got a popup menu
        ui.frame(style=style.engine_frame["menu"])
        ui.menu(style=style.engine_menu, menuitems=self.menu_items)

      elif self.show_buttons:
        # Normal buttons
        ui.frame(style=style.engine_frame["buttons"])

        ui.vbox() # The different rows of buttons
        ui.vbox() # The row of Next Unit and Next Turn buttons
        engine_button("Next Unit", clicked=ui.returns(self.SelectNextUnit))
        engine_button("End Turn", clicked=ui.returns(self.ConfirmEndTurn))
        ui.close() # End of the Next Unit / End Turn row
        ui.vbox() # The row of Move and Act buttons
        showMoveButton = (self.mode >= self.UNITSELECTED) and self.selected_unit.controller == self.current_player
        showActButton = showMoveButton
        if showMoveButton:
          enableMoveButton = (self.mode != self.MOVEMODE) and self.selected_unit.MP > 0 and self.selected_unit.can_move
          if enableMoveButton:
            clicked = ui.returns(self.CurriedSetMode(self, self.MOVEMODE))
          else:
            clicked = None
          engine_button("Move", clicked=clicked)
        if showActButton:
          enableActButton = (self.mode != self.ACTMODE and
            (self.movement_style == self.MP and
              (self.selected_unit.actions_left > 0 and self.selected_unit.can_act)) or
            (self.movement_style == self.AP and
              (self.selected_unit.AP >= 0 and self.selected_unit.can_act))
                               )
            # *** Todo: This should be a better criterion and/or more customisable
          if enableActButton:
            clicked = ui.returns(self.CurriedSetMode(self, self.ACTMODE))
          else:
            clicked = None
          engine_button("Act", clicked=clicked)
        ui.close() # End of the Move / Act row
        showCancelButton = (self.mode != self.NOSELECTION)
        if showCancelButton:
          if self.mode == self.MOVEMODE:
            cancelButtonText = "Cancel"
          elif self.mode == self.ACTMODE:
            cancelButtonText = "Cancel"
          else:
            cancelButtonText = "Cancel"
          engine_button(cancelButtonText, clicked=ui.returns(self.CancelAction))
        ui.close() # End of the vbox
If people are unfamiliar, I can attach the rpy files. Really, I'm just looking for something to switch off the overlay layer.

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: UnitEngine and Overlay displayables

#2 Post by Showsni »

How about $ renpy.scene(layer='overlay')? I think that would clear the entire overlay layer.

The other thing to do is add a variable, like
$ showingoverlays = True
then to change each overlay so that it has an
if showingoverlays:
at the start. That way you can just toggle the variable showing overlays to turn them all on or off at once. Looks like the overlays there already have something similar, with an if self.show_buttons. If you set that to False, it shouldn't show anything underneath it.

DesertFox
Regular
Posts: 196
Joined: Sun Jul 28, 2013 1:29 pm
Completed: Over The Hills And Far Away
Projects: My Little Dictator
Organization: WarGirl Games
Contact:

Re: UnitEngine and Overlay displayables

#3 Post by DesertFox »

I've tried variations but it doesn't seem to work.

Might as well attach the coding. The issue needs to be tackled at its source now rather than in the script or main menu, since even loading a game means that the displays persist. I know that I need to turn off show_unit_info and show_buttons but how I do that outside of the battle engine, I'm not certain. Perhaps I need to create a new Mode? It's most likely an 'else' statement somewhere...

DesertFox
Regular
Posts: 196
Joined: Sun Jul 28, 2013 1:29 pm
Completed: Over The Hills And Far Away
Projects: My Little Dictator
Organization: WarGirl Games
Contact:

Re: UnitEngine and Overlay displayables

#4 Post by DesertFox »

Still can't work it out, although I've sorted some other aspects.

Tsapas
Regular
Posts: 69
Joined: Mon Oct 14, 2013 8:18 am
Contact:

Re: UnitEngine and Overlay displayables

#5 Post by Tsapas »

I've been trying this on and off to no avail since you posted it.
Was hard to nail down, partly because the Ren'Py version it's based on is old and partly because the whole UnitEngine/TileEngine is a spaghetti, making initial class instantiation with dummy arguments a nightmare.

Anyway, the first solution would be this:

Code: Select all

label start:
python:
    config.overlay_functions = []
Which would clear the whole overlay list, but it's bad practice to touch it outside init blocks.

So I ended up with this.

Code: Select all

label start:
python:
    for item in config.overlay_functions:
        item_name = item.__name__
        if 'overlay_ShowButtons' in item_name:
            config.overlay_functions.remove(item)
    for item in config.overlay_functions:
        item_name = item.__name__
        if 'overlay_ShowUnitInfo' in item_name:
            config.overlay_functions.remove(item) 
What it does is at the start of the game it goes over every function in the config.overlay_functions list, and if the function's name contains either 'overlay_ShowButtons' or 'overlay_ShowUnitInfo', it removes that function from the list.
Tried it in the UnitEngine demo provided in the wiki and works as intended. Going to the main menu mid-battle and then starting a new game removes those battle info layers. It *should* work out-of-the-box for your implementation as well, provided the functions are similarly named.

(Don't ask me why it needs 2 separate for loops to clear both though. Tried every possible way to do it in a single loop but it always removed 1 layer, not both. Unless I made a very basic error in the single loop try).
DesertFox wrote:...since even loading a game means that the displays persist.
For that, you can duplicate the above piece of code in a label after_load: block (which gets called when a load occurs before control is passed to the player), or for less code mess, define that code as a function, and call it at start and after_load.

DesertFox
Regular
Posts: 196
Joined: Sun Jul 28, 2013 1:29 pm
Completed: Over The Hills And Far Away
Projects: My Little Dictator
Organization: WarGirl Games
Contact:

Re: UnitEngine and Overlay displayables

#6 Post by DesertFox »

This is perfect. Thank you so much for working that out.

Yeah, the UnitEngine demo is a bit spaghetti and a little outdated. Still useful though, it'll just require a bit of work.

Post Reply

Who is online

Users browsing this forum: No registered users