Changing mouse pointer midgame.

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Alex
Lemma-Class Veteran
Posts: 2364
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Changing mouse pointer midgame.

#1 Post by Alex » Sat Nov 03, 2012 11:37 am

It is possible to set custom mouse pointer using config.mouse, but changing config variables midgame won't be stored. To store changes, one can make a screen (let's say "cursor_changer"), that will constantly change config.mouse variable according to an ordinary variable value. This will work as long as this ordinary variable value can be properly stored.
So after making such screen it is neccessary to use it in main menu screen, save/load, preferences, yesno_prompt screens. Also, right in the beginning of start label one must set the value for this ordinary variable and show "cursor_changer" screen.

Code: Select all

screen cursor_changer:
    ######################################
    #
    # The green one for "pref", "save" and "load"
    if not renpy.get_screen("yesno_prompt") and ( renpy.get_screen("preferences") or renpy.get_screen("save") or renpy.get_screen("load") ):
        $ config.mouse = {"default" :[("cur1.png", 0, 0)]}
    
    # The red one for main menu
    elif renpy.get_screen("main_menu"):
        $ config.mouse = {"default" :[("cur2.png", 0, 0)]}
        
    # The grey one - when Ren'Py asks for confirmation
    elif renpy.get_screen("yesno_prompt"):
        $ config.mouse = {"default" :[("cur0.png", 0, 0)]}
    
    # This will change cursor in game
    elif cur_new != "def_cur":
        $ config.mouse = {"default" :[cur_new]}
    else:
        $ config.mouse = None     # The default value, that makes Ren'Py to use system cursor
    #
    ######################################

Code: Select all

screen main_menu:
    use cursor_changer

Code: Select all

screen save:

    # This ensures that any other menu screen is replaced.
    tag menu

    use navigation
    use cursor_changer
    use file_picker

screen load:

    # This ensures that any other menu screen is replaced.
    tag menu

    use navigation
    use cursor_changer
    use file_picker

Code: Select all

screen preferences:
    use cursor_changer

Code: Select all

screen yesno_prompt:
    use cursor_changer

Code: Select all

define e = Character('Eileen', color="#c8ffc8")

###################################################
# The game starts here.
label start:

    $ cur_new = ( "cur0.png", 0, 0)    # At first - we'll set the default value
    show screen cursor_changer         # Then - will show our screen, that will change the cursor during the game according to "cur_new" variable value
    e "Hi! Now we see grey cursor"
    $ cur_new = ("cur1.png", 0, 0)     # Changing the "cur_new" value will change the cursor
    e "Oh, it became green. That cursor change can be properly saved and restored from save, 'cause the cursor outlook is dinamically changing according to \"cur_new\" variable value - everything will work ok as long as we can save \"cur_new\"'s value."
    e "Rollback works too."
    $ cur_new = ( "cur2.png", 0, 0)
    e "And now - it's red."
    $ cur_new = "def_cur"
    e "We are able to use the default (system) cursor."
Attachments
cur0.png
cur0.png (1.35 KiB) Viewed 7702 times
cur1.png
cur1.png (3.87 KiB) Viewed 7702 times
cur2.png
cur2.png (3.96 KiB) Viewed 7702 times

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Changing mouse pointer midgame.

#2 Post by UselessCoder » Fri Apr 22, 2016 11:00 am

hi, congrats on this tutorial...The thing is, I just need the cursor to change once a specific label is reached and when that label is left, reverting back to the default $config.mouse= None
Is that possibile in renpy?

Thanks!

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Changing mouse pointer midgame.

#3 Post by xela » Fri Apr 22, 2016 11:23 am

UselessCoder wrote:hi, congrats on this tutorial...The thing is, I just need the cursor to change once a specific label is reached and when that label is left, reverting back to the default $config.mouse= None
Is that possibile in renpy?

Thanks!
This: viewtopic.php?f=8&t=37403&hilit=mouse
Like what we're doing? Support us at:
Image

UselessCoder
Regular
Posts: 96
Joined: Sun Jan 24, 2016 6:51 am
Projects: undisclosed...
Contact:

Re: Changing mouse pointer midgame.

#4 Post by UselessCoder » Fri Apr 22, 2016 11:30 am

xela wrote:
UselessCoder wrote:hi, congrats on this tutorial...The thing is, I just need the cursor to change once a specific label is reached and when that label is left, reverting back to the default $config.mouse= None
Is that possibile in renpy?

Thanks!
This: viewtopic.php?f=8&t=37403&hilit=mouse

You're a lifesaver Xela. Thanks!
Will I ever learn how to use "search" at some point...I always get everything but what I'm looking for. lol

kl7
Newbie
Posts: 13
Joined: Wed Jul 13, 2016 11:39 am
Contact:

Re: Changing mouse pointer midgame.

#5 Post by kl7 » Mon Jul 10, 2017 12:50 pm

I did all things like in this tutorial, but the cursor changes only for less than 1 sec and then returnes to default. Can anyone explain me why?

User avatar
Milkymalk
Miko-Class Veteran
Posts: 659
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Changing mouse pointer midgame.

#6 Post by Milkymalk » Mon Jul 10, 2017 7:09 pm

Doesn't work any more and was never supposed to work outside of init blocks.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Balanced
Newbie
Posts: 1
Joined: Sun Jul 22, 2018 6:36 pm
Contact:

Re: Changing mouse pointer midgame.

#7 Post by Balanced » Sun Jul 22, 2018 6:40 pm

Milkymalk wrote:
Mon Jul 10, 2017 7:09 pm
Doesn't work any more and was never supposed to work outside of init blocks.
I realize this is about a year old but can I have an explanation as to the purpose of this restriction? I was hoping to make a game similar to classic point and clicks where you can change the cursor to different actions, such as Look, Speak, Use, etc. with their own visual icons, and this update complete nullifies the capability to do that. It seems obtuse to have the cursor image restricted this way, and I can't get any other hack to work including ConditionSwitch which would seem like a fair compromise. Any tips as to where to look at underlying code to alter this behavior would be appreciated.

User avatar
Milkymalk
Miko-Class Veteran
Posts: 659
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Changing mouse pointer midgame.

#8 Post by Milkymalk » Fri Jul 27, 2018 7:57 am

No problem.

That method changes the cursor by changing a config variable, which can do all sorts of funny things outside of init blocks.

Funny thing is, I used this method:

Code: Select all

setattr(config, "mouse", {"default": [("mousecursor.png", 0, 0) ]})
And revert it with:

Code: Select all

setattr(config, "mouse", None)
Which works and basically does the same - but it's been a while since I did that and I can't really explain the difference. Also, it might not work for you because I actually replace the cursor with an empty image and display a screen that imitates the mouse cursor by following it around. Try around a little.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Post Reply

Who is online

Users browsing this forum: No registered users