<commit_before>﻿--[[--------------------------------------------------------------------
    Ovale Spell Priority
    Copyright (C) 2009, 2010, 2011, 2012 Sidoine
    Copyright (C) 2012, 2013 <NAME>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License in the LICENSE
    file accompanying this program.
--]]--------------------------------------------------------------------

local _, Ovale = ...

--inherits ActionButtonTemplate

--<private-static-properties>
local L = Ovale.L
local OvaleOptions = Ovale.OvaleOptions
local OvaleSpellBook = Ovale.OvaleSpellBook
local OvaleState = Ovale.OvaleState

local next = next
local pairs = pairs
local strfind = string.find
local strsub = string.sub
local tostring = tostring
--</private-static-properties>

--<public-methods>
local function SetValue(self, value, actionTexture)
	self.icone:Show()
	self.icone:SetTexture(actionTexture);
	self.icone:SetAlpha(1.0)
	self.cd:Hide()
	self.focusText:Hide()
	self.aPortee:Hide()	
	self.shortcut:Hide()
	if value then
		self.value = value
		self.spellId = nil
		if value < 10 then
			self.remains:SetFormattedText("%.1f", value)
		elseif value == math.huge then
			self.remains:SetFormattedText("inf")
		else
			self.remains:SetFormattedText("%d", value)
		end
		self.remains:Show()
	else
		self.remains:Hide()
	end
	self:Show()
end

local function Update(self, element, minAttente, actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration,
				actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId, actionTarget)
				
	self.spellId = spellId
	self.value = nil

	local profile = OvaleOptions:GetProfile()
	if (minAttente~=nil and actionTexture) then	
	
		if (actionTexture~=self.actionCourante or self.ancienneAttente==nil or 
			(minAttente~=OvaleState.now and minAttente>self.ancienneAttente+0.01) or
			(minAttente < self.finAction-0.01)) then
			if (actionTexture~=self.actionCourante or self.ancienneAttente==nil or 
					(minAttente~=OvaleState.now and minAttente>self.ancienneAttente+0.01)) then
				self.debutAction = OvaleState.now
			end
			self.actionCourante = actionTexture
			self.finAction = minAttente
			if (minAttente == OvaleState.now) then
				self.cd:Hide()
			else
				self.lastSound = nil
				if self.cdShown then
					self.cd:Show()
					self.cd:SetCooldown(self.debutAction, self.finAction - self.debutAction);
				end
			end
		end
		
		if not profile.apparence.flashIcon and minAttente<=OvaleState.now then
			self.cd:Hide()
		end
		
		self.ancienneAttente = minAttente
		
		-- L'icône avec le cooldown
		self.icone:Show()
		self.icone:SetTexture(actionTexture);
		
		if (actionUsable) then
			self.icone:SetAlpha(1.0)
		else
			self.icone:SetAlpha(0.33)
		end
		
		local red
		if minAttente > actionCooldownStart + actionCooldownDuration + 0.01
				and minAttente > OvaleState.now
				and minAttente > OvaleState.nextCast then
			self.icone:SetVertexColor(0.75,0.2,0.2)
			red = true
		else
			self.icone:SetVertexColor(1,1,1)
		end 
		
		--if (minAttente==OvaleState.now) then
			--self.cd:Hide()
		--end

		if element.params.sound and not self.lastSound then
			local delay = element.params.soundtime or 0.5
			if OvaleState.now>=minAttente - delay then
				self.lastSound = element.params.sound
			--	print("Play" .. self.lastSound)
				PlaySoundFile(self.lastSound)
			end
		end
		
		-- La latence
		if minAttente>OvaleState.now and profile.apparence.highlightIcon and not red then
			local lag = 0.6
			local newShouldClick
			if minAttente<OvaleState.now + lag then
				newShouldClick = true
			else
				newShouldClick = false
			end
			if self.shouldClick ~= newShouldClick then
				if newShouldClick then
					self:SetChecked(1)
				else
					self:SetChecked(0)
				end
				self.shouldClick = newShouldClick
			end
		elseif self.shouldClick then
			self.shouldClick = false
			self:SetChecked(0)
		end
		
		-- Le temps restant
		if ((profile.apparence.numeric or self.params.text == "always") and minAttente > OvaleState.now) then
			self.remains:SetFormattedText("%.1f", minAttente - OvaleState.now)
			self.remains:Show()
		else
			self.remains:Hide()
		end
		
		-- Le raccourcis clavier 
		if (profile.apparence.raccourcis) then
			self.shortcut:Show()
			self.shortcut:SetText(actionShortcut)
		else
			self.shortcut:Hide()
		end
		
		-- L'indicateur de portée
		self.aPortee:Show()
		if (actionInRange==1) then
			self.aPortee:SetVertexColor(0.6,0.6,0.6)
			self.aPortee:Show()
		elseif (actionInRange==0) then
			self.aPortee:SetVertexColor(1.0,0.1,0.1)
			self.aPortee:Show()
		else
			self.aPortee:Hide()
		end
		if actionTarget and actionTarget~="target" then
			self.focusText:SetText(actionTarget)
			self.focusText:Show()
		else
			self.focusText:Hide()
		end
		self:Show()
	else
		self.icone:Hide()
		self.aPortee:Hide()
		self.shortcut:Hide()
		self.remains:Hide()
		self.focusText:Hide()
		if profile.apparence.hideEmpty then
			self:Hide()
		else
			self:Show()
		end
		if self.shouldClick then
			self:SetChecked(0)
			self.shouldClick = false
		end
	end

	return minAttente,element
