Link to mapbutton for multiple maps

DoctorPervic

Well-Known Member
Game Developer
Aug 13, 2019
1,075
4,421
So I have a galaxy map that has 5 parts.

In my code

Code:
screen MapButton():
    imagebutton:
        xalign 0.98
        yalign 0.03
        idle "images/mapbutton.png"

        action Show("galaxymap1"), Hide("MapButton")

screen galaxymap1():
    modal True

    imagebutton:
        idle "images/maps/galaxymap1.jpg"
        action Hide("galaxymap1"), Show("MapButton")

my mapbutton is linked to the first map. but I would like to be able to display the other 4 maps throughout the game, but am wondering if I can use the same mapbutton or would I need to make a copy of the mapbutton 5 more times, and link each map button to a different galaxymap image

I can do it that way, but I was wondering if there a better way to do it without making so many copies of the mappbutton.png file

Any help is greatly apriciated. Thank you so much.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,583
2,224
It would depends on how your game deals with the universe in general.

You seem to be implying that as the game progresses, you move to a new area of the galaxy (or maybe a new galaxy) and are unable to travel back to previous galaxies.

If that's the case, you might consider something like:

Python:
default current_galaxy = 1

screen MapButton():
    imagebutton:
        xalign 0.98
        yalign 0.03
        idle "images/mapbutton.png"

        action Show("galaxymap{}".format(current_galaxy)), Hide("MapButton")

screen galaxymap1():
    modal True

    imagebutton:
        idle "images/maps/galaxymap1.jpg"
        action [ Hide("galaxymap1"), Show("MapButton") ]

screen galaxymap2():
    modal True

    imagebutton:
        idle "images/maps/galaxymap2.jpg"
        action [ Hide("galaxymap2"), Show("MapButton") ]

# etc, etc.

Where the "galaxymap{}".format(current_galaxy) will concatenate the string and the number together to create "galaxymap1" or "galaxymap2", etc. depending on the value of current_galaxy.

However, if you CAN travel back to previous galaxies/areas - then you might want to add links (imagebuttons) to each of the galaxy maps with buttons that can show the other maps too.

