There's a problem with the star system map.

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
User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

There's a problem with the star system map.

#1 Post by Andredron »

Hi everyone, I'm making a star system map of the star wars universe, while I was making the map I ran into some problems on them that I'm not quite getting around to solving. Please help me.

My code:

map_planet.rpy

Code: Select all

init python:
    # Initialize variables
    star_systems = {
        'tatooine': {
            'name': 'Tatooine',
            'x': 300,
            'y': 400,
            'description': 'A desert planet on the Outer Rim Territories.',
            'image': 'images/tatooine.png',
        },
        'alderaan': {
            'name': 'Alderaan',
            'x': 700,
            'y': 200,
            'description': 'A peaceful planet in the Core Worlds, destroyed by the Death Star.',
            'image': 'images/alderaan.png',
        },
        # Add more star systems here
    }


# Function to display star system information
    def display_system_info(system):
        renpy.show('system_info')
        renpy.system_name.text = system['name']
        renpy.system_description.text = system['description']
        renpy.system_image.image = system['image']

    # Load the click sound effect
    config.sound_volume = 0.5  # Adjust the volume as needed
    renpy.sound.load('click.ogg')

# Function to handle mouse-based navigation
    def star_map_scroll(ev):
        map_background = renpy.gui.interactables['map_background']
        x, y = ev.x - gui.center_x, ev.y - gui.center_y

        if ev.type == 'axismove' and ev.axis == 'mouse_scroll':
            scroll_amount = ev.value * 0.1
            map_background.xpos += scroll_amount * x
            map_background.ypos += scroll_amount * y

        elif ev.type == 'button_release' and ev.button == 1:  # Middle mouse button
            map_background.xpos -= x * 0.1
            map_background.ypos -= y * 0.1

    def display_system_info(system):
       renpy.show('system_info')
       renpy.system_name.text = system['name']
       renpy.system_description.text = system['description']
       renpy.system_image.image = system['image']

       if system['name'] == 'Tatooine':
          renpy.jump('tatooine_events')
       elif system['name'] == 'Alderaan':
          renpy.jump('alderaan_events')
      # Add more star systems here
      
 
event_planet.rpy

Code: Select all

label tatooine_events:
    # Event code for Tatooine

label alderaan_events:
    # Event code for Alderaan
screen.rpy

Code: Select all

screen star_map:
    tag menu
    vbox:
        text "Star Wars Galaxy Map"
        scene:
            # Replace 'background.png' with your own background image
            image "background.png" id "map_background"
           # Add star systems
            for system in star_systems.values():
                imagebutton:
                    xalign 0.5 yalign 0.5
                    xpos system['x'] ypos system['y']
                    idle system['image']
                    action [Function(display_system_info, system), Play('click.ogg')]
                    
            # Add trade routes (example)
            # image "images/trade_route.png" xpos 300 ypos 400 zorder 1
            
            # Add mouse-based navigation
            imagebutton:
                idle "transparent.png"  # Use a transparent image for the hitbox
                xfill True yfill True
                action Function(star_map_scroll, ev)

        window hide vbox:
            text "System Information"
            text "[system_name]"
            text "[system_description]"
            textbutton "Close" action Return()

        window system_info:
            has vbox
            text "[system_name]" style 'bold'
            text "[system_description]"
            textbutton "Close" action Hide('system_info')


1) I can't seem to make a zoom in and zoom out button for the map, and it makes it very difficult to navigate the current map.

2) (Optional) create a search by name, for quick orientation by object.

3) (Optional) how to spell out in function(def) increase by 0.2, manually writing for each planet is a pain,

4) How to facilitate the labor translator to another language, info about each planet, of course you can completely copy the entire rpy file in the folder tl, but he is bound to somewhere that entering the translated information.

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: There's a problem with the star system map.

#2 Post by jeffster »

You use "renpy" namespace for your data:

Code: Select all

renpy.system_name.text
I think you shouldn't do that because it's a namespace for renpy engine, and you can accidentally break the engine.
Use "store" namespace instead:

Code: Select all

