require "ISUI/ISPanel"

FakeISArtSupportUI = ISPanel:derive("FakeISArtSupportUI");
local this = FakeISArtSupportUI
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 FakeISArtSupportUI:initialise()
    ISPanel.initialise(self);
    self:create();
end

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

end

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

function FakeISArtSupportUI:render()

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

end
function FakeISArtSupportUI:create()

end

function FakeISArtSupportUI:update()
    self.tick = self.tick + 1
    if self.tick == 360 then
        self:destroy()
    end
    if self.tick == 20 then
        self.character:playSound(self.CrewLaungage .. "Art_Acknowledged")
    end
    if self.tick % 50 == 0 then
        self.character:playSound("Shellincoming")
    end
    local OriginSquareX = self.square:getX()
    local OriginSquareY = self.square: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 + ZombRand(-8, 8), OriginSquareY + ZombRand(-8, 8),
                self.square:getZ())
            if square then
                self.character:playSound("ground_explosion")
                PanzerDetectTarget(square, "Art")
            end
        end
    end
end

function FakeISArtSupportUI: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;
    this.instance = o
    local type = GetPanzerType(vehicle)
    o.CrewLaungage = PanzerList[type].CrewLaungage
    if player:getModData().CrewLaungage then
        o.CrewLaungage = player:getModData().CrewLaungage
    end
    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