Something that catches my eye (and it's not necessarily wrong) is that you seem to have made your entire map an imagebutton which returns back to the "main"? map.

I'd expect to see something more like:

Python:
screen galaxymap1():
    modal True

    add images/maps/galaxymap1.jpg"

    textbutton ("Return") action [ Hide("galaxymap1"), Show("MapButton") ]

If you DO decide to add imagebuttons to other galaxies on the current galaxy map, then you don't automatically need to make those buttons active. You could code something like:

Python:
default current_galaxy = 1
default max_galaxy = 2

screen MapButton():
    imagebutton:
        xalign 0.98
        yalign 0.03
        idle "images/mapbutton.png"

        action Show("galaxymap{}".format(current_galaxy)), Hide("MapButton")

screen galaxymap1():
    modal True

    add images/maps/galaxymap1.jpg"

    imagebutton: # current galaxy, so show the button - but don't actually use it
        pos (10, 150)
        idle ("galaxy1_button_idle.png")
        focus_mask True
        action  NullAction()

    if max_galaxy >= 2: # if galaxy 2 unlocked, use "real" button using both idle and hover images (using auto)
        imagebutton:
            pos (10, 250)
            auto ("galaxy2_button_%s.png")
            focus_mask True
            action  [ Hide("galaxymap1"), Show("galaxymap2") ]
    else:
        imagebutton: # otherwise show dummy button using only idle image.
            pos (10, 250)
            idle ("galaxy2_button_idle.png")
            focus_mask True
            action  NullAction()

    if max_galaxy >= 3:
        imagebutton:
            pos (10, 350)
            auto ("galaxy3_button_%s.png")
            focus_mask True
            action  [ Hide("galaxymap1"), Show("galaxymap3") ]
    else:
        imagebutton:
            pos (10, 350)
            idle ("galaxy3_button_idle.png")
            focus_mask True
            action  NullAction()

    # etc, etc.

    textbutton ("Return") action [ Hide("galaxymap1"), Show("MapButton") ]
# etc, etc.

In my imagined code, current_galaxy is where you are and max_galaxy is the highest unlocked galaxy currently available.


... and while I'm thinking about it... even the use of Show(): feels off. You appear to be jumping between separate full screen maps (difficult to tell without seeing the actual maps) - and therefore needing to Show/Hide screens as you move around (also your use of modal True. But that is what call screen() and action Call() are for. Where the action effectively ends the screen and hides it before executing the action(s).
 
Last edited:
  • Like
Reactions: DoctorPervic

DoctorPervic

Well-Known Member
Game Developer
Aug 13, 2019
1,075
4,421
WOW thank you so much for all that helpful information.

About my galaxy map.
Here it is.

galaxymap1.jpg

Basically, I want to show this map at the beginning of the game. and then I want to show other maps, that extend your ship's course through this galaxy.

for example. the next map I would show would be.

galaxymap2.jpg

Because that is where the player will go to next. Or if the player chooses a different choice, then I want to be able to show a different map.

and I would like to be able to use only one map button to display each map if I can.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,382
15,291
Python:
default current_galaxy = 1

screen MapButton():
    imagebutton:
        xalign 0.98
        yalign 0.03
        idle "images/mapbutton.png"

        action Show("galaxymap{}".format(current_galaxy)), Hide("MapButton")

screen galaxymap1():
    modal True

    imagebutton:
        idle "images/maps/galaxymap1.jpg"
        action [ Hide("galaxymap1"), Show("MapButton") ]

screen galaxymap2():
    modal True

    imagebutton:
        idle "images/maps/galaxymap2.jpg"
        action [ Hide("galaxymap2"), Show("MapButton") ]

# etc, etc.
Good thinking, but you stuck to the question and then missed a better approach.
You tried to link "MapButton" to one of the many galaxy screens, what correspond to the question. But you could have put the dynamism directly in the galaxy screen, and so have only one screen for all of them :

Code:
default current_galaxy = 1

screen MapButton():
    imagebutton:
        xalign 0.98
        yalign 0.03
        idle "images/mapbutton.png"

        action Show("galaxymap"), Hide("MapButton")

screen galaxymap():
    modal True

    imagebutton:
        idle "images/maps/galaxymap{}.jpg".format(current_galaxy)
        action [ Hide("galaxymap"), Show("MapButton") ]

and I would like to be able to use only one map button to display each map if I can.
From what I get, the only change is the blue squares, then why not add them instead of changing the whole map each time ?
You can have a screen with only those blue squares, and everything else at 100% transparency. Then your galaxy screen would looks like :

Python:
screen galaxymap1():
    modal True

    # Display the actual map, without blue squares, as background
    add "images/maps/galaxymap1.jpg"

    #  Then display the blue squares on top of it, according
    # to the actual context of the game.
    if some condition:
        add "images/maps/path/thisPath.jpg"
    elif some other condition:
        add "images/maps/path/thatPath.jpg"
    [...]

    # Button to close the map
    imagebutton:
        xalign 0.9
        yalign 0.0
        idle "images/maps/closeButton.jpg"
        action [ Hide("galaxymap1"), Show("MapButton") ]
The same can works if the "influence zone" (the redish ovals) can change. Just have an image, the size of the oval, where the red oval is at 50% transparency and everything else at 100% :

Python:
screen galaxymap1():
    modal True

    # Display the actual map, without blue squares, as background
    add "images/maps/galaxymap1.jpg"

    # Display the "influence zones".
    if kortexPrime:
        add "images/maps/influenceZones.jpg" pos( 356, 852 )
    if newEarthII:
        add "images/maps/influenceZones.jpg" pos( 0, 810 )
    [...]

    #  Then display the blue squares on top of it, according
    # to the actual context of the game.
    if some condition:
        add "images/maps/path/thisPath.jpg"
    elif some other condition:
        add "images/maps/path/thatPath.jpg"
    [...]

    # Button to close the map
    imagebutton:
        xalign 0.9
        yalign 0.0
        idle "images/maps/closeButton.jpg"
        action [ Hide("galaxymap1"), Show("MapButton") ]
And this way you can even add new planets and all ; once again with an image the size of the planets, and everything that isn't the planet at 100% transparency.

If you fear that the code for the screen become too big and hard to maintain, you can split it :

Python:
screen galaxymap1():
    modal True

    # Display the actual map, without blue squares, as background
    add "images/maps/galaxymap1.jpg"

    # Add the screen for the planets
    use galaxyMap1Planets

    # Add the screen for the "influence zones"
    use galaxyMap1Zones

    # Add the screen for the blue squares
    use galaxyMap1Path

    # Button to close the map
    imagebutton:
        xalign 0.9
        yalign 0.0
        idle "images/maps/closeButton.jpg"
        action [ Hide("galaxymap1"), Show("MapButton") ]

screen galaxyMap1Planets():

    if kortexPrimeKnown is True:
        add "images/maps/planets/kortexPrime.jpg" pos( 480, 980 )
    if newEarthIIKnown is True:
        add "images/maps/planets/newEarthII.jpg" pos( 70, 940 )
    [...]

screen galaxyMap1Zones():

    # Display the "influence zones".
    if kortexPrimeInfluence is True:
        add "images/maps/influenceZones.jpg" pos( 356, 852 )
    if newEarthIIInfluence is True:
        add "images/maps/influenceZones.jpg" pos( 0, 810 )
[...]


screen galaxyMap1Path():

    #  Then display the blue squares on top of it, according
    # to the actual context of the game.
    if some condition:
        add "images/maps/path/thisPath.jpg"
    elif some other condition:
        add "images/maps/path/thatPath.jpg"
    [...]
And finally because of this, you can filter what's shown on the screen:
Python:
screen galaxymap1():
    modal True

    # Display the actual map, without blue squares, as background
    add "images/maps/galaxymap1.jpg"

    # Add the screen for the planets, only if asked to
    showif showPlanets is True:
        use galaxyMap1Planets

    # Add the screen for the "influence zones", only if asked to
    showif showZones is True:
        use galaxyMap1Zones

    # Add the screen for the blue squares, only if asked to
    showif showPath is True:
        use galaxyMap1Path

    # Button to close the map
    imagebutton:
        xalign 0.9
        yalign 0.0
        idle "images/maps/closeButton.jpg"
        action [ Hide("galaxymap1"), Show("MapButton") ]

Finally, but it demand more works on the coding part, you don't necessarily need to effectively have an image for each path. You can just have a single image that is just one of those blue square:
Python:
# Position of the blue squares
define pathKortexPrime2Grarth = [ ( 512, 952 ), ( 538, 900 ), (560, 846), [...] ]

screen galaxyMap1Path():

    if some condition:
        for p in pathKortexPrime2Grath:
            add "images/maps/blueSquare.jpg" pos p
    if some other condition:
        for p in pathSomewhere2SomewhereElse:
            add "images/maps/blueSquare.jpg" pos p
    [...]
In your example it's apparently the path from Kortex Prime to Grath that is continued, so you can have :
Python:
# Position of the blue squares
# first half
define pathKortexPrime2Grarth1 = [ ( 512, 952 ), ( 538, 900 ), (560, 846), [...] ]
# second half
define pathKortexPrime2Grarth2 = [ ( 696, 478 ), ( 708, 426 ), (728, 372 ), [...] ]

screen galaxyMap1Path():

    if some condition:
        for p in pathKortexPrime2Grath1:
            add "images/maps/blueSquare.jpg" pos p
    if some condition and some other:
        for p in pathKortexPrime2Grath2:
            add "images/maps/blueSquare.jpg" pos p
    if some other condition:
        for p in pathSomewhere2SomewhereElse:
            add "images/maps/blueSquare.jpg" pos p
    [...]
 
  • Like
Reactions: 79flavors

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,583
2,224
[...] if the player chooses a different choice, then I want to be able to show a different map.

If I'm following it correctly so far... there is actually only 1 "map" as such - the "Qualaxian Star Map".

However, you want to show different versions of it, depending on which planets have been unlocked?
... and the impression I get is that planets will be unlocked in a sequence - following the story arc of the game.

So something like Kortex Prime -> Grarth M29K - > Clitoria -> Qualax Nebula -> Selice II -> New Earth II.

Or can the player unlock them in any sequence they like?

Also... based on your images. Can I assume that the first image is galaxymap1() and the second image is galaxymap2() ?
Or am I missing something, like the first image is actually MapButton() ?

Finally... are you actually using the map to allow the player to pick where to go? (an interactive navigation map). Or is it just a picture as a reminder of where the player is up to?
 

DoctorPervic

Well-Known Member
Game Developer
Aug 13, 2019
1,075
4,421
If I'm following it correctly so far... there is actually only 1 "map" as such - the "Qualaxian Star Map".

However, you want to show different versions of it, depending on which planets have been unlocked?
... and the impression I get is that planets will be unlocked in a sequence - following the story arc of the game.

So something like Kortex Prime -> Grarth M29K - > Clitoria -> Qualax Nebula -> Selice II -> New Earth II.

Or can the player unlock them in any sequence they like?

Also... based on your images. Can I assume that the first image is galaxymap1() and the second image is galaxymap2() ?
Or am I missing something, like the first image is actually MapButton() ?

Finally... are you actually using the map to allow the player to pick where to go? (an interactive navigation map). Or is it just a picture as a reminder of where the player is up to?
question 1. YES only 1 map. planets will be unlocked in a sequence - following the story arc of the game.

question 2. YES first image is galaxymap1, then galaxymap2, galaxymap3, galaxymap4 ect...

question 3. just a picture as a reminder of where the player is up to. So you want to get an idea on where you are from where you have been.
 

DoctorPervic

Well-Known Member
Game Developer
Aug 13, 2019
1,075
4,421
Thank you all for all of your wonderful code help. f95 is the best website I have ever been to for help like this. You are all so great, Thank you all very much. I will try some of your examples.