store.system_name.text
Also "display_system_info" is defined twice.
1) I can't seem to make a zoom in and zoom out button for the map, and it makes it very difficult to navigate the current map.
Maybe try something like transform with zooming - see example here:
https://renpy.org/doc/html/screens.html ... -statement
and set "zooming" as a variable of type float.
2) (Optional) create a search by name, for quick orientation by object.
Set an input field and when a value is entered, search for the name in the star_systems dict. If found, you could show a little screen at the position of that star, like a circle that would auto-hide in a few seconds by its own timer.

If you want to also center that star, I'm not sure how to move the screen but probably it should be set as draggable, and you could use "snap".
https://renpy.org/doc/html/drag_drop.html#Drag.snap
3) (Optional) how to spell out in function(def) increase by 0.2, manually writing for each planet is a pain,
I don't understand the question.
4) How to facilitate the labor translator to another language, info about each planet, of course you can completely copy the entire rpy file in the folder tl, but he is bound to somewhere that entering the translated information.
One (simple) way would be to use "_()" translation function in descriptions, though that would require setting the language before the game start.
Like this:

Code: Select all

'description': _('A peaceful planet in the Core Worlds, destroyed by the Death Star.'),
There may be other ways, see
https://renpy.org/doc/html/translation.html


User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: There's a problem with the star system map.

#4 Post by Andredron »

map_planet.rpy

Code: Select all

init python:
    # Initialize variables
    star_systems = {
        'tatooine': {
            'name': 'Tatooine',
            'x': 300,
            'y': 400,
            'description': 'A desert planet on the Outer Rim Territories.',
            'image': 'images/tatooine.png',
        },
        'alderaan': {
            'name': 'Alderaan',
            'x': 700,
            'y': 200,
            'description': 'A peaceful planet in the Core Worlds, destroyed by the Death Star.',
            'image': 'images/alderaan.png',
        },
        # Add more star systems here
    }
    zoom_level = 1.0  # New variable to store the current zoom level

    # Function to display star system information
    def display_system_info(system):
        renpy.show('system_info')
        store.system_name.text = system['name']
        store.system_description.text = system['description']
        store.system_image.image = system['image']

        if system['name'] == 'Tatooine':
            renpy.jump('tatooine_events')
        elif system['name'] == 'Alderaan':
            renpy.jump('alderaan_events')
        # Add more star systems here

    # Function to handle zooming in and out
    def update_zoom_level(factor):
        nonlocal zoom_level
        zoom_level *= factor
        map_background = renpy.gui.interactables['map_background']
        map_background.xscale = map_background.yscale = zoom_level

    # Load the click sound effect
    config.sound_volume = 0.5  # Adjust the volume as needed
    renpy.sound.load('click.ogg')

# Function to handle mouse-based navigation
    def star_map_scroll(ev):
        map_background = renpy.gui.interactables['map_background']
        x, y = ev.x - gui.center_x, ev.y - gui.center_y

        if ev.type == 'axismove' and ev.axis == 'mouse_scroll':
            scroll_amount = ev.value * 0.1
            map_background.xpos += scroll_amount * x
            map_background.ypos += scroll_amount * y

        elif ev.type == 'button_release' and ev.button == 1:  # Middle mouse button
            map_background.xpos -= x * 0.1
            map_background.ypos -= y * 0.1

screen.rpy

Code: Select all

screen star_map:
    tag menu
    vbox:
        text "Star Wars Galaxy Map"
        scene:
            # Replace 'background.png' with your own background image
            image "background.png" id "map_background"
            # Add star systems
            for system in star_systems.values():
                imagebutton:
                    xalign 0.5 yalign 0.5
                    xpos system['x'] ypos system['y']
                    idle system['image']
                    action [Function(display_system_info, system), Play('click.ogg')]

            # Add trade routes (example)
            # image "images/trade_route.png" xpos 300 ypos 400 zorder 1

            # Add mouse-based navigation
            imagebutton:
                idle "transparent.png"  # Use a transparent image for the hitbox
                xfill True yfill True
                action Function(star_map_scroll, ev)

        # Add zoom in and zoom out buttons
        hbox xalign 1.0:
            imagebutton:
                idle "images/zoom_in.png"
                action [Function(update_zoom_level, 1.1), Play('click.ogg')]
            imagebutton:
                idle "images/zoom_out.png"
                action [Function(update_zoom_level, 1 / 1.1), Play('click.ogg')]

        window hide vbox:
            text "System Information"
            text "[system_name]"
            text "[system_description]"
            textbutton "Close" action Return()

        window system_info:
            has vbox
            text "[system_name]" style 'bold'
            text "[system_description]"
            textbutton "Close" action Hide('system_info')

