--
-- cab
-- LS UK Modteam
--
-- author Henly20
-- date  20/11/2010
--

cabNHtk4060 = {};

function cabNHtk4060.prerequisitesPresent(specializations)
    return true;
end;

function cabNHtk4060:load(xmlFile)

	self.setCabVisibility = SpecializationUtil.callSpecializationsFunction("setCabVisibility");

      self.cabShows = {};
      local i = 0;
      while true do
          local key = string.format("vehicle.cabShows.cabShow(%d)", i);
          if not hasXMLProperty(xmlFile, key) then
              break;
          end;
          local node = Utils.indexToObject(self.components, getXMLString(xmlFile, key.."#index"));
          if node ~= nil then
              setVisibility(node, true);
              table.insert(self.cabShows, {node=node});
          end;
          i = i + 1;
      end;
	  

end;

function cabNHtk4060:delete()

end;

function cabNHtk4060:readStream(streamId, connection)
	self.isLoading = true;
	local visibility = streamReadBool(streamId);
	self:setCabVisibility(visibility, true);

	
end;

function cabNHtk4060:writeStream(streamId, connection)
	streamWriteBool(streamId, self.cabShowsActive);

	
end;

function cabNHtk4060:mouseEvent(posX, posY, isDown, isUp, button)
end;

function cabNHtk4060:keyEvent(unicode, sym, modifier, isDown)
end;

function cabNHtk4060:update(dt)

      if self:getIsActiveForInput() and self.isClient then
          if InputBinding.hasEvent(InputBinding.CAB) then
              self:setCabVisibility(not self.cabShowsActive);
          end;
	end;
end;

function cabNHtk4060:updateTick(dt)



end;

function cabNHtk4060:onLeave()

end;

function cabNHtk4060:draw()

end;

function cabNHtk4060:setCabVisibility(visibility, noEventSend)
      if visibility ~= self.cabShowsActive then
  
          if noEventSend == nil or noEventSend == false then
              if g_server ~= nil then
                  g_server:broadcastEvent(SetCabEvent:new(self, visibility), nil, nil, self);
              else
                  g_client:getServerConnection():sendEvent(SetCabEvent:new(self, visibility));
              end;
          end;
  
          self.cabShowsActive = visibility;
  
          for _, cabShow in pairs(self.cabShows) do
             setVisibility(cabShow.node, visibility);
          end;
          for _,v in pairs(self.specializations) do
              if v.setCabVisibility ~= nil then
                 v.setCabVisibility(self, visibility);
              end;
          end;
      end;
end;