---------------------------------------------------------------------------------------------------------
-- @Author: ViperGTS96-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
--------------------"The simplest design is the best design." -------------------------------------------
---------------------------------------------------------------------------------------------------------
-----The ability to add Masks/Hats/Helmets to player via this script is reserved by ViperGTS96-----------
---------------------------------------------------------------------------------------------------------

cowboyHatOL = {};
cowboyHatOL.active = true;
cowboyHatOL.overlayShown = false;
cowboyHatOL.inputs = {};
cowboyHatOL.inputs.modelKey = "HOME";
cowboyHatOL.inputs.clrPKey = "PAGEUP";
cowboyHatOL.inputs.clrBKey = "PAGEDOWN";
cowboyHatOL.inputs.xml = getUserProfileAppPath().."inputBinding.xml";
--------------------------------------------------------------------------------
cowboyHatOL.backgroundOL = createImageOverlay(g_currentModDirectory.."icons/background.dds");
cowboyHatOL.bgBorderOL = createImageOverlay(g_currentModDirectory.."icons/bgBorder.dds");
cowboyHatOL.bullriderOL = createImageOverlay(g_currentModDirectory.."icons/bullrider.dds");
cowboyHatOL.bullrider2OL = createImageOverlay(g_currentModDirectory.."icons/bullriderW.dds");
cowboyHatOL.bullriderBandOL = createImageOverlay(g_currentModDirectory.."icons/bullriderBand.dds");
cowboyHatOL.bullriderPBandOL = createImageOverlay(g_currentModDirectory.."icons/bullriderBand2.dds");
cowboyHatOL.cattlemanOL = createImageOverlay(g_currentModDirectory.."icons/cattleman.dds");
cowboyHatOL.cattleman2OL = createImageOverlay(g_currentModDirectory.."icons/cattlemanW.dds");
cowboyHatOL.cattlemanBandOL = createImageOverlay(g_currentModDirectory.."icons/cattlemanBand.dds");
cowboyHatOL.cattlemanPBandOL = createImageOverlay(g_currentModDirectory.."icons/cattlemanBand2.dds");
cowboyHatOL.helpersOL = createImageOverlay(g_currentModDirectory.."icons/helpers.dds");
cowboyHatOL.iconOL = createImageOverlay(g_currentModDirectory.."icons/icon.dds");
cowboyHatOL.userColorOL = createImageOverlay("dataS2/menu/hud/configurations/config_color.dds");
cowboyHatOL.platedOL = createImageOverlay("dataS2/menu/hud/configurations/config_edition.dds");
--------------------------------------------------------------------------------
cowboyHatOL.OLW = 0.2;
cowboyHatOL.OLH = cowboyHatOL.OLW * g_screenAspectRatio;
cowboyHatOL.OLX = 0.5 - (cowboyHatOL.OLW / 2);
cowboyHatOL.OLY = 0.5 - (cowboyHatOL.OLH / 2);
cowboyHatOL.borderW = cowboyHatOL.OLW*1.032;
cowboyHatOL.borderH = cowboyHatOL.borderW * g_screenAspectRatio;
cowboyHatOL.borderX = 0.5 - (cowboyHatOL.borderW / 2);
cowboyHatOL.borderY = 0.5 - (cowboyHatOL.borderH / 2);
cowboyHatOL.textSize = 0.01;
cowboyHatOL.textX = cowboyHatOL.OLX + cowboyHatOL.textSize;
cowboyHatOL.textY = cowboyHatOL.OLY + cowboyHatOL.textSize;
cowboyHatOL.indexSize = 0.02;
cowboyHatOL.indexX = cowboyHatOL.OLX + cowboyHatOL.indexSize;
cowboyHatOL.indexY = (cowboyHatOL.OLY + cowboyHatOL.OLH) - cowboyHatOL.indexSize;
cowboyHatOL.iconW = 0.045;
cowboyHatOL.iconH = cowboyHatOL.iconW * g_screenAspectRatio;
cowboyHatOL.iconSmlW = cowboyHatOL.iconW/2;
cowboyHatOL.iconSmlH = cowboyHatOL.iconH/2;
cowboyHatOL.iconX = (cowboyHatOL.OLX+cowboyHatOL.OLW)-(cowboyHatOL.iconW+0.01);
cowboyHatOL.iconSmlX = (cowboyHatOL.OLX+cowboyHatOL.OLW)-(cowboyHatOL.iconSmlW);
cowboyHatOL.iconY = cowboyHatOL.OLY+0.01;
--------------------------------------------------------------------------------
cowboyHatOL.tick = 0;
local cowboyHatXML = loadXMLFile("cowboyHatXML", g_currentModDirectory.."cowboyHat.xml");
cowboyHatOL.duration = Utils.getNoNil(getXMLInt(cowboyHatXML, "cowboyHat.menu.intervals.toggled#duration"), 60);
cowboyHatOL.durationMnu = Utils.getNoNil(getXMLInt(cowboyHatXML, "cowboyHat.menu.intervals.controls#duration"), 140);
delete(cowboyHatXML);
cowboyHatOL.userColor = false;
cowboyHatOL.platedColor = false;
cowboyHatOL.displayIndex = 0;
cowboyHatOL.displayMaxIndex = 0;
cowboyHatOL.renderCall = 0;
cowboyHatOL.textString = {};
cowboyHatOL.controlString = {};
cowboyHatOL.textFabric = "unassigned";
cowboyHatOL.textLeather = "unassigned";
cowboyHatOL.yesText = "unassigned";
cowboyHatOL.noText = "unassigned";
--------------------------------------------------------------------------------

