#:kivy 2.0.0
<PongBall>:
    size: 60, 60
    canvas:
        Ellipse:
            pos: self.pos
            size: self.size
            source: self.source

<PongPaddle>:
    size: 25, 200
    canvas:
        Rectangle:
            pos: self.pos
            size: self.size

<PongGame>:
    id: ponggame
    ball: pong_ball
    player1: player_left
    player2: player_right
    source: self.pathfinder.get_path() + "/data/imgs/black.png"
    canvas:
        Rectangle:
            size: self.width, self.height
            source: self.source
        Rectangle:
            pos: self.center_x - 5, 0
            size: 10, self.height

    #Winner Popup 1
    Popup:
        id: winner_popup
        title: "Vittoria!"
        on_parent:
            if self.parent == ponggame: self.parent.remove_widget(self)
        size: 400,300
        size_hint: .55, .45

        LabelChanging:
            id: winner_label
            text: "Vince il giocatore 0!!!"
            center_x: self.width / 2
            center_y: self.height / 2
            font_name: "Oswald"
            font_size: 30
            bold: True
            changing_interval: 0.12
            color_list: ["#ffc600","#fed801", "#fedb16", "#fedc1b","#ffff00","#fedd25","#fee034"]
            color_number_max: 6
            backward_repeat: True

    #Options Popup
    Popup:
        id: opt_popup
        title: "Opzioni"
        on_parent:
            if self.parent == ponggame: self.parent.remove_widget(self)
        on_dismiss:
            root.set_unpause()
        size: 400,400
        size_hint: .60, .85

        ##The layout is needed here because the popup needs ONLY a widget inside it. So we cheat.
        GridLayout:
            cols: 2
            rows: 14

            ToggleButton:
                id: music
                text: 'Musica On/Off'
                size_hint_y: None
                height: 44
                state: "down"
                on_press:
                    root.toggle_music()

            ToggleButton:
                id: sound_effects
                text: 'Suoni On/Off'
                size_hint_y: None
                height: 44
                state: "down"
                on_press:
                    root.toggle_seffects()

            ToggleButton:
                id: winbool
                text: "Vincere On/Off"
                state: "down"
                on_press:
                    root.toggle_winning()
                size_hint_y: None
                height: 44

            Spinner:
                id: music_spinner
                size_hint_y: None
                height: 44
                text: 'Scegli Musica'
                values: 'HappyHappy', 'Burpish', 'Burpish_nopiano'
                on_text:
                    root.bgm_prec = root.bgm
                    root.bgm = self.text
                    root.sounds["bgm"] = root.bgms[root.bgm]
                    root.backgroundstop("hi")
                    root.change_clock()
                    print("changed")
                    root.backgroundplay("hi1")


            Label:
                id: wininput_ask
                size_hint_y: None
                height: 44
                text: "Punteggio a cui si vince:"

            TextInput:
                id: winat_input
                text: "10"
                size_hint_y: None
                height: 44
                multiline: False


            Label:
                id: max_power_points_input_ask
                size_hint_y: None
                height: 44
                text: "Massimo di punti azione:"

            TextInput:
                id: max_power_points_input
                text: "10"
                size_hint_y: None
                height: 44
                multiline: False

            Label:
                text: "Volume musica: "+str(music_slider.value)

            Slider:
                id: music_slider
                min: 0
                max: 100
                step: 1
                orientation: 'horizontal'
                value: 0.1*100

            Label:
                text: "Volume suoni: "+str(sound_slider.value)

            Slider:
                id: sound_slider
                min: 0
                max: 100
                step: 1
                orientation: 'horizontal'
                value: 1*100

            Label:
                id: button_label
                text: "Dimensione bottoni: "+str(root.ids.button_slider.value)

            Slider:
                id: button_slider
                min: 10
                max: 175
                step: 1
                orientation: 'horizontal'
                value: 35


            Spinner:
                id: ball_spinner
                size_hint_y: None
                height: 44
                text: 'Icona Palla'
                values: "Salvagianni", "Ingranaggio", "Bursted", "Freezed", "Tondino", "Luna"
                on_text:
                    root.ball.source = root.ball_icons[self.text]

            Spinner:
                id: background_spinner
                size_hint_y: None
                height: 44
                text: 'Sfondo'
                values: "Default", "Galassia", "Electric", "PacMan", "Monti", "Alpi", "Prato", "Prato Alpino", "Foresta", "Lago", "Caverna", "Nuvole", "Albero", "Gradiente"
                on_text:
                    root.source = root.backgrounds[self.text]

            Button:
                id: github_button
                text: "Codice Sorgente"
                size_hint_y: None
                height: 44
                on_release:
                    import webbrowser
                    webbrowser.open('https://github.com/Emafire003/RuttoPong')

            Button:
                id: credits_button
                text: "Crediti"
                size_hint_y: None
                height: 44
                on_release:
                    credits_popup.open()

            Button:
                id: save_update
                text: "Salva e Aggiorna"
                size_hint_y: None
                height: 44
                on_release:
                    ##opt_popup.dismiss()
                    root.update_inputs()

            Button:
                id: close
                text: "Salva e Chiudi"
                size_hint_y: None
                height: 44
                on_release:
                    opt_popup.dismiss()
                    root.update_inputs()

            #SLider music TODO
            #Max power points

    #CREDITS
    Popup:
        id: credits_popup
        title: "Crediti"
        size: 400,400
        size_hint: .55, .45
        on_parent:
            if self.parent == ponggame: self.parent.remove_widget(self)
        GridLayout:
            cols: 1
            rows: 6
            Label:
                text: "Immagine bottone opzioni: https://www.freepik.com"
            Label:
                text: "Immagini sfondo: @Emafire003, https://designfup.com/, http://wallpapers4screen.com/, "
                font_size: 9
            Label:
                text: ", http://wallpapers4screen.com/, https://www.getsims.com"
                font_size: 9
            Label:
                text: "https://getwallpapers.com/collection/electronic-wallpaper-background"
                font_size: 9
            Label:
                text: "SoundTracks: Discord @Franzle#0347"
            Label:
                text: "Rutti: @Franzle, @DumboFante#1716, @Vorston#8326"


    #Error popup
    Popup:
        id: error_popup
        title: "ERRORE"
        size: 400,400
        size_hint: .55, .45
        on_parent:
            if self.parent == ponggame: self.parent.remove_widget(self)
        on_dismiss:
            root.ids.error_label1 = ""
            root.ids.error_label2 = ""
        GridLayout:
            cols: 1
            rows: 6
            Label:
                text: "ERRORE!"
                font_name: "Rubik"
                font_size: 20
            Label:
                id: error_label1
                text: ""
            Label:
                id: error_label2
                text: ""



    #StartButton
    Button:
        id: avvio
        center_x: root.width / 2
        center_y: root.height / 2 - 60
        top: root.top / 2
        text: "AVVIO"
        size: (110, 40)
        background_color: "cyan"
        on_press:
            self.parent.set_unpause()
            self.parent.serve_ball()
            self.parent.play_sound(self.parent.sounds["gl"], self.parent.sound_volume)
        on_release: self.parent.remove_widget(self)
        bold: True

    #Options button
    ButtonImg:
        id: optbutton
        center_x: root.width / 2
        center_y: root.height - 50
        size: (35, 35)
        source: root.pathfinder.get_path() + '/data/imgs/gear.png'
        on_press:
            source: root.pathfinder.get_path() + '/data/imgs/gearr.png'
            self.parent.set_pause()
            opt_popup.open()
        on_release:
            source: root.pathfinder.get_path() + '/data/imgs/gear.png'

    ##Freeze Button SX
    ButtonImg:
        id: freeze_sx
        ##center_x: root.width / 8
        center_x: burst_sx.center_x - self.width
        center_y: points_sx.center_y + self.width
        size: 52, 52
        source: root.pathfinder.get_path() + '/data/imgs/freeze.png'
        on_press:
            self.parent.freeze_ballSX()

    ##Freeze Label SX
    LabelChanging:
        id: label_freeze_sx
        text: "6"
        ##center_x: root.width / 8
        center_x: freeze_sx.center_x
        center_y: freeze_sx.center_y + 2
        font_name: "Karantina_Regular"
        font_size: 35
        changing_interval: 0.12
        color_list: ["#4e075f", "#6a0a83", "#870ca6","#af0fd7","#ce40f2"]
        color_number_max: 4
        backward_repeat: True

    ##Freeze button DX
    Button:
        id: freeze_dx
        center_x: burst_dx.center_x + 49
        center_y: points_dx.center_y - 10
        size: 35, 35
        background_normal: root.pathfinder.get_path() + '/data/imgs/freeze.png'
        background_down: root.pathfinder.get_path() + '/data/imgs/freezer.png'
        on_press:
            self.parent.freeze_ballDX()

    ##Freeze Label DX
    LabelChanging:
        id: label_freeze_dx
        text: "6"
        center_x: freeze_dx.center_x + 1
        center_y: freeze_dx.center_y + 1
        font_name: "Karantina_Regular"
        font_size: 35
        changing_interval: 0.12
        color_list: ["#4e075f", "#6a0a83", "#870ca6","#af0fd7","#ce40f2"]
        color_number_max: 4
        backward_repeat: True

    #Burst Button SX
    ButtonImg:
        id: burst_sx
        center_x: points_sx.center_x + 109
        center_y: points_sx.center_y + 48
        size: 52, 52
        source: root.pathfinder.get_path() + '/data/imgs/burst.png'
        on_press:
            self.parent.burst_ballSX()

    ##Burst Label SX
    LabelChanging:
        id: label_burst_sx
        text: "5"
        center_x: burst_sx.center_x
        center_y: burst_sx.center_y + 1
        font_name: "Karantina_Regular"
        font_size: 35
        changing_interval: 0.12
        color_list: ["#4e075f", "#6a0a83", "#870ca6","#af0fd7","#ce40f2"]
        color_number_max: 4
        backward_repeat: True

    #Burst Button DX
    Button:
        id: burst_dx
        center_x: points_dx.center_x - 109
        center_y: points_dx.center_y - 10
        size: 35, 35
        size_hint: (0.7,0.7)
        background_normal: root.pathfinder.get_path() + '/data/imgs/burst.png'
        background_down: root.pathfinder.get_path() + '/data/imgs/burstr.png'
        on_press:
            self.parent.burst_ballDX()

    ##Burst Label DX
    LabelChanging:
        id: label_burst_dx
        text: "5"
        center_x: burst_dx.center_x
        center_y: burst_dx.center_y
        font_name: "Karantina_Regular"
        font_size: 35
        changing_interval: 0.12
        color_list: ["#4e075f", "#6a0a83", "#870ca6","#af0fd7","#ce40f2"]
        color_number_max: 4
        backward_repeat: True


    LabelChanging:
        font_size: 70
        center_x: root.width / 4
        top: root.top - 50
        text: str(root.player1.score)
        font_name: "Karantina_Regular"
        changing_interval: 0.12
        color_list: ["#00e600", "#00ff00", "#1aff1a"]
        color_number_max: 2
        backward_repeat: True

    LabelChanging:
        font_size: 70
        center_x: root.width * 3 / 4
        top: root.top - 50
        text: str(root.player2.score)
        font_name: "Karantina_Regular"
        changing_interval: 0.12
        color_list: ["#00e600", "#00ff00", "#1aff1a"]
        color_number_max: 2
        backward_repeat: True

    PongBall:
        id: pong_ball
        center: self.parent.center

    PongPaddle:
        id: player_left
        x: root.x
        center_y: root.center_y

    PongPaddle:
        id: player_right
        x: root.width - self.width
        center_y: root.center_y

    ##Punti Power SX
    LabelChanging:
        id: points_sx
        text: "0"
        center_x: root.width / 20
        center_y: root.height - root.height + 35
        font_name: "Karantina_Regular"
        font_size: 45
        bold: True
        size_hint: .5,.5
        changing_interval: 0.12
        color_list: ["#4e075f", "#6a0a83", "#870ca6","#af0fd7","#ce40f2"]
        color_number_max: 4
        backward_repeat: True

    ##Punti Power DX
    LabelChanging:
        id: points_dx
        text: "0"
        center_x: root.width - root.width / 20
        center_y: root.height - 35
        color: "purple"
        font_name: "Karantina_Regular"
        font_size: 45
        bold: True
        size_hint: .5,.5
        changing_interval: 0.12
        color_list: ["#4e075f", "#6a0a83", "#870ca6","#af0fd7","#ce40f2"]
        color_number_max: 4
        backward_repeat: True

    ProgressBar:
        id: prog_sx
        value: 0
        min: 0
        max: 10
        size_hint: 1,1
        center_x: points_sx.center_x + 80
        center_y: burst_sx.center_y - 30
        max_power_points: 10

    ProgressBar:
        id: prog_dx
        value: 0
        min: 0
        max: 10
        size_hint: 1,1
        center_x: points_dx.center_x - 80
        center_y: burst_dx.center_y + 30
        max_power_points: 10