With magnification more or less figured out, it remains to do a search of the planet by text input

User avatar
m_from_space
Miko-Class Veteran
Posts: 975
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: There's a problem with the star system map.

#5 Post by m_from_space »

Andredron wrote: Tue Feb 27, 2024 5:56 am map_planet.rpy
[/code]
I don't know why this even works (does it?), but your screen contains faulty code:

- "scene" is not a valid statement for a screen, it's used in labels to clear the master layer
- "image" is not a valid statement for a screen, it's used for defining images, not displaying them; to display images in screens you should use "add"
- while a "window" is valid, there is no such thing as "window hide" as part of a screen
- what is "window system_info" doing? It should crash your game. Do you mean "use system_info" as in showing another screen within the star map?

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: There's a problem with the star system map.

#6 Post by jeffster »

Andredron wrote: Tue Feb 27, 2024 5:56 am With magnification more or less figured out, it remains to do a search of the planet by text input
The link that you mentioned has a suitable script for searching.

You also can search "on the fly", filtering star systems' names while user types, starting maybe from 3 symbols.
There's "changed" property of "input" that allows doing so:
https://www.renpy.org/dev-doc/html/screens.html#input

Here is a test script (function "search_fly" would be invoked every time the input value changes):

Code: Select all

default star_systems = {
        'tatooine': {
            'name': 'Tatooine',
            'x': 300,
            'y': 400,
            'description': 'A desert planet on the Outer Rim Territories.',
            'image': 'images/tatooine.png',
        },
        'alderaan': {
            'name': 'Alderaan',
            'x': 700,
            'y': 200,
            'description': 'A peaceful planet in the Core Worlds, destroyed by the Death Star.',
            'image': 'images/alderaan.png',
        },
    }
default filtered_names = []

init python:
    def search_fly(searching):
        if len(searching) > 2:
            store.filtered_names = [
                star_systems[x]['name'] for x in star_systems \
                if searching.casefold() in \
                renpy.translate_string(star_systems[x]['name']).casefold()]
            renpy.restart_interaction()

screen searched():
    input:
        default ""
        align (0.5, 0.0)
        changed search_fly

    vbox:
        align (1.0, 0.0)
        for n in filtered_names:
            textbutton n action Return(n)

label start:
    call screen searched
    "[_return]"
    $ del filtered_names[:]
    jump start
(Try to search Tatooine and Alderaan with any string of 3 or more symbols).

User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: There's a problem with the star system map.

#7 Post by Andredron »

m_from_space wrote: Tue Feb 27, 2024 7:08 am
Andredron wrote: Tue Feb 27, 2024 5:56 am map_planet.rpy
[/code]
I don't know why this even works (does it?), but your screen contains faulty code:

- "scene" is not a valid statement for a screen, it's used in labels to clear the master layer
- "image" is not a valid statement for a screen, it's used for defining images, not displaying them; to display images in screens you should use "add"
- while a "window" is valid, there is no such thing as "window hide" as part of a screen
- what is "window system_info" doing? It should crash your game. Do you mean "use system_info" as in showing another screen within the star map?
It shouldn't work now, as I'm writing from my phone on drafts at work, during the day I did what I did, as soon as I get home I'll make all the corrections and changes I made to finalize the code to a working state

map_planet.rpy

Code: Select all