function cowboyHatOL:loadMap(savegame)

	cowboyHatOL.events = {};

    Player.registerActionEvents = Utils.appendedFunction(Player.registerActionEvents, cowboyHatOL.registerActionEvents);
    Player.updateActionEvents = Utils.appendedFunction(Player.updateActionEvents, cowboyHatOL.updateActionEvents);
	Player.removeActionEvents = Utils.appendedFunction(Player.removeActionEvents, cowboyHatOL.removeActionEvents);
	
	setOverlayColor(cowboyHatOL.backgroundOL, 1.0, 1.0, 1.0, 0.99);
	setOverlayColor(cowboyHatOL.bgBorderOL, 1.0, 1.0, 1.0, 1.0);
	setOverlayColor(cowboyHatOL.userColorOL, 1.0, 1.0, 1.0, 1.0);
	setOverlayColor(cowboyHatOL.platedOL, 1.0, 1.0, 1.0, 1.0);
	local red, green, blue = cowboyHat:getHatColor(false, false, false);
	setOverlayColor(cowboyHatOL.bullriderOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.bullrider2OL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.cattlemanOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.cattleman2OL, red, green, blue, 1.0);
	red, green, blue = cowboyHat:getBandColor(false, false, false);
	setOverlayColor(cowboyHatOL.bullriderBandOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.cattlemanBandOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.bullriderPBandOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.cattlemanPBandOL, red, green, blue, 1.0);
	
	cowboyHatOL.textFabric = g_i18n:getText("cowboyHat_nonLeather");
	cowboyHatOL.textLeather = g_i18n:getText("cowboyHat_leather");
	cowboyHatOL.yesText = g_i18n:getText("button_yes");
	cowboyHatOL.noText = g_i18n:getText("button_no");
	cowboyHatOL:getTexts();
	cowboyHatOL:getHelpTexts();
	cowboyHatOL:getKeys();

end;
--[[
function cowboyHatOL:update(dt)
	if g_gui:getIsGuiVisible() and cowboyHatOL.active then
		cowboyHatOL.active = false;
	elseif not g_gui:getIsGuiVisible() and not cowboyHatOL.active then
		cowboyHatOL.active = true;
	end;
end;]]
--------------------------------------------------------------------------------

function cowboyHatOL:removeActionEvents()
	cowboyHatOL.events = {};
end;

