# Hide all character images (not chibi)
label hide_characters:
    hide hermione_main
    hide luna_main
    hide cho_main
    hide astoria_main
    hide susan_main
    hide tonks_main
    hide snape_main
    hide screen genie_main
    # Do not add transitions. Use one after return.
    return

label hide_screens:
    # Remove all displayables on layer 'screens'
    $ renpy.scene("screens")
    return

label update_interface_color(color=None):
    if color in ["gold", "gray"]:
        $ interface_color = color
    elif game.daytime:
        $ interface_color = "gold"
    else:
        $ interface_color = "gray"

    return

label stop_sound_effects:
    stop bg_sounds fadeout 0.5
    stop weather fadeout 0.5
    return

# Reset menu
label reset_menu_position:

    $ menu_x = 0.5
    $ menu_y = 0.6

    return

label bld(action=None):
    if action == "hide":
        hide screen bld1
    else:
        show screen bld1
    with d3

    return

label blktone:
    show screen bld1 # blktone looks stupid without bld1
    show screen blktone
    with d5

    return

label hide_blktone:
    hide screen blktone
    with d5

    return

label blktone_top:
    show screen bld1 # blktone looks stupid without bld1
    show screen blktone # Has higher zorder than normal blktone
    with d5

    return

label hide_blktone_top:
    hide screen blktone
    with d5

    return

label blkfade:
    hide screen bld1
    hide screen blktone
    show screen blkfade
    with d5
    pause.2

    return

label hide_blkfade:
    hide screen blkfade
    with d5

    return

label ctc:
    show screen ctc
    with d3
    pause
    hide screen ctc
    with d1

    return

label play_sound(sound=""):

    # Objects
    if sound in ["knock", "knocking"]: # knocking
        $ renpy.play('sounds/knocking.ogg')
    elif sound in ["knock2", "knocking2"]: # knocking
        $ renpy.play('sounds/knocking2.ogg')
    elif sound == "door":
        $ renpy.play('sounds/door.ogg')
    elif sound in ["lock","unlock"]: # lock
        $ renpy.play('sounds/09_lock.ogg')
    elif sound in ["desk","climb_desk"]: # climb_desk
        $ renpy.play('sounds/08_hop_on_desk.ogg')
    elif sound == "owl":
        play sound "sounds/owl.ogg"

    # Ambience
    elif sound == "applause":
        $ renpy.play('sounds/applause01.ogg')

    # Affection
    elif sound in ["gulp", "gulping", "swallow", "swallowing"]: # gulp
        $ renpy.play('sounds/gulp.ogg')
    elif sound == "slap_1":
        $ renpy.play('sounds/slap.ogg')
    elif sound == "slap": # slap_2
        $ renpy.play('sounds/slap_02.ogg')
    elif sound == "slap_3":
        $ renpy.play('sounds/slap_03.ogg')
    elif sound in ["spit", "spitting"]: # spit
        $ renpy.play('sounds/spit.ogg')
    elif sound in ["kick", "kicking", "bump"]: # kick
        $ renpy.play('sounds/kick.ogg')
    elif sound in ["kiss", "kissing"]: # kiss
        $ renpy.play('sounds/kiss.ogg')
    elif sound in ["insert", "inserting", "goo"]: # insert
        $ renpy.play('sounds/gltch.ogg')
    elif sound == "plop":
        $ renpy.play('sounds/plop.ogg')
    elif sound in ["pop", "bottle"]: # pop
        $ renpy.play('sounds/bottle.ogg')
    elif sound == "snore":
        $ renpy.play('sounds/snore1.ogg')
    elif sound == "snore_quiet":
        $ renpy.play('sounds/snore2.ogg')
    elif sound == "snore_loud":
        $ renpy.play('sounds/snore3.ogg')
    elif sound == "giggle":
        $ renpy.sound.play("sounds/giggle2_loud.ogg")
    elif sound == "gasp":
        $ renpy.sound.play("sounds/MaleGasp.ogg")

    # Magic
    elif sound == "spell":
        $ renpy.play('sounds/magic2.ogg')
    elif sound == "morph":
        $ renpy.sound.play("sounds/magic3.ogg")
    elif sound == "magic":
        $ renpy.play('sounds/magic4.ogg')

    # Movement
    elif sound == "footsteps":
        $ renpy.play('sounds/footsteps.ogg')
    elif sound == "walking":
        $ renpy.play('sounds/run_04.ogg')
    elif sound == "running":
        $ renpy.play('sounds/run_03.ogg')
    elif sound == "sprinting":
        $ renpy.play('sounds/run_02.ogg')
    elif sound in ["walking_on_grass", "grass"]: # walking_grass
        $ renpy.play('sounds/steps_grass.ogg')

    # Interface
    elif sound == "scroll":
        $ renpy.play('sounds/scroll.ogg')
    elif sound in ["equip", "equip_inventory", "cloth"]: # equip
        $ renpy.play('sounds/cloth_sound.ogg')

    # Misc
    elif sound == "scratch":
        $ renpy.play('sounds/scratch.ogg')
    elif sound == "shatter":
        $ renpy.play('sounds/glass_shatter.ogg')
    elif sound in ["glass_break","glass"]:
        $ renpy.play('sounds/glass_break.ogg')

    # Undefined sounds fallback
    elif renpy.loadable("sounds/{}.ogg".format(sound)):
        $ renpy.play("sounds/{}.ogg".format(sound))

    return

