require "ISUI/ISPanel"

FakeISAirSupportUI = ISPanel:derive("FakeISAirSupportUI");
local this = FakeISAirSupportUI
local FONT_HGT_SMALL = getTextManager():getFontHeight(UIFont.NewSmall)
local FONT_HGT_MEDIUM = getTextManager():getFontHeight(UIFont.NewMedium)
local FONT_HGT_LARGE = getTextManager():getFontHeight(UIFont.NewLarge)
local btnClose = getText("IGUI_CraftUI_Close")
local btnUpload = getText("IGUI_ISTigerCrewLevel_Equip")
local btnCloseWid = getTextManager():MeasureStringX(UIFont.NewSmall, btnClose) + 10
local btnCloseHgt = getTextManager():MeasureStringY(UIFont.NewSmall, btnClose) + 10
local btnUploadWid = getTextManager():MeasureStringX(UIFont.NewSmall, btnUpload) + 10
local btnUploadHgt = getTextManager():MeasureStringY(UIFont.NewSmall, btnUpload) + 10
function FakeISAirSupportUI:initialise()
    ISPanel.initialise(self);
    self:create();
end

function FakeISAirSupportUI:prerender()
    ISPanel.prerender(self);

end

function FakeISAirSupportUI:destroy()
    UIManager.setShowPausedMessage(true)
    self:setVisible(false)
    self:removeFromUIManager()
    this.instance = nil
end

function FakeISAirSupportUI:render()

end
function FakeISAirSupportUI:onOptionMouseDown(button, x, y)

end
function FakeISAirSupportUI:create()

end

function FakeISAirSupportUI:update()
    self.tick = self.tick + 1
    if self.tick == 360 then
        self:destroy()
    end
    if self.tick == 20 then
        self.character:playSound(self.CrewLaungage .. "AirSupportIncoming")
    end
    if self.tick % 50 == 0 then
        self.character:playSound("AirSupportSound")
    end
    local Zombies = getCell():getZombieList()
    if Zombies:size() - 1 >= 0 then
        local Zombie = Zombies:get(ZombRand(0, Zombies:size() - 1))
        local OriginSquareX = Zombie:getX()
        local OriginSquareY = Zombie:getY()
        if self.tick >= 100 then
            if ZombRand(0, math.max(20 - self.tick / 10, 11)) == 10 then
                -- DetectTarget(self.square, "Art")
                local square = getCell():getGridSquare(OriginSquareX, OriginSquareY, 0)
                if square then
                    self.character:playSound("AirSupportFire")
                    PanzerDetectTarget(square, "Air")
                end
            end
        end
    end

end

function FakeISAirSupportUI:new(x, y, width, height, player, square, vehicle)
    local o = {};
    o = ISPanel:new(x, y, width, height);
    setmetatable(o, self);
    o.character = player;
    self.__index = self;
    local type = GetPanzerType(vehicle)
    o.CrewLaungage = PanzerList[type].CrewLaungage
    if player:getModData().CrewLaungage then
        o.CrewLaungage = player:getModData().CrewLaungage
    end
    this.instance = o
    o.anchorRight = true
    o.anchorBottom = true
    o.tick = 0
    o.anchorTop = true
    o.anchorLeft = true
    o.vehicle = vehicle
    o.square = square
    o.moveWithMouse = true
    return o;
end