function cowboyHatOL:updateActionEvents()
	local visible = self.playerStateMachine:isAvailable("crouch");
	--or self.playerStateMachine:isAvailable("walk");	
	for _, eventName in pairs(cowboyHatOL.events) do	
        g_inputBinding:setActionEventActive(eventName, visible)
		g_inputBinding:setActionEventTextVisibility(eventName, visible);
	end;
end;

function cowboyHatOL:registerActionEvents()
	if #cowboyHatOL.events <=0 then
		cowboyHatOL.events = {};
		--Next Hat model
		--Shift + Hat model = Toggle helper hats
		local result, eventName = InputBinding.registerActionEvent(g_inputBinding, 'NEXTMODELKEY', self, cowboyHatOL.setNextModel, false, true, false, true)
		if result then
			table.insert(cowboyHatOL.events, eventName);
			g_inputBinding:setActionEventTextVisibility(eventName, false);
			g_inputBinding:setActionEventTextPriority(eventName, GS_PRIO_NORMAL);
		end;

		--Next primary color
		--Shift + primary color = Toggle Material
		local result, eventName = InputBinding.registerActionEvent(g_inputBinding, 'NEXTPCLRKEY', self, cowboyHatOL.setNextPrimaryColor, false, true, false, true)
		if result then
			table.insert(cowboyHatOL.events, eventName);
			g_inputBinding:setActionEventTextVisibility(eventName, false);
			g_inputBinding:setActionEventTextPriority(eventName, GS_PRIO_NORMAL);
		end;

		--Next band color
		--Shift + band color = Toggle Plated
		local result, eventName = InputBinding.registerActionEvent(g_inputBinding, 'NEXTBCLRKEY', self, cowboyHatOL.setNextSecondaryColor, false, true, false, true)
		if result then
			table.insert(cowboyHatOL.events, eventName);
			g_inputBinding:setActionEventTextVisibility(eventName, false);
			g_inputBinding:setActionEventTextPriority(eventName, GS_PRIO_NORMAL);
		end;

		--Display Extra Controls
		local result, eventName = InputBinding.registerActionEvent(g_inputBinding, 'SHOWCNTRLSKEY', self, cowboyHatOL.showControls, false, true, false, true)
		if result then
			table.insert(cowboyHatOL.events, eventName);
			g_inputBinding:setActionEventTextVisibility(eventName, true);
			g_inputBinding:setActionEventTextPriority(eventName, GS_PRIO_HIGH);
		end;
	
	end;
end;

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

function cowboyHatOL:renderModelOverlay()

	cowboyHat:nextHatStyle();
	local style = cowboyHat.plyrModelIndex;
	--if style == 0 then 
	--	style = "C";
	--end;
	cowboyHatOL.displayIndex = style;
	cowboyHatOL:getTexts();
	cowboyHatOL.tick = 0;
	cowboyHatOL.overlayShown = true;

end;

function cowboyHatOL:renderHatColorOverlay(setNotGet)

	local red, green, blue = cowboyHat:getHatColor(false, setNotGet, true);
	setOverlayColor(cowboyHatOL.bullriderOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.bullrider2OL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.cattlemanOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.cattleman2OL, red, green, blue, 1.0);

	cowboyHatOL.userColor = false;
	if cowboyHat.colors.mat.index > cowboyHat.numberOfPrimaryColors then 
		cowboyHatOL.userColor = true;
	end;

	cowboyHatOL.displayIndex = cowboyHat.colors.mat.index;
	cowboyHatOL.displayMaxIndex = cowboyHat.numberOfPrimaryColors+1;
	cowboyHatOL:getTexts();

	cowboyHatOL.tick = 0;
	cowboyHatOL.overlayShown = true;

end;