init python:
    # Initialize variables
    star_systems = {
        'tatooine': {
            'name': 'Tatooine',
            'x': 300,
            'y': 400,
            'description': 'A desert planet on the Outer Rim Territories.',
            'image': 'images/tatooine.png',
            'label': 'tatooine_events'  # Add a new key for the label
        },
        'alderaan': {
            'name': 'Alderaan',
            'x': 700,
            'y': 200,
            'description': 'A peaceful planet in the Core Worlds, destroyed by the Death Star.',
            'image': 'images/alderaan.png',
            'label': 'alderaan_events'  # Add a new key for the label
        },
        # Add more star systems here
    }
    zoom_level = 1.0  # New variable to store the current zoom level

# Function to display star system information
    def display_system_info(system):
        renpy.show('system_info')
        store.system_name.text = system['name']
        store.system_description.text = system['description']
        store.system_image.image = system['image']

        if system['name'] == 'Tatooine':
            renpy.Jump(system['label'])  # Use Jump or Replay instead of jump
        elif system['name'] == 'Alderaan':
            renpy.Jump(system['label'])  # Use Jump or Replay instead of jump
        # Add more star systems here


    # Function to handle zooming in and out
    def update_zoom_level(factor):
        nonlocal zoom_level
        zoom_level *= factor
        map_background = renpy.gui.interactables['map_background']
        map_background.xscale = map_background.yscale = zoom_level

    # Load the click sound effect
    config.sound_volume = 0.5  # Adjust the volume as needed
    renpy.sound.load('click.ogg')

# Function to handle mouse-based navigation
    def star_map_scroll(ev):
        map_background = renpy.gui.interactables['map_background']
        x, y = ev.x - gui.center_x, ev.y - gui.center_y

        if ev.type == 'axismove' and ev.axis == 'mouse_scroll':
            scroll_amount = ev.value * 0.1
            map_background.xpos += scroll_amount * x
            map_background.ypos += scroll_amount * y

        elif ev.type == 'button_release' and ev.button == 1:  # Middle mouse button
            map_background.xpos -= x * 0.1
            map_background.ypos -= y * 0.1


screen.rpy

Code: Select all

screen star_map:
    tag menu
    vbox:
        text "Star Wars Galaxy Map"
        add:
            # Replace 'background.png' with your own background image
            add "background.png" id "map_background"
            # Add star systems
            for system in star_systems.values():
                imagebutton:
                    xalign 0.5 yalign 0.5
                    xpos system['x'] ypos system['y']
                    idle system['image']
                    action [Function(display_system_info, system), Play('click.ogg')]

            # Add trade routes (example)
            # add "images/trade_route.png" xpos 300 ypos 400 zorder 1

            # Add mouse-based navigation
            imagebutton:
                idle "transparent.png"  # Use a transparent image for the hitbox
                xfill True yfill True
                action Function(star_map_scroll, ev)

        # Add zoom in and zoom out buttons
        hbox xalign 1.0:
            imagebutton:
                idle "images/zoom_in.png"
                action [Function(update_zoom_level, 1.1), Play('click.ogg')]
            imagebutton:
                idle "images/zoom_out.png"
                action [Function(update_zoom_level, 1 / 1.1), Play('click.ogg')]

        window hidden vbox:
            text "System Information"
            text "[system_name]"
            text "[system_description]"
            textbutton "Close" action Return()

screen system_info:
    has vbox
    text "[system_name]" style 'bold'
    text "[system_description]"
    textbutton "Close" action Hide('system_info')
    
    
screen filtered_search:
    default search = ""
    default input_search = ScreenVariableInputValue("search")

    default star_system_list = renpy.python.star_systems.values()
    default image_list = [system['image'] for system in star_system_list]

    input:
        value input_search
        xalign 0.5 yalign 0.0

    vbox:
        xalign 0.5 ypos 0.1
        for i, system in enumerate(star_system_list):
            if search.casefold() in system['name'].casefold():
                hbox:
                    imagebutton:
                        idle Transform(image_list[i], matrixcolor=SaturationMatrix(0))
                        hover image_list[i]
                        action Jump(system['label'])  # Use Jump or Replay
                    label system['name'] yalign 0.5


Post Reply

Who is online

Users browsing this forum: decocloud, Google [Bot], Li yuanlin