#####################################################################
#                NOTIFICTION DIALOGUES
#####################################################################

screen generic_notify(nTitle, nMsg, nOptions, img, accent, dim, alignM = "center", tags = []):
    $ dW = dim[0]
    $ dH = dim[1]
    if img:
        $ dW += 128
    if nTitle:
        $ dH += 40
    if nOptions:
        $ dH += 40

    frame xsize dW ysize dH xalign 0.5 yalign 0.5 padding 30,30:
        if nTitle:
            text ACCENTS[accent][0]+ nTitle+ACCENTS[accent][1] xalign 0.5
        # Center part
        $ xOffset = 0
        if img and alignM != "center":
            $ xOffset = 140

        frame xsize dW-60 ysize 100 xalign 0.5 yalign 0.5 background Solid ("#ffffff00"):
            if len(nOptions) > 4:
                yoffset - 20
            if img:
                image img zoom 0.25 yoffset -60
            vbox xsize dW-60-xOffset xpos xOffset yalign 0.5:
                if alignM != "center":
                    text nMsg  yalign 0.5 size FSIZE
                else:
                    text nMsg  yalign 0.5 size FSIZE xalign 0.5

        # Options
        $ buttonX = 140
        if "narrow_button" in tags:
            $ buttonX = 70
        if nOptions:
            $ optionslength = len(nOptions)
            $ optionnumber = 0
            $ colnumber = min(optionslength, 4)
            if "narrow_button" in tags and optionslength > 4:
                $ colnumber = 5
                
            #hbox xalign 0.5 yalign 1.0 spacing 20:
            vpgrid xalign 0.5 yalign 1.0:
                cols colnumber
                spacing 20
                #if len(nOptions) > 4:
                    #yoffset - 40
                for i in nOptions:
                    $ optionnumber += 1
                    frame xsize buttonX ysize 36 background Solid("#0099cc"):
                        #text "{b}"+i+"{/b}" xalign 0.5 size FSIZE yalign 0.5
                        text i xalign 0.5 size FSIZE yalign 0.5
                        button action Return(i)
            key "K_SPACE" action Return(nOptions[0])

        else:
            button action Return("Continue")
            key "K_SPACE" action Return("Continue")



label achievement_notify(npc, achievement, aImg = False):
    if achievement in npc.achievements:
        return()
    $ dH = 160
    if aImg:
        show image aImg with fade
    play sound "audio/success.wav"
    call screen generic_notify("ACHIEVEMENT GAINED - {}".format(npc.name.upper()), "\"{}\"" .format(achievement.upper()), ["Continue"],  "08_items/ico ITMCup.png", "pink", [460,dH], "center")

    if aImg:
        window hide  
        pause  
        hide image aImg
    $ npc.achievements.append(achievement)
    return()

label find_notify(item, nTitle, amount =1):
    play sound "audio/notify.wav"
    $ dH = 160
    $ multiplier = ""
    if amount > 1:
        $ multiplier = "({}x) ".format(amount)
    # item?
    if item in GAME.items.values():
        call screen generic_notify(nTitle, "{}{}".format(multiplier, item.getName([ "cap", "noArt"])), ["Continue"],  "08_items/ico {}.png".format(item.ID), "bright blue", [460,dH], "center")
        # call screen generic_notify([], nTitle, ["Continue"],  "08_items/ico {}.png".format(item.ID), "bright blue", [640,dH], "center")
        play sound "audio/{}".format(item.getSound())
    # gold?
    else:
        call screen generic_notify(nTitle, "{:,} Cr".format(item), ["Continue"],  "08_items/ico ITMCoin.png", "bright blue", [460,dH], "center")
        play sound "audio/coin.wav"
    return()

label simple_notify(nTitle, nMsg, nOptions = [], ico = False, accent = "bright blue", alignM = "center"):
    $ dH = 160
    call screen generic_notify(nTitle, nMsg, nOptions, ico, accent, [520,dH], alignM)
    return(_return)

label large_notify(nTitle, nMsg, nOptions, img=False, accent="bright blue", tags = []):
    call screen generic_notify(nTitle, nMsg, nOptions, img, accent, [620,280], "left", tags)
    return(_return)

label quest_notify(qID, nTitle):
    call screen generic_notify(nTitle, GAME.questSys.questDB[qID][0], ["Continue"], "05_gui/ico_gui_quest.png", "green", [560,160])
    return(_return)

#####################################################################
#                FAVOURS
#####################################################################


label fp_notify(actor,amount):
    if amount > 0:
        play sound "audio/success.wav"
        $ suf = {1: "", 2:"s"}[capValue(amount,1,2)]
        call simple_notify("{}".format(actor.name.upper()), "+{} Favour Point{} ".format(amount, suf), ["Continue"], "05_gui/ico_gui_heart.png") from _call_simple_notify_109
        $ actor.fp += amount
    else:
        queue sound "audio/notify.wav"        
        $ suf = {1: "", 2:"s"}[capValue(abs(amount),1,2)]
        call simple_notify("{}".format(actor.name.upper()), "-{} Favour Point{} ".format(abs(amount), suf), ["Continue"], "05_gui/ico_gui_heart.png", "orange") from _call_simple_notify_110
        $ actor.fp = capValue(actor.fp+amount,0,100)

    return()


#####################################################################
#                CHECK ACHIEVEMENTS
#####################################################################
label achievement_updater():
    # MC 
    if GAME.mc.attr["REP"] >= 3 and "trustworthy" not in GAME.mc.achievements:
        call achievement_notify(GAME.mc, "trustworthy") from _call_achievement_notify_15

    # T'Ris 
    # Nimhe 
    # Vee 
    return