function cowboyHatOL:renderBandColorOverlay(setNotGet)

	local red, green, blue = cowboyHat:getBandColor(false, setNotGet, true);
	setOverlayColor(cowboyHatOL.bullriderBandOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.cattlemanBandOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.bullriderPBandOL, red, green, blue, 1.0);
	setOverlayColor(cowboyHatOL.cattlemanPBandOL, red, green, blue, 1.0);

	cowboyHatOL.userColor = false;
	if cowboyHat.colors.band.index > cowboyHat.numberOfSecondaryColors then 
		cowboyHatOL.userColor = true;
	end;

	cowboyHatOL.displayIndex = cowboyHat.colors.band.index;
	cowboyHatOL.displayMaxIndex = cowboyHat.numberOfSecondaryColors+1;
	cowboyHatOL:getTexts();

	cowboyHatOL.tick = 0;
	cowboyHatOL.overlayShown = true;

end;

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

function cowboyHatOL:setNextModel(actionName, keyStatus, arg3, arg4, arg5)

	if cowboyHatOL.active then
		if Input.isKeyPressed(Input.KEY_lshift) or Input.isKeyPressed(Input.KEY_rshift) then
			if actionName == "NEXTMODELKEY" then
				cowboyHat.aiGetHats = not cowboyHat.aiGetHats;
				cowboyHatOL:getTexts();
				cowboyHatOL.renderCall = 4;
				cowboyHatOL.tick = 0;
				cowboyHatOL.overlayShown = true;
			end;
		else
			if actionName == "NEXTMODELKEY" then
				cowboyHatOL.renderCall = 1;
				cowboyHatOL:renderModelOverlay();
			end;
		end;
	end;

end;

function cowboyHatOL:setNextPrimaryColor(actionName, keyStatus, arg3, arg4, arg5)

	if cowboyHatOL.active then
		if Input.isKeyPressed(Input.KEY_lshift) or Input.isKeyPressed(Input.KEY_rshift) then
			if actionName == "NEXTPCLRKEY" then	
				if cowboyHat.colors.player.mat.var ~= 11.0 then 
					cowboyHat.colors.player.mat.var = 11.0;
				else
					cowboyHat.colors.player.mat.var = 11.5;
				end;
				cowboyHatOL.renderCall = 5;
				cowboyHatOL:renderHatColorOverlay(false);
			end;
		else
			if actionName == "NEXTPCLRKEY" then	
				cowboyHatOL.renderCall = 2;
				cowboyHatOL:renderHatColorOverlay(true);
			end;
		end;
	end;

end;

function cowboyHatOL:setNextSecondaryColor(actionName, keyStatus, arg3, arg4, arg5)

	if cowboyHatOL.active then
		if Input.isKeyPressed(Input.KEY_lshift) or Input.isKeyPressed(Input.KEY_rshift) then
			if actionName == "NEXTBCLRKEY" then	
				if cowboyHat.colors.player.band.var ~= 1.0 then 
					cowboyHat.colors.player.band.var = 1.0;
					cowboyHatOL.platedColor = false;
				else
					cowboyHat.colors.player.band.var = 2.0;
					cowboyHatOL.platedColor = true;
				end;
				cowboyHatOL.renderCall = 6;
				cowboyHatOL:renderHatColorOverlay(false);
			end;
		else
			if actionName == "NEXTBCLRKEY" then	
				cowboyHatOL.renderCall = 3;
				cowboyHatOL:renderBandColorOverlay(true);
			end;
		end;
	end;

end;

function cowboyHatOL:showControls(actionName, keyStatus, arg3, arg4, arg5)
	if cowboyHatOL.active then
		if actionName == "SHOWCNTRLSKEY" then	
			cowboyHatOL:getKeys();
			cowboyHatOL:getHelpTexts();
			cowboyHatOL.renderCall = 7;		
			cowboyHatOL.tick = 0;
			cowboyHatOL.overlayShown = true;
		end;
	end;
end;

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