end

local function SetHelp(self, help)
	self.help = help
end

local function SetParams(self, params, secure)
	self.params = params
	
	self.actionButton = false
	if secure then
		for k,v in pairs(params) do
			local f = strfind(k, "spell")
			if f then
				local prefix = strsub(k, 1, f-1)
				local suffix = strsub(k, f + 5)
				local param
				Ovale:FormatPrint("%stype%s", prefix, suffix)
				self:SetAttribute(prefix .. "type" .. suffix, "spell")
				self:SetAttribute("unit", self.params.target or "target")
				self:SetAttribute(k, OvaleSpellBook:GetSpellName(v))
				self.actionButton = true
			end
		end
	end
end

local function SetFontScale(self, scale)
	self.fontScale = scale
	self.shortcut:SetFont(self.fontName, self.fontHeight * self.fontScale, self.fontFlags)
	self.aPortee:SetFont(self.fontName, self.fontHeight * self.fontScale, self.fontFlags)
end

local function SetRangeIndicator(self, text)
	self.aPortee:SetText(text)
end
--</public-methods>

function OvaleIcone_OnMouseUp(self)
	if not self.actionButton then
		Ovale:ToggleOptions()
	end
	self:SetChecked(1)
end

function OvaleIcone_OnEnter(self)
	if self.help or next(Ovale.casesACocher) or next(Ovale.listes) or self.spellId or self.value then
		GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT")
		if self.help then
			GameTooltip:SetText(L[self.help])
		end
		if self.spellId then
			GameTooltip:AddLine(OvaleSpellBook:GetSpellName(self.spellId), 0.5, 1, 0.75)
		elseif self.value then
			local value = (value < math.huge) and tostring(value) or "infinity"
			GameTooltip:AddLine(value, 0.5, 1, 0.75)
		end
		if next(Ovale.casesACocher) or next(Ovale.listes) then<commit_msg>Fix tooltip display of a value instead of a spell on mouseover.<commit_after>﻿--[[--------------------------------------------------------------------
    Ovale Spell Priority
    Copyright (C) 2009, 2010, 2011, 2012 Sidoine
    Copyright (C) 2012, 2013 <NAME>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License in the LICENSE
    file accompanying this program.
--]]--------------------------------------------------------------------

local _, Ovale = ...

--inherits ActionButtonTemplate

--<private-static-properties>
local L = Ovale.L
local OvaleOptions = Ovale.OvaleOptions
local OvaleSpellBook = Ovale.OvaleSpellBook
local OvaleState = Ovale.OvaleState

local next = next
local pairs = pairs
local strfind = string.find
local strsub = string.sub
local tostring = tostring
--</private-static-properties>

--<public-methods>
local function SetValue(self, value, actionTexture)
	self.icone:Show()
	self.icone:SetTexture(actionTexture);
	self.icone:SetAlpha(1.0)
	self.cd:Hide()
	self.focusText:Hide()
	self.aPortee:Hide()	
	self.shortcut:Hide()
	if value then
		self.value = value
		self.spellId = nil
		if value < 10 then
			self.remains:SetFormattedText("%.1f", value)
		elseif value == math.huge then
			self.remains:SetFormattedText("inf")
		else
			self.remains:SetFormattedText("%d", value)
		end
		self.remains:Show()
	else
		self.remains:Hide()
	end
	self:Show()
end