#TODO One keyword per theme (maybe define everything in a dictionary to simplify code further?)
label play_music(music="", fadein=1.0, fadeout=1.0):
    if music == "stop":
        stop music fadeout fadeout
        return


    # Character Music
    if music in ["snape", "dark_fog"]: # snape
        play music "music/Dark Fog.ogg" fadein fadein fadeout fadeout if_changed
    elif music in ["hermione", "chipper_doodle"]: # hermione
        play music "music/Chipper Doodle v2.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "cho":
        play music "music/fuzzball-parade-by-kevin-macleod.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "astoria":
        play music "music/KMcL_OpenThoseBrightEyes.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "susan":
        play music "music/teddy-bear-waltz-by-kevin-macleod.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "tonks":
        play music "music/scheming-weasel-slower-version-by-kevin-macleod.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "luna":
        play music "music/wallpaper-by-kevin-macleod.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "playful_tension":
        play music "music/(Orchestral) Playful Tension by Shadow16nh.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "silly":
        play music "music/silly_fun_loop.ogg" fadein fadein fadeout fadeout if_changed

    # Store Music
    elif music == "weasley_store":
        play music "music/weasley_store.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "clothing_store":
        play music "music/clothing_store.ogg" fadein fadein fadeout fadeout if_changed

    # Background Music
    elif music == "day":
        play music "music/Brittle Rille.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "night":
        play music "music/Music for Manatees.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "night_outside":
        play music "sounds/night.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "jazz":
        play music "sounds/jazz take 2.ogg" fadein fadein fadeout fadeout if_changed

    # Interface
    elif music == "wardrobe":
        play music "music/Spring_In_My_Step.ogg" fadein fadein fadeout fadeout if_changed

    # Misc
    elif music == "hitman":
        play music "music/hitman.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "cardgame":
        play music "music/Juhani_Junkala.ogg" fadein fadein fadeout fadeout if_changed
    elif music in ["sad","grape_soda"]: # sad
        play music "music/GrapeSodaIsFuckingRawbyjrayteam6.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "anguish":
        play music "music/Anguish.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "trance":
        play music "music/Under-the-Radar by PhobyAk.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "despair":
        play music "music/Despair_by_erenik.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "agenda":
        play music "music/hidden-agenda-by-kevin-macleod.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "intro":
        play music "music/the-chamber-by-kevin-macleod.ogg" fadein fadein fadeout fadeout if_changed
    elif music == "snape_office":
        play music "music/the-other-side-of-the-door-by-kevin-macleod-from-filmmusic-io.ogg" fadein fadein fadeout fadeout if_changed

    # Fallback
    else:
        python:
            try:
                renpy.music.play(filenames="music/"+music+".ogg", channel="music", loop=True, fadeout=1.0, fadein=1.0)
            except IOError:
                if config.developer:
                    raise Exception("Music not found: {}".format(music))
    return

# Play day/night theme
label music_block:
    if current_room == "main_room":
        if game.daytime:
            call play_music("day")
        else:
            call play_music("night")
    elif current_room == "snape_office":
        call play_music("snape_office")
    return

label unlock_clothing(text="", item="interface/icons/box_blue_1.webp"):

    $ menu_x = 0.5
    $ menu_y = 0.75 #makes the menu lower so it isn't writing over the image.

    show screen clothing_unlock(item)
    show screen blktone
    with d3

    menu:
        "[text]"
        "-Done Reading-":
            pass

    hide screen clothing_unlock
    hide screen blktone
    with d3

    $ item.unlock()

    call reset_menu_position

    return


label describe_mood(name, value):
    call blktone
    if 5 > value >= 1:
        ">[name] is a little upset with you..."
    elif 10 > value >= 5:
        ">[name] is upset with you."
    elif 20 > value >= 10:
        ">[name] is very upset with you."
    elif 30 > value >= 20:
        ">[name] is mad at you."
    elif 40 > value >= 30:
        ">[name] is very mad at you."
    elif 50 > value >= 40:
        ">[name] is furious at you."
    elif value >= 50:
        ">[name] hates your guts."
    else:
        ">[name] is calm."
    call hide_blktone

    return


label describe_mood_after_gift(was_negative, mood, change):
    if was_negative and mood == 0:
        call notes
        "She's no longer upset with you."
    elif was_negative and change < 0:
        "But she's still upset with you."
    elif was_negative:
        "She's still upset with you."

    return


label notes():
    $ renpy.play('sounds/win_04.ogg')   #Not loud.
    hide screen notes
    show screen notes
    return

label not_implemented():
    "Not implemented."
    return

label end_of_content():
    $ renpy.choice_for_skipping()

    "SilverStudioGames" "This concludes story progression for this character as of version [config.version].\nThere still may be side events and activities that you have missed, but main story won't progress past this point."
    "SilverStudioGames" "We hope you have enjoyed yourself. Stay tuned for more in the future."
    call notes
    "> All stats have been maxed out. You can now use all of the wardrobe options."

    return
