function p.draw_trophy(wid, grid, row, col, name)
    have_trophy = ga_get_b("xar.player.trophy." .. name)
    debug = false
    --debug = true --DEBUGGING!!!
    if have_trophy or debug then
        tex_name = "trophy_" .. name
    else
        tex_name = "trophy_do_not_have"
    end
    --
    big_width = grid.max_x - grid.min_x
    big_height = grid.max_y - grid.min_y
    delta_x = big_width / (grid.num_x - 1)
    delta_y = big_height / (grid.num_y - 1)
    x = grid.min_x + (delta_x * col)
    y = grid.max_y - (delta_y * row)
    quad_min_x = x - (grid.trophy_width / 2)
    quad_max_x = x + (grid.trophy_width / 2)
    quad_min_y = y - (grid.trophy_height / 2)
    quad_max_y = y + (grid.trophy_height / 2)
    ga_win_quad(
        wid, 
        quad_min_x,
        quad_min_y,
        quad_max_x,
        quad_max_y,
        tex_name);
end

function p.__render(wid)
    ga_init_i("temp.xar.stats5.win_num", 1)

    ga_win_set_background(wid, std.vec(0.0, 0.0, 0.0), 0.95)
    
    ga_win_set_char_size(wid, 0.02, 0.04)
    ga_win_txt_center(wid, 0.92, "TROPHIES")

    ga_win_set_char_size(wid, 0.01, 0.02)
    ga_win_txt_center(wid, 0.88, "USE LEFT / RIGHT ARROWS")

    ga_win_set_char_size(wid, 0.02, 0.04)

    type_y = 0.8

    win_num = ga_get_i("temp.xar.stats5.win_num")
    if win_num == 1 then
        ga_win_txt_center(wid, type_y, "YING WORLD TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "library_ying")
        p.draw_trophy(wid, grid, 0,1, "noob_flower") 
        p.draw_trophy(wid, grid, 0,2, "small_yellow_flower")
        p.draw_trophy(wid, grid, 0,3, "jumbo_yellow_flower")
        p.draw_trophy(wid, grid, 1,0, "ying_island_1")
        p.draw_trophy(wid, grid, 1,1, "ying_island_2")
        p.draw_trophy(wid, grid, 1,2, "ying_island_3")
        p.draw_trophy(wid, grid, 1,3, "ying_island_4")
        p.draw_trophy(wid, grid, 2,0, "small_cannon_pyramid")
        p.draw_trophy(wid, grid, 2,1, "large_cannon_pyramid")
        p.draw_trophy(wid, grid, 2,2, "ying_exit_maze")
        p.draw_trophy(wid, grid, 2,3, "ying_flower")
        p.draw_trophy(wid, grid, 3,0, "ying_tower")
        p.draw_trophy(wid, grid, 3,1, "sponge_pure")
        --s
        --p.draw_trophy(grid, 0,0, "trophy_do_not_have")
        --p.draw_trophy(grid, 0,1, "trophy")
        --more!!!
    end
    if win_num == 2 then
        ga_win_txt_center(wid, type_y, "MIDWAY TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "richmond")
        p.draw_trophy(wid, grid, 0,1, "richmond_sewers")
        p.draw_trophy(wid, grid, 0,2, "tau_caves_map")
        p.draw_trophy(wid, grid, 0,3, "richmond_caves")
        
        p.draw_trophy(wid, grid, 1,0, "stoney_cave_1")
        p.draw_trophy(wid, grid, 1,1, "stoney_cave_2")
        p.draw_trophy(wid, grid, 1,2, "stoney_cave_3")
        p.draw_trophy(wid, grid, 1,3, "stoney_church")
        p.draw_trophy(wid, grid, 2,0, "blackberry")
        p.draw_trophy(wid, grid, 2,1, "black_cube")
        p.draw_trophy(wid, grid, 2,2, "jericho")
        p.draw_trophy(wid, grid, 2,3, "catacombs")
        p.draw_trophy(wid, grid, 3,0, "orange")
        p.draw_trophy(wid, grid, 3,1, "tweed_cave")
        p.draw_trophy(wid, grid, 3,2, "ice_cube")
        p.draw_trophy(wid, grid, 3,3, "blue_bubble")
        --more!!!
    end
    if win_num == 3 then
        ga_win_txt_center(wid, type_y, "I1 TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "blue_bubble_breach")
        p.draw_trophy(wid, grid, 0,1, "botany_lab_1")
        p.draw_trophy(wid, grid, 0,2, "botany_lab_2")
        p.draw_trophy(wid, grid, 0,3, "botany_lab_3")
        p.draw_trophy(wid, grid, 1,0, "botany_lab_4")
        p.draw_trophy(wid, grid, 1,1, "botany_lab_5")
        p.draw_trophy(wid, grid, 1,2, "botany_lab_6")
        p.draw_trophy(wid, grid, 1,3, "library_i1")
        p.draw_trophy(wid, grid, 2,0, "lighthouse")
        p.draw_trophy(wid, grid, 2,1, "infinity_flower")
        p.draw_trophy(wid, grid, 2,2, "williston")
        p.draw_trophy(wid, grid, 2,3, "williston_caves")
        p.draw_trophy(wid, grid, 3,0, "bristol")
        p.draw_trophy(wid, grid, 3,1, "emp_castle")
        p.draw_trophy(wid, grid, 3,2, "zube_castle")
        --more!!!
    end
    if win_num == 4 then
        ga_win_txt_center(wid, type_y, "I2 TROPHIES PART 1")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "library_i2")
        p.draw_trophy(wid, grid, 0,1, "wig_prison")
        p.draw_trophy(wid, grid, 0,2, "montreal")
        p.draw_trophy(wid, grid, 0,3, "toronto")
        p.draw_trophy(wid, grid, 1,0, "toronto_underground")
        p.draw_trophy(wid, grid, 1,1, "danville")
        p.draw_trophy(wid, grid, 1,2, "small_blue_flower_1")
        p.draw_trophy(wid, grid, 1,3, "small_blue_flower_2")
        p.draw_trophy(wid, grid, 2,0, "willow_tree")
        p.draw_trophy(wid, grid, 2,1, "willow_tree_dark")
        p.draw_trophy(wid, grid, 2,2, "mystic_vine")
        p.draw_trophy(wid, grid, 2,3, "raspberry")
        p.draw_trophy(wid, grid, 3,0, "weed_rings")
        p.draw_trophy(wid, grid, 3,1, "blue_mushroom")
        p.draw_trophy(wid, grid, 3,2, "fanatic_spire")
        p.draw_trophy(wid, grid, 3,3, "creeping_jeni")
        --more!!!
    end
    if win_num == 5 then
        ga_win_txt_center(wid, type_y, "I2 TROPHIES PART 2")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "violets")
    end
    if win_num == 6 then
        ga_win_txt_center(wid, type_y, "I3 TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "library_i3")
        p.draw_trophy(wid, grid, 0,1, "colchester")
        p.draw_trophy(wid, grid, 0,2, "large_white_flower")
        p.draw_trophy(wid, grid, 0,3, "red_maze_flower")
        p.draw_trophy(wid, grid, 1,0, "jackfruit")
        p.draw_trophy(wid, grid, 1,1, "cactus")
        p.draw_trophy(wid, grid, 1,2, "aladdin_cave")
        p.draw_trophy(wid, grid, 1,3, "desert_cave")
        p.draw_trophy(wid, grid, 2,0, "desert_flower")
        p.draw_trophy(wid, grid, 2,1, "salmon_mushroom")
        p.draw_trophy(wid, grid, 2,2, "black_mushroom")
        p.draw_trophy(wid, grid, 2,3, "yellow_mushroom")
        p.draw_trophy(wid, grid, 3,0, "red_mushroom")
        p.draw_trophy(wid, grid, 3,1, "river")
        p.draw_trophy(wid, grid, 3,2, "tangerine")
        --more!!!
    end
    if win_num == 7 then
        ga_win_txt_center(wid, type_y, "BURLINGTON TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "burlington_cols")
        p.draw_trophy(wid, grid, 0,1, "burlington")
        p.draw_trophy(wid, grid, 0,2, "tegan_garden")
        p.draw_trophy(wid, grid, 0,3, "green_apple_club")
        --more!!!
    end
    if win_num == 8 then
        ga_win_txt_center(wid, type_y, "SPACE TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "library_space")
        p.draw_trophy(wid, grid, 0,1, "moon_alpha")
        p.draw_trophy(wid, grid, 0,2, "moon_beta")
        p.draw_trophy(wid, grid, 0,3, "moon_gamma")
        p.draw_trophy(wid, grid, 1,0, "moon_tau")
        p.draw_trophy(wid, grid, 1,1, "moon_ice")
        p.draw_trophy(wid, grid, 1,2, "moon_fire_rate")
        p.draw_trophy(wid, grid, 1,3, "planet_small_minigun")
        p.draw_trophy(wid, grid, 2,0, "planet_clay")
        p.draw_trophy(wid, grid, 2,1, "sun")
        p.draw_trophy(wid, grid, 2,2, "sponge_alpha")
        --more!!!
    end
    if win_num == 9 then
        ga_win_txt_center(wid, type_y, "THE BULK TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "ice_castle")
        --more!!!
    end
    if win_num == 10 then
        ga_win_txt_center(wid, type_y, "MYLANTIS TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "mylantis")
        p.draw_trophy(wid, grid, 0,1, "farmhouse")
        p.draw_trophy(wid, grid, 0,2, "laser_genesis")
        p.draw_trophy(wid, grid, 0,3, "sapphire_maze")
        p.draw_trophy(wid, grid, 1,0, "sponge_beta")
        p.draw_trophy(wid, grid, 1,1, "topaz")
        p.draw_trophy(wid, grid, 1,2, "iolite")
        p.draw_trophy(wid, grid, 1,3, "emerald")
        p.draw_trophy(wid, grid, 2,0, "denver")
        p.draw_trophy(wid, grid, 2,1, "amethyst_maze")
        p.draw_trophy(wid, grid, 2,2, "edge_of_world")
        --more!!!
    end
    if win_num == 11 then
        ga_win_txt_center(wid, type_y, "HELL TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "hell_flower")
        p.draw_trophy(wid, grid, 0,1, "inner_core")
        p.draw_trophy(wid, grid, 0,2, "credits")
        --more!!!
    end
    if win_num == 12 then
        ga_win_txt_center(wid, type_y, "NO WAYPOINT TROPHIES")
        grid = {
            min_x = 0.25,
            max_x = 0.75,
            num_x = 4,
            min_y = 0.2,
            max_y = 0.7,
            num_y = 4,
            trophy_width = 0.13,
            trophy_height = 0.16}
        p.draw_trophy(wid, grid, 0,0, "small_white_flower")
        p.draw_trophy(wid, grid, 0,1, "small_black_flower")
        p.draw_trophy(wid, grid, 0,2, "apple_tree")
        p.draw_trophy(wid, grid, 1,0, "health_tower")
        p.draw_trophy(wid, grid, 1,1, "alpha_cube")
        --more!!!
    end

    ga_win_set_char_size(wid, 0.02, 0.04)
    ga_win_txt_center(wid, 0.06, "Go Back (ESC)")
end

function p.__process_input(wid)
    if ga_win_key_pressed(wid, "ESC") then
        ga_window_pop()
        return
    end

    if ga_win_key_pressed(wid, "F1") then
        --Opening the xar menu.
        ga_window_pop()
        ga_main_menu_push("main_menu")
        return
    end
    if ga_win_key_pressed(wid, "F2") then
        if( not ga_genesis() ) then
            ga_window_pop()
            ga_window_push("win_stats2")
            return
        end
    end
    if ga_win_key_pressed(wid, "F3") then
        if( not ga_genesis() ) then
            ga_window_pop()
            ga_window_push("win_stats3")
            return
        end
    end
    if ga_win_key_pressed(wid, "F4") then
        if( not ga_genesis() ) then
            ga_window_pop()
            ga_window_push("win_stats4")
            return
        end
    end
    if ga_win_key_pressed(wid, "F5") then
        ga_window_pop()
        ga_window_push("win_stats5")
        return
    end
    --
    if ga_win_key_pressed(wid, "F7") then
        ga_window_pop()
        ga_window_push("win_stats7")
        return
    end

    num = ga_get_i("temp.xar.stats5.win_num")
    if ( ( ga_win_mouse_wheel_down(wid) or ga_win_key_pressed(wid, "LEFT")  ) and num > 1 ) then num = num - 1 end
    if ( ( ga_win_mouse_wheel_up(wid)   or ga_win_key_pressed(wid, "RIGHT") ) and num < 12 ) then num = num + 1 end
    ga_set_i("temp.xar.stats5.win_num", num)
end