local function Update(self, element, minAttente, actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration,
				actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId, actionTarget)
				
	self.spellId = spellId
	self.value = nil

	local profile = OvaleOptions:GetProfile()
	if (minAttente~=nil and actionTexture) then	
	
		if (actionTexture~=self.actionCourante or self.ancienneAttente==nil or 
			(minAttente~=OvaleState.now and minAttente>self.ancienneAttente+0.01) or
			(minAttente < self.finAction-0.01)) then
			if (actionTexture~=self.actionCourante or self.ancienneAttente==nil or 
					(minAttente~=OvaleState.now and minAttente>self.ancienneAttente+0.01)) then
				self.debutAction = OvaleState.now
			end
			self.actionCourante = actionTexture
			self.finAction = minAttente
			if (minAttente == OvaleState.now) then
				self.cd:Hide()
			else
				self.lastSound = nil
				if self.cdShown then
					self.cd:Show()
					self.cd:SetCooldown(self.debutAction, self.finAction - self.debutAction);
				end
			end
		end
		
		if not profile.apparence.flashIcon and minAttente<=OvaleState.now then
			self.cd:Hide()
		end
		
		self.ancienneAttente = minAttente
		
		-- L'icône avec le cooldown
		self.icone:Show()
		self.icone:SetTexture(actionTexture);
		
		if (actionUsable) then
			self.icone:SetAlpha(1.0)
		else
			self.icone:SetAlpha(0.33)
		end
		
		local red
		if minAttente > actionCooldownStart + actionCooldownDuration + 0.01
				and minAttente > OvaleState.now
				and minAttente > OvaleState.nextCast then
			self.icone:SetVertexColor(0.75,0.2,0.2)
			red = true
		else
			self.icone:SetVertexColor(1,1,1)
		end 
		
		--if (minAttente==OvaleState.now) then
			--self.cd:Hide()
		--end

		if element.params.sound and not self.lastSound then
			local delay = element.params.soundtime or 0.5
			if OvaleState.now>=minAttente - delay then
				self.lastSound = element.params.sound
			--	print("Play" .. self.lastSound)
				PlaySoundFile(self.lastSound)
			end
		end
		
		-- La latence
		if minAttente>OvaleState.now and profile.apparence.highlightIcon and not red then
			local lag = 0.6
			local newShouldClick
			if minAttente<OvaleState.now + lag then
				newShouldClick = true
			else
				newShouldClick = false
			end
			if self.shouldClick ~= newShouldClick then
				if newShouldClick then
					self:SetChecked(1)
				else
					self:SetChecked(0)
				end
				self.shouldClick = newShouldClick
			end
		elseif self.shouldClick then
			self.shouldClick = false
			self:SetChecked(0)
		end
		
		-- Le temps restant
		if ((profile.apparence.numeric or self.params.text == "always") and minAttente > OvaleState.now) then
			self.remains:SetFormattedText("%.1f", minAttente - OvaleState.now)
			self.remains:Show()
		else
			self.remains:Hide()
		end
		
		-- Le raccourcis clavier 
		if (profile.apparence.raccourcis) then
			self.shortcut:Show()
			self.shortcut:SetText(actionShortcut)
		else
			self.shortcut:Hide()
		end
		
		-- L'indicateur de portée
		self.aPortee:Show()
		if (actionInRange==1) then
			self.aPortee:SetVertexColor(0.6,0.6,0.6)
			self.aPortee:Show()
		elseif (actionInRange==0) then
			self.aPortee:SetVertexColor(1.0,0.1,0.1)
			self.aPortee:Show()
		else
			self.aPortee:Hide()
		end
		if actionTarget and actionTarget~="target" then
			self.focusText:SetText(actionTarget)
			self.focusText:Show()
		else
			self.focusText:Hide()
		end
		self:Show()
	else
		self.icone:Hide()
		self.aPortee:Hide()
		self.shortcut:Hide()
		self.remains:Hide()
		self.focusText:Hide()
		if profile.apparence.hideEmpty then
			self:Hide()
		else
			self:Show()
		end
		if self.shouldClick then
			self:SetChecked(0)
			self.shouldClick = false
		end
	end

	return minAttente,element
end

local function SetHelp(self, help)
	self.help = help
end

local function SetParams(self, params, secure)
	self.params = params
	
	self.actionButton = false
	if secure then
		for k,v in pairs(params) do
			local f = strfind(k, "spell")
			if f then
				local prefix = strsub(k, 1, f-1)
				local suffix = strsub(k, f + 5)
				local param
				Ovale:FormatPrint("%stype%s", prefix, suffix)
				self:SetAttribute(prefix .. "type" .. suffix, "spell")
				self:SetAttribute("unit", self.params.target or "target")
				self:SetAttribute(k, OvaleSpellBook:GetSpellName(v))
				self.actionButton = true
			end
		end
	end
end

local function SetFontScale(self, scale)
	self.fontScale = scale
	self.shortcut:SetFont(self.fontName, self.fontHeight * self.fontScale, self.fontFlags)
	self.aPortee:SetFont(self.fontName, self.fontHeight * self.fontScale, self.fontFlags)
end

local function SetRangeIndicator(self, text)
	self.aPortee:SetText(text)
end
--</public-methods>

function OvaleIcone_OnMouseUp(self)
	if not self.actionButton then
		Ovale:ToggleOptions()
	end
	self:SetChecked(1)
end

function OvaleIcone_OnEnter(self)
	if self.help or next(Ovale.casesACocher) or next(Ovale.listes) or self.spellId or self.value then
		GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT")
		if self.help then
			GameTooltip:SetText(L[self.help])
		end
		if self.spellId then
			GameTooltip:AddLine(OvaleSpellBook:GetSpellName(self.spellId), 0.5, 1, 0.75)
		elseif self.value then
			local value = (self.value < math.huge) and tostring(self.value) or "infinity"
			GameTooltip:AddLine(value, 0.5, 1, 0.75)
		end
		if next(Ovale.casesACocher) or next(Ovale.listes) then
{'fraction_non_alphanumeric': 0.12386196769456681, 'fraction_numerical': 0.013950073421439061, 'mean_word_length': 3.5028099173553717, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5580549', 'n_tokens_mistral': 5466, 'n_tokens_neox': 4757, 'n_words': 1072}