#####################################################################
#                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 img and "spaceloc" not in tags:
                if "side" in img and "medium_button" in tags:
                    image img zoom 0.4 yoffset -275 xoffset -30
                else:
                    image img zoom 0.25 yalign 0.5
            elif img:
                if "medium_button" in tags:
                    image img zoom 0.4 yoffset -275 xoffset -30
                else:
                    image img zoom 0.25 yoffset -60
            if "medium_button" in tags:
                vbox xsize 500 xpos xOffset + 60 yalign 0.5:
                    if alignM != "center":
                        text nMsg  yalign 0.5 size FSIZE
                    else:
                        text nMsg  yalign 0.5 size FSIZE xalign 0.5
            else:
                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 "medium_button" in tags:
            $ buttonX = 100
        if nOptions:
            $ optionslength = len(nOptions)
            $ optionnumber = 0
            $ colnumber = min(optionslength, 4)
            if "narrow_button" in tags and optionslength > 4:
                $ colnumber = 5
            if "medium_button" in tags and optionslength > 4:
                if optionslength < 7:
                    $ colnumber = optionslength
                elif optionslength < 9:
                    $ colnumber = 4
                elif optionslength < 11:
                    $ colnumber = 5
                else:
                    $ colnumber = 6
                
            #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 - {}".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 larger_notify(nTitle, nMsg, nOptions, img=False, accent="bright blue", tags = "medium_button"):
    call screen generic_notify(nTitle, nMsg, nOptions, img, accent, [640,360], "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)

label spaceloc_notify(sLocID, mode = "found", defTitle = "UNDEFINED"): 
    play sound "audio/success.wav"
    $ mTitle = {"found": "SPACE LOCATION DISCOVERED!", "unlocked": "GATEWAY UNLOCKED!", "locked": "GATEWAY BLOCKED!"  }.get(mode, defTitle) 
    $ dH = 160
    $ sLoc = GAME.getStarSys().locs.get(sLocID, False)
    if not sLoc:
        return(False)
    call screen generic_notify(mTitle, "{}".format(sLoc.name), ["Continue"],  "02_locations/ico {}_hover.png".format(sLoc.guiImg), "bright blue", [460,dH], "center", ["spaceloc"])
    play sound "audio/notify.wav"   
    if mode == "found":
        $ sLoc.found = True
    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_133 
        $ 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_134 
        $ 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_17 

    # T'Ris 
    # Nimhe 
    # Vee 
    return()

#####################################################################
#              UNCRATE REPORT
#####################################################################

#####################################################################
#              UNCRATING REPORT
#####################################################################
screen display_uncrating(uncrateTally, mode = "liquor_crates"):
    $ C_X = {"liquor_crates": 400, "bot_crates": 580}[mode]
    $ C_Y = {"liquor_crates": 540, "bot_crates": 740}[mode]

    frame xsize C_X+100 ysize C_Y xalign 0.5 yalign 0.5 padding 20,20:    
        modal True
        $ frameBG = "#ffffff00"
        # title
        text ACCENTS["blue"][0]+ "UNCRATING REPORT" +ACCENTS["blue"][1] xalign 0.5 ypos 10 size FSIZE_LARGE

        if mode == "liquor_crates":
            # liquor
            vbox xsize C_X xpos 20 ypos 80 spacing 10: 
                frame xsize C_X ysize 96 background Solid(frameBG):
                    image "05_gui/ico_gui_crate.png" zoom 0.25 yalign 0.5
                    text "x {}".format(uncrateTally["ITMCrateLiquor"]) xpos 100 yalign 1.0 xalign 1.0
                bar xsize C_X+20 ysize 3
                for i in ["ITMLiquorDrengar", "ITMLiquorIltari", "ITMLiquorFairy", "ITMLiquorVortex"]:
                    frame xsize C_X ysize 40 background Solid(frameBG):
                        text "{}".format(GAME.items[i].getName(["noArt", "cap"])) xpos 20 yalign 0.5
                        if uncrateTally.get(i,0):
                            text "{}".format(uncrateTally.get(i,0)) xpos C_X-20 xalign 1.0 yalign 0.5
                        else:
                            text "-" xpos 380 xalign 1.0 yalign 0.5

        elif mode == "bot_crates":
            $ crateTypes = [x for x in ["ITMCrateBots", "ITMCrateBotsRare", "ITMCrateBotsMil", "ITMCrateBotsPre"] if uncrateTally[x]]
            # bot crates
            vbox xsize C_X xpos 20 ypos 80 spacing 10: 
                frame xsize C_X ysize 96 background Solid(frameBG):
                    hbox spacing 10:
                        for i in crateTypes:
                            frame xsize 96 ysize 96 background Solid(frameBG):
                                image "08_items/ico {}.png".format(i) zoom 0.25 yalign 0.5 xalign 0.5
                                text "x {}".format(uncrateTally.get(i,0)) xpos 100 yalign 1.0 xalign 1.0

                bar xsize C_X+20 ysize 3
                #text " "
                frame xsize C_X ysize 40 background Solid(frameBG):
                    text "Total Parts" xpos 20 yalign 0.5
                    text "{}".format(uncrateTally.get("Parts",0)) xpos C_X-20 xalign 1.0 yalign 0.5

                frame xsize 580 ysize 40 background Solid(frameBG):
                    text C_GO_B+"High Grade"+C_GO_E xpos 20 yalign 0.5

                $ n = 0
                for i in uncrateTally["Special"]:
                    if n < 5:
                        frame xsize 580 ysize 40 background Solid(frameBG):
                            text "{}".format(i) xpos 40 yalign 0.5
                            $ n += 1
                    elif n == 5:
                        frame xsize 580 ysize 40 background Solid(frameBG):
                            text "{}and {} more...{}".format(C_GO_B, len(uncrateTally["Special"])-n, C_GO_E) xpos 20 yalign 0.5
                            $ n += 1
                if not uncrateTally["Special"]:
                    frame xsize 580 ysize 40 background Solid(frameBG):
                        text "None" xpos 40 yalign 0.5
                        $ n += 1

                    



        # bot parts 

        # buttons
        frame xsize 140 ysize 36 background Solid("#0099cc") yalign 0.95 xalign 0.5:
            text "Continue"  size FSIZE xalign 0.5
            button action Return("Continue")
            key "K_SPACE" action Return("Continue")

#####################################################################
#              SURPRISE CRATE REPORT
#####################################################################

screen display_crate(cTitle, cItems, accent = "blue"):
    $ singles = set(cItems)
    frame xsize 760 ysize 560 xalign 0.5 yalign 0.5 padding 20,20:    
        modal True
        # title
        image "05_gui/ico_gui_crate.png" ypos -30 xalign 1.0 zoom 0.25

        text ACCENTS[accent][0]+ cTitle.upper()+ACCENTS[accent][1] xalign 0.5 ypos 10

        # contents
        vbox spacing 5 xalign 0.5 xsize 640 ypos 110:
            for item in singles:
                frame xsize 640 ysize 60 background Solid ("#0099cc00"):
                    image "08_items/ico bg1.png" zoom 0.1 yalign 0.5 xpos 40
                    image "08_items/ico {}.png".format(item.ID) zoom 0.1 yalign 0.5 xpos 40
                    text "{}".format(item.getName(["col", "cap", "noArt"])) size FSIZE yalign 0.5 xpos 140
                    text "{}x".format(cItems.count(item)) size FSIZE xpos 440 xalign 1.0 yalign 0.5
                    text "{:,} Cr".format(GAME.getSpaceLoc().getPrice(item, None)) size FSIZE xalign 1.0 yalign 0.5 xpos 600
        # buttons
        frame xsize 140 ysize 36 background Solid("#0099cc") yalign 0.95 xalign 0.5:
            text "Continue"  size FSIZE xalign 0.5
            button action Return("Continue")
            key "K_SPACE" action Return("Continue")