function cowboyHatOL:getTexts()

	local yesOrNoText = cowboyHatOL.noText;
	if cowboyHat.aiGetHats then
		yesOrNoText = cowboyHatOL.yesText;
	end;
	local materialType = cowboyHatOL.textFabric;
	if cowboyHat.colors.player.mat.var ~= 11.0 then 
		materialType = cowboyHatOL.textLeather;
	end;
	local utf8String1 = asciiToUtf8(tostring(cowboyHatOL.displayIndex));	
	if cowboyHatOL.displayMaxIndex ~= 0 then
		utf8String1 = asciiToUtf8(tostring(cowboyHatOL.displayIndex.."/"..cowboyHatOL.displayMaxIndex));
		cowboyHatOL.displayMaxIndex = 0;
	end;

	local utf8String2 = asciiToUtf8(g_i18n:getText("cowboyHat_helperHats").." : "..yesOrNoText);
	local utf8String3 = asciiToUtf8(g_i18n:getText("cowboyHat_material").." : "..materialType);

	cowboyHatOL.textString = {utf8String1,utf8String2,utf8String3};
	
end;

function cowboyHatOL:getHelpTexts()

	local utf8String1 = asciiToUtf8(g_i18n:getText("cowboyHat_control5").." = Shift + "..cowboyHatOL.inputs.modelKey);
	local utf8String2 = asciiToUtf8(g_i18n:getText("cowboyHat_control6").." = Shift + "..cowboyHatOL.inputs.clrPKey);
	local utf8String3 = asciiToUtf8(g_i18n:getText("cowboyHat_control7").." = Shift + "..cowboyHatOL.inputs.clrBKey);

	cowboyHatOL.controlString = {utf8String1,utf8String2,utf8String3};

end;

function cowboyHatOL:getKeys()

	local xmlFile = loadXMLFile("inputBinding", cowboyHatOL.inputs.xml)
	
	local i = 0;
	local iCount = 0;
	while true do
		local objKey = string.format("inputBinding.actionBinding(%d)", i);
		local inputKey = getXMLString(xmlFile, objKey.."#action")
		if inputKey == nil or iCount >= 3 then
			break;
		end;
		if inputKey == "NEXTMODELKEY" then
			cowboyHatOL.inputs.modelKey = getXMLString(xmlFile, objKey..".binding#input")
			cowboyHatOL.inputs.modelKey = string.sub(cowboyHatOL.inputs.modelKey, 5);
			cowboyHatOL.inputs.modelKey = string.upper(cowboyHatOL.inputs.modelKey);
			iCount = iCount + 1;
		end;
		if inputKey == "NEXTPCLRKEY" then
			cowboyHatOL.inputs.clrPKey = getXMLString(xmlFile, objKey.. ".binding#input")
			cowboyHatOL.inputs.clrPKey = string.sub(cowboyHatOL.inputs.clrPKey, 5);
			cowboyHatOL.inputs.clrPKey = string.upper(cowboyHatOL.inputs.clrPKey);
			iCount = iCount + 1;
		end;
		if inputKey == "NEXTBCLRKEY" then
			cowboyHatOL.inputs.clrBKey = getXMLString(xmlFile, objKey..".binding#input")
			cowboyHatOL.inputs.clrBKey = string.sub(cowboyHatOL.inputs.clrBKey, 5);
			cowboyHatOL.inputs.clrBKey = string.upper(cowboyHatOL.inputs.clrBKey);
			iCount = iCount + 1;
		end;
        i = i + 1;
    end;

	delete(xmlFile);

end;

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

