----------------------------------------------------------------------------------------------------------------------
-- @date:         Initial Release Unknown
-- @history:     Unknown
-- @author:        Unknown
-- @version     1.4a    --  EditDate 09.06.2018 Edit by Ahran Modding
-- @version:     1.4     --     EditDate 03.06.2017 Edit by Marc-Modding & Blacky_BPG
-- @version:     1.3a     --     Convert to FS17 / EditDate 27.05.2017 Edit by Marc-Modding & Blacky_BPG
-- @version:     1.1     --     Convert to FS15 / EditDate 20.02.2016 Edit by Marc-Modding & Blacky_BPG

----------------------------------------------------------------------------------------------------------------------

--MODDESC Entries:
--<specialization name="LuefterSound"             className="LuefterSound"             filename="XXX/LuefterSound.lua"/>
--<vehicleTypes> 
--<type name="XXX" className="" filename="$dataS/scripts/vehicles/Vehicle.lua"> 
--<specialization name="LuefterSound"/> 
--</type> 
--</vehicleTypes>
--
--
--XML Entries:    
--<fanSound file="" pitchOffset="" volume="" radius="" innerRadius=""/>
--
----------------------------------------------------------------------------------------------------------------------


DisplayBoot = {}
DisplayBoot.modDir = g_currentModDirectory
function DisplayBoot.prerequisitesPresent(specializations) return true end
function DisplayBoot:load(savegame)
    self.speedWaitingMaxTimeHud = 1400
    self.speedWaitingTimerBoot = 0
    self.bootScreen = 1
    local bootTime = 0
    if hasXMLProperty(self.xmlFile,"vehicle.bootLoader") then
        self.bootLoader = {}
        self.speedWaitingMaxTimeHud = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.bootLoader#defaultTime"),self.speedWaitingMaxTimeHud)
        local i = 0;
        while true do
            local key = string.format("vehicle.bootLoader.screen(%d)",i)
            if not hasXMLProperty(self.xmlFile, key) then
                break
            end
            i = i + 1
            self.bootLoader[i] = {}
            self.bootLoader[i].wasSet = false
            self.bootLoader[i].time = math.max(Utils.getNoNil(getXMLFloat(self.xmlFile, key.."#showTime"),self.speedWaitingMaxTimeHud),60) + bootTime
            self.bootLoader[i].stayOn = Utils.getNoNil(getXMLBool(self.xmlFile, key.."#stayOn"),false)
            bootTime = self.bootLoader[i].time
            local screen = getXMLString(self.xmlFile, key.."#index")
            if screen ~= nil then
                self.bootLoader[i].screen = Utils.indexToObject(self.components, screen)
                setVisibility(self.bootLoader[i].screen, false)
            end
            local other = getXMLString(self.xmlFile, key.."#other")
            if other ~= nil then
                self.bootLoader[i].other = Utils.indexToObject(self.components, other)
                setVisibility(self.bootLoader[i].other, false)
            end
        end
    end
    
end

function DisplayBoot:update(dt)
    if self.isMotorStarted then
        if self.bootLoader ~= nil then
            if self.bootLoader[self.bootScreen] ~= nil then
                if self.speedWaitingTimerBoot < self.bootLoader[self.bootScreen].time then
                    if not self.bootLoader[self.bootScreen].wasSet then
                        if self.bootLoader[self.bootScreen].screen ~= nil then
                            setVisibility(self.bootLoader[self.bootScreen].screen, true)
                        end
                        if self.bootLoader[self.bootScreen].other ~= nil then
                            setVisibility(self.bootLoader[self.bootScreen].other, true)
                        end
                        self.bootLoader[self.bootScreen].wasSet = true
                    end
                else
                    if self.speedWaitingTimerBoot >= self.bootLoader[self.bootScreen].time then
                        if self.bootLoader[self.bootScreen].wasSet then
                            if not self.bootLoader[self.bootScreen].stayOn then
                                if self.bootLoader[self.bootScreen].screen ~= nil then
                                    setVisibility(self.bootLoader[self.bootScreen].screen, false)
                                end
                                if self.bootLoader[self.bootScreen].other ~= nil then
                                    setVisibility(self.bootLoader[self.bootScreen].other, false)
                                end
                            end
                            self.bootLoader[self.bootScreen].wasSet = false
                        end
                        self.bootScreen = self.bootScreen + 1
                    end
                end
            end
        end
        self.speedWaitingTimerBoot = self.speedWaitingTimerBoot + dt
    else
        for i=1, table.getn(self.bootLoader) do
            if self.bootLoader[i] ~= nil then
                if self.bootLoader[i].screen ~= nil then
                    setVisibility(self.bootLoader[i].screen, false)
                end
                if self.bootLoader[i].other ~= nil then
                    setVisibility(self.bootLoader[i].other, false)
                end
                self.bootLoader[i].wasSet = false
            end
        end
        self.speedWaitingTimerBoot = 0
        self.bootScreen = 1
    end;
end

function DisplayBoot:delete()
end

function DisplayBoot:getSaveAttributesAndNodes(nodeIdent) end
function DisplayBoot:updateTick(dt) end
function DisplayBoot:draw() end
function DisplayBoot:mouseEvent(posX, posY, isDown, isUp, button) end
function DisplayBoot:keyEvent(unicode, sym, modifier, isDown) end
function DisplayBoot:onAttach(attacherVehicle, jointDescIndex) end
function DisplayBoot:onDetach() end
function DisplayBoot:onDeactivate() end
