The issue with using the code as I gave it to you is that it doesn't solve the original problem (renpy.variant having "medium" instead of "small", most likely) on its own. The code in my previous post would be a better replacement if you just want all mobile devices to use the "small" variant, but I'll post some more code and details on the layout swapping.
First, we have the gui.rpy code from before, which needs to be in init python at level -2:
Code: Select all
## phones and tablets can change orientation
if renpy.variant("mobile"):
config.has_quicksave = False
if persistent.mobile_layout == None:
if renpy.variant("small"):
persistent.mobile_layout = "small"
else:
persistent.mobile_layout = "big"
if persistent.mobile_layout == "small":
config.variants.append("small")
else:
if renpy.variant("small"):
config.variants.remove("small")
What this code is doing:
- If we're on a mobile device, disable quicksaves.
- If we're on a mobile device and the layout is not set, we set the default to what Ren'Py thinks we are.
- If we're on a mobile device and the layout is set to small, force the game to use the "small" variant.Otherwise, make sure to remove the "small" variant.
(The gui.init should be whatever you want the base resolution to be. The stuff in the code from before is specific to my game, which has different orientations based on the layout selected.)
Next, I have a function defined in the screens.rpy, but as long as it's in an init python at level -1 it should work the same:
Code: Select all
init python:
def toggle_layout():
if (persistent.mobile_layout == "small"):
persistent.mobile_layout = "big"
else:
persistent.mobile_layout = "small"
renpy.quit(relaunch=True)
This mostly just toggles the layout value, then forces the game to restart. (Styles don't refresh well mid-game, so restarting is how we clear styles here.)
Then, within the screens.rpy definition for the main_menu screen, I have this:
Code: Select all
style_prefix "main_menu"
## above is mostly default
if renpy.variant("mobile"):
button:
if (persistent.mobile_layout == "big"):
xsize 100 ysize 100
align (1.00,0.0)
text "↕" align (0.5, 0.5) style "main_menu_button_text" size 75
else:
xsize 75 ysize 75
align (0.5,0.91)
text "↔" align (0.5, 0.5) style "main_menu_button_text" size 75
action Confirm(_("Change the game layout?\nThis will close the game, and may require several restarts."), Function(toggle_layout, _update_screens=True))
## continue to navigation buttons and such
What this code does is add a button to the menu if we're playing on a mobile device. I made it different based on the current layout, but you can probably put it in one place if the actual layout doesn't change much. (For me, portrait <-> landscape meant I needed to move it a bit for each variant.) The "Confirm" action basically prompts the player using the text given as a warning before they accept, then only runs the toggle function if they agree. The button text and confirm text may need to be altered for your purposes, since this is directly from my game (where, again, the layout is pretty different between the two versions).
So, that's the way I've handled the issue with phones that count as "medium" devices in Ren'Py. And as I mentioned before, my previous post has the simpler option that forces medium phones and tablets to use the small phone variants. Hopefully one of these options helps in figuring out what to do here.
Edit: For the variants check, the issue is that you seem to be using the function as if it were the variable. To elaborate:
renpy.variant(string) - This returns "True" if the string given is in the variant list, or otherwise returns False. Example:
Code: Select all
if (renpy.variant("small")): ## or if (renpy.variant("small") == True)
pass ## blank code
config.variants (where the variants are actually stored) is a Python list, which means equality checks (==) with strings won't work. Instead, you'd have to do something like:
Code: Select all
if "small" in config.variants:
$ someVar = "small"
(If you simply typed config.variants into the console, you'd get a list notation, such as: ["small", "mobile", "touch"] or something like that.)
Personally, I'd probably use a screen text/label to check the variants on the phone before just removing the text element, but for now here are two less coding-intensive ways:
Code: Select all
label variantcheck: ## making a renpy label
$ listver = str(config.variants) ## string of the list of variants
"Variants are: [listver]"
for v in config.variants: ## for loop through the variant list, then output them line-by-line
"Running [v] variant"
After you have this, just call or jump to it. Let me know if it doesn't work... I only tested the first one fully.