function cowboyHatOL:draw()

	if cowboyHatOL.active then
		if cowboyHatOL.overlayShown then
			local duration = cowboyHatOL.duration;
			if cowboyHatOL.renderCall == 7 then duration = cowboyHatOL.durationMnu; end;
			cowboyHatOL.tick = cowboyHatOL.tick + 1;
			if cowboyHatOL.tick < duration then
				local style = cowboyHat.plyrModelIndex;
				--if style == 0 then 
				--	style = cowboyHat.plyrModel;
				--end;

				renderOverlay(cowboyHatOL.bgBorderOL, cowboyHatOL.borderX, cowboyHatOL.borderY, cowboyHatOL.borderW, cowboyHatOL.borderH);
				renderOverlay(cowboyHatOL.backgroundOL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.OLW, cowboyHatOL.OLH);
				setTextColor(1.0, 1.0, 1.0, 1.0);

				if cowboyHatOL.renderCall ~= 7 then -- Not Control Menu

					local bullBandOL = cowboyHatOL.bullriderBandOL;
					local cattleBandOL = cowboyHatOL.cattlemanBandOL;
					if cowboyHatOL.platedColor then 						
						bullBandOL = cowboyHatOL.bullriderPBandOL;
						cattleBandOL = cowboyHatOL.cattlemanPBandOL;
					end;

					if style <= 1 then 
						renderOverlay(cowboyHatOL.bullriderOL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.OLW, cowboyHatOL.OLH);
						renderOverlay(bullBandOL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.OLW, cowboyHatOL.OLH);
					elseif style <= 2 then
						renderOverlay(cowboyHatOL.cattlemanOL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.OLW, cowboyHatOL.OLH);
						renderOverlay(cattleBandOL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.OLW, cowboyHatOL.OLH);
					elseif style <= 3 then
						renderOverlay(cowboyHatOL.bullrider2OL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.OLW, cowboyHatOL.OLH);
						renderOverlay(bullBandOL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.OLW, cowboyHatOL.OLH);
					else -- style > 3
						renderOverlay(cowboyHatOL.cattleman2OL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.OLW, cowboyHatOL.OLH);
						renderOverlay(cattleBandOL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.OLW, cowboyHatOL.OLH);
					end;

					local showIndex = true;
					if cowboyHatOL.renderCall == 4 then --Helper Hats
						renderOverlay(cowboyHatOL.helpersOL, cowboyHatOL.iconX, cowboyHatOL.iconY, cowboyHatOL.iconW*0.75, cowboyHatOL.iconH*0.75);
						renderText(cowboyHatOL.textX, cowboyHatOL.textY, cowboyHatOL.textSize*1.5, cowboyHatOL.textString[2]);
						showIndex = false;
					end;
					
					if cowboyHatOL.renderCall == 5 then -- Material Type
						renderText(cowboyHatOL.textX, cowboyHatOL.textY, cowboyHatOL.textSize*1.5, cowboyHatOL.textString[3]);--cowboyHatOL.textY+(cowboyHatOL.textSize*2), cowboyHatOL.textSize
						showIndex = false;
					end;

					if showIndex then
						if cowboyHatOL.userColor and cowboyHatOL.renderCall ~= 1 then 
							renderOverlay(cowboyHatOL.userColorOL, cowboyHatOL.OLX, cowboyHatOL.OLY, cowboyHatOL.iconSmlW, cowboyHatOL.iconSmlH); --Custom Color
						end;
						if cowboyHatOL.platedColor then 
							renderOverlay(cowboyHatOL.platedOL, cowboyHatOL.iconSmlX, cowboyHatOL.OLY, cowboyHatOL.iconSmlW, cowboyHatOL.iconSmlH); --Plated
						end;
						renderText(cowboyHatOL.indexX, cowboyHatOL.indexY, cowboyHatOL.indexSize, cowboyHatOL.textString[1]);--Index Number
					end;

				else -- Display Controls Menu

					renderOverlay(cowboyHatOL.iconOL, cowboyHatOL.iconX, cowboyHatOL.iconY, cowboyHatOL.iconW, cowboyHatOL.iconH);
					local yLocation = cowboyHatOL.indexY-(cowboyHatOL.indexSize*2);
					renderText(cowboyHatOL.indexX, yLocation, cowboyHatOL.textSize, cowboyHatOL.controlString[1]);
					yLocation = yLocation - (cowboyHatOL.indexSize*2);
					renderText(cowboyHatOL.indexX, yLocation, cowboyHatOL.textSize, cowboyHatOL.controlString[2]);
					yLocation = yLocation - (cowboyHatOL.indexSize*2);
					renderText(cowboyHatOL.indexX, yLocation, cowboyHatOL.textSize, cowboyHatOL.controlString[3]);

				end;

			else--Timer duration reached; stop and reset.				
				cowboyHatOL.overlayShown = false;
				cowboyHatOL.tick = 0;
				cowboyHatOL.renderCall = 0;
			end;
		end;
	end;

end;

addModEventListener(cowboyHatOL);
--------------------------------------------------------------------------------