`
--reload language
if(uiTranslationFile) then
	Infinity_DoFile("L_" .. uiTranslationFile)
else
	Infinity_DoFile("L_en_us")
end
listMetaInfo = {}

currentPanelID = 0

function displayTHAC()
	thactxt = ''
	thactxt =  characters[currentID].THAC0.current

	if (characters[currentID].THAC0.offhand ) then
		thactxt = thactxt .. '\n' .. characters[currentID].THAC0.offhand
	end

	return thactxt
end

function displayLabelTHAC()
	thactxt = ''
	thactxt =  characters[currentID].THAC0.current

	if (characters[currentID].THAC0.offhand ) then
		thactxt = thactxt .. '\n' .. t('OFFHAND_LABEL')  .. ': ' .. characters[currentID].THAC0.offhand
	end

	return thactxt
end

function displayLabelDamage()
	local str = characters[currentID].damage.min .. ' - ' .. characters[currentID].damage.max
	if(characters[currentID].damage.minOffhand and characters[currentID].damage.maxOffhand) then
		str = str .. '\n' .. t('OFFHAND_LABEL') .. ': ' .. characters[currentID].damage.minOffhand .. ' - ' .. characters[currentID].damage.maxOffhand 
	end
	return str
end

function displayCompiledAC()
	local compiledAC = characters[currentID].AC.current

	if characters[currentID].AC.crushing ~= 0 or characters[currentID].AC.missile ~= 0 or characters[currentID].AC.piercing ~= 0 or characters[currentID].AC.slashing ~= 0 then
		compiledAC = compiledAC .. " (" .. t("MODIFIERS_LABEL") .. ": "

		local numMods = 0
		if characters[currentID].AC.crushing > 0 then
			numMods = numMods + 1
			setStringTokenLua("<ACTOKEN>","+"..characters[currentID].AC.crushing)
			compiledAC = compiledAC .. " " .. t("ACMOD_VS_CRUSHING")
			removeStringTokenLua("<ACTOKEN>")
		elseif characters[currentID].AC.crushing < 0 then
			numMods = numMods + 1
			setStringTokenLua("<ACTOKEN>",characters[currentID].AC.crushing)
			compiledAC = compiledAC .. " " .. t("ACMOD_VS_CRUSHING")
			removeStringTokenLua("<ACTOKEN>")
		end

		if characters[currentID].AC.missile > 0 then
			if numMods > 0 then
				compiledAC = compiledAC .. ", "
			end
			numMods = numMods + 1
			setStringTokenLua("<ACTOKEN>","+"..characters[currentID].AC.missile)
			compiledAC = compiledAC .. " " .. t("ACMOD_VS_MISSILE")
			removeStringTokenLua("<ACTOKEN>")
		elseif characters[currentID].AC.missile < 0 then
			if numMods > 0 then
				compiledAC = compiledAC .. ", "
			end
			numMods = numMods + 1
			setStringTokenLua("<ACTOKEN>",characters[currentID].AC.missile)
			compiledAC = compiledAC .. " " .. t("ACMOD_VS_MISSILE")
			removeStringTokenLua("<ACTOKEN>")
		end

		if characters[currentID].AC.piercing > 0 then
			if numMods > 0 then
				compiledAC = compiledAC .. ", "
			end
			numMods = numMods + 1
			setStringTokenLua("<ACTOKEN>","+"..characters[currentID].AC.piercing)
			compiledAC = compiledAC .. " " .. t("ACMOD_VS_PIERCING")
			removeStringTokenLua("<ACTOKEN>")
		elseif characters[currentID].AC.piercing < 0 then
			if numMods > 0 then
				compiledAC = compiledAC .. ", "
			end
			numMods = numMods + 1
			setStringTokenLua("<ACTOKEN>",characters[currentID].AC.piercing)
			compiledAC = compiledAC .. " " .. t("ACMOD_VS_PIERCING")
			removeStringTokenLua("<ACTOKEN>")
		end

		if characters[currentID].AC.slashing > 0 then
			if numMods > 0 then
				compiledAC = compiledAC .. ", "
			end
			numMods = numMods + 1
			setStringTokenLua("<ACTOKEN>","+"..characters[currentID].AC.slashing)
			compiledAC = compiledAC .. " " .. t("ACMOD_VS_SLASHING")
			removeStringTokenLua("<ACTOKEN>")
		elseif characters[currentID].AC.slashing < 0 then
			if numMods > 0 then
				compiledAC = compiledAC .. ", "
			end
			numMods = numMods + 1
			setStringTokenLua("<ACTOKEN>",characters[currentID].AC.slashing)
			compiledAC = compiledAC .. " " .. t("ACMOD_VS_SLASHING")
			removeStringTokenLua("<ACTOKEN>")
		end

		compiledAC = compiledAC .. ")"
	end

	return compiledAC
end

function displaySTR()
	strtxt = characters[currentID].attr.str.current

	if characters[currentID].attr.str.current == 18 and characters[currentID].attr.str.extra > 0 then
		if characters[currentID].attr.str.extra == 100 then
			strtxt = strtxt .. '/00'
		elseif characters[currentID].attr.str.extra > 9 then
			strtxt = strtxt .. '/' .. characters[currentID].attr.str.extra
		elseif characters[currentID].attr.str.extra > 0 then
			strtxt = strtxt .. '/0' .. characters[currentID].attr.str.extra
		end
	end
	if(characters[currentID].attr.str.current > characters[currentID].attr.str.base or characters[currentID].attr.str.extra > characters[currentID].attr.str.extraBase) then
		strtxt = '^G' .. strtxt .. '^-'
	end
	if(characters[currentID].attr.str.current < characters[currentID].attr.str.base or characters[currentID].attr.str.extra < characters[currentID].attr.str.extraBase) then
		strtxt = '^R' .. strtxt .. '^-'
	end
	return strtxt
end

function GetProfs(str)
	local t = {}
	local tprof = {}
	local tcount = 0
	proftext = ""
	if characters[currentID].proficiencies.weapons.current == nil or characters[currentID].proficiencies.weapons.current == "" then return proftext end
	linescount = select(2, str:gsub('\n', '\n')) + 1
	if linescount ~= 0 then
		local function helper(line) table.insert(t, line) return "" end
		helper((str:gsub("(.-)\r?\n", helper)))
			
		for i = 1, #t, 1 do
			if string.find(string.lower(t[i]), string.lower("%+%+%+%+%+")) then
				justprof = string.gsub(t[i] , " %+%+%+%+%+$", "")
				lvlprof = "+++++"
				profdesc = 1
				elseif string.find(string.lower(t[i]), string.lower("%+%+%+%+")) then
				justprof = string.gsub(t[i] , " %+%+%+%+$", "")
				lvlprof = "++++"
				profdesc = 2
			elseif string.find(string.lower(t[i]), string.lower("%+%+%+")) then
				justprof = string.gsub(t[i] , " %+%+%+$", "")
				lvlprof = "+++"
				profdesc = 3
			elseif string.find(string.lower(t[i]), string.lower("%+%+")) then
				justprof = string.gsub(t[i] , " %+%+$", "")
				lvlprof = "++"
				profdesc = 4
			elseif string.find(string.lower(t[i]), string.lower("%+")) then
				justprof = string.gsub(t[i] , " %+$", "")
				lvlprof = "+"
				profdesc = 5
			end
			
			
			table.insert(tprof, {justprof, lvlprof, profdesc})
		end
		
		for i = 1, linescount, 1 do
			if i == 1 then
				proftext = '^D' .. tprof[i][1] .. ' ' .. tprof[i][2] .. '^B' .. '\n' .. PDD[tprof[i][3]] .. '\n'
			else
				proftext = proftext .. '^D' .. '\n' .. tprof[i][1] .. ' ' .. tprof[i][2] .. '^B' .. '\n' .. PDD[tprof[i][3]] .. '\n'
			end
		end
		return proftext
	end
end
function GetStyles(str)
	local t = {}
	local tprof = {}
	local tcount = 0
	fstext = ""
	if characters[currentID].proficiencies.fightingstyles.current == nil or characters[currentID].proficiencies.fightingstyles.current == "" then return fstext end
	linescount = select(2, str:gsub('\n', '\n')) + 1
	if linescount ~= 0 then
		local function helper(line) table.insert(t, line) return "" end
		helper((str:gsub("(.-)\r?\n", helper)))
			
		for i = 1, #t, 1 do
			if string.find(string.lower(t[i]), string.lower("%+%+%+%+%+")) then
				justfs = "Club"
				lvlfs = "+++++"
				fsdesc = 1
			elseif string.find(string.lower(t[i]), string.lower("%+%+%+%+")) then
				justfs = "Club"
				lvlfs = "++++"
				fsdesc = 2
			elseif string.find(string.lower(t[i]), string.lower("%+%+%+")) then
				justfs = string.gsub(t[i] , " %+%+%+$", "")
				lvlfs = "+++"
				if justfs == "Club" then
					fsdesc = 3
				else
					fsdesc = 12
				end
			elseif string.find(string.lower(t[i]), string.lower("%+%+")) then
				justfs = string.gsub(t[i] , " %+%+$", "")
				lvlfs = "++"
				if justfs == "Two-Handed Weapon Style" then
					fsdesc = 6
				elseif justfs == "Sword And Shield Style" then
					fsdesc = 8
				elseif justfs == "Two-Weapon Style" then
					fsdesc = 13
				elseif justfs == "Single-Weapon Style" then
					fsdesc = 10
				elseif justfs == "Club" then
					fsdesc = 4
				end
			elseif string.find(string.lower(t[i]), string.lower("%+")) then
				justfs = string.gsub(t[i] , " %+$", "")
				lvlfs = "+"
				if justfs == "Two-Handed Weapon Style" then
					fsdesc = 7
				elseif justfs == "Sword and Shield Style" then
					fsdesc = 9
				elseif justfs == "Two-Weapon Style" then
					fsdesc = 14
				elseif justfs == "Single-Weapon Style" then
					fsdesc = 11
				elseif justfs == "Club" then
					fsdesc = 5
				end
			end
			table.insert(tprof, {justfs, lvlfs, fsdesc})
		end
		
		for i = 1, linescount, 1 do
			if i == 1 then
				fstext = '^D' .. tprof[i][1] .. ' ' .. tprof[i][2] .. '^B' .. '\n' .. PDD[tprof[i][3]] .. '\n'
			else
				fstext = fstext .. '\n' .. tprof[i][1] .. ' ' .. tprof[i][2] .. '^B' .. '\n' .. PDD[tprof[i][3]] .. '\n'
			end
		end
		return fstext
	end
end

function has_value(val)
    for index, value in ipairs(statusEffectsReal) do
        if value == val then
            return true
        end
    end

    return false
end

listStrengthAbility = {}
function strengthAbility()
    for k, v in ipairs(characters[currentID].proficiencies.ability) do
		if v.current == 'To hit: +3' then
		table.insert(listStrengthAbility, {v.current, ''})
		end
	end
end

function updateAttrTablex()
listItems = {}

	if statusEffects[1] ~= nil then
        table.insert(listItems, { nil, '^D' .. t('STATUS_EFFECTS_LABEL') .. ':' .. '^B'})
    end
	for k, v in pairs(characters[currentID].statusEffects) do
		table.insert(listItems, {v.current, '    ' .. Infinity_FetchString(v.strRef)})
	end
	if statusEffects[1] ~= nil then
        table.insert(listItems, { nil, '' })
    end
	table.insert(listItems, { nil, '^D' .. t('SKILLS_LABEL') .. ':' .. '^B'})
	table.insert(listItems, { nil, t('LORE_LABEL') .. ': ' .. characters[currentID].proficiencies.lore.current })
	table.insert(listItems, { nil, t('REPUTATION_LABEL') .. ': ' .. characters[currentID].proficiencies.reputation.current })
	
	
	for k, v in ipairs(characters[currentID].proficiencies.class_skills) do
		table.insert(listItems, { nil, Infinity_FetchString(v.strRef) .. ': '.. v.current .. '^-'})
	end
	
	table.insert(listItems, { nil, '' })
	table.insert(listItems, { nil, '^D' .. t('PROFICIENCIES_LABEL') .. ':' .. '^B'})
	if characters[currentID].proficiencies.weapons.current ~= "" then
		table.insert(listItems, { nil, characters[currentID].proficiencies.weapons.current })
	end
	
	if characters[currentID].proficiencies.fightingstyles.current ~= "" then
		table.insert(listItems, { nil, characters[currentID].proficiencies.fightingstyles.current})
	end
	
	table.insert(listItems, { nil, '' })
	table.insert(listItems, { nil, '^D' .. t('SAVING_THROWS_LABEL') .. ':' .. '^B'})
	table.insert(listItems, { nil, characters[currentID].proficiencies.savingThrows})
	table.insert(listItems, { nil, '' })
	table.insert(listItems, { nil, '^D' .. t('RESISTANCES_LABEL') .. ':' .. '^B' .. '^B'})
	table.insert(listItems, { nil, characters[currentID].proficiencies.resistances})
	--table.insert(listItems, { nil, '' })
	table.insert(listItems, { nil, '^D' .. '\n' .. 'Ability bonuses:' .. '^B'})
	for k, v in ipairs(characters[currentID].proficiencies.ability) do
		table.insert(listItems, {nil, v.current})
	end
end

function updateAttrTable()
	
	--statusEffectsReal = { }
	--for k, v in pairs(characters[currentID].statusEffects) do
	--	table.insert(statusEffectsReal, v)
	--	
	--end
	statusEffects = { }
	for k, v in pairs(characters[currentID].statusEffects) do
		table.insert(statusEffects, v)
		
	end
	--for k, v in pairs(characters[currentID].proficiencies.class_skills) do
	--	table.insert(statusEffects, v)
	--end
	
	--table.insert(statusEffects, 'SKILLS_LABEL')
	
	listAbilities = { }
	for k, v in ipairs(characters[currentID].proficiencies.ability) do
			table.insert(listAbilities, {v.strRef, v.current, v.helpStrRef})
			--table.insert(listAbilities, {v.helpStrRef, ''})
		end
		
		showAbilityBonuses = 1
		showJustText = 0
		showStats = 0
		showSpells = 0
		for k, v in ipairs(listAbilities) do
			helpTextString = helpTextString .. '^M' .. v[2] .. '\n \n'
		end

	listItems = { }
	listTest = { }

	lastID = currentID
	helpTextString = ''
	showClassInfo = 0
	showJustText = 0
	showMemorized = 0
	showBothLists = 0
	showStats = 1
	showAbilityBonuses = 0

	otherlist = { }

	attributeItems = {
		{ characters[currentID].attr.str, 9582 },
		{ characters[currentID].attr.dex, 9584 },
		{ characters[currentID].attr.con, 9583 },
		{ characters[currentID].attr.int, 9585 },
		{ characters[currentID].attr.wis, 9586 },
		{ characters[currentID].attr.cha, 9587 }
		}



	if statusEffects[1] ~= nil then
        table.insert(listItems, { nil, '^D' .. t('STATUS_EFFECTS_LABEL') .. ':' .. '^B'})
    end
	for k, v in pairs(characters[currentID].statusEffects) do
		table.insert(listItems, {v.current, '    ' .. Infinity_FetchString(v.strRef)})
	end
	if statusEffects[1] ~= nil then
        table.insert(listItems, { nil, '' })
    end
	table.insert(listItems, { nil, '^D' .. t('SKILLS_LABEL') .. ':' .. '^B'})
	table.insert(listItems, { nil, t('LORE_LABEL') .. ': ' .. characters[currentID].proficiencies.lore.current })
	table.insert(listItems, { nil, t('REPUTATION_LABEL') .. ': ' .. characters[currentID].proficiencies.reputation.current })
	
	
	for k, v in ipairs(characters[currentID].proficiencies.class_skills) do
		table.insert(listItems, { nil, Infinity_FetchString(v.strRef) .. ': '.. v.current .. '^-'})
	end
	
	table.insert(listItems, { nil, '' })
	table.insert(listItems, { nil, '^D' .. t('PROFICIENCIES_LABEL') .. ':' .. '^B'})
	if characters[currentID].proficiencies.weapons.current ~= "" then
		table.insert(listItems, { nil, characters[currentID].proficiencies.weapons.current })
	end
	
	if characters[currentID].proficiencies.fightingstyles.current ~= "" then
		table.insert(listItems, { nil, characters[currentID].proficiencies.fightingstyles.current})
	end
	
	table.insert(listItems, { nil, '' })
	table.insert(listItems, { nil, '^D' .. t('SAVING_THROWS_LABEL') .. ':' .. '^B'})
	table.insert(listItems, { nil, characters[currentID].proficiencies.savingThrows})
	table.insert(listItems, { nil, '' })
	table.insert(listItems, { nil, '^D' .. t('RESISTANCES_LABEL') .. ':' .. '^B' .. '^B'})
	table.insert(listItems, { nil, characters[currentID].proficiencies.resistances})
	--table.insert(listItems, { nil, '' })
	table.insert(listItems, { nil, '^D' .. '\n' .. 'Ability bonuses:' .. '^B'})
	for k, v in ipairs(characters[currentID].proficiencies.ability) do
		table.insert(listItems, {nil, v.current})
	end

end

characters = {}
statusEffects = { }

currentID = 16974083
canLevelUp = 0
openAdvance = 0
notrealValue = 0

function trunc(str, len)
	if str:len() < len then
		return str
	else
		return str:sub(1,len) .. "..."
	end
end

function characterDescString(char)
	return Infinity_FetchString(char.gender) .. "\n" .. Infinity_FetchString(char.race) .. "\n" .. char.class .. "\n" .. Infinity_FetchString(char.alignment) .. ""
end

function isStatModified(index)
	if (index == 1 ) then
		--strength
		return (characters[currentID].attr.str.current ~= characters[currentID].attr.str.base or characters[currentID].attr.str.extra ~= characters[currentID].attr.str.extraBase)
	else
		return attributeItems[index][1].current ~= attributeItems[index][1].base
	end
end

function displayAttr(index)
	str = 0
	if (index == 1 ) then
		str = displaySTR()
	else
		str = displayBuff( attributeItems[index][1].current, attributeItems[index][1].base, 1)
	end
	return str
end

function getPercent(first, second)
	tempNumber = ( first/second ) *100
	return tempNumber
end

function displayBuff( current, base, highisbetter)
	
	tmpstr = ''	
	--Infinity_Log( current .. ' - '.. base )
	if(highisbetter) then
		if(current > base) then
			tmpstr	= '^G' .. current .. '^-'
		elseif (current < base) then
			tmpstr	= '^R' .. current .. '^-'			
		end
	else
		if(current > base) then
			tmpstr	= '^R' .. current .. '^-'
		elseif (current < base) then
			tmpstr	= '^G' .. current .. '^-'			
		end
	end
	if(current == base) then
		tmpstr = current		
	end
	return tmpstr
end

function getNextLevelString()
	local nextLevelXp = characters[currentID].level.nextLvlXp - characters[currentID].level.xp
	local str = ""
	if(nextLevelXp > 0) then
		str = t("NEXT_LEVEL_LABEL")
		str = str .. " "
		str = str .. nextLevelXp
		str = str .. " "
		str = str .. t("XP_LABEL")
	else
		str = t("READY_TO_LEVEL_LABEL")
	end
	return str
	
end

function CurrentlyInGame()
	if characterScreen:IsInGame() == true then
		return true
	else
		return false
	end
end
function getClassString()
	local out = characters[currentID].classlevel.first.details
	if ( characters[currentID].classlevel.second ) then
		out = out .. '\n\n' .. characters[currentID].classlevel.second.details
	end
	if ( characters[currentID].classlevel.third ) then
		out = out .. '\n\n' .. characters[currentID].classlevel.third.details
	end

	out = out .. '\n\n' .. characters[currentID].kitDesc

	return out
end

function rgtoggleCombatStats()
		if(toggleCombatStats == 1) then return 0 else return 1 end
end

function getGeneralInfo()
	local out = characters[currentID].classlevel.first.details
	if ( characters[currentID].classlevel.second ) then
		out = out .. '\n\n' .. characters[currentID].classlevel.second.details
	end
	if ( characters[currentID].classlevel.third ) then
		out = out .. '\n\n' .. characters[currentID].classlevel.third.details
	end

	out = out .. '\n\n' .. t('LORE_LABEL') .. ': ' .. characters[currentID].proficiencies.lore.current
	 .. '\n' .. t('REPUTATION_LABEL') .. ': ' .. characters[currentID].proficiencies.reputation.current
	 .. '\n' .. t('CURRENT_SCRIPT_LABEL') .. ': ' .. characters[currentID].proficiencies.currentScript.. '\n\n'

	return out
end

function getClassString1()
	local firstClass = ',' .. characters[currentID].classlevel.first.details
	local out = ''
	if ( characters[currentID].classlevel.second ) then
		local firstClass1 = string.match(firstClass, ',.-:')
		out = string.match(firstClass1, '[^,:]+') .. ' -'
	end
    
    return out
end
function getClassString2()
	local secondClass = ',' .. characters[currentID].classlevel.second.details
    local secondClass1 = string.match(secondClass, ',.-:')
	local out = string.match(secondClass1, '[^,:]+')
    return out
end
function getClassString3()
	local thirdClass = ',' .. characters[currentID].classlevel.third.details
    local thirdClass1 = string.match(thirdClass, ',.-:')
	local out = string.match(thirdClass1, '[^,:]+')
    return out
end
function getLevelString1()
    local firstLevel = string.match(characters[currentID].classlevel.first.details, '%d.')
	local out = string.match(firstLevel, '[^\n]+')
    return out
end
function getLevelString2()
    local secondLevel = string.match(characters[currentID].classlevel.second.details, '%d.')
	local out = string.match(secondLevel, '[^\n]+')
    return out
end
function getLevelString3()
    local thirdLevel = string.match(characters[currentID].classlevel.third.details, '%d.')
	local out = string.match(thirdLevel, '[^\n]+')
    return out
end
function getStrengthDetail()
    local outList = { }
    for k, v in ipairs(characters[currentID].proficiencies.ability) do
        table.insert(outList, {v.current})
    end
    local out = outList[1][1] .. ', ' .. outList[2][1]
    return out
end
function getDexDetail()
    local outList = { }
    for k, v in ipairs(characters[currentID].proficiencies.ability) do
        table.insert(outList, {v.current})
    end
    local out = outList[5][1]
    return out
end
function getConDetail()
    local outList = { }
    for k, v in ipairs(characters[currentID].proficiencies.ability) do
        table.insert(outList, {v.current})
    end
    local out = outList[8][1]
    return out
end
function getChaDetail()
    local outList = { }
	local out = ''
    for k, v in ipairs(characters[currentID].proficiencies.ability) do
        table.insert(outList, {v.current})
    end
	if characters[currentID].hasMageBook and (tablelength(outList) < 11) then
		out = outList[10][1]
	elseif characters[currentID].hasMageBook and (tablelength(outList) >= 11) then
		out = outList[12][1]
	else
		out = outList[9][1]
	end
    return out
end
function tablelength(T)
  local count = 0
  for _ in pairs(T) do count = count + 1 end
  return count
end
function getTHAC()
	local thactxt = characters[currentID].THAC0.current
	if (characters[currentID].THAC0.offhand ) then
		thactxt = thactxt .. '^X' .. '  |  ' .. characters[currentID].THAC0.offhand .. '^B'
	end
	return thactxt
end
function getDmg()
	local str = characters[currentID].damage.min .. ' - ' .. characters[currentID].damage.max
	if(characters[currentID].damage.minOffhand and characters[currentID].damage.maxOffhand) then
		str = str .. '^X' .. '  |  ' .. characters[currentID].damage.minOffhand .. ' - ' .. characters[currentID].damage.maxOffhand .. '^B'
	end
	return str
end

overviewList = { }


function getStatistics1()
	local out = Infinity_FetchString(characters[currentID].Stats.bestenemy.strRef) .. '\n\n' .. Infinity_FetchString(characters[currentID].Stats.timespent.strRef) .. '\n\n' .. Infinity_FetchString(characters[currentID].Stats.favspell.strRef) .. '\n\n' .. Infinity_FetchString(characters[currentID].Stats.favweapon.strRef)
	return out
end
function getStatistics2()
	local out = characters[currentID].Stats.bestenemy.current .. '\n\n' .. characters[currentID].Stats.timespent.current .. '\n\n' .. characters[currentID].Stats.favspell.current .. '\n\n' .. characters[currentID].Stats.favweapon.current
	return out
end
function getStatistics3()
	local out = '\n\n' .. Infinity_FetchString(characters[currentID].Stats.partychapxp.strRef) .. '\n\n' .. Infinity_FetchString(characters[currentID].Stats.partychapkills.strRef) .. '\n\n' .. Infinity_FetchString(characters[currentID].Stats.chapxpvalue.strRef) .. '\n\n' .. Infinity_FetchString(characters[currentID].Stats.chapkills.strRef)
	return out
end
function getStatistics4()
	local out = t('CHAPTER_LABEL') .. '\n\n' .. characters[currentID].Stats.partychapxp.current .. '%' .. '\n\n' .. characters[currentID].Stats.partychapkills.current .. '%' .. '\n\n' .. characters[currentID].Stats.chapxpvalue.current .. '\n\n' .. characters[currentID].Stats.chapkills.current
	return out
end
function getStatistics5()
	local out = t('GAME_LABEL') .. '\n\n' .. characters[currentID].Stats.partygamexp.current .. '%' .. '\n\n' .. characters[currentID].Stats.partygamekills.current .. '%' .. '\n\n' .. characters[currentID].Stats.gamexpvalue.current .. '\n\n' .. characters[currentID].Stats.gamekills.current
	return out
end
--function getClassString()
--	local str = Infinity_FetchString(11959)
--    return (str:gsub("^%l", string.upper))
--end
function getClassTitle()
	local MultiClass = ',' .. characters[currentID].proficiencies.details
	local out = ''
	if ( characters[currentID].classlevel.second ) then
		local MultiClass1 = string.match(MultiClass, ',.-\n\n')
		out = string.match(MultiClass1, '[^,\n\n]+')
	else
		local MultiClass2 = Infinity_FetchString(11959)
		out = (MultiClass2:gsub("^%l", string.upper))
	end
    
    return out
end

	listItems = { }
	listTest = { }
	overviewList = { }

	helpTextString = ''
	currentTabIndex = 0
	currentTab = 0
	currentItem = 0
	ShowClassInfo = 0
	showStats = 0
	showJustText = 0
	showMemorized = 0
	showBothLists = 0

Record = {}

function Record:create(id)
	local character = characters[id]
	if character == nil then
		error('invalid character id: ' .. id)
	end

	local classes = {}
	local record = {
		id = id,
		name = character.name,
		class = character.class,
		classes = classes
	}

	local index = {first = 1, second = 2, third = 3}
	for key, level in pairs(character.classlevel) do
		local details = level.details
		if details == nil then
			break
		end

		-- Lines are (might be localized):
		-- [1] [className]: Level [N]
		-- [2] Experience: [XP]
		-- [3] One of these:
		--   a) Next Level: [XP] # multi-class
		--   b) Inactive         # inactive dual-class
		--   c) nil              # active dual-class
		local lines = {}
		for s in details:gmatch('[^\r\n]+') do
			table.insert(lines, s)
		end

		local class = {
			name = lines[1]:match('[^:]+'),
			xp = {
				current = level.xp,
				next = level.nextLvlXp,
				label = level.xp .. ' / ' .. level.nextLvlXp .. ' XP'
			},
			progress = 100 * level.xp / level.nextLvlXp
		}

		if key ~= 'first' then
			local extra = lines[3]

			if extra and extra:match('[0-9]+') then
				record.multiclass = true
			else
				record.dualclass = true
				class.xp.current = lines[2]:match('[0-9]+')
				class.xp.label = class.xp.current .. ' XP'
				class.xp.next = nil
				class.xp.progress = nil

				if extra then
					class.inactive = true
					class.inactiveLocalized = extra
				else
					class.inactive = false
				end
			end
		end

		classes[index[key]] = class
	end

	return record
end

`
menu
{
	name	'CHARACTER'
	modal lua "not CurrentlyInGame()"
	align center center
	ignoreEsc
	onopen
	"
		currentTab = 1
		currentTabIndex = 1
		currentItem = 0
		showStats = 0
		showJustText = 0
		showClassInfo = 0
		showAbilityBonuses = 0
		showMemorized = 0
		showBothLists = 0
		toggleCombatStats = 0
		showOverview = 1
		showClass = 0
		showBiography = 0
		showStatistics = 0
		rgrecpage = nil
		
		if(CurrentlyInGame()) then
			pushSidebars()
		end
		updateAttrTable()
		--getOverview()
		
		if(currentPanelID == const.EXPORT_ID) then 
			Infinity_PushMenu('CHARACTER_EXPORT')
		else 
			if(currentPanelID == const.CUSTOMIZE_ID) then 
				Infinity_PushMenu('CHARACTER_CUSTOMIZE')
			else
				currentPanelID = 0
			end
		end
		Infinity_PopMenu('WORLD_QUICKLOOT');

		record = Record:create(currentID)
	"
	onclose
	"
		record = nil
		popSidebars()
	"

	label
	{
		area	0 0 1364 756
		mosaic	"GUIREC2"
	}
	--label
	--{
	--	enabled "currentTab == 6"
	--	area	804 84 254 624
	--	mosaic	"RGRECBOX"
	--}
	
	
	label
	{
		name		"LABEL_2_268435495"
		area		250 34 868 40
		text		'RG_RECORD'
		text style  	'title'
		text align	center center
	}
	
	label
	{
		area		568 86 226 38
		text		lua "characters[currentID].name"
		text style  	'normal'
		text align	center center
	}

	label
	{
		area		280 214 210 4
		progressbar lua "record.classes[1].progress"  -- progress percentage, number 0-100
		greyscale	0 --display greyscale or not, number 0-1
		progressbar color	128 0 0 255	 --color when percentage != 100
		progressbar full	128 0 0 255	 --color when percentage == 100
	}
	label
	{
		area		278 212 214 8
		mosaic rgprogb
	}
	label
	{
		area		280 190 237 30
		text		lua "record.classes[1].xp.label"
		text style  'normal'
		text align	left top
		text shadow 1
	}
	label
	{
		area		280 244 210 4
		enabled		"record.multiclass"
		progressbar	lua "record.classes[2].progress"  -- progress percentage, number 0-100
		greyscale	0 --display greyscale or not, number 0-1
		progressbar color	128 0 0 255	 --color when percentage != 100
		progressbar full	128 0 0 255	 --color when percentage == 100
	}
	label
	{
		area		278 242 214 8
		enabled		"record.multiclass"
		mosaic rgprogb
	}
	label
	{
		area		280 220 237 30
		enabled		"record.classes[2] ~= nil"
		text		lua "record.classes[2].xp.label"
		text style  'normal'
		text align	left top
		text shadow 1
	}
	label
	{
		area		280 245 237 30
		enabled		"record.dualclass and record.classes[2].inactive"
		text		lua "record.classes[2].inactiveLocalized"
		text style  'normal'
		text align	left top
		text shadow 1
	}
	label
	{
		area		280 274 210 4
		enabled		"record.classes[3] ~= nil"
		progressbar	lua "record.classes[3].progress"  -- progress percentage, number 0-100
		greyscale	0 --display greyscale or not, number 0-1
		progressbar color	128 0 0 255	 --color when percentage != 100
		progressbar full	128 0 0 255	 --color when percentage == 100
	}
	label
	{
		area		278 272 214 8
		enabled		"record.classes[3] ~= nil"
		mosaic rgprogb
	}
	label
	{
		area		280 250 237 30
		enabled		"record.classes[3] ~= nil"
		text		lua "record.classes[3].xp.label"
		text style  'normal'
		text align	left top
		text shadow 1
	}
	
	label
	{
		area		27 100 237 30
		text lua 	"Infinity_FetchString(1048) .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		27 130 237 30
		text lua 	"Infinity_FetchString(1049) .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		27 160 237 30
		text lua 	"getClassTitle() .. ': '" --19721 multi, 19722 dual, inactive 24371
		text style  'normal'
		text align	right top
	}
	label
	{
		area		27 190 237 30
		text lua 	"getClassString1() .. ' ' .. Infinity_FetchString(7192) .. ' ' .. getLevelString1() .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		27 220 237 30
		enabled		"record.classes[2] ~= nil"
		text lua 	"getClassString2() .. ' - ' .. Infinity_FetchString(7192) .. ' ' .. getLevelString2() .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		27 250 237 30
		enabled 	"record.classes[3] ~= nil"
		text lua 	"getClassString3() .. ' - ' .. Infinity_FetchString(7192) .. ' ' .. getLevelString3() .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area 280 100 270 30
		text lua "Infinity_FetchString(characters[currentID].gender) .. ' ' .. Infinity_FetchString(characters[currentID].race)"
		text style 'normal'
		text align left top
	}
	label
	{
		area 280 130 270 30
		text lua "Infinity_FetchString(characters[currentID].alignment)"
		text style 'normal'
		text align left top
	}
	label
	{
		area 280 160 270 30
		text lua "characters[currentID].class"
		text style 'normal'
		text align left top
	}
	--label
	--{
	--	area 280 190 38 30
	--	text lua "getLevelString1()"
	--	text style 'normal'
	--	text align left top
	--}
	--label
	--{
	--	area 280 220 38 30
	--	text lua "getLevelString2()"
	--	text style 'normal'
	--	text align left top
	--}
	--label
	--{
	--	area 280 250 38 30
	--	text lua "getLevelString3()"
	--	text style 'normal'
	--	text align left top
	--}
	label
	{
		area		70 305 194 30
		text		lua "Infinity_FetchString( attributeItems[1][1].strRef) .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 335 194 30
		text		lua "Infinity_FetchString( attributeItems[2][1].strRef) .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 365 194 30
		text		lua "Infinity_FetchString( attributeItems[3][1].strRef) .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 395 194 30 
		text		lua "Infinity_FetchString( attributeItems[4][1].strRef) .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 425 194 30
		text		lua "Infinity_FetchString( attributeItems[5][1].strRef) .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 455 194 30
		text		lua "Infinity_FetchString( attributeItems[6][1].strRef) .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		280 305 270 30
		text		lua  "displayAttr(1) .. '^X' .. '   (' .. getStrengthDetail() .. ')' .. '^B'"
		text style  'normal'
		text align left top
		
	}
	label
	{
		area		280 335 270 30
		text		lua  "displayAttr(2) .. '^X' .. '   (' .. getDexDetail() .. ')' .. '^B'"
		text style  'normal'
		text align left top
		
	}
	label
	{
		area		280 365 270 30
		text		lua  "displayAttr(3) .. '^X' .. '   (' .. getConDetail() .. ')' .. '^B'"
		text style  'normal'
		text align left top
		
	}
	label
	{
		area		280 395 270 30
		text		lua  "displayAttr(4)"
		text style  'normal'
		text align left top
		
	}
	label
	{
		area		280 425 270 30 
		text		lua  "displayAttr(5)"
		text style  'normal'
		text align left top
		
	}
	label
	{
		area		280 455 270 30 
		text		lua  "displayAttr(6) .. '^X' .. '   (' .. getChaDetail() .. ')' .. '^B'"
		text style  'normal'
		text align left top
		
	}
	label
	{
		area		344 512 34 30
		text lua 	'characters[currentID].AC.slashing'
		text style  'normal'
		text align	left top
		text color	X
	}
	label
	{
		area		398 512 30 30
		text lua 	'characters[currentID].AC.piercing'
		text style  'normal'
		text align	left top
		text color	X
	}
	label
	{
		area		446 512 32 30
		text lua 	'characters[currentID].AC.crushing'
		text style  'normal'
		text align	left top
		text color	X
	}
	label
	{
		area		498 512 38 30
		text lua 	'characters[currentID].AC.missile'
		text style  'normal'
		text align	left top
		text color	X
	}
	--70 305 194 30
	label
	{
		area		70 512 194 30
		text lua 	"t('ARMOR_CLASS_LABEL') .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 542 194 30
		text lua 	"t('HIT_POINTS_LABEL') .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 572 194 30
		text lua 	"t('THAC0_LABEL') .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 602 194 30
		text lua 	"t('DAMAGE_LABEL') .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 632 194 30
		text lua 	"Infinity_FetchString(characters[currentID].proficiencies.numAttacks.strRef) .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		70 662 194 30
		text lua 	"t('CURRENT_SCRIPT_LABEL') .. ': '"
		text style  'normal'
		text align	right top
	}
	label
	{
		area		280 512 42 30
		text lua 	"characters[currentID].AC.current"
		text style  'normal'
		text align	left top
	}
	label
	{
		area		280 542 270 30
		text lua 	"characters[currentID].HP.current .. '/' .. characters[currentID].HP.max"
		text style  'normal'
		text align	left top
	}
	label
	{
		area		280 572 270 30
		text lua 	"getTHAC()"
		text style  'normal'
		text align	left top
	}
	label
	{
		area		280 602 270 30
		text lua 	"getDmg()"
		text style  'normal'
		text align	left top
	}
	label
	{
		area		280 632 270 30
		text lua 	"characters[currentID].proficiencies.numAttacks.current"
		text style  'normal'
		text align	left top
	}
	label
	{
		area		280 662 270 30
		text lua 	"characters[currentID].proficiencies.currentScript"
		text style  'normal'
		text align	left top
	}
	button
	{
		area 816 668 114 32
		bam 'RGRECBTS'
		highlightgroup	rgrecpage
		text 'RG_OVERVIEW'
		text style "button"
		pad 10 4 10 4
		--action "currentTab = 1; updateAttrTable()"
		action "showOverview = 1; showClass = 0; showBiography = 0; showStatistics = 0; updateAttrTable()"
	}
	button
	{
		area 936 668 114 32
		bam 'RGRECBTS'
		highlightgroup	rgrecpage
		text 'STATS_NORMAL'
		text style "button"
		pad 10 4 10 4
		--action "currentTab = 6; updateAttrTable()"
		action "showOverview = 0; showClass = 0; showBiography = 0; showStatistics = 1; updateAttrTable()"
	}
	button
	{
		area 1056 668 114 32
		bam 'RGRECBTS'
		highlightgroup	rgrecpage
		text 'BIOGRAPHY_LABEL'
		text style "button"
		pad 10 4 10 4
		--action "currentTab = 7; updateAttrTable()"
		action "showOverview = 0; showClass = 0; showBiography = 1; showStatistics = 0; updateAttrTable()"
	}
	button
	{
		area 1176 668 114 32
		bam 'RGRECBTS'
		highlightgroup	rgrecpage
		text 'CLASS_BUTTON'
--		text 'RG_CLASS_BUTTON'
		text style "button"
		pad 10 4 10 4
		--action "currentTab = 2; updateAttrTable()"
		action "showOverview = 0; showClass = 1; showBiography = 0; showStatistics = 0; updateAttrTable()"
	}
	
	list
	{
		column
        {
            width 100

            -- status effect icon
            label
            {
                area        0 5 -1 -1 -- '5' aligns the icon with the text
                bam         'STATES'
                sequence    lua "listItems[rowNumber][1]"
                enabled     "listItems[rowNumber][1] ~= nil"
            }

            label
            {
                area        0 0 -1 -1
				text        lua "listItems[rowNumber][2]"
				text style  'normal'
                text align    left bottom    
				--pad 0 -3 0 0
            }
        }
    
		enabled "showOverview == 1"
		area 830 102 454 558
		rowheight	dynamic
		table		"listItems"
		var		notrealValue
		scrollbar	'GUISCRC'
		hidehighlight	
	}
	
	-- class section
		
	text
	{
		enabled		"showClass == 1"
		area		830 102 454 558
		text		lua "getClassString()"
		text style  'normal'
		scrollbar	'GUISCRC'
	}
	
	text
	{
		enabled		"showBiography == 1"
		area		830 102 454 558
		text		lua "Infinity_FetchString(characters[currentID].biography)"
		text style  'normal'
		scrollbar	'GUISCRC'
	}
	
	--getStatistics1()
	
	label
	{
		enabled		"showStatistics == 1"
		area		812 112 254 263
		text		lua "getStatistics1()"
		text style  'normal'
		text align	right top
		scrollbar	'GUISCRC'
	}
	label
	{
		enabled		"showStatistics == 1"
		area		1078 112 212 263
		text		lua "getStatistics2()"
		text style  'normal'
		text align	left top
		scrollbar	'GUISCRC'
	}
	label
	{
		enabled		"showStatistics == 1"
		area		806 386 290 270
		text		lua "getStatistics3()"
		text style  'normal'
		text align	right top
		scrollbar	'GUISCRC'
	}
	label
	{
		enabled		"showStatistics == 1"
		area		1100 386 106 270
		text		lua "getStatistics4()"
		text style  'normal'
		text align	center top
		scrollbar	'GUISCRC'
	}
	label
	{
		enabled		"showStatistics == 1"
		area		1206 386 98 270
		text		lua "getStatistics5()"
		text style  'normal'
		text align	center top
		scrollbar	'GUISCRC'
	}
	
	button
	{
		name		"BUTTON_2_2"
		area		577 156 210 330
		--text		lua "characters[currentID].portrait"
		text align	center center
		text point	10
		text color	B
		bitmap		lua "characters[currentID].portrait"
		action
		"
			Infinity_Log(dump(characters, 0))
		"
	}
	
	button
	{
		enabled 	"CurrentlyInGame()"
		name		"BUTTON_2_50"
		area		572 587 220 42
		text		"CUSTOMIZE_BUTTON"
		text style "button"
		bam		RGRECBTW
		sequence	2
		pad 8 8 8 8
		action 
		"
			characterScreen:OnCustomizeButtonClick();
		"
	}
	button
	{
		enabled 	"CurrentlyInGame()"
		name		"BUTTON_2_36"
		area		572 671 220 42
		text		"EXPORT_BUTTON"
		text style "button"
		bam		RGRECBTW
		sequence	2
		pad 8 8 8 8
		action 
		"
			characterScreen:OnExportButtonClick();
		"
	}
	
	button
	{
		enabled 	"CurrentlyInGame()"
		clickable	lua "characterScreen:IsReformPartyButtonClickable()"
		name		"BUTTON_2_51"
		area		572 629 220 42
		text		"REFORM_PARTY_BUTTON"
		text style "button"
		bam		RGRECBTW
		sequence	2
		pad 8 8 8 8
		action		"characterScreen:OnReformPartyButtonClick();"
	}
	button
	{
		enabled 	"CurrentlyInGame()"
		name		"BUTTON_2_0"
		area		572 545 220 42
		text		"DUAL_CLASS_BUTTON"
		text style "button"
		bam		RGRECBTW
		sequence	2
		pad 8 8 8 8
		clickable	lua "characterScreen:IsDualClassButtonClickable()"
		action 		"characterScreen:OnDualClassButtonClick();"
	}
	button
	{
		enabled 	"CurrentlyInGame()"
		name		"BUTTON_2_37"
		area		572 503 220 42
		text		"LEVEL_UP_BUTTON"
		text style "button"
		bam		RGRECBTW
		sequence	3
		pad 8 8 8 8
		clickable	lua "characterScreen:IsLevelUpButtonClickable()"
		action		" characterScreen:OnLevelUpButtonClick();"
	}
	
	button
	{
		enabled 	"CurrentlyInGame()"
		on escape
		area		1298 16 53 44
		action
		"
			e:SelectEngine(worldScreen)
		"
	}

	button
	{
		enabled 	"not CurrentlyInGame()"
		area		394 664 200 44
		text		"DONE_BUTTON"
		text style 	"button"
		bam			GUIBUTNT
		sequence	3
		action		"Infinity_PopMenu()"
	}
}

menu
{
	name 'CHARACTER_CUSTOMIZE'
	align center center
	modal
	ignoreesc
	onOpen
	"
		currentPanelID = const.CUSTOMIZE_ID
	"
	label 
	{
		area 0 0 864 710
		mosaic	GUICGWDE
	}

	text
	{
		area 380 100 446 490
		text 11327 --Customize help text
		scrollbar 'GUISCRC'
		text style	normal
	}
	label
	{
		area	234 38 396 44
		text	"CUSTOMIZE_TITLE"
		text style	title
	}
	button
	{
		bam 'GUIBUTWS'
		sequence 0
		area 23 100 340 32		
		text style "button"
		text "APPEARANCE_BUTTON"		
		clickable lua
		"
			characterScreen:IsAppearanceButtonClickable();
		"		
		action 
		"
			characterScreen:OnAppearanceButtonClick()
		"
	}
	button
	{
		bam 'GUIBUTWS'
		sequence 0
		area 23 133 340 32		
		text style "button"
		text "SOUNDS_BUTTON"		
		clickable lua
		"
			characterScreen:IsAppearanceButtonClickable();
		"	
		action 
		"
			characterScreen:OnSoundsButtonClick()
		"
	}
	button
	{
		bam 'GUIBUTWS'
		sequence 0
		area 23 165 340 32		
		text style "button"
		text "COLORS_BUTTON"		
		clickable lua
		"
			characterScreen:IsAppearanceButtonClickable();
		"	
		action 
		"
			characterScreen:OnHairSkinButtonClick()
		"
	}
	button
	{
		bam 'GUIBUTWS'
		sequence 0
		area 23 198 340 32		
		text style "button"
		text "SCRIPT_BUTTON"		
		action 
		"
			characterScreen:OnScriptButtonClick()
		"
	}
	button
	{
		bam 'GUIBUTWS'
		sequence 0
		area 23 231 340 32		
		text style "button"
		text "BIOGRAPHY_BUTTON"		
		clickable lua
		"
			characterScreen:IsAppearanceButtonClickable();
		"
		action 
		"
			characterScreen:OnCusomizeBiographyButtonClick()
		"
	}
	button
	{
		on escape
		bam 'GUIBUTMT'
		sequence 0
		area 196 653 230 44
		text style "button"
		text	"CANCEL_BUTTON"
		action 
		"
			characterScreen:OnCancelButtonClick()
			currentPanelID = 0
			Infinity_PopMenu('CHARACTER_CUSTOMIZE')
		"
	}
	button
	{
		bam 'GUIBUTMT'
		sequence 0
		area  438 653 230 44
		text style "button"
		text "DONE_BUTTON"		
		action 
		"
			characterScreen:OnDoneButtonClick()
			currentPanelID = 0
			Infinity_PopMenu('CHARACTER_CUSTOMIZE')
		"
	}
}
`
recBioEdit = ""
recBioEditBackup = ""
`
menu
{
	name 'CHARACTER_BIOGRAPHY'
	align center center
	ignoreesc
	onOpen
	"
		recBioEditBackup = recBioEdit
		currentPanelID = 23
	"
	label
	{
		area 0 0 864 710
		mosaic GUICGWDE
	}
	label
	{
		area 82 37 700 44
		text	"BIOGRAPHY_TITLE"
		text style	'title'
	}
	label
	{
		area		372 92 466 498
		fill        112 111 111 64
	}
	edit
	{
		name		"recBioEditArea"
		area		372 92 466 498
		var			recBioEdit
		scrollbar	'GUISCRC'
		text style	"edit"
	}

	button
	{
		bam 'GUIBUTWS'
		sequence 0
		area	23 100 340 32		
		text style "button"
		text	"CLEAR_BUTTON"		
		action 
		"
			recBioEdit = ''
		"
	}
	button
	{
		bam 'GUIBUTWS'
		sequence 0
		area 23 133 340 32		
		text style "button"
		text "REVERT_BUTTON"		
		action 
		"
			recBioEdit = recBioEditBackup
		"
	}
	button
	{
		on escape
		bam 'GUIBUTMT'
		sequence 0
		area 196 653 230 44
		text style "button"
		text	"CANCEL_BUTTON"
		action 
		"
			characterScreen:OnCancelButtonClick()
			Infinity_PopMenu()
			currentPanelID = 17
		"
	}
	button
	{
		bam 'GUIBUTMT'
		sequence 0
		area  438 653 230 44
		text style "button"
		text "DONE_BUTTON"		
		action 
		"
			characterScreen:OnDoneButtonClick()
			Infinity_PopMenu()
			currentPanelID = 17
		"
	}
}
`
scriptList_idx = 0
showingSmartOptions = false
function formatScriptName(text)
	local i =  string.find(text, ":", #text)
	if(i) then 
		text = string.sub(text,1, i - 1)
	end
	if(#text > 35) then
		text = string.sub(text,1, 35)
		text = text .. "..."
	end
	return text
end

scriptOptions = 
{
	{'SCRIPT_ATTACK_ENEMIES_LABEL',			'SCRIPT_ATTACK_ENEMIES_DESCRIPTION',		 1, 0, 0},
	{'SCRIPT_USE_MELEE_WEAPONS_LABEL',		'SCRIPT_USE_MELEE_WEAPONS_DESCRIPTION',		 2, 0, 0},
	{'SCRIPT_USE_RANGED_WEAPONS_LABEL',		'SCRIPT_USE_RANGED_WEAPONS_DESCRIPTION',	 3, 0, 0},
	{'SCRIPT_USE_ITEMS_LABEL',				'SCRIPT_USE_ITEMS_DESCRIPTION',				 4, 0, 0},
	{'SCRIPT_USE_SPECIAL_ABILITIES_LABEL',	'SCRIPT_USE_SPECIAL_ABILITIES_DESCRIPTION',	 5, 0, 0},
	{'SCRIPT_USE_OFFENSIVE_SPELLS_LABEL',	'SCRIPT_USE_OFFENSIVE_SPELLS_DESCRIPTION',	 6, 0, 0},
	{'SCRIPT_USE_DEFENSIVE_SPELLS_LABEL',	'SCRIPT_USE_DEFENSIVE_SPELLS_DESCRIPTION',	 7, 0, 0},
	{'SCRIPT_FIND_TRAPS_LABEL',				'SCRIPT_FIND_TRAPS_DESCRIPTION',			 8, 0, 0},
	{'SCRIPT_HIDE_IN_SHADOWS_LABEL',		'SCRIPT_HIDE_IN_SHADOWS_DESCRIPTION',		 9, 0, 0},
	{'SCRIPT_SING_BATTLESONG_LABEL',		'SCRIPT_SING_BATTLESONG_DESCRIPTION',		10, 0, 0},
	{'SCRIPT_TURN_UNDEAD_LABEL',			'SCRIPT_TURN_UNDEAD_DESCRIPTION',			11, 0, 0}
}

function handleScriptOptionChange(option)
	local wasOn = scriptOptions[option][4] == 2

	if option == 2 then --Melee
		if wasOn == true then
			scriptOptions[option][4] = 0
			scriptOptions[option][5] = false
		else
			scriptOptions[option][4] = 2
			scriptOptions[option][5] = true
			scriptOptions[option+1][4] = 0
			scriptOptions[option+1][5] = false
		end
	elseif option == 3 then --Ranged
		if wasOn == true then
			scriptOptions[option][4] = 0
			scriptOptions[option][5] = false
		else
			scriptOptions[option][4] = 2
			scriptOptions[option][5] = true
			scriptOptions[option-1][4] = 0
			scriptOptions[option-1][5] = false
		end
	elseif option == 8 then --Find Traps
		if wasOn == true then
			scriptOptions[option][4] = 0
			scriptOptions[option][5] = false
		else
			scriptOptions[option][4] = 2
			scriptOptions[option][5] = true
			scriptOptions[option+1][4] = 0
			scriptOptions[option+1][5] = false
			scriptOptions[option+2][4] = 0
			scriptOptions[option+2][5] = false
			scriptOptions[option+3][4] = 0
			scriptOptions[option+3][5] = false
		end
	elseif option == 9 then --Hide
		if wasOn == true then
			scriptOptions[option][4] = 0
			scriptOptions[option][5] = false
		else
			scriptOptions[option][4] = 2
			scriptOptions[option][5] = true
			scriptOptions[option-1][4] = 0
			scriptOptions[option-1][5] = false
			scriptOptions[option+1][4] = 0
			scriptOptions[option+1][5] = false
			scriptOptions[option+2][4] = 0
			scriptOptions[option+2][5] = false
		end
	elseif option == 10 then --Sing
		if wasOn == true then
			scriptOptions[option][4] = 0
			scriptOptions[option][5] = false
		else
			scriptOptions[option][4] = 2
			scriptOptions[option][5] = true
			scriptOptions[option-2][4] = 0
			scriptOptions[option-2][5] = false
			scriptOptions[option-1][4] = 0
			scriptOptions[option-1][5] = false
			scriptOptions[option+1][4] = 0
			scriptOptions[option+1][5] = false
		end
	elseif option == 11 then --Turn
		if wasOn == true then
			scriptOptions[option][4] = 0
			scriptOptions[option][5] = false
		else
			scriptOptions[option][4] = 2
			scriptOptions[option][5] = true
			scriptOptions[option-3][4] = 0
			scriptOptions[option-3][5] = false
			scriptOptions[option-2][4] = 0
			scriptOptions[option-2][5] = false
			scriptOptions[option-1][4] = 0
			scriptOptions[option-1][5] = false
		end
	else
		scriptOptions[option][4] = toggleFrame(scriptOptions[option][4])
		if scriptOptions[option][4] == 0 then
			scriptOptions[option][5] = false
		else
			scriptOptions[option][5] = true
		end
	end
end
`
menu
{
	name 'CHARACTER_SCRIPT'
	align center center
	ignoreesc
	onOpen 
	"
		doneEnabled = characterScreen:IsDoneButtonClickable(currentID)
		currentPanelID = const.SCRIPT_ID

		showingSmartOptions = (scriptList_idx == 2)
		scriptDescription = t(scriptOptions[scriptList_idx][2])

		for index, var in pairs(scriptOptions) do
			var[5] = characterScreen:GetTempSmartScriptLocal(var[3])
			if var[5] == false then
				var[4] = 0
			else
				var[4] = 2
			end
		end
	"
	label
	{
		area 0 0 864 710 
		mosaic GUIPOP55
	}
	label
	{
		area 94 32 690 54
		text "SCRIPTS_TITLE"
		text style "title"
	}
	
	label
	{
		area 426 468 414 168
		mosaic GUINOTE
		enabled "showingSmartOptions == true"
	}

	text
	{
		area 444 478 376 110
		text lua "scriptDescription"
		scrollbar 'GUISCRC'
		text style	normal
		enabled "showingSmartOptions == true"
	}

	text
	{
		area 444 102 376 486
		text lua "scriptDescription"
		scrollbar 'GUISCRC'
		text style	normal
		enabled "showingSmartOptions == false"
	}

	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 -1 -1
				enabled "scriptList[rowNumber] ~= ''"
				text lua "formatScriptName(scriptList[rowNumber])"
				text style	"normal"
				pad 8 0 0 0
			}
			label
			{
				area -10 -10 10000 10000
				enabled "scriptList[rowNumber] == ''"
				rectangle	1
			}
		}
		area 44 102 376 492
		rowheight	18
		table		"scriptList"
		var			"scriptList_idx"
		scrollbar	'GUISCRC'
		action
		"
			showingSmartOptions = (scriptList_idx == 2)
			if scriptList[scriptList_idx] ~= '' then
				Infinity_OnScriptItemSelect(scriptList_idx - 1)
				doneEnabled = characterScreen:IsDoneButtonClickable(currentID)
			else
				scriptList_idx = 0
				scriptDescription = ''
				doneEnabled = false
			end
		"
	}

	list
	{
		
		column 
		{ 
			width 80
			label
			{
				area 10 0 -1 -1
				text lua "t( scriptOptions[rowNumber][1])"
				text style	"normal"
				text align right center
			}
		}
		column 
		{ 
			width 20
			label
			{
				area		10 8 -1 -1
				bam			ROUNDBUT
				align 		left center
				frame		lua "scriptOptions[rowNumber][4]"
			}
		}

		area 444 102 376 358
		
		rowheight	50
		table		"scriptOptions"
		var			selScriptOpt
		scrollbar	'GUISCRC'
		enabled 	"showingSmartOptions == true"

		action		
		"
			scriptDescription = t(scriptOptions[selScriptOpt][2])
			selectedSL = 0
			selFeedOpt = 0

			if(cellNumber == 2) then
				Infinity_PlaySound('GAM_09')
				handleScriptOptionChange(selScriptOpt)
			end
		"
	}
	
	button
	{
		on escape
		bam 'GUIBUTMT'
		sequence 0
		area 196 653 230 44
		text style "button"
		text	"CANCEL_BUTTON"
		action 
		"
			characterScreen:OnCancelButtonClick()
			Infinity_PopMenu()
			currentPanelID = 17
		"
	}
	button
	{
		clickable lua "doneEnabled"
		bam 'GUIBUTMT'
		sequence 0
		area  438 653 230 44
		text style "button"
		text "DONE_BUTTON"		
		action 
		"
			if showingSmartOptions == true then
				for index, var in pairs(scriptOptions) do
					characterScreen:SetTempSmartScriptLocal(var[3], var[5])
				end
			end

			characterScreen:OnDoneButtonClick()
			Infinity_PopMenu()
			currentPanelID = 17
			
		"
	}
}
`
list_GUIREC_13_0_idx = 0
characterExportCharacterEdit = ""
`
menu
{
	name 'CHARACTER_EXPORT'
	align center center
	modal
	ignoreEsc
	onOpen
	"
		currentPanelID = const.EXPORT_ID
	"
	label 
	{
		area 0 0 864 710
		mosaic	GUICGSND
	}
	label
	{
		area	220 34 426 44
		text	"EXPORT_TITLE"
		text style	title
	}

	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 -1 -1
				text lua "list_GUIREC_13_0[rowNumber]"
				text style "list"
				pad 8 0 0 0
			}
		}
		area 28 88 340 290
		rowheight	18
		table		"list_GUIREC_13_0"
		var			"list_GUIREC_13_0_idx"
		scrollbar	'GUISCRC'
		action
		"
			Infinity_OnCharacterItemSelect(list_GUIREC_13_0_idx - 1)
		"
	}
	label
	{
		area		35 382 332 23
		text		"EXPORT_FILENAME_LABEL"
		text style	"label"
		text color 	3
	}
	edit
	{
		name		"characterExportCharacterEditArea"
		area		35 405 332 31
		var			characterExportCharacterEdit
		text style	"edit"
		maxlines	1
		fill            112 111 111 64
		action
		"
			if(characterExportCharacterEdit:len() > 7 and key_pressed ~= 8) then				
				return 0
			else
				Infinity_UpdateCharacterRecordExportPanel()
				return 1
			end
		"

	}
	text
	{
		area 404 88 420 500
		text 10962
		text style	normal
		scrollbar 'GUISCRC'
	}
	button
	{
		bam 'GUIBUTMT'
		on escape
		sequence 0
		area 196 653 230 44
		text style "button"
		text	"CANCEL_BUTTON"
		action 
		"
			characterScreen:OnCancelButtonClick()
			Infinity_PopMenu('CHARACTER_EXPORT')
			currentPanelID = 0
		"
	}
	button
	{
		clickable	lua "characterScreen:IsDoneButtonClickable(currentID)"
		bam 'GUIBUTMT'
		sequence 0
		area  438 653 230 44
		text style "button"
		text "DONE_BUTTON"		
		action 
		"
			characterScreen:OnDoneButtonClick()
		"
	}
}
`
list_GUIREC_20_5_idx = 0
doneEnabled = 0
`
menu
{
	name 'CHARACTER_SOUND'
	align center center
	ignoreesc
	onOpen 
	"
		currentPanelID = const.SOUND_ID
		Infinity_OnSoundItemSelect(0)
		doneEnabled = characterScreen:IsDoneButtonClickable(currentID)
	"
	label
	{
		area 0 0 864 710
		mosaic GUICGSND
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 -1 -1
				text lua "getFileNameStringRef(rowNumber, list_GUIREC_20_5)"
				text style	"list"
				pad 8 0 0 0
			}
		}
		area 46 86 312 346
		rowheight	18
		table		"list_GUIREC_20_5"
		var			"list_GUIREC_20_5_idx"
		scrollbar	'GUISCRC'
		action
		"
			Infinity_OnSoundItemSelect(list_GUIREC_20_5_idx - 1)
			doneEnabled = characterScreen:IsDoneButtonClickable(currentID)
		"
	}
	text
	{
		area 398 90 420 505
		text 11315
		scrollbar 'GUISCRC'
		text style	normal
	}
	button
	{
		clickable lua "list_GUIREC_20_5_idx"
		bam 'GUIBUTWT'
		sequence 0
		area 45 462 300 44
		text style "button"
		text	"PLAY_IMPORT_BUTTON"
		action 
		"	
			characterScreen:OnPlayButtonClick();			
		"
	}
	button
	{
		on escape
		bam 'GUIBUTMT'
		sequence 0
		area 196 653 230 44
		text style "button"
		text	"CANCEL_BUTTON"
		action 
		"
			characterScreen:OnCancelButtonClick()
			Infinity_PopMenu()
			currentPanelID = 17
		"
	}
	button
	{
		clickable lua "doneEnabled"
		bam 'GUIBUTMT'
		sequence 0
		area  438 653 230 44
		text style "button"
		text "DONE_BUTTON"		
		action 
		"
			characterScreen:OnDoneButtonClick()
			Infinity_PopMenu()
			currentPanelID = 17
		"
	}
}
`
function toggleFrame(curFrame)
	if curFrame == 0 then 
		return 2
	else 
		return 0
	end 
end
function getSelected(cur, my)
	if cur == my then 
		return 1
	else 
		return 0
	end 
end
function removeStoryModeOption()
	for index = 1, #toggleTitles-1, 1 do
		toggleTitles[index] = toggleTitles[index+1]
	end
	toggleTitles[#toggleTitles] = nil
end
function addStoryModeOption()
	for index = #toggleTitles, 1, -1 do
		toggleTitles[index+1] = toggleTitles[index]
	end
	toggleTitles[1] = {'DIFFICULTY_LABEL_STORYMODE',	'DIFFICULTY_DESCRIPTION_STORYMODE',	65, 0, 0}
end

toggleTitles = {
{"DIFFICULTY_LABEL_STORYMODE_MIXED",	"DIFFICULTY_DESCRIPTION_STORYMODE",	65, 0, 0},
{"ENABLE_CLOUD_LABEL",					"ENABLE_CLOUD_DESCRIPTION", 		60, 0, 0},
{"WORLDMAP_HIGHLIGHT_LABEL",			"WORLDMAP_HIGHLIGHT_DESCRIPTION", 	66, 0, 0},
{"MP_CHAT_LABEL",						"MP_CHAT_DESCRIPTION",				67, 0, 0},
{"GORE_LABEL",							"GORE_DESCRIPTION", 				19, 0, 0},
{"WEATHER_LABEL",						"WEATHER_DESCRIPTION", 				47, 0, 0},
{"GROUP_INFRA_LABEL",					"GROUP_INFRA_DESCRIPTION", 			42, 0, 0},
{"HEAL_ON_REST_LABEL",					"HEAL_ON_REST_DESCRIPTION", 		50, 0, 0},
{"MAX_HP_ON_LEVEL_LABEL",				"MAX_HP_ON_LEVEL_DESCRIPTION", 		55, 0, 0},
{"NO_DAMAGE_INCREASE_LABEL",			"NO_DAMAGE_INCREASE_DESCRIPTION", 	64, 0, 0},
{"AUTO_USE_MAGIC_AMMO_LABEL",			"AUTO_USE_MAGIC_AMMO_DESCRIPTION", 	68, 0, 0},
}

selectedOpt = 0
helpString = 0

ttDelaySLDR = 0
keyboardSLDR = 0
mouseSLDR = 0
difficultySLDR = 0

panelID = 8

function getDifficulty(d)
	local text = ""
	if ( d ==0 ) then
		text = t("DIFFICULTY_LABEL_EASY")
	elseif (d == 1) then
		text = t("DIFFICULTY_LABEL_NORMAL")
	elseif (d == 2) then
		text = t("DIFFICULTY_LABEL_CORERULES")
	elseif (d == 3) then
		text = t("DIFFICULTY_LABEL_HARD")
	elseif (d == 4) then
		text = t("DIFFICULTY_LABEL_INSANE")
	elseif (d == 5) then
		text = string.upper(t("MULTIPLAYER_DIFFICULTY_LABEL")).." "..t("DIFFICULTY_LABEL_LEGACYOFBHAAL")
	end
	return text
end
`
menu
{
	name	'OPTIONS_GAMEPLAY'
	align center center
	modal
	onOpen
	"
		panelID = 8
		helpString = 'GAMEPLAY_DESCRIPTION'
		selectedOpt = 0
		selectedSL = 0

		if Infinity_GetOption(59, 8) ~= 0 and toggleTitles[1][3] == 65 then
			removeStoryModeOption()
		elseif Infinity_GetOption(59, 8) == 0 and toggleTitles[1][3] ~= 65 then
			addStoryModeOption()
		end

		ttDelaySLDR = Infinity_GetOption(1, panelID)
		keyboardSLDR = Infinity_GetOption(3, panelID)
		mouseSLDR = Infinity_GetOption(2, panelID)
		difficultySLDR = Infinity_GetOption(12, panelID)
		
		for index, var in pairs(toggleTitles) do
			var[5] = Infinity_GetOption(var[3], panelID)
			if var[5] == 0 then
				var[4] = 0
			else
				var[4] = 2
 			end
		end
	"

	button
	{
		area	0 0 1444 818
		mosaic	RGOPTIO
		action
		"
			helpString = 'GAMEPLAY_DESCRIPTION'
			selectedOpt = 0
			selectedSL = 0
		"
	}
	label
	{
		area		252 32 944 44
		text		"GAMEPLAY_TITLE"
		text style	title
	}

	list
	{
		
		column 
		{ 
			width 90
			label
			{
				area 10 0 -1 -1
				text lua "t( toggleTitles[rowNumber][1])"
				text style "normal"
				text align left center
			}
		}
		column 
		{ 
			width 10
			label
			{
				area		10 8 -1 -1
				bam			ROUNDBUT
				align 		center center
				frame		lua "toggleTitles[rowNumber][4]"
			}
		}

		area 146 138 400 574
		
		rowheight	46
		table		"toggleTitles"
		var		selectedOpt
		scrollbar	'GUISCRC'

		action		
		"
			panelID = 8
			selectedSL = 0
			helpString = toggleTitles[selectedOpt][2]

			if(cellNumber == 2) then
				Infinity_PlaySound('GAM_09')

				toggleTitles[selectedOpt][4] = toggleFrame(toggleTitles[selectedOpt][4])

				if toggleTitles[selectedOpt][4] == 0 then
					toggleTitles[selectedOpt][5] = 0
				else 
					toggleTitles[selectedOpt][5] = 1
				end
			end
		"
	}
	
	label
	{
		area 1010 134 316 578
		Rectangle 3
	}
	
	text
	{
		area		1036 158 268 534
		text		lua "t(helpString)"
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}

	text
	{
		area		600 153 200 34
		text		"TOOLTIP_DELAY_LABEL"
		text style	"label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 1)"
		action 
		"
			helpString = 'TOOLTIP_DELAY_DESCRIPTION' 
			selectedOpt = 0
			selectedSL = 1
		" 
	}
	slider
	{
		area 806 148 200 39
		position "ttDelaySLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	40
		pad 8 0 10 0
		action 
		"
			helpString = 'TOOLTIP_DELAY_DESCRIPTION' 
			selectedOpt = 0
			selectedSL = 1
		" 
	}

	text
	{
		area		600 203 200 35	
		text		"KEYBOARD_SCRLSPEED_LABEL"
		text style	"label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 2)"
		action 
		"
			helpString = 'KEYBOARD_SCRLSPEED_DESCRIPTION' 
			selectedOpt = 0
			selectedSL = 2
		" 
	}
	slider
	{
		area 806 198 200 40
		position "keyboardSLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	40
		pad 8 0 10 0
		action 
		"
			helpString = 'KEYBOARD_SCRLSPEED_DESCRIPTION' 
			selectedOpt = 0
			selectedSL = 2
		" 
	}

	text
	{
		area		600 254 200 36	
		text		"MOUSE_SCRLSPEED_LABEL"
		text style	"label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 3)"
		action 
		"
			helpString = 'MOUSE_SCRLSPEED_DESCRIPTION' 
			selectedOpt = 0
			selectedSL = 3
		" 
	}
	slider
	{
		area 806 250 200 40
		position "mouseSLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	40
		pad 8 0 10 0
		action 
		"
			helpString = 'MOUSE_SCRLSPEED_DESCRIPTION' 
			selectedOpt = 0
			selectedSL = 3
		" 
	}

	text
	{
		area		600 349 200 35
		text		"DIFFICULTY_LABEL"
		text style	"label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 4)"
		enabled "Infinity_GetOption(59, 8) == 0"
		action 
		"
			helpString = 'DIFFICULTY_DESCRIPTION' 
			selectedOpt = 0
			selectedSL = 4
		" 
	}
	slider
	{
		area 806 345 200 39
		position "difficultySLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	5
		pad 8 0 10 0
		enabled "Infinity_GetOption(59, 8) == 0 and toggleTitles[1][4] == 0"
		action 
		"
			helpString = 'DIFFICULTY_DESCRIPTION' 
			selectedOpt = 0
			selectedSL = 4
		" 
	}
	label
	{
		area		806 384 200 35	
		text		lua "t( getDifficulty(difficultySLDR) )"
		text style	"label"
		text align	center center
		enabled "Infinity_GetOption(59, 8) == 0 and toggleTitles[1][4] == 0"
	}
	--fakes for story mode
	slider
	{
		area 806 345 200 39
		position "0"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	5
		pad 8 0 10 0
		enabled "Infinity_GetOption(59, 8) == 0 and toggleTitles[1][4] ~= 0"
		action 
		"
			helpString = 'DIFFICULTY_DESCRIPTION' 
			selectedOpt = 0
			selectedSL = 4
		" 
	}
	label
	{
		area		806 384 200 35	
		text		lua "t( getDifficulty(0) )"
		text style	"label"
		text align	center center
		enabled "Infinity_GetOption(59, 8) == 0 and toggleTitles[1][4] ~= 0"
	}
	label
	{
		area 806 345 200 35
		enabled "Infinity_GetOption(59, 8) == 0 and toggleTitles[1][4] ~= 0"
		rectangle 0
		rectangle opacity 150	
	}
	
	button
	{
		bam			GUIBUTNT
		sequence	0
		area		712 492 200 44
		text		"ASSIGN_KEYS_BUTTON"
		text style	"button"
		action
		"
			Infinity_PushMenu( 'OPTIONS_KEYBINDINGS' );
			selectedOpt = 0
		"
	}
	button
	{
		area		712 600 200 44
		bam			GUIBUTNT
		sequence	2
		text 		"FEEDBACK_BUTTON"
		text style	"button"
		action
		"

			Infinity_PushMenu( 'OPTIONS_FEEDBACK' );
			selectedOpt = 0
		"
	}
	button
	{
		area		712 546 200 44
		bam			GUIBUTNT
		sequence	2
		text 		"AUTO_PAUSE_BUTTON"
		text style	"button"
		action
		"
			selectedOpt = 0
			Infinity_PushMenu( 'OPTIONS_AUTOPAUSE' );
		"
	}
	button
	{
		area		712 654 200 44
		bam			GUIBUTNT
		text 		"RG_UI_SETTINGS"
		text style	"button"
		action
		"
			selectedOpt = 0
			Infinity_PushMenu('UI_SETTINGS');
		"
	}
	button
	{
		area		304 734 200 44
		bam			GUIBUTNT
		sequence	2
		text 		"CANCEL_BUTTON"
		text style	"button"
		action
		"			
			Infinity_PopMenu()
		"
	}
	button
	{
		area		968 734 200 44		
		bam			GUIBUTNT
		sequence	2
		text 		"DONE_BUTTON" -- Done
		text style	"button"
		action
		"
			panelID = 8
			Infinity_ChangeOption( 1, ttDelaySLDR, panelID)
			Infinity_ChangeOption( 3, keyboardSLDR, panelID )
			Infinity_ChangeOption( 2, mouseSLDR, panelID )
			Infinity_ChangeOption( 12, difficultySLDR + 1, panelID) -- cannot set story mode through slider

			selectedOpt = 0
			selectedSL = 0

			for index, var in pairs(toggleTitles) do
				
				Infinity_ChangeOption( var[3], var[5], panelID)
						
			end

			panelID = 8
			Infinity_PopMenu()
		"
	}

}
`
UIhelp = 0
function selectedENum(text)
	if QuicklootENum == "Ten" then
		ENumCheck = 10
	elseif QuicklootENum == "Six" then
		ENumCheck = 6
	elseif QuicklootENum == "Five" then
		ENumCheck = 5
	elseif QuicklootENum == "Four" then
		ENumCheck = 4
	elseif QuicklootENum == "Three" then
		ENumCheck = 3
	elseif QuicklootENum == "Two" then
		ENumCheck = 2
	end
	if ENumCheck == tonumber(text) then
		return '^R' .. text .. '^-'
	end
	return text
end
function selectedQLPref(text)
	if QuicklootPref ==  text then
		return '^R' .. text .. '^-'
	end
	return text
end
function selectedQLstartPref(text)
	if QuicklootStartPref ==  text then
		return '^R' .. text .. '^-'
	end
	return text
end
`
menu
{
	name 'UI_SETTINGS'
	align center center
	modal
	onOpen
	"
		CheatMode = Infinity_GetINIValue('Game Options','CheatMode',1)
		LeftSideMenu = Infinity_GetINIValue('Game Options','LeftSideMenu',1)
		ClassicDialog = Infinity_GetINIValue('Game Options','ClassicDialog',1)
		MultiPortraitPicker = Infinity_GetINIValue('Game Options','MultiPortraitPicker',1)
		LargePortraits = Infinity_GetINIValue('Game Options','LargePortraits',1)
		PermThief = Infinity_GetINIValue('Game Options','PermThief',1)
		QuicklootMode = Infinity_GetINIString('Game Options','QuicklootMode',1)
		QuicklootENum = Infinity_GetINIString('Game Options','QuicklootENumber',1)
		JournalSize = Infinity_GetINIString('Game Options','SelectedJournalSize',1)
		QuicklootStartPref = Infinity_GetINIString('Game Options','QuicklootStartPreference',1)
	"
	
	label
	{
		area	0 0 1024 768
		mosaic	GUITUTB
	}
	label
	{
		area		450 40 150 44
		text		'RG_UI_TITLE'
		text style	title
	}
	
	
-- Left Side Menu >> Toggles to Right Side Menu

-- Classic dialog toggle
	label
	{
		area 	106 130 315 46
		text 	"RG_UI_CLASSIC_DIALOG"
		text style "normal"
		text align left center
	}
	button
	{
		area		421 130 83 46
		bam			ROUNDBUT
		glow lua 	"Infinity_GetINIValue('Game Options','ClassicDialog','1')"
		align 		center center
		action		"
		"
	}
	button
	{
		area		106 130 400 46
		action		"
					if ClassicDialog == 1 then
						ClassicDialog = 0
						Infinity_SetINIValue('Game Options','ClassicDialog','0')
						Infinity_SetINIValue('Game Options','ShowMessageHistory','On')
					else
						ClassicDialog = 1
						Infinity_SetINIValue('Game Options','ClassicDialog','1')
						Infinity_SetINIValue('Game Options','ShowMessageHistory','Off')
					end
					"
		actionEnter	"UIhelp = 1"
		actionExit "UIhelp = 0"
	}

	
-- Cheat Mode >> Toggles to ON / OFF
	label
	{
		area 	106 180 315 46
		text	'RG_UI_CHEAT'
		text style "normal"
		text align left center
	}
	button
	{
		area		421 180 85 46
		bam			ROUNDBUT
		glow lua 	"Infinity_GetINIValue('Game Options','CheatMode','1')"
		align 		center center
		action		"
		"
	}
	button
	{
		area		106 180 400 46
		action		"
					if CheatMode == 1 then
						CheatMode = 0
						Infinity_SetINIValue('Game Options','CheatMode','0')
					else
						CheatMode = 1
						Infinity_SetINIValue('Game Options','CheatMode','1')
					end
					"
		actionEnter	"UIhelp = 4"
		actionExit "UIhelp = 0"
	}
	
-- Enable multiportrait picker
	label
	{
		area 	106 230 315 46
		text	'RG_UI_MPPICKER'
		text style "normal"
		text align left center
	}
	button
	{
		area		421 230 85 46
		bam			ROUNDBUT
		glow lua 	"Infinity_GetINIValue('Game Options','MultiPortraitPicker','1')"
		align 		center center
		action		"
		"
	}
	button
	{
		area		106 230 400 46
		action		"
					if MultiPortraitPicker == 1 then
						MultiPortraitPicker = 0
						Infinity_SetINIValue('Game Options','MultiPortraitPicker','0')
					else
						MultiPortraitPicker = 1
						Infinity_SetINIValue('Game Options','MultiPortraitPicker','1')
					end
					"
		actionEnter	"UIhelp = 8"
		actionExit "UIhelp = 0"
	}
	
-- Large portraits
	label
	{
		area 	106 280 315 46
		text	'RG_UI_LPORTRAITS'
		text style "normal"
		text align left center
	}
	button
	{
		area		421 280 85 46
		bam			ROUNDBUT
		glow lua 	"Infinity_GetINIValue('Game Options','LargePortraits','1')"
		align 		center center
		action		"
		"
	}
	button
	{
		area		106 280 400 46
		action		"
					if LargePortraits == 1 then
						LargePortraits = 0
						Infinity_SetINIValue('Game Options','LargePortraits','0')
					else
						LargePortraits = 1
						Infinity_SetINIValue('Game Options','LargePortraits','1')
					end
					"
		actionEnter	"UIhelp = 9"
		actionExit "UIhelp = 0"
	}
	
-- Permanent thieving button
	label
	{
		area 	106 330 315 46
		text	'RG_UI_THIEFBUTT'
		text style "normal"
		text align left center
	}
	button
	{
		area		421 330 85 46
		bam			ROUNDBUT
		glow lua 	"Infinity_GetINIValue('Game Options','PermThief','1')"
		align 		center center
		action		"
		"
	}
	button
	{
		area		106 330 400 46
		action		"
					if PermThief == 1 then
						PermThief = 0
						Infinity_SetINIValue('Game Options','PermThief','0')
					else
						PermThief = 1
						Infinity_SetINIValue('Game Options','PermThief','1')
					end
					"
		actionEnter	"UIhelp = 10"
		actionExit "UIhelp = 0"
	}

	
-- Journal Size
	text
	{
		area		106 380 315 46
		text lua	'UIStrings.UI_JMode'
		text style	normal
		text align	left center
	}
	button
	{
		area		421 380 85 46
		text lua	'JournalSize'
		text style 	"normal"
		text align 	center center
		text color	'R'
	}
	button
	{
		area		106 380 400 46
		action		"
					if JournalSize == UIStrings.UI_Large then
						JournalSize = UIStrings.UI_Small
						Infinity_SetINIValue('Game Options','SelectedJournalSize',UIStrings.UI_Small)
					else
						JournalSize = UIStrings.UI_Large
						Infinity_SetINIValue('Game Options','SelectedJournalSize',UIStrings.UI_Large)
					end
					"
		actionEnter	"UIhelp = 2"
		actionExit "UIhelp = 0"
	}

	
-- Quickloot Mode
	label
	{
		area 		106 430 315 46
		text lua 	'UIStrings.UI_QLMode'
		text style 	"normal"
		text align 	left center
	}
	button
	{
		area		421 430 85 46
		text lua	'QuicklootMode'
		text style 	"normal"
		text align 	center center
		text color	'R'
	}
	button
	{
		area		106 430 400 46
		action		"
					if QuicklootMode == UIStrings.UI_Expert then
						QuicklootMode = UIStrings.UI_Advanced
						Infinity_SetINIValue('Game Options','QuicklootMode',UIStrings.UI_Advanced)
					else
						QuicklootMode = UIStrings.UI_Expert
						Infinity_SetINIValue('Game Options','QuicklootMode',UIStrings.UI_Expert)
					end
					"
		actionEnter	"UIhelp = 5"
		actionExit "UIhelp = 0"
	}
	

-- Quickloot Expert Mode - Rows Choice
	text
	{
		enabled 	"QuicklootMode == UIStrings.UI_Expert"
		area		131 480 99 38
		text lua	'UIStrings.UI_QRows'
		text style	normal
		text align	left center
		actionEnter	"UIhelp = 7"
		actionExit "UIhelp = 0"
	}
	button
	{
		enabled 	"QuicklootMode == UIStrings.UI_Expert"
		area		230 480 46 38
		text lua	"selectedENum('2')"
		text style	"normal"
		text align 	center center
		action
		"
		QuicklootENum = 'Two'
		Infinity_SetINIValue('Game Options','QuicklootENumber','Two')
		"
	}
	button
	{
		enabled 	"QuicklootMode == UIStrings.UI_Expert"
		area		276 480 46 38
		text lua	"selectedENum('3')"
		text style	"normal"
		text align 	center center
		action
		"
		QuicklootENum = 'Three'
		Infinity_SetINIValue('Game Options','QuicklootENumber','Three')
		"
	}
	button
	{
		enabled 	"QuicklootMode == UIStrings.UI_Expert"
		area		322 480 46 38
		text lua	"selectedENum('4')"
		text style	"normal"
		text align 	center center
		action
		"
		QuicklootENum = 'Four'
		Infinity_SetINIValue('Game Options','QuicklootENumber','Four')
		"
	}
	button
	{
		enabled 	"QuicklootMode == UIStrings.UI_Expert"
		area		368 480 46 38
		text lua	"selectedENum('5')"
		text style	"normal"
		text align 	center center
		action
		"
		QuicklootENum = 'Five'
		Infinity_SetINIValue('Game Options','QuicklootENumber','Five')
		"
	}
	button
	{
		enabled 	"QuicklootMode == UIStrings.UI_Expert"
		area		414 480 46 38
		text lua	"selectedENum('6')"
		text style	"normal"
		text align 	center center
		action
		"
		QuicklootENum = 'Six'
		Infinity_SetINIValue('Game Options','QuicklootENumber','Six')
		"
	}
	button
	{
		enabled 	"QuicklootMode == UIStrings.UI_Expert"
		area		460 480 46 38
		text lua	"selectedENum('10')"
		text style	"normal"
		text align 	center center
		action
		"
		QuicklootENum = 'Ten'
		Infinity_SetINIValue('Game Options','QuicklootENumber','Ten')
		"
	}

-- Quickloot Hidden/Visible
	text
	{
		area		131 530 375 38
		text lua	'UIStrings.UI_QShow'
		text style	normal
		text align	left center
		actionEnter	"UIhelp = 6"
		actionExit "UIhelp = 0"
	}
	button
	{
		area		421 530 85 38
		text lua	"QuicklootStartPref"
		text style	"normal"
		text align 	center center
		text color	'R'
		action
		"
			if QuicklootStartPref == UIStrings.UI_Hidden then
				QuicklootStartPref = UIStrings.UI_Visible
				Infinity_SetINIValue('Game Options','QuicklootStartPreference',UIStrings.UI_Visible)
				groundItemsButtonToggle = 1
			else
				QuicklootStartPref = UIStrings.UI_Hidden
				Infinity_SetINIValue('Game Options','QuicklootStartPreference',UIStrings.UI_Hidden)
				groundItemsButtonToggle = 0
			end
		"
	}
	
-- UI Help section
	text
	{
		enabled 	"UIhelp == 1"
		area		574 130 402 110
		text		'RG_UI_CLASSIC_DIALOG1'
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled 	"UIhelp == 2"
		area		574 130 402 110
		text lua	'UIStrings.UI_JToggle'
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled 	"UIhelp == 4"
		area		574 130 402 110
		text		'RG_UI_CHEAT1'
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled 	"UIhelp == 5"
		area		574 130 402 110
		text lua	'UIStrings.UI_QToggle'
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled 	"UIhelp == 6"
		area 		574 130 402 110
		text lua	'UIStrings.UI_QShowExp'
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled 	"UIhelp == 7"
		area		574 130 402 110
		text lua	'UIStrings.UI_QRowsExp'
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled 	"UIhelp == 8"
		area		574 130 402 110
		text	'RG_UI_MPPICKER1'
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled 	"UIhelp == 9"
		area		574 130 402 110
		text	'RG_UI_LPORTRAITS1'
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled 	"UIhelp == 10"
		area		574 130 402 110
		text	'RG_UI_THIEFBUTT1'
		text style	normal
		text align	left top
		text point	12
		scrollbar	'GUISCRC'
	}
	button
	{
		bam			GUIBUTNT
		area		188 700 201 43
		text  "CANCEL_BUTTON"
		text style	"button"
		action
		"
			Infinity_PopMenu()
		"
	}	
	button
	{
		bam			GUIBUTNT
		area		638 700 201 43
		text  "DONE_BUTTON"
		text style	"button"
		action
		"
			Infinity_PopMenu()
		"
	}
}
`
autoPauseToggles = { 
{'WEAPON_UNUSABLE_LABEL',18036, 5 , 0, 0},
{'END_OF_ROUND_LABEL',10640, 25, 0, 0},
{'ENEMY_SIGHTED_LABEL',23514, 26, 0, 0},
{'SPELL_CAST_LABEL',24432, 31, 0, 0},
{'TRAP_FOUND_LABEL',24433, 34, 0, 0}
}

characterPauseToggles = { 
{'CENTER_MEMBER_LABEL',24434, 37, 0, 0},
{'CHARACTER_HIT_LABEL',18032, 1 , 0, 0},
{'CHARACTER_INJURED_LABEL',18033, 2 , 0, 0},
{'CHARACTER_DEATH_LABEL',18034, 3 , 0, 0},
{'CHARACTER_ATTACKED_LABEL',18035, 4 , 0, 0},
{'CHARACTER_TARGET_DESTROYED',18037, 13, 0, 0},
}

selOptAP = 0

`
menu
{
	name	'OPTIONS_AUTOPAUSE'
	modal
	align center center
	onOpen
	"
		panelID = 10
		selOptAP = 0
		autopauseString = 18044
		
		for index, var in pairs(autoPauseToggles) do
			var[5] = Infinity_GetOption(var[3], panelID)
			if var[5] == 0 then
				var[4] = 0
			else
				var[4] = 2
			end
		end
		
		for index, var in pairs(characterPauseToggles) do
			var[5] = Infinity_GetOption(var[3], panelID)
			if var[5] == 0 then
				var[4] = 0
			else
				var[4] = 2
			end
		end
	"

	button
	{
		area 0 0 864 710
		mosaic	GUICHISD
		action
		"
			autopauseString = 18044
			selOptAP = 0
		"
	}
	label
	{
		area		94 8 674 44
		text		"AUTO_PAUSE_TITLE"
		text style	title
	}
	list
	{
		
		column 
		{ 
			width 90 
			label
			{
				area 10 0 -1 -1
				text lua "t( autoPauseToggles[rowNumber][1])"
				text style "normal"
				text align left center
			}
		}
		column 
		{ 
			width 10 
			label
			{
				area		10 8 -1 -1
				bam			ROUNDBUT
				align 		center center
				frame		lua "autoPauseToggles[rowNumber][4]"
			}
		}

		area 448 186 372 428
		
		rowheight	50
		table		"autoPauseToggles"
		var		selOptAP
		scrollbar	'GUISCRC'

		action		
		"
			selOptAPC = 0
			autopauseString = autoPauseToggles[selOptAP][2]

			if(cellNumber == 2) then
				Infinity_PlaySound('GAM_09')

				autoPauseToggles[selOptAP][4] = toggleFrame(autoPauseToggles[selOptAP][4])

				if autoPauseToggles[selOptAP][4] == 0 then
					autoPauseToggles[selOptAP][5] = 0
				else 
					autoPauseToggles[selOptAP][5] = 1
				end
			end
		"
	}
	list
	{
	
		column 
		{ 
			width 90 
			label
			{
				area 10 0 -1 -1
				text lua "t( characterPauseToggles[rowNumber][1])"
				text style "normal"
				text align left center
			}
		}
		column 
		{ 
			width 10 
			label
			{
				area		10 8 -1 -1
				bam			ROUNDBUT
				align 		center center
				frame		lua "characterPauseToggles[rowNumber][4]"
			}
		}

		area 34 186 372 428
		
		rowheight	50
		table		"characterPauseToggles"
		var		selOptAPC
		scrollbar	'GUISCRC'

		action		
		"
			selOptAP = 0
			autopauseString = characterPauseToggles[selOptAPC][2]

			if(cellNumber == 2) then
				Infinity_PlaySound('GAM_09')

				characterPauseToggles[selOptAPC][4] = toggleFrame(characterPauseToggles[selOptAPC][4])

				if characterPauseToggles[selOptAPC][4] == 0 then
					characterPauseToggles[selOptAPC][5] = 0
				else 
					characterPauseToggles[selOptAPC][5] = 1
				end

				--Infinity_ChangeOption(characterPauseToggles[selOptAPC][3], characterPauseToggles[selOptAPC][5], panelID )
			end
		"
	}
	
	text
	{
		area		54 118 758 44
		text		lua "Infinity_FetchString(autopauseString)"
		text style	normal
		scrollbar	'GUISCRC'
	}


	button
	{
		area		102 634 230 44		
		bam			GUIBUTMT
		sequence	2
		text 		"CANCEL_BUTTON"
		text style	"button"
		action
		"
			panelID = 8
			helpString = 'GAMEPLAY_DESCRIPTION'
			Infinity_PopMenu()
		"
	}
	button
	{
		area		514 634 230 44
		bam			GUIBUTMT
		sequence	2
		text 		"DONE_BUTTON" --Done
		text style	"button"
		action
		"
			panelID = 10

			for index, var in pairs(autoPauseToggles) do
				Infinity_ChangeOption( var[3], var[5], panelID)
			end
			for index, var in pairs(characterPauseToggles) do
				Infinity_ChangeOption( var[3], var[5], panelID)
			end

			panelID = 8
			Infinity_PopMenu()
		"
	}	
}
`
graphicsToggles = {
{'FULL_SCREEN_LABEL',18000, 9 , 0, 0, 0},
{'HARDWARE_CURSOR_LABEL',32205, 13, 0, 0, 0},
{'SCALE_UI_LABEL',32206, 14, 0, 0, 0},
{'ZOOM_LOCK_LABEL',66654, 36, 0, 0, 0},
{'SPRITE_OUTLINE_LABEL',65909, 15, 0, 0, 0},
{'GREYSCALE_ON_PAUSE_LABEL',32709, 66, 0, 0, 0},
{'HIGHLIGHT_SPRITE_LABEL',32710, 67, 0, 0, 0},
{'DITHER_ALWAYS_LABEL',18021, 52, 0, 0, 0},
{'SHOW_HP_LABEL',66657, 53, 0, 0, 0},
{'SHOW_HEALTHBAR_LABEL',69567, 65, 0, 0, 0},
{'SHOW_BLACK_SPACE_LABEL','SHOW_BLACK_SPACE_DESCRIPTION', 69, 0, 0, 0},
{'NEAREST_NEIGHBOUR_LABEL','NEAREST_NEIGHBOUR_DESCRIPTION', 70, 0, 0, 0},
}

addedDirectx = false
function appendDirectXOption()
	if addedDirectx == false then
		dxOption = {'DIRECTX_LABEL', 32725, 68, 0, 0, 0}
		table.insert(graphicsToggles, dxOption)
		addedDirectx = true
	end
end

selectedGraphicOpt = 0

fontSizeSLDR = 0
fontSizeCancel = 0
function formatGraphicsInfoString()
	return options['Graphics']['version'] .. "\nrunning on " .. options['Graphics']['renderer'] .. "\ndriver provided by " .. options['Graphics']['vendor']
end
`
menu
{
	name	'OPTIONS_GRAPHICS'
	modal
	align center center
	onOpen
	"
		if e:HasDirectX() then
			appendDirectXOption()
		end
		panelID = 6
		helpString = 18042
		selectedGraphicOpt = 0
		selectedSL = 0
		fontSizeSLDR = Infinity_GetOption(22, panelID)
		fontSizeCancel = Infinity_GetOption(22, panelID)
		
		for index, var in pairs(graphicsToggles) do
			var[5] = Infinity_GetOption(var[3], panelID)
			var[6] = 0
			if var[5] == 0 then
				var[4] = 0
			else
				var[4] = 2
			end
		end
	"


	button
	{
		area	0 0 1444 818
		mosaic	RGOPTIO
		action
		"
			helpString = 18042
			selectedSL = 0
		"
	}

	label
	{
		area		252 32 944 44
		text		"GRAPHICS_TITLE"
		text style	title
	}

	label
	{
		area		618 222 380 478
		text		lua "formatGraphicsInfoString()"
		text style	normal
		text align	center center
	}
	
	text
	{
		area		178 138 366 44
		text		"DISPLAY_OPTIONS_LABEL"
		text style	"button"
		text align 	right center
		text highlight lua "getSelected(selectedSL, 1)"
		action
		"
			selectedGraphicOpt = 0
			selectedSL = 1
		"
	}

	list
	{
		
		column 
		{ 
			width 90
			label
			{
				area 0 0 -1 -1
				text lua "t( graphicsToggles[rowNumber][1])"
				text style "normal"
				text align right center
			}
		}
		column 
		{ 
			width 10 
			label
			{
				area		10 4 -1 -1
				bam			ROUNDBUT
				align 		center center
				frame		lua "graphicsToggles[rowNumber][4]"
			}
		}

		area 154 186 390 526
		
		rowheight	40
		table		"graphicsToggles"
		var		selectedGraphicOpt
		scrollbar	'GUISCRC'

		action		
		"
			panelID = 6
			helpString = graphicsToggles[selectedGraphicOpt][2]
			selectedSL = 0
			if(cellNumber == 2) then
				Infinity_PlaySound('GAM_09')
				graphicsToggles[selectedGraphicOpt][4] = toggleFrame(graphicsToggles[selectedGraphicOpt][4])

				if graphicsToggles[selectedGraphicOpt][4] == 0 then
					graphicsToggles[selectedGraphicOpt][5] = 0
				else 
					graphicsToggles[selectedGraphicOpt][5] = 1
				end
				graphicsToggles[selectedGraphicOpt][6] = 1
				--Infinity_ChangeOption(graphicsToggles[selectedGraphicOpt][3], graphicsToggles[selectedGraphicOpt][5], panelID )
			end
		"
	}

	label
	{
		area 1010 134 316 578
		Rectangle 3
	}

	text
	{
		area		1038 160 264 532
		text		lua "Infinity_FetchString(helpString)"
		text style	normal
		scrollbar	'GUISCRC'
	}

	text
	{
		area		596 150 196 36
		text		"FONT_SIZE_LABEL"
		text style	"label"
		text align	right center
		text upper
		text useFontZoom 1
		text highlight lua "getSelected(selectedSL, 2)"
		action 
		"
			helpString = 17204 
			selectedGraphicOpt = 0
			selectedSL = 2
		" 
	}

	slider
	{
		area 798 150 200 36
		position "fontSizeSLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	7
		pad 8 0 10 0
		action
		"
			Infinity_ChangeOption( 22, fontSizeSLDR, 6)
			helpString = 17204 
			selectedGraphicOpt = 0
			selectedSL = 1
		"
	}

	
	button
	{
		area		288 734 230 44
		bam			GUIBUTMT
		sequence	2
		text 		"CANCEL_BUTTON"
		text style	"button"
		action
		"
			panelID = 6
			Infinity_ChangeOption( 22, fontSizeCancel, panelID)

			selectedSL = 0
			Infinity_PopMenu()
		"
	}
	button
	{
		area		950 734 230 44
		bam			GUIBUTMT
		sequence	2
		text 		"DONE_BUTTON" --Done
		text style	"button"
		action
		"
			panelID = 6
			Infinity_ChangeOption( 22, fontSizeSLDR, panelID)

			for index, var in pairs(graphicsToggles) do
				
				if ( var[6] == 1 ) then
					Infinity_ChangeOption( var[3], var[5], panelID)
				end				
			end

			selectedSL = 0
			Infinity_PopMenu()
		"
	}
}
`
soundsToggles = {
{'CHARACTER_SUBTITLES_LABEL',18015, 5, 0, 0},
{'BATTLE_CRIES_LABEL',18013, 6, 0, 0},
{'MOVEMENT_SOUNDS_LABEL',18014, 7, 0, 0}
}
selectedsoundOpt = 0
command = {
{'ALWAYS_LABEL',0, 8, 0, 0},
{'SELDOM_LABEL',0, 9, 0, 0},
{'NEVER_LABEL',0, 10, 0, 0}
}
commandSel = 0
selectOpt = {
{'ALWAYS_LABEL',0, 58, 0, 0},
{'SELDOM_LABEL',0, 59, 0, 0},
{'NEVER_LABEL',0, 60, 0, 0}
}
selectSel = 0
ambientSLDR = 0
sfxSLDR = 0
voiceSLDR = 0
musicSLDR = 0
movieSLDR = 0

`
menu
{
	name	'OPTIONS_SOUND'
	align center center
	modal
	onOpen
	"
		panelID = 7
		helpString = 18042
		selectedsoundOpt = 0
		selectedSL = 0

		ambientSLDR = Infinity_GetOption(1, panelID)
		sfxSLDR = Infinity_GetOption(2, panelID)
		voiceSLDR = Infinity_GetOption(3, panelID)
		musicSLDR = Infinity_GetOption(4, panelID)
		movieSLDR = Infinity_GetOption(22, panelID)

		for index, var in pairs(command) do
				var[5] = Infinity_GetOption(var[3], panelID)
				if var[5] == 0 then
					var[4] = 0
				else
					var[4] = 2
					commandSel = index
				end
			end
		for index, var in pairs(selectOpt) do
			var[5] = Infinity_GetOption(var[3], panelID)
			if var[5] == 0 then
				var[4] = 0
			else
				var[4] = 2
				selectSel = index
			end
		end
		for index, var in pairs(soundsToggles) do
			var[5] = Infinity_GetOption(var[3], panelID)
			if var[5] == 0 then
				var[4] = 0
			else
				var[4] = 2
				selectSel = index
			end
		end
	"
	
	button
	{
		area	0 0 1444 818
		mosaic	RGOPTIO
		action
		"
			helpString = 18042
		"
	}
	label
	{
		area		250 32 946 44
		text		"SOUND_TITLE"
		text style	title
	}
	
	text
	{
		area		146 524 400 44
		text		"CHARACTER_SOUNDS_LABEL"
		text style	"button"
		text align 	right center
		text highlight lua "getSelected(selectedSL, 3)"
	}

	list
	{
		
		column 
		{ 
			width 90
			label
			{
				area 0 0 -1 -1
				text lua "t( soundsToggles[rowNumber][1])"
				text style "normal"
				text align right center
			}
		}
		column 
		{ 
			width 10 
			label
			{
				area		10 8 -1 -1
				bam			ROUNDBUT
				align 		center center
				frame		lua "soundsToggles[rowNumber][4]"
			}
		}

		area 146 568 400 140
		
		rowheight	46
		table		"soundsToggles"
		var		selectedsoundOpt
		scrollbar	'GUISCRC'

		action		
		"
			panelID = 7
			helpString = soundsToggles[selectedsoundOpt][2]
			selectedSL = 0
			if(cellNumber == 2) then
				Infinity_PlaySound('GAM_09')
				soundsToggles[selectedsoundOpt][4] = toggleFrame(soundsToggles[selectedsoundOpt][4])

				if soundsToggles[selectedsoundOpt][4] == 0 then
					soundsToggles[selectedsoundOpt][5] = 0
				else 
					soundsToggles[selectedsoundOpt][5] = 1
				end
				
			end
		"
	}
	
	text
	{
		area		146 138 400 44
		text		"COMMAND_SOUNDS_BUTTON"
		text style	"button"
		text align 	right center
		text highlight lua "getSelected(selectedSL, 1)"
		action 
		"
			helpString = 18016 
			selectedsoundOpt = 0
			selectedSL = 1
		"
	}

	
	list
	{
		
		column 
		{ 
			width 90 
			label
			{
				area 10 0 -1 -1
				text lua "t( command[rowNumber][1])"
				text style	"normal"
				text align right center
			}
		}
		column 
		{ 
			width 10
			label
			{
				area		10 8 -1 -1
				bam			ROUNDBUT
				text align 	center center
				frame		lua "command[rowNumber][4]"
			}
		}

		area 146 182 400 140
		
		rowheight	46
		table		"command"
		var		commandSel
		scrollbar	'GUISCRC'
		hidehighlight

		action		
		"
			panelID = 7
			helpString = 18016 
			selectedSL = 1
			selectedsoundOpt = 0
			opt = commandSel
			command[1][4] = 0
			command[2][4] = 0
			command[3][4] = 0
			
			Infinity_PlaySound('GAM_09')
			command[opt][4] = 2
		"
	}

	text
	{
		area		146 331 400 44
		text		"SELECTION_BUTTON"
		text style	"button"
		text align 	right center
		text highlight lua "getSelected(selectedSL, 2)"
		action 
		"
			helpString = 11352 
			selectedsoundOpt = 0
			selectedSL = 2
		"
	}

	list
	{
		
		column 
		{ 
			width 90
			label
			{
				area 10 0 -1 -1
				text lua "t( selectOpt[rowNumber][1])"
				text style	"normal"
				text align right center
			}
		}
		column 
		{ 
			width 10
			label
			{
				area		10 8 -1 -1
				bam			ROUNDBUT
				align 		center center
				frame		lua "selectOpt[rowNumber][4]"
			}
		}

		area 146 375 400 140
		
		rowheight	46
		table		"selectOpt"
		var		selectSel
		scrollbar	'GUISCRC'
		hidehighlight
		action		
		"
			panelID = 7
			helpString = 11352 
			selectedSL = 2
			opt = selectSel
			selectOpt[1][4] = 0
			selectOpt[2][4] = 0
			selectOpt[3][4] = 0
			selectedsoundOpt = 0
			
			Infinity_PlaySound('GAM_09')
			selectOpt[opt][4] = 2
		"
	}
	
	label
	{
		area 1010 134 316 578
		Rectangle 3
	}
	
	text
	{
		area		1036 162 266 530
		text		lua "Infinity_FetchString(helpString)"
		text style	normal
		scrollbar	'GUISCRC'
	}
	
	text
	{
		area		606 138 394 44
		text		"VOLUME_CONTROLS_LABEL"
		text style	"button"
		text align 	right center
	}

	text
	{
		area		610 202 173 40
		text		"AMBIENT_VOLUME_LABEL"
		text style	"label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 4)"
		action 
		"
			helpString = 18008 
			selectedsoundOpt = 0
			selectedSL = 4
		"
	}
	slider
	{
		area 796 206 200 36
		position "ambientSLDR"
		mosaic GUISLDR
		bam	 'SLDRSTAR'
		sequence 0
		frame	 1
		settings	40
		pad 8 0 10 0
		action 
		"
			helpString = 18008 
			selectedsoundOpt = 0
			selectedSL = 4
		"
	}

	text
	{
		area		598 272 185 40	
		text		"SFX_VOLUME_LABEL"
		text style	"label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 5)"
		action 
		"
			helpString = 18009 
			selectedsoundOpt = 0
			selectedSL = 5
		"
		
	}
	slider
	{
		area 796 276 200 36
		mosaic GUISLDR
		position "sfxSLDR"
		bam	 'SLDRSTAR'
		sequence 0
		frame	 1
		settings	40
		pad 8 0 10 0
		action 
		"
			helpString = 18009 
			selectedsoundOpt = 0
			selectedSL = 5
		"
	}

	text
	{
		area		610 340 173 40	
		text		"VOICE_VOLUME_LABEL"
		text style	"label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 6)"
		action 
		"
			helpString = 18010 
			selectedsoundOpt = 0
			selectedSL = 6
		"
	}
	slider
	{
		area 796 344 200 36
		position "voiceSLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	40
		pad 8 0 10 0
		action 
		"
			helpString = 18010 
			selectedsoundOpt = 0
			selectedSL = 6
		"
	}

	text
	{
		area		610 410 173 40	
		text		"MUSIC_VOLUME_LABEL"
		text style	"label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 7)"
		action 
		"
			helpString = 18011 
			selectedsoundOpt = 0
			selectedSL = 7
		"
		
	}
	slider
	{
		area 796 414 200 36
		position "musicSLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	40
		pad 8 0 10 0
		action 
		"
			helpString = 18011 
			selectedsoundOpt = 0
			selectedSL = 7
		"
	}

	text
	{
		area		610 480 173 44	
		text		"MOVIE_VOLUME_LABEL"
		text style	"label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 8)"
		action 
		"
			helpString = 18012
			selectedsoundOpt = 0
			selectedSL = 8
		"
	}
	slider
	{
		area 796 484 200 40
		position "movieSLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	40
		pad 8 0 10 0
		action 
		"
			helpString = 18012
			selectedsoundOpt = 0
			selectedSL = 8
		"
	}

	button
	{
		area		298 734 200 44
		bam			GUIBUTNT
		sequence	2
		text 		"CANCEL_BUTTON"
		text style	"button"
		action
		"
			selectedSL = 0
			panelID = 8
			Infinity_PopMenu()
		"
	}
	button
	{
		area		972 734 200 44		
		bam			GUIBUTNT
		sequence	2
		text 		"DONE_BUTTON"
		text style	"button"
		action
		"
			panelID = 7
			
			for index, var in pairs(command) do
				Infinity_Log('Com var[4] #' .. index .. ': ' .. var[4])
				if var[4] == 2 then
					Infinity_ChangeOption( var[3], 1, panelID)
				end
			end
			for index, var in pairs(selectOpt) do
				Infinity_Log('Sel var[4] #' .. index .. ': ' .. var[4])
				if var[4] == 2 then
					Infinity_ChangeOption( var[3], 1, panelID)	
				end	
			end
			Infinity_ChangeOption( 1, ambientSLDR, panelID)
			Infinity_ChangeOption( 2, sfxSLDR, panelID )
			Infinity_ChangeOption( 3, voiceSLDR, panelID )
			Infinity_ChangeOption( 4, musicSLDR, panelID)
			Infinity_ChangeOption( 22, movieSLDR, panelID)

			selectedOpt = 0
			selectedSL = 0

			for index, var in pairs(soundsToggles) do				
				Infinity_ChangeOption( var[3], var[5], panelID)						
			end

			panelID = 8
			Infinity_PopMenu()
		"
	}
}
`

feedbackToggles = {
{'COLORED_MARKERS_LABEL',			'COLORED_MARKERS_HELP', 			38, 0, 0},
{'CLASSIC_MARKERS_LABEL',			'CLASSIC_MARKERS_HELP', 			45, 0, 0},
{'ENABLE_CONFIRMATION_LABEL',		'ENABLE_CONFIRMATION_HELP', 		41, 0, 0},
{'DISABLE_COSMETIC_ATTACKS_LABEL',	'DISABLE_COSMETIC_ATTACKS_HELP', 	43, 0, 0},
{'JOURNAL_POPUPS_LABEL',			'JOURNAL_POPUPS_HELP', 				44, 0, 0}
}

messagesToggles = { 
{'TO_HIT_ROLLS_LABEL',		'TO_HIT_ROLLS_HELP', 	10, 0, 0},
{'ACTIONS_LABEL', 			'ACTIONS_HELP', 		12, 0, 0},
{'STATE_CHANGES_LABEL',		'STATE_CHANGES_HELP', 	13, 0, 0},
{'COMBAT_INFO_LABEL',		'COMBAT_INFO_HELP', 	11, 0, 0},
{'SELECTION_TEXT_LABEL',	'SELECTION_TEXT_HELP',	14, 0, 0},
{'MISC_LABEL',				'MISC_HELP', 			15, 0, 0}
}

selFeedOpt = 0
selMessageOpt = 0
helpString = 0

markerFeedSLDR = 0
locatorFeedSLDR = 0

function getFrequency(d,includeHighter)
	strref = ""
	if ( d ==0 ) then
		strref = "MINIMUM"
	elseif (d == 1) then
		strref = "LOW"
	elseif (d == 2) then
		strref = "MEDIUM"
	elseif (d == 3) then
		strref = "HIGH"
	elseif (d == 4 and includeHighter == true) then
		strref = "HIGHER"
	elseif (d == 4 and includeHighter == false) then
		strref = "MAXIMUM"
	elseif (d == 5) then
		strref = "MAXIMUM"
	end
	return t(strref)
end

`
menu
{
	name	'OPTIONS_FEEDBACK'
	align center center
	modal
	onOpen
	"
		panelID = 9

		helpString = 'FEEDBACK_HELP'
		selFeedOpt = 0
		selMessageOpt = 0
		selectedSL = 0

		markerFeedSLDR = Infinity_GetOption(8, panelID)
		locatorFeedSLDR = Infinity_GetOption(9, panelID)
		
		for index, var in pairs(feedbackToggles) do
				var[5] = Infinity_GetOption(var[3], panelID)
				if var[5] == 0 then
					var[4] = 0
				else
					var[4] = 2
				end
			end

		for index, var in pairs(messagesToggles) do
			var[5] = Infinity_GetOption(var[3], panelID)
			if var[5] == 0 then
				var[4] = 0
			else
				var[4] = 2
			end
		end

	"

	button
	{
		area	0 0 1024 768
		mosaic	GUITUTB
		action
		"
			helpString = 'FEEDBACK_HELP'
			selFeedOpt = 0
			selMessageOpt = 0
			selectedSL = 0
		"
	}
	label
	{
		area		126 32 768 54
		text		"FEEDBACK_TITLE"
		text style	title
	}



	label
	{
		area		100 338 407 44
		text		"VISUAL_FEEDBACK_LABEL"
		text style	"button"
		text align 	right center
	}

	list
	{
		
		column 
		{ 
			width 90
			label
			{
				area 0 0 -1 -1
				text lua "t( feedbackToggles[rowNumber][1])"
				text style "normal"
				text align right center
			}
		}
		column 
		{ 
			width 10 
			label
			{
				area		10 8 -1 -1
				bam			ROUNDBUT
				align 		center center
				frame		lua "feedbackToggles[rowNumber][4]"
			}
		}

		area 100 382 407 268
		
		rowheight	50
		table		"feedbackToggles"
		var		selFeedOpt
		scrollbar	'GUISCRC'

		action		
		"
			selectedSL = 0
			selMessageOpt = 0
			helpString = feedbackToggles[selFeedOpt][2]

			if(cellNumber == 2) then
				Infinity_PlaySound('GAM_09')
				feedbackToggles[selFeedOpt][4] = toggleFrame(feedbackToggles[selFeedOpt][4])

				if feedbackToggles[selFeedOpt][4] == 0 then
					feedbackToggles[selFeedOpt][5] = 0
				else 
					feedbackToggles[selFeedOpt][5] = 1
				end
			end
		"
	}

	label
	{
		area		568 128 416 44
		text		"FEEDBACK_MESSAGES_LABEL"
		text style	"button"
		text align 	right center
	}

	list
	{
		
		column 
		{ 
			width 90
			label
			{
				area 10 0 -1 -1
				text lua "t( messagesToggles[rowNumber][1])"
				text style	"normal"
				text align right center
			}
		}
		column 
		{ 
			width 10
			label
			{
				area		10 8 -1 -1
				bam			ROUNDBUT
				align 		center center
				frame		lua "messagesToggles[rowNumber][4]"
			}
		}

		area 568 172 422 328
		
		rowheight	50
		table		"messagesToggles"
		var		selMessageOpt
		scrollbar	'GUISCRC'

		action		
		"

			helpString = messagesToggles[selMessageOpt][2]
			selectedSL = 0
			selFeedOpt = 0

			if(cellNumber == 2) then
				Infinity_PlaySound('GAM_09')
				messagesToggles[selMessageOpt][4] = toggleFrame(messagesToggles[selMessageOpt][4])

				if messagesToggles[selMessageOpt][4] == 0 then
					messagesToggles[selMessageOpt][5] = 0
				else 
					messagesToggles[selMessageOpt][5] = 1
				end
			end
		"
	}

	label
	{
		area 560 522 425 142
		mosaic GUINOTE
	}
	
	text
	{
		area		576 534 398 110
		text		lua "t(helpString)"
		text style	normal
		scrollbar	'GUISCRC'
	}

	text 
	{
		area		110 142 186 36
		text		"MARKER_FEEDBACK_LABEL"
		text style "label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 1)"
		action 
		"
			helpString = 'MARKER_FEEDBACK_HELP' 
			selFeedOpt = 0
			selMessageOpt = 0
			selectedSL = 1
		"
		
	}
	slider
	{
		area		300 142 200 36
		position "markerFeedSLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	6
		action 
		"
			helpString = 'MARKER_FEEDBACK_HELP' 
			selFeedOpt = 0
			selMessageOpt = 0
			selectedSL = 1
		"
	}
	label
	{
		area		300 178 200 36
		text		lua "getFrequency(markerFeedSLDR,true)"
		text style	"label"
		text align	center center
	}

	text
	{
		area		110 242 186 36	
		text		"LOCATOR_FEEDBACK_LABEL"
		text style "label"
		text align	right center
		text upper
		text highlight lua "getSelected(selectedSL, 2)"
		action 
		"
			helpString = 'LOCATOR_FEEDBACK_HELP'
			selFeedOpt = 0
			selMessageOpt = 0
			selectedSL = 2
		"
	}
	slider
	{
		area 300 242 200 36
		position "locatorFeedSLDR"
		bam	 'SLDRSTAR'
		mosaic GUISLDR
		sequence 0
		frame	 1
		settings	5
		action 
		"
			helpString = 'LOCATOR_FEEDBACK_HELP'
			selFeedOpt = 0
			selMessageOpt = 0
			selectedSL = 2
		"
	}
	label
	{
		area		300 278 200 36
		text		lua "getFrequency(locatorFeedSLDR,false)"
		text style	"label"	
		text align	center center
	}
	button
	{
		area		188 700 200 44
		bam			GUIBUTNT
		sequence	2
		text 		"CANCEL_BUTTON"
		text style	"button"
		action
		"
			helpString = 'GAMEPLAY_DESCRIPTION'
			selectedSL = 0
			panelID = 8
			Infinity_PopMenu()
		"
	}
	button
	{
		area		638 700 200 44		
		bam			GUIBUTNT
		sequence	2
		text 		"DONE_BUTTON" --Done
		text style	"button"
		action
		"
			helpString = 'GAMEPLAY_DESCRIPTION'
			panelID = 9
			Infinity_ChangeOption( 8, markerFeedSLDR, panelID)
			Infinity_ChangeOption( 9, locatorFeedSLDR, panelID )

			selectedOpt = 0
			selectedSL = 0

			for index, var in pairs(messagesToggles) do
				
				Infinity_ChangeOption( var[3], var[5], panelID)
						
			end

			for index, var in pairs(feedbackToggles) do
				
				Infinity_ChangeOption( var[3], var[5], panelID)
						
			end
			Infinity_PopMenu()
		"
	}
}
`
function getGooglePlaySignInText()
	if(Infinity_GooglePlaySignedIn() == 1) then
		return t("SIGN_OUT_BUTTON")
	else
		return t("SIGN_IN_BUTTON")
	end
end

keyCategory = 1
key = 0

function displayHelp()
	if not (key == 0) then
		return 24680
	end
	return 0
end

function getHotkeyName(category,number)
	local ret = ""
	if category < 5 then
		ret = t(keybindings[category][number][4])
	else
		ret = Infinity_FetchString(keybindings[category][number][4])
	end
	return ret
end
`
menu
{
	name	'OPTIONS_KEYBINDINGS'
	modal
	align center center
	
	button -- Background
	{
		area 0 0 864 710
		mosaic GUICHISD 
	}
	
	label -- Title
	{
		area 82 12 700 40
		text  "ASSIGN_KEYS_TITLE" 
		text style	"title"
	}
	
	label -- Instruction
	{
		area 252 60 367 42
		text  "ASSIGN_KEYS_SUBTITLE" 
		text style	"label"
	}
	label -- Contextual instruction
	{
		area 42 112 778 50
		text lua "Infinity_FetchString(displayHelp())"
		text style	"label"
	}

	list -- Key categories
	{
		column 
		{ 
			width 100 
			label
			{
				area 0 0 -1 -1
				text lua "t(keycategories[rowNumber][2])"
				text style	"normal"
				text align	center center 
			}
		}
		area 42 190 360 420
		
		rowheight	24
		table		"keycategories"
		var			keyCategory
		scrollbar	'GUISCRC'
		action
		"
			Infinity_StopKeybind()
			key = 0
		"
	}

	
	list -- Key bindings
	{
		column 
		{ 
			width 90 
			label
			{
				area 0 0 -1 -1
				text lua "getHotkeyName(keyCategory,rowNumber)"
				text style	"normal"
				align left center
			}
		}
		column 
		{ 
			width 10
			label
			{
				area 0 0 -1 -1
				text lua "string.format('%c', keybindings[keyCategory][rowNumber][6])"
				text style	"normal"
				text upper
				text align right center 
			}
		}
		
		area 448 190 372 420
		rowheight	24
		table		"keybindings[keyCategory]"
		var			key
		scrollbar	'GUISCRC'
		action
		"
		if(key > 0) then
			Infinity_StartKeybind(key);
			keybindings[keyCategory][key][6] = 0
		end
		"
	}
	
	button
	{
		area		514 634 230 44
		bam			GUIBUTMT
		sequence	6
		text		"DONE_BUTTON"
		text style	"button"
		action
		"
			Infinity_StopKeybind()
			key = 0
			Infinity_PopMenu();
		"	
	}
	button
	{
		area		102 634 230 44
		bam			GUIBUTMT
		sequence	6
		text		"REVERT_BUTTON"
		text style	"button"
		
		action
		"
			revertKeymap();
		"	
	}
}
`
function generateMegaCredits()
	megacredits = ''
	for k,v in pairs(credits) do
		megacredits = megacredits .. Infinity_FetchString(v)..'\n'
	end
end
`
menu
{
	name	'CREDITS'
	align center center
	modal
	onOpen
	"
		generateMegaCredits()
	"
	label
	{
		area	0 0 1444 818
		mosaic	RGOPTIO2
	}
	label
	{
		area	180 82 1080 644
		rectangle 3
	}
	
	label
	{
		area 236 36 970 36
		text "CREDITS_TITLE"
		text style "title"
	}
	
	text
	{
		area 204 104 1032 602
		text lua "megacredits"
		scrollbar	'GUISCRC'
		scrollbar func "resetScrollbar"
		text style "normal"
		text align center top
	}
	
	button
	{
		area		598 730 230 44
		bam			GUIBUTMT
		sequence	6
		text  "DONE_BUTTON"
		text style "button"
		action
		"
			Infinity_PopMenu();
		"	
	}
}
`
language = 0
showsubtitles = 0
function languageDetails()
	if languages[language] ~= nil then
		return Infinity_FetchString(languages[language][2]) .. '\n'  .. Infinity_FetchString(languages[language][3])
	else
		return ""
	end
end
function findCurrentLanguage()
	local lang = Infinity_GetINIString('Language', 'Text', '')
	for k,v in pairs(languages) do
		if v[1] == lang then
			language = k
  		end
	end
end
`
menu
{
	name	'OPTIONS_LANGUAGE'
	modal
	align center center
	onOpen
	"
		showsubtitles = Infinity_GetINIValue('Program Options', 'Display Subtitles', 1)
		findCurrentLanguage()
	"
	
	button
	 {
		area	0 0 1444 818
		mosaic	RGOPTIO
	 }
--	label
--	{
--		area 368 64 636 650
--		Rectangle 3
--	}
--	label
--	{
--		area 372 588 624 111
--		mosaic	GUWBTP39
--	}
	
	label
	{
		area 250 26 948 56
		text "LANGUAGE_TITLE"
		text style "title"
	}
	list
	{
		column { 
			width 100
			label
			{
				area 0 0 -1 -1
				text lua "languages[rowNumber][4]"
				text style	"normal"
				text align center center 
			}
		}
	
		area		146 138 392 450
		rowheight	28
		table		"languages"
		var			language
		scrollbar	'GUISCRC'
	}
	text
	{
		area		600 140 722 466
		text lua	"languageDetails()"
		text style	normal
		text align	center top
		scrollbar	'GUISCRC'
	}
	
	label
	{
		area		234 596 170 34
		text	"SHOW_SUBTITLES_LABEL"
		text style	"label"
		text align	right center
		text upper
	}
	label
	{
		area		186 642 318 46
		text lua 	"Infinity_FetchString(32129)"
		text style	"normal"
		text align	center center
		text upper
	}
	label
	{
		area		600 616 722 96
		text lua 	"Infinity_FetchString(32208)"
		text style	"normal"
		text align	center center
		text color 	'$'
	}
	
	button
	{
		area		412 596 36 34
		bam			ROUNDBUT
		toggle		showsubtitles
	}
	
	button
	{
		area		304 732 230 44
		bam			GUIBUTMT
		text	"CANCEL_BUTTON"
		text style	"button"
		sequence 1
		action
		"
			-- cancel
			for index, var in pairs(languages) do
				Infinity_Log(var[3])
			end
			Infinity_PopMenu();
		"
	}
	
	button
	{
		area		936 732 230 44
		bam			GUIBUTMT
		text 		"DONE_BUTTON"
		text style	"button"
		action
		"
			-- done
			Infinity_SetLanguage(languages[language][1],showsubtitles)
			Infinity_PopMenu()
		"
	}
	
}
`
function restoreOverlayFromQuit()
	--restore the old overlay if applicable
	if(oldOverlayMenuName) then
		Infinity_SetOverlay(oldOverlayMenuName)
	else
		Infinity_SetOverlay(nil)
	end
end
`
menu
{
	name 'QuitMenu'
	modal
	align center center
	label -- Background
	{
		area 0 0 657 234
		mosaic GUIERR6 
	}
	label --Title
	{
		area 40 20 600 120
		text  20186
		text style	"label"
	}
	button
	{
		area		370 170 230 44
		bam			GUIBUTMT
		sequence	0
		text  "QUIT_GAME_BUTTON"
		text style	"button"
		on 			return
		action
		"
			restoreOverlayFromQuit()
			Infinity_ShutdownGame()
		"	
	}
	button
	{
		area		88 170 230 44
		bam			GUIBUTMT
		sequence	0
		text  "CANCEL_BUTTON"
		text style	"button"
		on 			escape
		action
		"
			restoreOverlayFromQuit()
		"	
	}
}
`
selectedSlot = nil
itemRequestAmt = 0

function showItemAmountRequester(slotName)
	local slot = characters[id].equipment[slotName]
	if(slot.item.count == nil) then
		Infinity_Log("Nil count in requester!")
		return
	end
	if(slot.item.count > 1) then
		selectedSlot = slotName
		popupRequester(slot.item.count, inventorySplitStack, false)
	end
end
function inventorySplitStack(cnt)
	Infinity_SplitItemStack(characters[id].equipment[selectedSlot].id, cnt,'slot_inv_' .. characters[id].equipment[selectedSlot].id)
end

function GetAbilityIdentifyString()
	if(characters[id].equipment[selectedSlot].item.identified == 0) then
		return t("IDENTIFY_BUTTON")
	end
	
	if(characters[id].equipment[selectedSlot].abilityMode == 1) then
		return t("ABILITIES_BUTTON")
	end
	
	return ""
end
requester = {}
requester.requesterMax = 0
requester.requesterFunc = nil
requester.selling = false
itemRequestAmt = 0
requestAmt = 0

`
menu
{
	name 'POPUP_REQUESTER'
	align center center
	modal
	onOpen
	"
		if requester.selling == false then
			itemRequestAmt = 0
			requestAmt = 0
		elseif requester.selling < 10 then
			itemRequestAmt = 1
			requestAmt = 1
		else
			itemRequestAmt = requester.requesterMax
			requestAmt = requester.requestMax
			
		end
	"
	
	label
	{
		area 0 0 465 500
		mosaic GUIERR
	}
	label
	{
		area	132 84 208 47
		text	"CHOOSE_AMT_LABEL"
		text align center center
		text style "label"
	}
	edit
	{
		area		147 142 86 48
		var			itemRequestAmt
		text style	"edit"
		align center center
		maxlines	1
		fill            112 111 111 64
		action
		"
			-- only permit numbers as letters.
			-- character limit of 4
			if((tonumber(letter_pressed) ~= nil and #tostring(itemRequestAmt) < 4) or not letter_pressed) then
				return 1
			else
				return 0
			end
		"
	}
	button
	{
		bam			GUIBUTNT
		sequence	6
		area		138 345 201 43
		text  "CANCEL_BUTTON"
		text style	"button"
		action
		"
			Infinity_PopMenu('POPUP_REQUESTER')
			requestAmt = 0
			itemRequestAmt = 1
		"
	}	
	button
	{
		bam			GUIBUTNT
		sequence	6
		area		138 289 201 43
		clickable	lua "itemRequestAmt > 0"
		text  "DONE_BUTTON"
		text style	"button"
		action
		"
			local cnt = tonumber(itemRequestAmt)
			Infinity_PopMenu('POPUP_REQUESTER')
			if(cnt and cnt > 0 and cnt <= requester.requesterMax) then
				requester.requesterFunc(cnt)
			end
			requestAmt = 0
			itemRequestAmt = 1
		"
	}
	slider
	{
		area 130 227 212 39
		position "requestAmt"
		bam	 'SLDRSTAR'
		mosaic RGSCALE
		sequence 0
		frame	 1
		settings 	21
		pad 4 0 6 0
		enabled "requester.requesterMax > 10"
		action
		"
			selectedOpt = 0
			selectedSL = 0
			itemRequestAmt = math.floor(requestAmt * requester.requesterMax / 20)
		" 
	}

	button	{	enabled "requester.requesterMax > 10"	sequence	6	area	118 190 46 38	text	"0"	text style	"button"	text point 	10
		action	"	local amt = tonumber(itemRequestAmt)	itemRequestAmt = 0	"	}
	button	{	enabled "requester.requesterMax > 10"	sequence	6	area	164 190 46 38	text lua	"math.floor(requester.requesterMax/4)"	text style	"button"	text point 10
		action	"	local amt = tonumber(itemRequestAmt)	itemRequestAmt = math.floor(requester.requesterMax/4)	"	}
	button	{	enabled "requester.requesterMax > 10"	sequence	6	area	210 190 52 38	text lua	"math.floor(requester.requesterMax/2)"	text style	"button"	text point 10
		action	"	local amt = tonumber(itemRequestAmt)	itemRequestAmt = math.floor(requester.requesterMax/2)	"	}
	button	{	enabled "requester.requesterMax > 10"	sequence	6	area	262 190 46 38	text lua	"math.floor(3*requester.requesterMax/4)"	text style	"button"	text point 10
		action	"	local amt = tonumber(itemRequestAmt)	itemRequestAmt = math.floor(3*requester.requesterMax/4)	"	}
	button	{	enabled "requester.requesterMax > 10"	sequence	6	area	311 190 42 38	text lua	"math.floor(requester.requesterMax)"	text style	"button"	text point 10
		action	"	local amt = tonumber(itemRequestAmt)	itemRequestAmt = math.floor(requester.requesterMax)	"	}

	button
	{
		bam GUIOSW
		area 242 146 44 44
		sequence 0
		action
		"
			local amt = tonumber(itemRequestAmt)
			if(amt < requester.requesterMax) then
				itemRequestAmt = amt + 1
			end
		"
		actionHold
		"
			local amt = tonumber(itemRequestAmt)
			if(amt < requester.requesterMax) then
				itemRequestAmt = amt + 1
			end
		"
	}
	button
	{
		bam GUIOSW
		area 290 146 44 44
		sequence 1
		action
		"
			local amt = tonumber(itemRequestAmt)
			if(amt > 1) then
				itemRequestAmt = amt - 1
			end
		"
		actionHold
		"
			local amt = tonumber(itemRequestAmt)
			if(amt > 1) then
				itemRequestAmt = amt - 1
			end
		"
	}
}
`
selectedAbility = -1
function initAbilities()
	--initialize selected ability
	local i = 1
	while ( i < 4 ) do
		local ability = characters[id].equipment[selectedSlot].abilities[i]
		if(ability ~= nil) then
			if(ability.selected == 1) then
				selectedAbility = i
				return
			end
		end
		i = i + 1
	end
end
`
menu
{
	name 'ITEM_ABILITIES'
	align center center
	onOpen "initAbilities()"
	
	label
	{
		area	0 0 539 668
		mosaic	GUICGGEN
	}
	label
	{
		area 0 16 539 44
		text "ITEM_ABILITIES_TITLE"
		text style	"title"
	}
	text
	{
		area 22 74 496 52
		text highlight lua "selectedAbility == 1"
		enabled "characters[id].equipment[selectedSlot].abilities[1] ~= nil"
		text lua "characters[id].equipment[selectedSlot].abilities[1].text"
		text style	"label"
		action "selectedAbility = 1"
	}
	button
	{
		area 22 74 52 52
		bam "STONSL10"
		enabled "characters[id].equipment[selectedSlot].abilities[1] ~= nil"
		icon lua "characters[id].equipment[selectedSlot].abilities[1].icon"
		action "selectedAbility = 1"
	}

	
	text
	{
		area 22 138 496 52
		text highlight lua "selectedAbility == 2"
		enabled "characters[id].equipment[selectedSlot].abilities[2] ~= nil"
		text lua "characters[id].equipment[selectedSlot].abilities[2].text"
		text style	"label"
		action "selectedAbility = 2"
	}
	button
	{
		area 22 138 52 52
		bam "STONSL10"
		enabled "characters[id].equipment[selectedSlot].abilities[2] ~= nil"
		icon lua "characters[id].equipment[selectedSlot].abilities[2].icon"
		action "selectedAbility = 2"
	}

	text
	{
		area 22 202 496 52
		text highlight lua "selectedAbility == 3"
		enabled "characters[id].equipment[selectedSlot].abilities[3] ~= nil"
		text lua "characters[id].equipment[selectedSlot].abilities[3].text"
		text style	"label"
		action "selectedAbility = 3"
	}
	button
	{
		area 22 202 52 52
		bam "STONSL10"
		enabled "characters[id].equipment[selectedSlot].abilities[3] ~= nil"
		icon lua "characters[id].equipment[selectedSlot].abilities[3].icon"
		action "selectedAbility = 3"
	}
	
	label
	{
		area 32 397 470 158
		text 11322
		text style "label"
	}
	
	button
	{
		area 278 607 232 44
		bam			GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		action
		"
			local itemNum = characters[id].equipment[selectedSlot].abilities[selectedAbility].itemNum
			Infinity_SelectItemAbility(selectedAbility - 1, itemNum, characters[id].equipment[selectedSlot].id)
			Infinity_PopMenu()
		"
	}
	
	button
	{
		area 50 607 232 44
		bam			GUIBUTMT
		text "CANCEL_BUTTON"
		text style "button"
		action
		"
			Infinity_PopMenu()
		"
	}

}
`
TEXT_popup_info = 0
`
menu
{
	name 'POPUP_INFO'
	align center center
	modal
	label
	{
		area 0 0 657 234
		mosaic GUIERR6
	}
	label
	{
		area 29 21 580 126
		text lua "getStringFromAmbiguousSource(TEXT_popup_info)"
		text style	"label"
	}
	button
	{
		area 213 170 200 44
		bam GUIBUTNT
		text "DONE_BUTTON"
		text style	"button"
		action 
		"
			Infinity_PopMenu()
		"
	}
}
menu
{
	name 'POPUP_TWOBUTTON'
	align center center
	modal
	label
	{
		area 0 0 657 234
		mosaic GUIERR6
	}
	label
	{
		area 29 21 580 126
		text lua "getStringFromAmbiguousSource(Popup2Button.info)"
		text style	"label"
		text align center center
	}
	button
	{
		area 79 170 230 44
		bam GUIBUTMT
		text lua "t(Popup2Button.cancelText or 'CANCEL_BUTTON')"
		text style	"button"
		action 
		"
			Infinity_PopMenu('POPUP_TWOBUTTON')
			if (Popup2Button.cancelFunc) then
				Popup2Button.cancelFunc()
			end
		"
	}
	button
	{
		area 343 170 230 44
		bam GUIBUTMT
		text style	"button"
		text lua "t(Popup2Button.okText or 'DONE_BUTTON')"
		action 
		"
			Infinity_PopMenu('POPUP_TWOBUTTON')
			if (Popup2Button.okFunc) then
				Popup2Button.okFunc()
			end
		"
	}
}
menu
{
	name 'POPUP_THREEBUTTON'
	align center center
	modal
	label
	{
		area 0 0 657 234
		mosaic GUIERR6
	}
	label
	{
		area 29 21 580 126
		text lua "getStringFromAmbiguousSource(Popup3Button.info)"
		text style	"label"
		text align center center
	}
	button
	{
		area 440 170 200 44
		bam GUIBUTNT
		text lua "t(Popup3Button.rightText)"
		text style	"button"
		action 
		"
			Infinity_PopMenu()
			if (Popup3Button.rightFunc) then
				Popup3Button.rightFunc()
			end
		"
	}
	button
	{
		area 228 170 200 44
		bam GUIBUTNT
		text style	"button"
		text lua "t(Popup3Button.midText)"
		action 
		"
			Infinity_PopMenu()
			if (Popup3Button.midFunc) then
				Popup3Button.midFunc()
			end
		"
	}
	button
	{
		area 18 170 200 44
		bam GUIBUTNT
		text style	"button"
		text lua "t(Popup3Button.leftText)"
		action 
		"
			Infinity_PopMenu()
			if (Popup3Button.leftFunc) then
				Popup3Button.leftFunc()
			end
		"
	}
}
menu
{
	name 'POPUP_FOURBUTTON'
	align center center
	modal
	label
	{
		area 0 0 900 234
		mosaic GUIERR7
	}
	label
	{
		area 55 21 789 126
		text lua "getStringFromAmbiguousSource(Popup4Button.info)"
		text style	"label"
		text align center center
	}
	button
	{
		area 668 170 200 44
		bam GUIBUTNT
		text lua "t(Popup4Button.farRightText)"
		text style	"button"
		action 
		"
			Infinity_PopMenu()
			if (Popup4Button.farRightFunc) then
				Popup4Button.farRightFunc()
			end
		"
	}
	button
	{
		area 458 170 200 44
		bam GUIBUTNT
		text style	"button"
		text lua "t(Popup4Button.rightText)"
		action 
		"
			Infinity_PopMenu()
			if (Popup4Button.rightFunc) then
				Popup4Button.rightFunc()
			end
		"
	}
	button
	{
		area 248 170 200 44
		bam GUIBUTNT
		text style	"button"
		text lua "t(Popup4Button.leftText)"
		action 
		"
			Infinity_PopMenu()
			if (Popup4Button.leftFunc) then
				Popup4Button.leftFunc()
			end
		"
	}
	button
	{
		area 38 170 200 44
		bam GUIBUTNT
		text style	"button"
		text lua "t(Popup4Button.farLeftText)"
		action 
		"
			Infinity_PopMenu()
			if (Popup4Button.farLeftFunc) then
				Popup4Button.farLeftFunc()
			end
		"
	}
}
menu
{
	name 'ITEM_IDENTIFY'
	align center center
	label
	{
		area 0 0 657 234
		mosaic GUIERR6
	}
	text 
	{
		area 29 21 580 126
		text 19394
		text style "label"
		align center center
	}
	button
	{
		area 440 170 200 44
		bam GUIBUTNT
		text style "button"
		text "SPELL_BUTTON"
		
		clickable lua "Infinity_GetSpellIdentifyEnabled(characters[id].equipment[selectedSlot].id)"
		action 
		"
			Infinity_OnSpellIdentify(characters[id].equipment[selectedSlot].id); 
			Infinity_PopMenu()
			itemDesc.item = characters[id].equipment[selectedSlot].item --update itemDesc item
		"
	}
	button
	{
		area 228 170 200 44
		bam GUIBUTNT
		text style "button"
		text "CANCEL_BUTTON"
		action
		"
			Infinity_PopMenu()
		"
	}
	button
	{
		area 18 170 200 44
		bam GUIBUTNT
		text style "button"
		text "SCROLL_BUTTON"
		
		clickable lua "Infinity_GetScrollIdentifyEnabled(characters[id].equipment[selectedSlot].id)"
		action 
		"
			Infinity_OnScrollIdentify(characters[id].equipment[selectedSlot].id)
			Infinity_PopMenu()
			itemDesc.item = characters[id].equipment[selectedSlot].item --update itemDesc item
		"
	}
	
	
}
`
function showItemDescriptionInventory(slotName)
	if(characters[id].equipment[slotName].empty ~= 0) then
		return
	end
	
	selectedSlot = slotName
	
	Infinity_CheckItemIdentify(characters[id].equipment[slotName].id)
	showItemDescription(characters[id].equipment[slotName].item, 0)
end

itemDesc = {}
function showItemDescription(item, mode)
	itemDesc.item = item
	itemDesc.mode = mode
	Infinity_PushMenu('ITEM_DESCRIPTION',0,0)
end

function itemDescLeftButtonEnabled()
	if(itemDesc.mode == 0) then
		return GetAbilityIdentifyString() ~= ""
	else
		return itemDesc.item.isBag
	end
	return 0
end
function itemDescLeftButtonText()
	if(itemDesc.mode == 0) then
		return GetAbilityIdentifyString()
	else
		return t('OPEN_CONTAINER_BUTTON')
	end
	return ""
end
function itemDescLeftButtonAction()
	if(itemDesc.mode == 0) then
		if(characters[id].equipment[selectedSlot].item.identified == 0) then
			Infinity_PushMenu('ITEM_IDENTIFY',0,0)
		else
			Infinity_PushMenu('ITEM_ABILITIES',0,0)
		end
	else 
		storeScreen:OpenBag(itemDesc.item.res)
		Infinity_PopMenu()
	end
end

function itemDescRightButtonEnabled()
	if(itemDesc.mode == 0) then
		return characters[id].equipment[selectedSlot].useMode ~= -1
	else
		return 0
	end
end
function itemDescRightButtonText()
	return Infinity_GetUseButtonText(characters[id].equipment[selectedSlot].id, characters[id].equipment[selectedSlot].useMode)
end
function itemDescRightButtonAction()
	Infinity_PopMenu()
	Infinity_OnUseButtonClick(characters[id].equipment[selectedSlot].id, characters[id].equipment[selectedSlot].useMode)
end
`
menu
{
	name 'ITEM_DESCRIPTION'
	align center center
	modal
	label
	{
		area 0 0 1364 756
		mosaic GUIINVHI
	}
	label
	{
		area 335 31 700 44
		text "ITEM_TITLE"
		text style title
	}
	label
	{
		area 344 89 52 52
		icon lua "itemDesc.item.icon"
	}
	label
	{
		area 531 82 359 84
		text lua "itemDesc.item.name"
		text align center center
		text style "label"
	}
	label
	{
		area 152 206 280 46
		text lua "itemDesc.item.name"
		text style "normal_parchment"
		text align center top
	}
	text
	{
		area 448 206 759 454
		text lua "itemDesc.item.description"
		scrollbar 'GUISCRP'
		text style "normal_parchment"
	}
	label
	{
		area 152 276 280 348
		bam lua "itemDesc.item.descPicture"
		sequence 0
		frame 0
		align center center
	}
	button
	{
		bam			GUIBUTMT
		sequence	6
		area		331 679 230 44
		enabled "itemDescLeftButtonEnabled()"
		text lua "itemDescLeftButtonText()"
		text style "button"
		action
		"
			itemDescLeftButtonAction()
		"
	}
	button
	{
		bam			GUIBUTMT
		sequence	6
		area		580 679 230 44
		text  "DONE_BUTTON"
		text style "button"
		action
		"
			Infinity_PopMenu( );
		"
	}
	button
	{
		bam			GUIBUTMT
		sequence	6
		area		805 679 230 44
		enabled "itemDescRightButtonEnabled()"
		text lua "itemDescRightButtonText()"
		text style "button"
		action
		"
			itemDescRightButtonAction()
		"
	}
}
`
function highlightSidebarButton(engine)
	return (engine == e:GetActiveEngine())
end
sidebarVisible =
{
	LEFT = 1,
	RIGHT = 1
}
function toggleSidebar(side)
	local show = side .. "_SIDEBAR"
	local hide = show .. "_HIDDEN"
	if(sidebarVisible[side] == 1) then
		local temp = show
		show = hide
		hide = temp
		sidebarVisible[side] = 0
	else
		sidebarVisible[side] = 1
	end
	Infinity_PushMenu(show)
	Infinity_PopMenu(hide)
end

function rggbuttHighlight1()	if rgHighlightLog == 1 then return 1 else return 0 end
end
function rggbuttHighlight2()	if rgHighlightMap == 1 then return 1 else return 0 end
end
function rggbuttHighlight3()	if rgHighlightJou == 1 then return 1 else return 0 end
end
function rggbuttHighlight4()	if rgHighlightInv == 1 then return 1 else return 0 end
end
function rggbuttHighlight5()	if rgHighlightRec == 1 then return 1 else return 0 end
end
function rggbuttHighlight6()	if rgHighlightMag == 1 then return 1 else return 0 end
end
function rggbuttHighlight7()	if rgHighlightPri == 1 then return 1 else return 0 end
end
function rggbuttHighlight8()	if rgHighlightSav == 1 then return 1 else return 0 end
end
function rggbuttHighlight9()	if rgHighlightQLo == 1 then return 1 else return 0 end
end
function rggbuttHighlight10()	if rgHighlightRes == 1 then return 1 else return 0 end
end
function rggbuttHighlight11()	if rgHighlightRev == 1 then return 1 else return 0 end
end
function rggbuttHighlight12()	if rgHighlightSAI == 1 then return 1 else return 0 end
end
function rggbuttHighlight13()	if rgHighlightSel == 1 then return 1 else return 0 end
end
function rggbuttHighlight14()	if rgHighlightMul == 1 then return 1 else return 0 end
end
sidebarForceTooltips = 0
`
menu
{
	name 'LEFT_SIDEBAR'
	align left top
	ignoreEsc
	onOpen 
	"
		if(sidebarVisible.LEFT == 1) then
			Infinity_PushMenu('LEFT_SIDEBAR_BOTTOM')
		else
			Infinity_PopMenu('LEFT_SIDEBAR')
			Infinity_PushMenu('LEFT_SIDEBAR_HIDDEN')
		end
		if(showJournal == 1) then
			Infinity_PushMenu('JOURNAL')
		end
		sidebarForceTooltips = 0
	"
	onClose 
	"
		Infinity_PopMenu('LEFT_SIDEBAR_BOTTOM')
		Infinity_PopMenu('JOURNAL')
	"
	label
	{
		area 0 0 0 0
	}
}
menu
{
	name 'LEFT_SIDEBAR_BOTTOM'
	align left bottom
--	offset 0 -22
	--combined height of these buttons makes a menu with height = 231, menu is placed into lower left. y pos is offset from top of this menu.
	ignoreEsc
	
	label
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small"
		area 0 0 119 116
		mosaic RGGAM01
	}
	label
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small"
		area 0 63 400 53
		mosaic RGGAM02
	}
	label
	{
		enabled "JournalSize ~= UIStrings.UI_Large"
		area 0 0 119 116
		mosaic RGGAM01
	}
	label
	{
		enabled "JournalSize ~= UIStrings.UI_Large"
		area 0 63 400 53
		mosaic RGGAM02
	}
	button
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		area 69 68 48 47
		bam RGGBUT
		sequence 0
		frame lua "rggbuttHighlight2()"
		tooltip lua "getTooltipWithHotkey(4,15418)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(mapScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(1)
		"
		actionhold
		"
			worldMapScreen:StartWorldMap(0)
			e:SelectEngine(worldMapScreen)
		"
		actionEnter
		"
			rgHighlightMap = 1
		"
		actionExit
		"
			rgHighlightMap = 0
		"
	}
	button
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		area 119 69 48 47
		bam RGGBUT
		sequence 2
		frame lua "rggbuttHighlight3()"
		tooltip lua "getTooltipWithHotkey(3,16308)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "showJournal == 1"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(0)
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
		"
		actionEnter
		"
			rgHighlightJou = 1
		"
		actionExit
		"
			rgHighlightJou = 0
		"
	}
	button
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		area 169 68 48 47
		bam RGGBUT
		sequence 1
		frame lua "rggbuttHighlight4()"
		tooltip lua "getTooltipWithHotkey(0,16307)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(inventoryScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(3)
		"
		actionEnter
		"
			rgHighlightInv = 1
		"
		actionExit
		"
			rgHighlightInv = 0
		"
	}
	button
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		area 216 69 48 47
		bam RGGBUT
		sequence 3
		frame lua "rggbuttHighlight5()"
		tooltip lua "getTooltipWithHotkey(1,16306)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(characterScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(4)
		"
		actionEnter
		"
			rgHighlightRec = 1
		"
		actionExit
		"
			rgHighlightRec = 0
		"
	}
	button
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		area 261 69 48 47
		bam RGGBUT
		sequence 4
		frame lua "rggbuttHighlight6()"
		tooltip lua "getTooltipWithHotkey(5,16309)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(mageScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(5)
		"
		actionEnter
		"
			rgHighlightMag = 1
		"
		actionExit
		"
			rgHighlightMag = 0
		"
	}
	button
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		area 309 69 48 47
		bam RGGBUT
		sequence 5
		frame lua "rggbuttHighlight7()"
		tooltip lua "getTooltipWithHotkey(6,14930)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(priestScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(6)
		"
		actionEnter
		"
			rgHighlightPri = 1
		"
		actionExit
		"
			rgHighlightPri = 0
		"
	}
	button
	{
		enabled "JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		area 69 68 48 47
		bam RGGBUT
		sequence 0
		frame lua "rggbuttHighlight2()"
		tooltip lua "getTooltipWithHotkey(4,15418)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(mapScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(1)
		"
		actionhold
		"
			worldMapScreen:StartWorldMap(0)
			e:SelectEngine(worldMapScreen)
		"
		actionEnter
		"
			rgHighlightMap = 1
		"
		actionExit
		"
			rgHighlightMap = 0
		"
	}
	button
	{
		enabled "JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		area 119 69 48 47
		bam RGGBUT
		sequence 2
		frame lua "rggbuttHighlight3()"
		tooltip lua "getTooltipWithHotkey(3,16308)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "showJournal == 1"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(0)
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
		"
		actionEnter
		"
			rgHighlightJou = 1
		"
		actionExit
		"
			rgHighlightJou = 0
		"
	}
	button
	{
		enabled "JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		area 169 68 48 47
		bam RGGBUT
		sequence 1
		frame lua "rggbuttHighlight4()"
		tooltip lua "getTooltipWithHotkey(0,16307)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(inventoryScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(3)
		"
		actionEnter
		"
			rgHighlightInv = 1
		"
		actionExit
		"
			rgHighlightInv = 0
		"
	}
	button
	{
		enabled "JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		area 216 69 48 47
		bam RGGBUT
		sequence 3
		frame lua "rggbuttHighlight5()"
		tooltip lua "getTooltipWithHotkey(1,16306)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(characterScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(4)
		"
		actionEnter
		"
			rgHighlightRec = 1
		"
		actionExit
		"
			rgHighlightRec = 0
		"
	}
	button
	{
		enabled "JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		area 261 69 48 47
		bam RGGBUT
		sequence 4
		frame lua "rggbuttHighlight6()"
		tooltip lua "getTooltipWithHotkey(5,16309)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(mageScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(5)
		"
		actionEnter
		"
			rgHighlightMag = 1
		"
		actionExit
		"
			rgHighlightMag = 0
		"
	}
	button
	{
		enabled "JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		area 309 69 48 47
		bam RGGBUT
		sequence 5
		frame lua "rggbuttHighlight7()"
		tooltip lua "getTooltipWithHotkey(6,14930)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(priestScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(6)
		"
		actionEnter
		"
			rgHighlightPri = 1
		"
		actionExit
		"
			rgHighlightPri = 0
		"
	}
	
	
	--begin clock
	label
	{
		enabled "showJournal ~= 1"
		area 0 48 64 68
		bam "CGEAR"
		frame lua "timer:GetCurrentTime()"
	}
	label
	{
		enabled "showJournal ~= 1"
		area 0 48 64 68
		mosaic RGCLOCK
	}
	label
	{
		area 0 48 64 68
		enabled "worldScreen == e:GetActiveEngine() and worldScreen:CheckIfPaused() and showJournal ~= 1"
		mosaic RGCLOCK1	
	}
	button
	{
		enabled "worldScreen == e:GetActiveEngine() and showJournal ~= 1"
		area 0 48 64 68
		tooltip lua "worldScreen:GetCurrentTimeString()"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			worldScreen:TogglePauseGame(true)
		"
	}
	label
	{
		enabled "JournalSize ~= UIStrings.UI_Large"
		area 0 48 64 68
		bam "CGEAR"
		frame lua "timer:GetCurrentTime()"
	}
	label
	{
		enabled "JournalSize ~= UIStrings.UI_Large"
		area 0 48 64 68
		mosaic RGCLOCK
	}
	label
	{
		area 0 48 64 68
		enabled "worldScreen == e:GetActiveEngine() and worldScreen:CheckIfPaused() and JournalSize ~= UIStrings.UI_Large"
		mosaic RGCLOCK1	
	}
	button
	{
		enabled "worldScreen == e:GetActiveEngine() and JournalSize ~= UIStrings.UI_Large"
		area 0 48 64 68
		tooltip lua "worldScreen:GetCurrentTimeString()"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			worldScreen:TogglePauseGame(true)
		"
	}
	--end clock
	label
	{
		--area is preset
		enabled "gameOptions.m_bRenderFrameTimes"
		frameTimes
	}
	button
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and worldScreen ~= e:GetActiveEngine()" 
		area 0 51 58 59
		bam RGGLOGO
		sequence 0
		frame lua "rggbuttHighlight1()"
		tooltip lua "getTooltipWithHotkey(2,16313)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(0)
		"
		actionEnter
		"
			rgHighlightLog = 1
		"
		actionExit
		"
			rgHighlightLog = 0
		"
	}
	button
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_SOD and worldScreen ~= e:GetActiveEngine()" 
		area 1 52 58 59
		bam RGGLOGO
		sequence 1
		frame lua "rggbuttHighlight1()"
		tooltip lua "getTooltipWithHotkey(2,16313)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(0)
		"
		actionEnter
		"
			rgHighlightLog = 1
		"
		actionExit
		"
			rgHighlightLog = 0
		"
	}
	button
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BP and worldScreen ~= e:GetActiveEngine()" 
		area 1 51 58 59
		bam RGGLOGO
		sequence 2
		frame lua "rggbuttHighlight1()"
		tooltip lua "getTooltipWithHotkey(2,16313)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(0)
		"
		actionEnter
		"
			rgHighlightLog = 1
		"
		actionExit
		"
			rgHighlightLog = 0
		"
	}
	button
	{
		enabled "e:IsMultiplayer() and sidebarsGreyed ~= 1"
		area 16 1 48 50
		bam RGGBUT
		sequence 12
		frame lua "rggbuttHighlight14()"
		tooltip lua "getTooltipWithHotkey(8,16312)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(multiplayerScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(8)
		"
		actionEnter
		"
			rgHighlightMul = 1
		"
		actionExit
		"
			rgHighlightMul = 0
		"
	}

	button
	{
		area 0 10 21 52
		bam RGGHID
		action
		"
			toggleSidebar('LEFT')
		"
	}
	
}
menu
{
	name 'LEFT_SIDEBAR_HIDDEN'
	align left bottom
	ignoreEsc
	button
	{
		area 0 10 21 106
		bam RGGHID
		action
		"
			toggleSidebar('LEFT')
		"
	}
}
`
	mouseOverPortrait = -1
	draggedPortrait = nil
	function swapPortraits(dest)
		worldScreen:SwapPortraits(dest,draggedPortrait)
		draggedPortrait = nil
	end
	
	function getPartyAITooltip()
		if aiButtonToggle == 1 then
			return Infinity_FetchString(15918)
		else
			return Infinity_FetchString(15917)
		end
	end
	
	function hidePortraits()
		--if LargePortraits == 1 then
			if Infinity_GetNumCharacters() == 1 and LargePortraits == 1 then
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 2 and LargePortraits == 1 then
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 3 and LargePortraits == 1 then
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 4 and LargePortraits == 1 then
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 5 and LargePortraits == 1 then
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 6 and LargePortraits == 1 then
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 86, 131)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 82, 123)
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			end
		--else
			if Infinity_GetNumCharacters() == 1 and LargePortraits == 0 then
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 2 and LargePortraits == 0 then
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 3 and LargePortraits == 0 then
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 4 and LargePortraits == 0 then
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 5 and LargePortraits == 0 then
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			elseif Infinity_GetNumCharacters() == 6 and LargePortraits == 0 then
			Infinity_SetArea('portrait1ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait1ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait2ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait2ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait3ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait3ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait4ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait4ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait5ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait5ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait6ShadowSmall', nil, nil, 68, 99)
			Infinity_SetArea('portrait6ButtonSmall', nil, nil, 64, 91)
			Infinity_SetArea('portrait1ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait1ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait2ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait3ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait4ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait5ButtonBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ShadowBig', nil, nil, 0, 0)
			Infinity_SetArea('portrait6ButtonBig', nil, nil, 0, 0)
			end
		--end
	end
`
menu
{
	name 'RIGHT_SIDEBAR'
	align right top
	ignoreEsc
	onOpen 
	"
		if(sidebarVisible.RIGHT == 1) then
			Infinity_PushMenu('RIGHT_SIDEBAR_BOTTOM')
		else
			Infinity_PopMenu('RIGHT_SIDEBAR')
			Infinity_PushMenu('RIGHT_SIDEBAR_HIDDEN')
		end
		if(worldScreen == e:GetActiveEngine() and game:GetPartyAI()) then aiButtonToggle = 1 end
		if(worldScreen == e:GetActiveEngine()) then Infinity_PushMenu('WORLD_LEVEL_UP_BUTTONS') end
		if QuicklootStartPref == UIStrings.UI_Visible and groundItemsButtonToggle == 1 then
			worldScreen:StartGroundItems()
			groundItemsButtonToggle = 1
		elseif QuicklootStartPref == UIStrings.UI_Visible and groundItemsButtonToggle == 0 then
			worldScreen:StopGroundItems()
			groundItemsButtonToggle = 0
		elseif QuicklootStartPref == UIStrings.UI_Hidden and groundItemsButtonToggle == 1 then
			worldScreen:StartGroundItems()
			groundItemsButtonToggle = 1
		elseif QuicklootStartPref == UIStrings.UI_Hidden and groundItemsButtonToggle == 0 then
			worldScreen:StopGroundItems()
			groundItemsButtonToggle = 0
		end
	"
	onClose
	"
		Infinity_PopMenu('RIGHT_SIDEBAR_BOTTOM')
		Infinity_PopMenu('WORLD_LEVEL_UP_BUTTONS')
	"
	button
	{
		area 7 0 88 1
		text lua "hidePortraits()"
	}
	
	
	
	label
	{
		name "portrait1ShadowSmall"
		enabled "Infinity_GetNumCharacters() > 0 and rgEscPortrait ~= 1 and LargePortraits == 0"
		area 22 10 68 99
		mosaic RGGFRM4
	}
	button
	{
		name "portrait1ButtonSmall"
		area 24 14 64 91
		portrait 0
		bam RGGFRM3
		enabled "Infinity_GetNumCharacters() > 0 and rgEscPortrait ~= 1 and LargePortraits == 0"
		glow lua "draggedPortrait and draggedPortrait ~= 0"
		action "Infinity_OnPortraitLClick(0)"
		actionAlt "Infinity_OnPortraitRClick(0)"
		actionDbl "Infinity_OnPortraitDblClick(0)"
		actiondrag "Infinity_SwapWithPortrait(0)"
		actionEnter "mouseOverPortrait = 0"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 0"
		actionSimpleDrop "swapPortraits(0)"
		tooltip lua "Infinity_GetPortraitTooltip(0)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait2ShadowSmall"
		enabled "Infinity_GetNumCharacters() > 1 and rgEscPortrait ~= 1 and LargePortraits == 0"
		area 22 108 68 99
		mosaic RGGFRM4
	}
	button
	{
		name "portrait2ButtonSmall"
		area 24 112 64 91
		portrait 1
		bam RGGFRM3
		enabled "Infinity_GetNumCharacters() > 1 and rgEscPortrait ~= 1 and LargePortraits == 0"
		glow lua "draggedPortrait and draggedPortrait ~= 1"
		action "Infinity_OnPortraitLClick(1)"
		actionAlt "Infinity_OnPortraitRClick(1)"
		actionDbl "Infinity_OnPortraitDblClick(1)"
		actiondrag "Infinity_SwapWithPortrait(1)"
		actionEnter "mouseOverPortrait = 1"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 1"
		actionSimpleDrop "swapPortraits(1)"
		tooltip lua "Infinity_GetPortraitTooltip(1)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait3ShadowSmall"
		enabled "Infinity_GetNumCharacters() > 2 and rgEscPortrait ~= 1 and LargePortraits == 0"
		area 22 206 68 99
		mosaic RGGFRM4
	}
	button
	{
		name "portrait3ButtonSmall"
		area 24 210 64 91
		portrait 2
		bam RGGFRM3
		enabled "Infinity_GetNumCharacters() > 2 and rgEscPortrait ~= 1 and LargePortraits == 0"
		glow lua "draggedPortrait and draggedPortrait ~= 2"
		action "Infinity_OnPortraitLClick(2)"
		actionAlt "Infinity_OnPortraitRClick(2)"
		actionDbl "Infinity_OnPortraitDblClick(2)"
		actiondrag "Infinity_SwapWithPortrait(2)"
		actionEnter "mouseOverPortrait = 2"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 2"
		actionSimpleDrop "swapPortraits(2)"
		tooltip lua "Infinity_GetPortraitTooltip(2)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait4ShadowSmall"
		enabled "Infinity_GetNumCharacters() > 3 and rgEscPortrait ~= 1 and LargePortraits == 0"
		area 22 304 68 99
		mosaic RGGFRM4
	}
	button
	{
		name "portrait4ButtonSmall"
		area 24 308 64 91
		portrait 3
		bam RGGFRM3
		enabled "Infinity_GetNumCharacters() > 3 and rgEscPortrait ~= 1 and LargePortraits == 0"
		glow lua "draggedPortrait and draggedPortrait ~= 3"
		action "Infinity_OnPortraitLClick(3)"
		actionAlt "Infinity_OnPortraitRClick(3)"
		actionDbl "Infinity_OnPortraitDblClick(3)"
		actiondrag "Infinity_SwapWithPortrait(3)"
		actionEnter "mouseOverPortrait = 3"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 3"
		actionSimpleDrop "swapPortraits(3)"
		tooltip lua "Infinity_GetPortraitTooltip(3)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait5ShadowSmall"
		enabled "Infinity_GetNumCharacters() > 4 and rgEscPortrait ~= 1 and LargePortraits == 0"
		area 22 402 68 99
		mosaic RGGFRM4
	}
	button
	{
		name "portrait5ButtonSmall"
		area 24 406 64 91
		portrait 4
		bam RGGFRM3
		enabled "Infinity_GetNumCharacters() > 4 and rgEscPortrait ~= 1 and LargePortraits == 0"
		glow lua "draggedPortrait and draggedPortrait ~= 4"
		action "Infinity_OnPortraitLClick(4)"
		actionAlt "Infinity_OnPortraitRClick(4)"
		actionDbl "Infinity_OnPortraitDblClick(4)"
		actiondrag "Infinity_SwapWithPortrait(4)"
		actionEnter "mouseOverPortrait = 4"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 4"
		actionSimpleDrop "swapPortraits(4)"
		tooltip lua "Infinity_GetPortraitTooltip(4)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait6ShadowSmall"
		enabled "Infinity_GetNumCharacters() > 5 and rgEscPortrait ~= 1 and LargePortraits == 0"
		area 22 500 68 99
		mosaic RGGFRM4
	}
	button
	{
		name "portrait6ButtonSmall"
		area 24 504 64 91
		portrait 5
		bam RGGFRM3
		enabled "Infinity_GetNumCharacters() > 5 and rgEscPortrait ~= 1 and LargePortraits == 0"
		glow lua "draggedPortrait and draggedPortrait ~= 5"
		action "Infinity_OnPortraitLClick(5)"
		actionAlt "Infinity_OnPortraitRClick(5)"
		actionDbl "Infinity_OnPortraitDblClick(5)"
		actiondrag "Infinity_SwapWithPortrait(5)"
		actionEnter "mouseOverPortrait = 5"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 5"
		actionSimpleDrop "swapPortraits(5)"
		tooltip lua "Infinity_GetPortraitTooltip(5)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	
	
	label
	{
		name "portrait1ShadowBig"
		enabled "Infinity_GetNumCharacters() > 0 and rgEscPortrait ~= 1 and LargePortraits == 1"
		area 2 10 0 0
		mosaic RGGFRM6
	}
	button
	{
		name "portrait1ButtonBig"
		area 4 14 0 0
		portrait 0
		bam RGGFRM5
		enabled "Infinity_GetNumCharacters() > 0 and rgEscPortrait ~= 1 and LargePortraits == 1"
		glow lua "draggedPortrait and draggedPortrait ~= 0"
		action "Infinity_OnPortraitLClick(0)"
		actionAlt "Infinity_OnPortraitRClick(0)"
		actionDbl "Infinity_OnPortraitDblClick(0)"
		actiondrag "Infinity_SwapWithPortrait(0)"
		actionEnter "mouseOverPortrait = 0"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 0"
		actionSimpleDrop "swapPortraits(0)"
		tooltip lua "Infinity_GetPortraitTooltip(0)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait2ShadowBig"
		enabled "Infinity_GetNumCharacters() > 1 and rgEscPortrait ~= 1 and LargePortraits == 1"
		area 2 140 0 0
		mosaic RGGFRM6
	}
	button
	{
		name "portrait2ButtonBig"
		area 4 144 0 0
		portrait 1
		bam RGGFRM5
		enabled "Infinity_GetNumCharacters() > 1 and rgEscPortrait ~= 1 and LargePortraits == 1"
		glow lua "draggedPortrait and draggedPortrait ~= 1"
		action "Infinity_OnPortraitLClick(1)"
		actionAlt "Infinity_OnPortraitRClick(1)"
		actionDbl "Infinity_OnPortraitDblClick(1)"
		actiondrag "Infinity_SwapWithPortrait(1)"
		actionEnter "mouseOverPortrait = 1"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 1"
		actionSimpleDrop "swapPortraits(1)"
		tooltip lua "Infinity_GetPortraitTooltip(1)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait3ShadowBig"
		enabled "Infinity_GetNumCharacters() > 2 and rgEscPortrait ~= 1 and LargePortraits == 1"
		area 2 270 0 0
		mosaic RGGFRM6
	}
	button
	{
		name "portrait3ButtonBig"
		area 4 274 0 0
		portrait 2
		bam RGGFRM5
		enabled "Infinity_GetNumCharacters() > 2 and rgEscPortrait ~= 1 and LargePortraits == 1"
		glow lua "draggedPortrait and draggedPortrait ~= 2"
		action "Infinity_OnPortraitLClick(2)"
		actionAlt "Infinity_OnPortraitRClick(2)"
		actionDbl "Infinity_OnPortraitDblClick(2)"
		actiondrag "Infinity_SwapWithPortrait(2)"
		actionEnter "mouseOverPortrait = 2"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 2"
		actionSimpleDrop "swapPortraits(2)"
		tooltip lua "Infinity_GetPortraitTooltip(2)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait4ShadowBig"
		enabled "Infinity_GetNumCharacters() > 3 and rgEscPortrait ~= 1 and LargePortraits == 1"
		area 2 400 0 0
		mosaic RGGFRM6
	}
	button
	{
		name "portrait4ButtonBig"
		area 4 404 0 0
		portrait 3
		bam RGGFRM5
		enabled "Infinity_GetNumCharacters() > 3 and rgEscPortrait ~= 1 and LargePortraits == 1"
		glow lua "draggedPortrait and draggedPortrait ~= 3"
		action "Infinity_OnPortraitLClick(3)"
		actionAlt "Infinity_OnPortraitRClick(3)"
		actionDbl "Infinity_OnPortraitDblClick(3)"
		actiondrag "Infinity_SwapWithPortrait(3)"
		actionEnter "mouseOverPortrait = 3"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 3"
		actionSimpleDrop "swapPortraits(3)"
		tooltip lua "Infinity_GetPortraitTooltip(3)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait5ShadowBig"
		enabled "Infinity_GetNumCharacters() > 4 and rgEscPortrait ~= 1 and LargePortraits == 1"
		area 2 530 0 0
		mosaic RGGFRM6
	}
	button
	{
		name "portrait5ButtonBig"
		area 4 534 0 0
		portrait 4
		bam RGGFRM5
		enabled "Infinity_GetNumCharacters() > 4 and rgEscPortrait ~= 1 and LargePortraits == 1"
		glow lua "draggedPortrait and draggedPortrait ~= 4"
		action "Infinity_OnPortraitLClick(4)"
		actionAlt "Infinity_OnPortraitRClick(4)"
		actionDbl "Infinity_OnPortraitDblClick(4)"
		actiondrag "Infinity_SwapWithPortrait(4)"
		actionEnter "mouseOverPortrait = 4"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 4"
		actionSimpleDrop "swapPortraits(4)"
		tooltip lua "Infinity_GetPortraitTooltip(4)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	label
	{
		name "portrait6ShadowBig"
		enabled "Infinity_GetNumCharacters() > 5 and rgEscPortrait ~= 1 and LargePortraits == 1"
		area 2 660 0 0
		mosaic RGGFRM6
	}
	button
	{
		name "portrait6ButtonBig"
		area 4 664 0 0
		portrait 5
		bam RGGFRM5
		enabled "Infinity_GetNumCharacters() > 5 and rgEscPortrait ~= 1 and LargePortraits == 1"
		glow lua "draggedPortrait and draggedPortrait ~= 5"
		action "Infinity_OnPortraitLClick(5)"
		actionAlt "Infinity_OnPortraitRClick(5)"
		actionDbl "Infinity_OnPortraitDblClick(5)"
		actiondrag "Infinity_SwapWithPortrait(5)"
		actionEnter "mouseOverPortrait = 5"
		actionExit "mouseOverPortrait = -1"
		actionSimpleDrag "draggedPortrait = 5"
		actionSimpleDrop "swapPortraits(5)"
		tooltip lua "Infinity_GetPortraitTooltip(5)"
		clickable lua "sidebarsGreyed ~= 1"
	}
}
menu
{
	name 'RIGHT_SIDEBAR_BOTTOM'
	align right bottom
	ignoreEsc
	--Buttons form a menu aligned bottom right, with height = 197, y is offset from top of that menu.
--	button
--	{
--		area 3 0 74 50
--		enabled "e:IsTouchUI() and worldScreen == e:GetActiveEngine() and showJournal ~= 1"
--		toggle selectionButtonToggle
--		bam GUILS10
--		sequence 14
--		clickable lua "sidebarsGreyed ~= 1"
--		action
--		"
--			worldScreen:OnSelectionButtonClick()
--		"
--	}
	
	label
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small"
		area 281 0 119 116
		mosaic RGGAM11
	}
	label
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small"
		area 0 63 400 53
		mosaic RGGAM12
	}
	label
	{
		enabled "JournalSize ~= UIStrings.UI_Large"
		area 281 0 119 116
		mosaic RGGAM11
	}
	label
	{
		enabled "JournalSize ~= UIStrings.UI_Large"
		area 0 63 400 53
		mosaic RGGAM12
	}
	button
	{
		enabled "PermThief == 1"
		area 346 15 33 33
		bam RGGTHIEF
		action "Infinity_PressKeyboardButton('f')"
	}
	button
	{
		area 40 69 48 47
		enabled "worldScreen ~= e:GetActiveEngine() and showJournal ~= 1 and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 17
	}
	button
	{
		area 40 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 10
		frame lua "rggbuttHighlight8()"
		tooltip lua "getTooltipWithHotkey(15,74261)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			worldScreen:OnQuickSaveButtonClick()
		"
		actionEnter
		"
			rgHighlightSav = 1
		"
		actionExit
		"
			rgHighlightSav = 0
		"
	}
	button
	{
		area 40 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 10
		frame lua "rggbuttHighlight8()"
		tooltip lua "getTooltipWithHotkey(15,74261)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			worldScreen:OnQuickSaveButtonClick()
		"
		actionEnter
		"
			rgHighlightSav = 1
		"
		actionExit
		"
			rgHighlightSav = 0
		"
	}
	button
	{
		area 86 69 48 47
		enabled "worldScreen ~= e:GetActiveEngine() and showJournal ~= 1 and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 15
	}
	button
	{
		area 86 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 8
		frame lua "rggbuttHighlight9()"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		area 86 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 8
		frame lua "rggbuttHighlight9()"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		area 86 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 8
		tooltip lua "Infinity_FetchString(99897)"
		toggle groundItemsButtonToggle
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			if(groundItemsButtonToggle == 0) then
				worldScreen:StopGroundItems()
				
			else
				worldScreen:StartGroundItems()
			end
		"
		actionEnter
		"
			rgHighlightQLo = 1
		"
		actionExit
		"
			rgHighlightQLo = 0
		"
	}
	button
	{
		area 86 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 8
		tooltip lua "Infinity_FetchString(99897)"
		toggle groundItemsButtonToggle
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			if(groundItemsButtonToggle == 0) then
				worldScreen:StopGroundItems()
				
			else
				worldScreen:StartGroundItems()
			end
		"
		actionEnter
		"
			rgHighlightQLo = 1
		"
		actionExit
		"
			rgHighlightQLo = 0
		"
	}
--	button
--	{
--		area 3 56 73 55
--		enabled "worldScreen == e:GetActiveEngine()"
--		bam GUILS10
--		sequence 16
--		tooltip lua "getTooltipWithHotkey(16,31827)"
--		tooltip force lua "sidebarForceTooltips == 1"
--		tooltip force top
--		clickable lua "sidebarsGreyed ~= 1"
--		toggle sidebarForceTooltips
--	}
	button
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		area 134 69 48 47
		bam RGGBUT
		sequence 7
		frame lua "rggbuttHighlight10()"
		tooltip lua "getTooltipWithHotkey(9,11942)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnRestButtonClick()
		"
		actionEnter
		"
			rgHighlightRes = 1
		"
		actionExit
		"
			rgHighlightRes = 0
		"
	}
	button
	{
		enabled "JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		area 134 69 48 47
		bam RGGBUT
		sequence 7
		frame lua "rggbuttHighlight10()"
		tooltip lua "getTooltipWithHotkey(9,11942)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnRestButtonClick()
		"
		actionEnter
		"
			rgHighlightRes = 1
		"
		actionExit
		"
			rgHighlightRes = 0
		"
	}
	button
	{
		area 185 69 48 47
		enabled "worldScreen ~= e:GetActiveEngine() and showJournal ~= 1 and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 14
	}
	button
	{
		area 185 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 6
		frame lua "rggbuttHighlight11()"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		area 185 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 6
		frame lua "rggbuttHighlight11()"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		area 185 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		toggle highlightButtonToggle
		tooltip lua "Infinity_FetchString(103144)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			worldScreen:SetHighlightEnabled(highlightButtonToggle == 1)
		"
		actionhold
		"
		if Infinity_GetINIValue('Game Options','CheatMode',1) == 1 then
			C:ExploreArea()
		end
		"
		actionEnter
		"
			rgHighlightRev = 1
		"
		actionExit
		"
			rgHighlightRev = 0
		"
	}
	button
	{
		area 185 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		toggle highlightButtonToggle
		tooltip lua "Infinity_FetchString(103144)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			worldScreen:SetHighlightEnabled(highlightButtonToggle == 1)
		"
		actionhold
		"
		if Infinity_GetINIValue('Game Options','CheatMode',1) == 1 then
			C:ExploreArea()
		end
		"
		actionEnter
		"
			rgHighlightRev = 1
		"
		actionExit
		"
			rgHighlightRev = 0
		"
	}
	button
	{
		area 233 69 48 47
		enabled "worldScreen ~= e:GetActiveEngine() and showJournal ~= 1 and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 16
	}
	button
	{
		area 233 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 9
		frame lua "rggbuttHighlight12()"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		area 233 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 9
		frame lua "rggbuttHighlight12()"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		area 233 69 48 47
		enabled "worldScreen == e:GetActiveEngine() and showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 9
		tooltip lua "getPartyAITooltip()"
		toggle aiButtonToggle
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			game:ToggleAI()
		"
		actionEnter
		"
			rgHighlightSAI = 1
		"
		actionExit
		"
			rgHighlightSAI = 0
		"
	}
	button
	{
		area 233 68 48 47
		enabled "worldScreen == e:GetActiveEngine() and JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 9
		tooltip lua "getPartyAITooltip()"
		toggle aiButtonToggle
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			game:ToggleAI()
		"
		actionEnter
		"
			rgHighlightSAI = 1
		"
		actionExit
		"
			rgHighlightSAI = 0
		"
	}
	button
	{
		area 278 68 48 47
		enabled "worldScreen ~= e:GetActiveEngine() and showJournal ~= 1 and sidebarsGreyed ~= 1"
		bam RGGBUT
		sequence 18
	}
	button
	{
		area 278 68 48 48
		enabled "worldScreen == e:GetActiveEngine() and showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small and sidebarsGreyed ~= 1"
		tooltip lua "Infinity_FetchString(10485)"
		bam RGGBUT
		sequence 11
		frame lua "rggbuttHighlight13()"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			game:SelectAll()
		"
		actionDbl
		"
			game:CenterOnGroupLeader()
		"
		actionEnter
		"
			rgHighlightSel = 1
		"
		actionExit
		"
			rgHighlightSel = 0
		"
	}
	button
	{
		area 278 68 48 48
		enabled "worldScreen == e:GetActiveEngine() and JournalSize ~= UIStrings.UI_Large and sidebarsGreyed ~= 1"
		tooltip lua "Infinity_FetchString(10485)"
		bam RGGBUT
		sequence 11
		frame lua "rggbuttHighlight13()"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			game:SelectAll()
		"
		actionDbl
		"
			game:CenterOnGroupLeader()
		"
		actionEnter
		"
			rgHighlightSel = 1
		"
		actionExit
		"
			rgHighlightSel = 0
		"
	}
	button
	{
		enabled "showJournal ~= 1 and JournalSize ~= UIStrings.UI_Small"
		area 347 61 49 43
		bam RGGOPT
		tooltip lua "getTooltipWithHotkey(7,16311)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(optionsScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(7)
		"
	}
	button
	{
		enabled "JournalSize ~= UIStrings.UI_Large"
		area 347 61 49 43
		bam RGGOPT
		tooltip lua "getTooltipWithHotkey(7,16311)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(optionsScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(7)
		"
	}
	button
	{
		area 379 10 21 52
		bam RGGHID
		sequence 1
		action
		"
			toggleSidebar('RIGHT')
		"
	}
}
menu
{
	name 'RIGHT_SIDEBAR_HIDDEN'
	align right bottom
	ignoreEsc
	button
	{
		area 21 10 21 106
		bam RGGHID
		sequence 1
		action
		"
			toggleSidebar('RIGHT')
		"
	}
}
`
	TEXT_inventoryError = ""

function resetStatsDisplay()
	tempStats = {}
end
function getTempDamage()
	local str = ""
	local dmgMinTemp = getTempStat(characters[id].damage.min,'dmgMin',1)
	local dmgMaxTemp = getTempStat(characters[id].damage.max,'dmgMax',1)
	if(dmgMinTemp == "-" and dmgMaxTemp == "-") then
		return "-"
	end
	if(dmgMinTemp == "-") then
		str = characters[id].damage.min
	else
		str = dmgMinTemp
	end
	str = str .. " - "
	if(dmgMaxTemp == "-") then
		str = str .. characters[id].damage.max
	else
		str = str .. dmgMaxTemp
	end

	return str
end
function getStat(old, newName, coeff)
	return old
end
function getTempStat(old, newName, coeff)
	if(tempStats[id] == nil) then
		return "-"
	end
	local new = tempStats[id][newName]
	local score = coeff * (new - old)
	if(score == 0) then
		return "-"
	end
	if(score < 0) then
		return "^R" .. new .. "^-"
	end
	if(score > 0) then
		return "^G" .. new .. "^-"
	end
end
function getStatsTitle()
	if(tempStats[id] ~= nil) then
		return tempStats[id].tempItem
	else
		return ""
	end
end
function slotDoubleClick(slotName, force)
	local slot = characters[id].equipment[slotName]
	
	if(string.sub(slotName,1,6) == "ground" and force == nil) then
		--this hack is needed because the unlike other slots, ground item add/remove is a message (doesnt get executed immediately)
		--since the double click removes the item before re-adding it, we need to wait for that re-add to complete before continuing.
		doubleClickEventScheduled = slotName
		return
	end
	
	if(slot ~= nil) then
		if(slot.item.isBag ~= 0) then
			Infinity_OpenInventoryContainer(slot.item.res)
		else
			showItemAmountRequester(slotName)
		end
	end
end
function checkDoubleClickScheduled(slotName)
	if(doubleClickEventScheduled == slotName) then
		slotDoubleClick(doubleClickEventScheduled, true)
		doubleClickEventScheduled = nil
	end
end
function getTempHP()
	local maxHP = getTempStat(characters[id].HP.max,'maxHP',1)
	local currentHP = getTempStat(characters[id].HP.current, 'currentHP',1)
	if(maxHP == "-" and currentHP == "-") then
		--nothing changed.
		return "-"
	end
	if(maxHP == "-") then
		--only current HP changed.
		maxHP = characters[id].HP.max
	end
	if(currentHP == "-") then
		--only max HP changed.
		currentHP = characters[id].HP.current
	end

	return currentHP .. '/' .. maxHP
end
function shouldGreyOutInventory()
	return characters[id].HP.current <= 0 or inventoryScreen:IsSpriteOrderable() == false
end
function shouldGreyOutInventory1()
	return characters[id].HP.current > 0 and inventoryScreen:IsSpriteOrderable() == false
end
function getInventoryTHAC0()
	local str = characters[id].THAC0.current
	if(characters[id].THAC0.offhand) then
		str = str .. "\n" .. characters[id].THAC0.offhand
	end
	return str
end
function getInventoryDamage()
	local str = characters[id].damage.min .. ' - ' .. characters[id].damage.max
	if(characters[id].damage.minOffhand and characters[id].damage.maxOffhand) then
		str = str .. "\n" .. characters[id].damage.minOffhand .. ' - ' .. characters[id].damage.maxOffhand 
	end
	return str
end
function getInventoryDamageDetails()
	if characters[id].damage.detailsOffhand == nil or characters[id].damage.detailsOffhand == "" then
		return characters[id].damage.details
	else
		return characters[id].damage.details.."\n\n"..characters[id].damage.detailsOffhand
	end
end
function getInventoryTHAC0Details()
	if characters[id].THAC0.detailsOffhand == nil or characters[id].THAC0.detailsOffhand == "" then
		return characters[id].THAC0.details
	else
		return characters[id].THAC0.details.."\n\n"..characters[id].THAC0.detailsOffhand
	end
end


local function patchObject(object, keys, wrapper)
	local store = {}

	for _, key in pairs(keys) do
		local value = object[key]
		store[key] = value
		object[key] = wrapper(value)
	end

	return store
end

Inventory = {
	invalidSlot = { valid = 0 }
}


function Inventory:create()
	local self = setmetatable({}, { __index = self })

	self.name_to_idx = {}
	self.idx_to_id = {}
	self.count = Infinity_GetNumCharacters()
	local selected = Infinity_GetSelectedCharacterName()

	for i = 1, self.count do
		Infinity_SetArea('slotsArea' .. i, nil, nil, 392, 98)
		Infinity_OnPortraitLClick(i - 1)
		Infinity_UpdateLuaStats()
		local char = characters[id]
		self.name_to_idx[char.name] = i
		self.idx_to_id[i] = id
	end

	for i = self.count + 1, 6 do
		Infinity_SetArea('slotsArea' .. i, nil, nil, 0, 0)
	end

	-- auto updated
	-- hovered: updated on slots area hover
	-- selected: gets updated on every frame
	-- this will set these variables to the synced state
	self:onSlotsAreaEnter(self.name_to_idx[selected])

	-- Inject updateSlotsHighlight to the functions listed below.
	-- It's needed to update slots' highlighting on item drag start/stop.
	local names = {
		'Infinity_SwapSlot',
		'Infinity_SwapWithPortrait',
		'Infinity_SwapWithAppearance'
	}

	local function wrapper(f)
		return function(...)
			-- result = 1: item picked up, 2: put down
			local result = f(...)
			self:updateSlotsHighlight()
			return result
		end
	end

	self._patched = patchObject(_G, names, wrapper)

	return self
end

function Inventory:deinit()
	-- restore patched swap slot functions
	for key, original in pairs(self._patched) do
		_G[key] = original
	end
	self._patched = {}
end

function Inventory:slot(slot_idx, char_idx)
	if char_idx > self.count then
		return self.invalidSlot
	end

	local char = characters[self.idx_to_id[char_idx]]
	if char then
		return char.equipment['group' .. (slot_idx - 1)]
	end

	return self.invalidSlot
end

function Inventory:update()
	local selected = self.name_to_idx[Infinity_GetSelectedCharacterName()]

	if self.selected ~= selected then
		Infinity_SetArea('encumberanceButton', nil, 85 + (selected - 1) * 106, nil, nil)
		self.selected = selected

		-- we pressed a 1-6 key, we might be desynced
		if self.hovered and selected ~= self.hovered then
			Infinity_SetArea('slotsAreaCover', nil, 85 + 106 * (self.hovered - 1), 392, 98)
		else
			Infinity_SetArea('slotsAreaCover', nil, nil, 0, 0)
		end
	end

	return true
end

function Inventory:updateSlotsHighlight()
	local n = self.selected
	for i = 1, self.count do
		if i ~= n then
			self:select(i)
		end
	end
	self:select(n)
end

function Inventory:select(i)
	Infinity_PressKeyboardButton(i)
end

function Inventory:onSlotsAreaEnter(n)
	if self.hovered ~= n then
		-- we are in sync, i.e. hovered == nil or hovered == selected
		-- remove the cover
		Infinity_SetArea('slotsAreaCover', nil, nil, 0, 0)

		-- restore previously hovered area
		if self.hovered then
			Infinity_SetArea('slotsArea' .. self.hovered, nil, nil, 392, 98)
		end

		-- invalid area, we're done
		if n == nil then
			self.hovered = nil
			return
		end

		-- valid area, hide it, select hovered char
		-- NOTE: triggers actionExit for the slotsArea
		Infinity_SetArea('slotsArea' .. n, nil, nil, 0, 0)
		self.hovered = n
		self:select(n)
	end
end

`
menu
{
	name 'INVENTORY'
	align center center
	ignoreEsc
	
	onOpen 
	"
		Infinity_ActivateInventory()
		pushSidebars()
		doubleClickEventScheduled = nil
		Infinity_PopMenu('WORLD_QUICKLOOT')
		inventory = Inventory:create()
	"
	onClose 
	"
		inventory:deinit()
		inventory = nil
		Infinity_PopMenu('CHARACTER_COLOR')
		popSidebars()
	"

	-- This is needed to keep track of the selected character after pressing keys 1-6.
	-- Updates on every frame, so every ~33 ms for 30 fps.
	text { enabled "inventory:update()" }

	label
	{
		area 0 0 1364 756
		mosaic INVENTOR 
	}

	-- Since we can't use actionExit for slots areas, this is a hack to set hovered to nil.
	-- This is needed to hide the area cover, we only want it when the mouse cursor is on
	-- a slots area.
	-- As a side effect it fixes an issue with portraits.
	-- With the "portrait X" property dragged items can't move over the element,
	-- staying just outside until the mouse leaves the area.
	text {
		area 0 0 788 756
		actionEnter "inventory:onSlotsAreaEnter(nil)"
	}

	text
	{
		area		82 590 92 109
		text		""--"ARMOR_CLASS_LABEL"
		text style	"label"
		tooltip lua "characters[id].AC.details"
		text color 'D'
		text align left center
	}
	text
	{
		area		186 590 99 109
		text		""--"HIT_POINTS_LABEL"
		text style	"label"
		tooltip lua "characters[id].HP.details"
		text color 'D'
		text align left center
	}
	text
	{
		area		298 594 86 105
		text		""--"THAC0_LABEL"
		text style	"label"
		tooltip lua "characters[id].THAC0.details"
		text color 'D'
		text align left center
	}
	text
	{
		area		398 594 96 105
		text		""--"DAMAGE_LABEL"
		text style	"label"
		tooltip lua "characters[id].damage.details"
		text color 'D'
		text align left center
	} 
	
	label
	{
--		enabled		"tempStats[id] == nil"
		area		82 646 92 51
		text lua	"characters[id].AC.current"
		text style	"label"
		text color 'D'
		align center center
	}
	label
	{
--		enabled		"tempStats[id] == nil"
		area		184 646 101 51
		text lua	"characters[id].HP.current .. '/' .. characters[id].HP.max"
		text style	"label"
		text color 'D'
		align center center
	}

	label
	{
--		enabled		"tempStats[id] == nil"
		area		298 646 86 53
		text lua	"getInventoryTHAC0()"
		text style	"label"
		text color 'D'
		align center center
	}
	label
	{
--		enabled		"tempStats[id] == nil"
		area		398 646 96 53
		text lua	"getInventoryDamage()"
		text style	"label"
		text color 'D'
		align center center
	}
	label
	{
--		enabled		"tempStats[id] == nil"
		area		511 646 81 53
		text lua	"characters[id].proficiencies.numAttacks.current"
		text style	"label"
		text color 'D'
		align center center
	}
	button
	{
		area 356 214 128 160
		paperdoll 1
		actiondrag "Infinity_SwapWithAppearance()"
	}

	label
	{
		area 712 85 73 98
		enabled "inventory.count > 0"
		bam "contback"
	}
	label
	{
		area 712 191 73 98
		enabled "inventory.count > 1"
		bam "contback"
	}
	label
	{
		area 712 297 73 98
		enabled "inventory.count > 2"
		bam "contback"
	}
	label
	{
		area 712 403 73 98
		enabled "inventory.count > 3"
		bam "contback"
	}
	label
	{
		area 712 509 73 98
		enabled "inventory.count > 4"
		bam "contback"
	}
	label
	{
		area 712 615 73 98
		enabled "inventory.count > 5"
		bam "contback"
	}
	button
	{
		name "encumberanceButton"
		area 710 191 73 98
		encumbrance
	}

	label
	{
		area 108 88 240 38
		text lua "characters[id].name"
		text style "button"
	}
	label
	{
		area 214 32 936 44
		text "INVENTORY_TITLE"
		text style "title"
	}
	label
	{
		area 85 234 200 37
		text "QUICK_WEAPONS_LABEL"
		text style "label"
	}
	label
	{
		area 86 341 162 37
		text "QUICK_ITEMS_LABEL"
		text style "label"
	}
	label
	{
		area 108 132 150 35
		text "QUIVER_LABEL"
		text style "label"
	}
	label
	{
		area 1210 116 63 32
		text "GROUND_LABEL"
		text style "label"
		align center center
	}
	label
	{
		area 1210 148 63 30
		text lua "Infinity_GetCurrentGroundPage()+1 .. '/' .. Infinity_GetMaxGroundPage()+1"
		text style "label"
		align center center
	}
	label
	{
		area 82 532 80 38
		text lua "characters[id].gold"
		text style "label"
		text color '$'
	}
	label
	{
		area 348 88 266 38
		text lua "characters[id].class"
		text style "button"
	}
	text
	{
		area 186 482 400 82
		text lua "TEXT_inventoryError"
		scrollbar 'GUISCRC'
		text style normal
	}

	slot {name "slot_inv_1"		area 81 280 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.weapon0"		}
	slot {name "slot_inv_2"		area 134 280 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.weapon1"		}
	slot {name "slot_inv_3"		area 187 280 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.weapon2"		}
	slot {name "slot_inv_4"		area 240 280 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.weapon3"		}
	
	slot {name "slot_inv_5"		area 82 386 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.personal0"	}
	slot {name "slot_inv_6"		area 134 386 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.personal1"	}
	slot {name "slot_inv_7"		area 186 386 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.personal2"	}
	
	slot {name "slot_inv_11"		area 274 155 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.armor"		}
	slot {name "slot_inv_12"		area 337 134 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.gauntlets"	}
	slot {name "slot_inv_13"		area 393 134 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.helmet"		}
	slot {name "slot_inv_14"		area 449 134 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.amulet"		}
	slot {name "slot_inv_15"		area 104 175 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.quiver0"		}
	slot {name "slot_inv_16"		area 156 175 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.quiver1"		}
	slot {name "slot_inv_17"		area 208 175 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.quiver2"		}
	slot {name "slot_inv_21"		area 449 400 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.belt"		}
	slot {name "slot_inv_22"		area 274 341 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ringleft"	}
	slot {name "slot_inv_23"		area 512 340 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ringright"	}
	slot {name "slot_inv_24"		area 337 400 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.cloak"		}
	slot {name "slot_inv_25"		area 393 400 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.boots"		}
	slot {name "slot_inv_26"		area 512 282 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.shield"		}

	slot { name  "slot_inv_30"  bam "RGSTONSL"  slotinfo "inventory:slot(1, 1)"   area 789 85 49 49 }
	slot { name  "slot_inv_31"  bam "RGSTONSL"  slotinfo "inventory:slot(2, 1)"   area 789 134 49 49 }
	slot { name  "slot_inv_32"  bam "RGSTONSL"  slotinfo "inventory:slot(3, 1)"   area 838 85 49 49 }
	slot { name  "slot_inv_33"  bam "RGSTONSL"  slotinfo "inventory:slot(4, 1)"   area 838 134 49 49 }
	slot { name  "slot_inv_34"  bam "RGSTONSL"  slotinfo "inventory:slot(5, 1)"   area 887 85 49 49 }
	slot { name  "slot_inv_35"  bam "RGSTONSL"  slotinfo "inventory:slot(6, 1)"   area 887 134 49 49 }
	slot { name  "slot_inv_36"  bam "RGSTONSL"  slotinfo "inventory:slot(7, 1)"   area 936 85 49 49 }
	slot { name  "slot_inv_37"  bam "RGSTONSL"  slotinfo "inventory:slot(8, 1)"   area 936 134 49 49 }
	slot { name  "slot_inv_38"  bam "RGSTONSL"  slotinfo "inventory:slot(9, 1)"   area 985 85 49 49 }
	slot { name  "slot_inv_39"  bam "RGSTONSL"  slotinfo "inventory:slot(10, 1)"  area 985 134 49 49 }
	slot { name  "slot_inv_40"  bam "RGSTONSL"  slotinfo "inventory:slot(11, 1)"  area 1034 85 49 49 }
	slot { name  "slot_inv_41"  bam "RGSTONSL"  slotinfo "inventory:slot(12, 1)"  area 1034 134 49 49 }
	slot { name  "slot_inv_42"  bam "RGSTONSL"  slotinfo "inventory:slot(13, 1)"  area 1083 85 49 49 }
	slot { name  "slot_inv_43"  bam "RGSTONSL"  slotinfo "inventory:slot(14, 1)"  area 1083 134 49 49 }
	slot { name  "slot_inv_44"  bam "RGSTONSL"  slotinfo "inventory:slot(15, 1)"  area 1132 85 49 49 }
	slot { name  "slot_inv_45"  bam "RGSTONSL"  slotinfo "inventory:slot(16, 1)"  area 1132 134 49 49 }

	slot { name  "slot_inv_30"  bam "RGSTONSL"  slotinfo "inventory:slot(1, 2)"   area 789 191 49 49 }
	slot { name  "slot_inv_31"  bam "RGSTONSL"  slotinfo "inventory:slot(2, 2)"   area 789 240 49 49 }
	slot { name  "slot_inv_32"  bam "RGSTONSL"  slotinfo "inventory:slot(3, 2)"   area 838 191 49 49 }
	slot { name  "slot_inv_33"  bam "RGSTONSL"  slotinfo "inventory:slot(4, 2)"   area 838 240 49 49 }
	slot { name  "slot_inv_34"  bam "RGSTONSL"  slotinfo "inventory:slot(5, 2)"   area 887 191 49 49 }
	slot { name  "slot_inv_35"  bam "RGSTONSL"  slotinfo "inventory:slot(6, 2)"   area 887 240 49 49 }
	slot { name  "slot_inv_36"  bam "RGSTONSL"  slotinfo "inventory:slot(7, 2)"   area 936 191 49 49 }
	slot { name  "slot_inv_37"  bam "RGSTONSL"  slotinfo "inventory:slot(8, 2)"   area 936 240 49 49 }
	slot { name  "slot_inv_38"  bam "RGSTONSL"  slotinfo "inventory:slot(9, 2)"   area 985 191 49 49 }
	slot { name  "slot_inv_39"  bam "RGSTONSL"  slotinfo "inventory:slot(10, 2)"  area 985 240 49 49 }
	slot { name  "slot_inv_40"  bam "RGSTONSL"  slotinfo "inventory:slot(11, 2)"  area 1034 191 49 49 }
	slot { name  "slot_inv_41"  bam "RGSTONSL"  slotinfo "inventory:slot(12, 2)"  area 1034 240 49 49 }
	slot { name  "slot_inv_42"  bam "RGSTONSL"  slotinfo "inventory:slot(13, 2)"  area 1083 191 49 49 }
	slot { name  "slot_inv_43"  bam "RGSTONSL"  slotinfo "inventory:slot(14, 2)"  area 1083 240 49 49 }
	slot { name  "slot_inv_44"  bam "RGSTONSL"  slotinfo "inventory:slot(15, 2)"  area 1132 191 49 49 }
	slot { name  "slot_inv_45"  bam "RGSTONSL"  slotinfo "inventory:slot(16, 2)"  area 1132 240 49 49 }

	slot { name  "slot_inv_30"  bam "RGSTONSL"  slotinfo "inventory:slot(1, 3)"   area 789 297 49 49 }
	slot { name  "slot_inv_31"  bam "RGSTONSL"  slotinfo "inventory:slot(2, 3)"   area 789 346 49 49 }
	slot { name  "slot_inv_32"  bam "RGSTONSL"  slotinfo "inventory:slot(3, 3)"   area 838 297 49 49 }
	slot { name  "slot_inv_33"  bam "RGSTONSL"  slotinfo "inventory:slot(4, 3)"   area 838 346 49 49 }
	slot { name  "slot_inv_34"  bam "RGSTONSL"  slotinfo "inventory:slot(5, 3)"   area 887 297 49 49 }
	slot { name  "slot_inv_35"  bam "RGSTONSL"  slotinfo "inventory:slot(6, 3)"   area 887 346 49 49 }
	slot { name  "slot_inv_36"  bam "RGSTONSL"  slotinfo "inventory:slot(7, 3)"   area 936 297 49 49 }
	slot { name  "slot_inv_37"  bam "RGSTONSL"  slotinfo "inventory:slot(8, 3)"   area 936 346 49 49 }
	slot { name  "slot_inv_38"  bam "RGSTONSL"  slotinfo "inventory:slot(9, 3)"   area 985 297 49 49 }
	slot { name  "slot_inv_39"  bam "RGSTONSL"  slotinfo "inventory:slot(10, 3)"  area 985 346 49 49 }
	slot { name  "slot_inv_40"  bam "RGSTONSL"  slotinfo "inventory:slot(11, 3)"  area 1034 297 49 49 }
	slot { name  "slot_inv_41"  bam "RGSTONSL"  slotinfo "inventory:slot(12, 3)"  area 1034 346 49 49 }
	slot { name  "slot_inv_42"  bam "RGSTONSL"  slotinfo "inventory:slot(13, 3)"  area 1083 297 49 49 }
	slot { name  "slot_inv_43"  bam "RGSTONSL"  slotinfo "inventory:slot(14, 3)"  area 1083 346 49 49 }
	slot { name  "slot_inv_44"  bam "RGSTONSL"  slotinfo "inventory:slot(15, 3)"  area 1132 297 49 49 }
	slot { name  "slot_inv_45"  bam "RGSTONSL"  slotinfo "inventory:slot(16, 3)"  area 1132 346 49 49 }

	slot { name  "slot_inv_30"  bam "RGSTONSL"  slotinfo "inventory:slot(1, 4)"   area 789 403 49 49 }
	slot { name  "slot_inv_31"  bam "RGSTONSL"  slotinfo "inventory:slot(2, 4)"   area 789 452 49 49 }
	slot { name  "slot_inv_32"  bam "RGSTONSL"  slotinfo "inventory:slot(3, 4)"   area 838 403 49 49 }
	slot { name  "slot_inv_33"  bam "RGSTONSL"  slotinfo "inventory:slot(4, 4)"   area 838 452 49 49 }
	slot { name  "slot_inv_34"  bam "RGSTONSL"  slotinfo "inventory:slot(5, 4)"   area 887 403 49 49 }
	slot { name  "slot_inv_35"  bam "RGSTONSL"  slotinfo "inventory:slot(6, 4)"   area 887 452 49 49 }
	slot { name  "slot_inv_36"  bam "RGSTONSL"  slotinfo "inventory:slot(7, 4)"   area 936 403 49 49 }
	slot { name  "slot_inv_37"  bam "RGSTONSL"  slotinfo "inventory:slot(8, 4)"   area 936 452 49 49 }
	slot { name  "slot_inv_38"  bam "RGSTONSL"  slotinfo "inventory:slot(9, 4)"   area 985 403 49 49 }
	slot { name  "slot_inv_39"  bam "RGSTONSL"  slotinfo "inventory:slot(10, 4)"  area 985 452 49 49 }
	slot { name  "slot_inv_40"  bam "RGSTONSL"  slotinfo "inventory:slot(11, 4)"  area 1034 403 49 49 }
	slot { name  "slot_inv_41"  bam "RGSTONSL"  slotinfo "inventory:slot(12, 4)"  area 1034 452 49 49 }
	slot { name  "slot_inv_42"  bam "RGSTONSL"  slotinfo "inventory:slot(13, 4)"  area 1083 403 49 49 }
	slot { name  "slot_inv_43"  bam "RGSTONSL"  slotinfo "inventory:slot(14, 4)"  area 1083 452 49 49 }
	slot { name  "slot_inv_44"  bam "RGSTONSL"  slotinfo "inventory:slot(15, 4)"  area 1132 403 49 49 }
	slot { name  "slot_inv_45"  bam "RGSTONSL"  slotinfo "inventory:slot(16, 4)"  area 1132 452 49 49 }

	slot { name  "slot_inv_30"  bam "RGSTONSL"  slotinfo "inventory:slot(1, 5)"   area 789 509 49 49 }
	slot { name  "slot_inv_31"  bam "RGSTONSL"  slotinfo "inventory:slot(2, 5)"   area 789 558 49 49 }
	slot { name  "slot_inv_32"  bam "RGSTONSL"  slotinfo "inventory:slot(3, 5)"   area 838 509 49 49 }
	slot { name  "slot_inv_33"  bam "RGSTONSL"  slotinfo "inventory:slot(4, 5)"   area 838 558 49 49 }
	slot { name  "slot_inv_34"  bam "RGSTONSL"  slotinfo "inventory:slot(5, 5)"   area 887 509 49 49 }
	slot { name  "slot_inv_35"  bam "RGSTONSL"  slotinfo "inventory:slot(6, 5)"   area 887 558 49 49 }
	slot { name  "slot_inv_36"  bam "RGSTONSL"  slotinfo "inventory:slot(7, 5)"   area 936 509 49 49 }
	slot { name  "slot_inv_37"  bam "RGSTONSL"  slotinfo "inventory:slot(8, 5)"   area 936 558 49 49 }
	slot { name  "slot_inv_38"  bam "RGSTONSL"  slotinfo "inventory:slot(9, 5)"   area 985 509 49 49 }
	slot { name  "slot_inv_39"  bam "RGSTONSL"  slotinfo "inventory:slot(10, 5)"  area 985 558 49 49 }
	slot { name  "slot_inv_40"  bam "RGSTONSL"  slotinfo "inventory:slot(11, 5)"  area 1034 509 49 49 }
	slot { name  "slot_inv_41"  bam "RGSTONSL"  slotinfo "inventory:slot(12, 5)"  area 1034 558 49 49 }
	slot { name  "slot_inv_42"  bam "RGSTONSL"  slotinfo "inventory:slot(13, 5)"  area 1083 509 49 49 }
	slot { name  "slot_inv_43"  bam "RGSTONSL"  slotinfo "inventory:slot(14, 5)"  area 1083 558 49 49 }
	slot { name  "slot_inv_44"  bam "RGSTONSL"  slotinfo "inventory:slot(15, 5)"  area 1132 509 49 49 }
	slot { name  "slot_inv_45"  bam "RGSTONSL"  slotinfo "inventory:slot(16, 5)"  area 1132 558 49 49 }

	slot { name  "slot_inv_30"  bam "RGSTONSL"  slotinfo "inventory:slot(1, 6)"   area 789 615 49 49 }
	slot { name  "slot_inv_31"  bam "RGSTONSL"  slotinfo "inventory:slot(2, 6)"   area 789 664 49 49 }
	slot { name  "slot_inv_32"  bam "RGSTONSL"  slotinfo "inventory:slot(3, 6)"   area 838 615 49 49 }
	slot { name  "slot_inv_33"  bam "RGSTONSL"  slotinfo "inventory:slot(4, 6)"   area 838 664 49 49 }
	slot { name  "slot_inv_34"  bam "RGSTONSL"  slotinfo "inventory:slot(5, 6)"   area 887 615 49 49 }
	slot { name  "slot_inv_35"  bam "RGSTONSL"  slotinfo "inventory:slot(6, 6)"   area 887 664 49 49 }
	slot { name  "slot_inv_36"  bam "RGSTONSL"  slotinfo "inventory:slot(7, 6)"   area 936 615 49 49 }
	slot { name  "slot_inv_37"  bam "RGSTONSL"  slotinfo "inventory:slot(8, 6)"   area 936 664 49 49 }
	slot { name  "slot_inv_38"  bam "RGSTONSL"  slotinfo "inventory:slot(9, 6)"   area 985 615 49 49 }
	slot { name  "slot_inv_39"  bam "RGSTONSL"  slotinfo "inventory:slot(10, 6)"  area 985 664 49 49 }
	slot { name  "slot_inv_40"  bam "RGSTONSL"  slotinfo "inventory:slot(11, 6)"  area 1034 615 49 49 }
	slot { name  "slot_inv_41"  bam "RGSTONSL"  slotinfo "inventory:slot(12, 6)"  area 1034 664 49 49 }
	slot { name  "slot_inv_42"  bam "RGSTONSL"  slotinfo "inventory:slot(13, 6)"  area 1083 615 49 49 }
	slot { name  "slot_inv_43"  bam "RGSTONSL"  slotinfo "inventory:slot(14, 6)"  area 1083 664 49 49 }
	slot { name  "slot_inv_44"  bam "RGSTONSL"  slotinfo "inventory:slot(15, 6)"  area 1132 615 49 49 }
	slot { name  "slot_inv_45"  bam "RGSTONSL"  slotinfo "inventory:slot(16, 6)"  area 1132 664 49 49 }

	text
	{
		name "slotsArea1"
		area		789 85 0 0
		actionEnter "inventory:onSlotsAreaEnter(1)"
	}
	text
	{
		name "slotsArea2"
		area		789 191 392 98
		actionEnter "inventory:onSlotsAreaEnter(2)"
	}
	text
	{
		name "slotsArea3"
		area		789 297 392 98
		actionEnter "inventory:onSlotsAreaEnter(3)"
	}
	text
	{
		name "slotsArea4"
		area		789 403 392 98
		actionEnter "inventory:onSlotsAreaEnter(4)"
	}
	text
	{
		name "slotsArea5"
		area		789 509 392 98
		actionEnter "inventory:onSlotsAreaEnter(5)"
	}
	text
	{
		name "slotsArea6"
		area		789 615 392 98
		actionEnter "inventory:onSlotsAreaEnter(6)"
	}
	
	button
	{
		name "invPortrait0"
		area 642 90 64 90
		portrait 0
		bam GUIRSP10
		enabled "inventory.count > 0"
		action "inventory:select(1)"
		actionAlt "Infinity_OnPortraitRClick(0)"
		actiondrag "Infinity_SwapWithPortrait(0)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		name "invPortrait1"
		area 642 196 64 90
		portrait 1
		bam GUIRSP10
		enabled "inventory.count > 1"
		action "inventory:select(2)"
		actionAlt "Infinity_OnPortraitRClick(1)"
		actiondrag "Infinity_SwapWithPortrait(1)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		name "invPortrait2"
		area 642 302 64 90
		portrait 2
		bam GUIRSP10
		enabled "inventory.count > 2"
		action "inventory:select(3)"
		actionAlt "Infinity_OnPortraitRClick(2)"
		actiondrag "Infinity_SwapWithPortrait(2)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		name "invPortrait3"
		area 642 408 64 90
		portrait 3
		bam GUIRSP10
		enabled "inventory.count > 3"
		action "inventory:select(4)"
		actionAlt "Infinity_OnPortraitRClick(3)"
		actiondrag "Infinity_SwapWithPortrait(3)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		name "invPortrait4"
		area 642 514 64 90
		portrait 4
		bam GUIRSP10
		enabled "inventory.count > 4"
		action "inventory:select(5)"
		actionAlt "Infinity_OnPortraitRClick(4)"
		actiondrag "Infinity_SwapWithPortrait(4)"
		clickable lua "sidebarsGreyed ~= 1"
	}
	button
	{
		name "invPortrait5"
		area 642 620 64 90
		portrait 5
		bam GUIRSP10
		enabled "inventory.count > 5"
		action "inventory:select(6)"
		actionAlt "Infinity_OnPortraitRClick(5)"
		actiondrag "Infinity_SwapWithPortrait(5)"
		clickable lua "sidebarsGreyed ~= 1"
	}

	slot {name "slot_inv_68"		area 1214 220 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ground0"		}
	slot {name "slot_inv_69"		area 1214 273 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ground1"		}
	slot {name "slot_inv_70"		area 1214 326 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ground2"		}
	slot {name "slot_inv_71"		area 1214 379 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ground3"		}
	slot {name "slot_inv_72"		area 1214 432 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ground4"		}
	slot {name "slot_inv_73"		area 1214 485 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ground5"		}
	slot {name "slot_inv_74"		area 1214 538 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ground6"		}
	slot {name "slot_inv_75"		area 1214 591 52 52	bam "STONSL10"	slotinfo "characters[id].equipment.ground7"		}

	button
	{
		area 1210 646 68 47
		bam RGAROW
		sequence 0
		action
		"
			Infinity_OnGroundPage(1)
		"
	}
	button
	{
		area 1210 178 63 42
		bam RGAROW
		sequence 1
		action
		"
			Infinity_OnGroundPage(-1)
		"
	}
	button
	{
		area 511 157 50 52
		bam INVBUT
		colordisplay 2
		action
		"
			Infinity_PushMenu('CHARACTER_COLOR', 0, 0)
		"
	}
	label --this has to be last so it draws over top of everything.
	{
		area 0 0 630 756
		enabled "shouldGreyOutInventory()"
		mosaic RGINVDE2
	}

	-- When mouse enters a slots area the character it belongs to gets selected,
	-- but then the player can press 1-6 keys to select someone else, now we if
	-- we click on a slot in the current area of the unselected character, we
	-- will get an item from the corresponding slot of the selected character.
	--
	-- This add an overlay on top of the hovered slots, you can no longer click on
	-- the slots. Although double clicking still sends the dragged item to the
	-- currently selected character, doesn't always work for whatever reason.
	text
	{
		name "slotsAreaCover"
		mosaic "RGJBACK"
		area 789 403 0 0
		tooltip force lua "''"

		-- actionExit doesn't work without actionEnter
		actionEnter ""
		actionExit "
			if inventory.hovered and inventory.hovered ~= inventory.selected then
				Infinity_SetArea('slotsArea' .. inventory.hovered, nil, nil, 392, 98)
				inventory.hovered = nil
			end
			Infinity_SetArea('slotsAreaCover', nil, nil, 0, 0)
		"
	}
}

`
SLIDER_color_hair_start = 1
SLIDER_color_skin_start = 1
SLIDER_color_major_start = 1
SLIDER_color_minor_start = 1

SLIDER_color_hair = 1
SLIDER_color_skin = 1
SLIDER_color_major = 1
SLIDER_color_minor = 1

function rgColorBackground()
	if (e:GetActiveEngine() == createCharScreen) then
	return "RGCOLOR"
	else return "RGCOLOR2"
	end
end
`
menu
{
	name 'CHARACTER_COLOR'
	align center center
	ignoreesc
	
	onOpen
	"
		Infinity_UpdateLuaStats()
		
		SLIDER_color_hair = characters[id].colors.hair
		SLIDER_color_skin = characters[id].colors.skin
		SLIDER_color_major = characters[id].colors.major
		SLIDER_color_minor = characters[id].colors.minor
		
		SLIDER_color_hair_start = SLIDER_color_hair
		SLIDER_color_skin_start = SLIDER_color_skin
		SLIDER_color_major_start = SLIDER_color_major
		SLIDER_color_minor_start = SLIDER_color_minor
		greySidebars()
	"
	onClose
	"
		if(SLIDER_color_hair_start ~= -1) then Infinity_SetHairColor(SLIDER_color_hair_start) end
		if(SLIDER_color_skin_start ~= -1) then Infinity_SetSkinColor(SLIDER_color_skin_start) end
		if(SLIDER_color_major_start ~= -1) then Infinity_SetMajorColor(SLIDER_color_major_start) end
		if(SLIDER_color_minor_start ~= -1) then Infinity_SetMinorColor(SLIDER_color_minor_start) end
		ungreySidebars()
	"
	label
	{
		area 0 0 1444 818
		mosaic lua "rgColorBackground()"
	}
	label
	{
		area 340 288 760 396
		rectangle 3
	}
	label
	{
		area 330 82 780 44
		text "COLOR_CHOICES_TITLE"
		text style "title"
	}
	label
	{
		area 331 32 780 44
		enabled "e:GetActiveEngine() == createCharScreen"
		text "CHARGEN_TITLE"
		text style "title"
	}
	
	button
	{
		area 594 134 114 160
		paperdoll 0
	}
	button
	{
		area 728 134 114 160
		paperdoll 1
	}
	
	label
	{
		enabled "characters[id].PC == 1"
		area 1030 370 42 44
		colordisplay 6
	}
	label
	{
		enabled "characters[id].PC == 1"
		area 1030 444 42 44
		colordisplay 3
	}
	label
	{
		area 1030 550 42 44
		colordisplay 2
	}
	label
	{
		area 1030 624 42 44
		colordisplay 1
	}
	
	label
	{
		area 368 308 704 32
		text "APPEARANCE_LABEL"
		text style "label"
		text point 14
	}
	
	label
	{
		enabled "characters[id].PC == 1"
		area 368 340 704 30
		text "HAIR_LABEL"
		text style "label"
	}
	slider
	{
		palette 6
		enabled "characters[id].PC == 1"
		area 368 370 662 44
		bam	 'SLDRSTAR'
		position "SLIDER_color_hair"
		sequence 0
		frame	 1
		settings lua "game:GetPaletteSize(6)"
		action
		"
			Infinity_SetHairColor(SLIDER_color_hair)
		"
	}

	label
	{
		enabled "characters[id].PC == 1"
		area 368 414 704 30
		text "SKIN_LABEL"
		text style "label"
	}
	slider
	{
		palette 3
		enabled "characters[id].PC == 1"
		area 368 444 662 44
		bam	 'SLDRSTAR'
		position "SLIDER_color_skin"
		sequence 0
		frame	 1
		settings lua "game:GetPaletteSize(3)"
		action
		"
			Infinity_SetSkinColor(SLIDER_color_skin)
		"
	}
	
	label
	{
		area 368 488 704 32
		text "CLOTHING_LABEL"
		text style "label"
		text point 14
	}
	
	label
	{
		area 368 520 704 30
		text "MAJOR_LABEL"
		text style "label"
	}
	slider
	{
		palette 2
		area 368 550 662 44
		bam	 'SLDRSTAR'
		position "SLIDER_color_major"
		sequence 0
		frame	 1
		settings lua "game:GetPaletteSize(2)"
		action
		"
			Infinity_SetMajorColor(SLIDER_color_major)
		"
	}
	
	label
	{
		area 368 594 704 30
		text "MINOR_LABEL"
		align center center
		text style "label"
	}
	slider
	{
		palette 1
		area 368 624 662 44
		bam	 'SLDRSTAR'
		position "SLIDER_color_minor"
		sequence 0
		frame	 1
		settings lua "game:GetPaletteSize(1)"
		action
		"
			Infinity_SetMinorColor(SLIDER_color_minor)
		"
	}
	button
	{
		on escape
		area 382 724 230 44
		bam GUIBUTMT
		sequence 2
		text "CANCEL_BUTTON"
		text style "button"
		action
		"
			Infinity_PopMenu('CHARACTER_COLOR',0,0)
		"
	}
	button
	{
		on return
		area 818 724 230 44
		bam GUIBUTMT
		sequence 2
		text "DONE_BUTTON"
		text style "button"
		action
		"
			--save settings
			SLIDER_color_hair_start = SLIDER_color_hair
			SLIDER_color_skin_start = SLIDER_color_skin
			SLIDER_color_major_start = SLIDER_color_major
			SLIDER_color_minor_start = SLIDER_color_minor
			
			if (e:GetActiveEngine() == createCharScreen) then
				createCharScreen:OnDoneButtonClick()
			end
			
			Infinity_PopMenu('CHARACTER_COLOR',0,0)
		"
	}
}
menu
{
	name 'WORLD_LEVEL_UP_BUTTONS'
	align right top
	offset -65 0
	ignoreesc
	enabled "0" --disable this menu for now.
	button
	{
		enabled "Infinity_CanLevelUp(0)"
		bam GUIOSW
		area 0 14 44 44
		sequence 0
		action "Infinity_ActivateRecord(0)"
		pulse 1
	}
	button
	{
		enabled "Infinity_CanLevelUp(1)"
		bam GUIOSW
		area 0 106 44 44
		sequence 0
		action "Infinity_ActivateRecord(1)"
		pulse 1
	}
	button
	{
		enabled "Infinity_CanLevelUp(2)"
		bam GUIOSW
		area 0 198 44 44
		sequence 0
		action "Infinity_ActivateRecord(2)"
		pulse 1
	}
	button
	{
		enabled "Infinity_CanLevelUp(3)"
		bam GUIOSW
		area 0 290 44 44
		sequence 0
		action "Infinity_ActivateRecord(3)"
		pulse 1
	}
	button
	{
		enabled "Infinity_CanLevelUp(4)"
		bam GUIOSW
		area 0 382 44 44
		sequence 0
		action "Infinity_ActivateRecord(4)"
		pulse 1
	}
	button
	{
		enabled "Infinity_CanLevelUp(5)"
		bam GUIOSW
		area 0 474 44 44
		sequence 0
		action "Infinity_ActivateRecord(5)"
		pulse 1
	}
	
}
menu
{
	name 'textflash'
	opacity lua 'getOpacityForInfoBlock(1000)'
	enabled 'getOpacityForInfoBlock(1000) ~= 0'
	align center top
	offset 0 10

	label
	{
		area 0 0 500 140
		mosaic 'GUINOTE'	
	}
	label
	{
		area 75 10 348 26
		text lua "getTitleString()"
		text style "label"
		text align left center
		text point 14
		text color C
	}
	label
	{
		area 75 36 348 26
		text lua "getSubtitleString()"
		text style "label"
		text align left center
		text point 14
		text color D
	}

	label
	{
		area 20 64 472 62
		text lua "getBodyString()"
		text style "normal"
		text align left center
	}
	label
	{
		area 16 9 50 50
		bam RGGBUT
		sequence 2
		frame lua "rggbuttHighlight2()"
	}
	button
	{
		area 0 0 500 140
		action
		"
			FindTitle = getSubtitleString()
			if(sidebarsGreyed ~= 1) and journalOpen ~= 1 then
				if JournalSize == UIStrings.UI_Large then
					e:GetActiveEngine():OnLeftPanelButtonClick(2)
				elseif JournalSize == UIStrings.UI_Small then
					e:GetActiveEngine():OnLeftPanelButtonClick(2)
				end
			end
			CloseAll_Small()
			findQuestPopUp()
			local tf = next(textflashes)
			setSelectedQuest(textflashes[tf][5])
			CheckForOpenedQuests_Small()
		"
	}
	button
	{
		bam GUIOSW
		on esc
		area 448 4 44 44
		sequence 2
		action 
		"
			--end the animation
			local tf = next(textflashes)
			textflashes[tf] = nil
		"
	}
}
`
function hasMatchingJournal()
	FindTitle = string.sub(getSubtitleString(),1,15)
	for i=1,#questDisplay,1 do
		local rowTab =  questDisplay[i]
		local text = Infinity_FetchString(rowTab.text)
		if string.find(string.lower(text), string.lower(FindTitle)) then
			return 1
		end
	end
	return nil
end

function getNewTitle()
	if hasMatchingJournal() then
		return '^C' .. getTitleString() .. '^-\n^D' .. getSubtitleString() .. '^-'
	else
		return '^D' .. getSubtitleString() .. '^-'
	end
end

luaEdit = ""
luaEditDebugDump = 0
luaEditHistory = {}
luaEditMaxHistory = 10
luaEditHistoryIndex = 0
luaEditShowHistoryList = 0
luaEditHistoryListSelected = 0
function updateLuaHistory()
	local i = 2
	local tempTab = {}
	tempTab[1] = luaEdit
	while ( i <= luaEditMaxHistory ) do
		tempTab[i] = luaEditHistory[i-1]
		i = i + 1
	end
	luaEditHistory = tempTab
end
function loadLuaHistory()
	local i = 1
	while (i <= luaEditMaxHistory ) do
		luaEditHistory[i] = Infinity_GetINIString("Lua Edit","String"..i-1, "")
		i = i + 1
	end
end
function saveLuaHistory()
	local i = 1
	while (i <= luaEditMaxHistory ) do
		Infinity_SetINIValue("Lua Edit","String"..i-1, luaEditHistory[i])
		i = i + 1
	end
end
function luaEditHistoryUp()
	if(luaEditHistoryIndex <= 1) then return end
	luaEditHistoryIndex = luaEditHistoryIndex - 1
	luaEdit = luaEditHistory[luaEditHistoryIndex]
end
function luaEditHistoryDown()
	if(luaEditHistoryIndex == luaEditMaxHistory) then return end
	if(luaEditHistory[luaEditHistoryIndex + 1] == "") then return end
	luaEditHistoryIndex = luaEditHistoryIndex + 1
	luaEdit = luaEditHistory[luaEditHistoryIndex]
end

cheatGoldAmt = 1000000
cheatXpAmt = 500000

`
menu
{
	name 'cheatMenu'
	ignoreEsc

	label
	{
		area 100 0 809 298
		mosaic 'GUWBTP30'	
	}
	list
	{
		column 
		{ 
			width 20 
			label
			{
				area 0 0 -1 -1
				text lua "cheatAreas[rowNumber][1]"
				text style "list"
			}
		}
		column 
		{ 
			width 80 
			label
			{
				area 0 0 -1 -1
				text lua "cheatAreas[rowNumber][2]"
				text style "list"
			}
		}

		area 122 6 492 240
		
		rowheight	18
		table		"cheatAreas"
		var		cheatTeleportArea
		scrollbar	'GUISCRC'
	}
	button
	{
		area		122 252 140 30
		bam			GUIBUTNS
		sequence	6
		text		"TRAVEL_BUTTON"
		text style	"button"
		action 		"C:MoveToArea(cheatAreas[cheatTeleportArea][1])"
	}
	button
	{
		area		620 186 140 30
		bam			GUIBUTNS
		sequence	6
		text			"GODBOW_LABEL"
		text style	"button"
		action		"C:CreateItem('godbow')"
	}
	button
	{
		area		620 216 140 30
		bam			GUIBUTNS
		sequence	6
		text			"GIVE_GOLD_LABEL"
		text style	"button"
		action		"C:AddGold(cheatGoldAmt)"
	}
	edit
	{
		area		766 222 138 30
		var		cheatGoldAmt
		text style	"edit"
		maxlines	1
		fill            112 111 111 64
	}

	button
	{
		area		620 252 140 30
		bam			GUIBUTNS
		sequence	6
		text			"GIVE_XP_LABEL"
		text style	"button"
		action		"C:SetCurrentXP(cheatXpAmt)"
	}
	edit
	{
		area		766 258 138 30
		var		cheatXpAmt
		text style	"edit"
		maxlines	1
		fill            112 111 111 64
	}

	button
	{
		area		766 186 140 30
		bam			GUIBUTNS
		sequence	6
		text			"EXPLORE_LABEL"
		text style	"button"
		action		"C:ExploreArea()"
	}

}
menu
{
	name "luaHistoryMenu"
	offset 500 -32
	align right bottom
	label
	{
		area 0 0 809 300
		mosaic 'GUWBTP30'
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 -1 -1
				text lua "luaEditHistory[rowNumber]"
				text style	"list"
			}
		}
		area 20 10 400 298
		rowheight	24
		var luaEditHistoryListSelected
		table		"luaEditHistory"
		scrollbar	'GUISCRC'
		action
		"
			luaEdit = luaEditHistory[luaEditHistoryListSelected]
		"
	}
}
menu
{
	name 'cheatConsole'
	align center bottom
	ignoreEsc

	onOpen 
	"
		toolbarTop = 50
		Infinity_PushMenu('WORLD_MESSAGES')
		Infinity_PushMenu('cheatMenu', 0, 0);
		Infinity_FocusTextEdit('luaEditArea'); 
		luaEdit = trim(luaEdit)
		loadLuaHistory()
	"
	onClose 
	"
		Infinity_PopMenu('cheatMenu', 0, 0);
		Infinity_PopMenu('luaHistoryMenu', 0, 0);
	"
	label
	{
		area 0 0 809 50
		mosaic GUWBTP20
	}
	edit
	{
		name				"luaEditArea"
		area				12 8 790 24
		var					luaEdit
		scrollbar			'GUISCRC'
		text style			"edit"
		fill            	112 111 111 64
		text useFontZoom	0
		action
		"
			--if key_pressed is return
			if (key_pressed == 13) then
				updateLuaHistory()
				saveLuaHistory()
				Infinity_LuaConsoleInput(luaEditObjectId,luaEditDebugDump)
				return -1
			end
			if (key_pressed == 27) then
				return 0
			end
			return 1
		"
	}
	button
	{
		area		816 6 32 32
		bam			ROUNDBUT
		toggle		luaEditShowHistoryList
		action
		"
			if(luaEditShowHistoryList == 0) then
				Infinity_PopMenu('luaHistoryMenu',0,0)
			else
				Infinity_PushMenu('luaHistoryMenu',0,0)
			end
		"
	}
	button
	{
		enabled "Infinity_TextEditHasFocus()"
		on up
		action
		"
			luaEditHistoryUp()
		"
	}
	button
	{
		enabled "Infinity_TextEditHasFocus()"
		on down
		action
		"
			luaEditHistoryDown()
		"
	}

}
`
cloudLoadState=0
function CheckCloudSaveStatus()
	Infinity_UpdateCloudSaveState()
	if(cloudLoadState == 0) then
		Infinity_PopMenu()
	end
	return GetCloudLoadingText()
end
function GetCloudLoadingText()
	if(cloudLoadState == 1 or cloudLoadState == 0) then
		return t('DOWNLOADING_SAVE_NORMAL')
	end
	if(cloudLoadState == 2) then
		return t('SEARCHING_SAVE_NORMAL')
	end
	return t('CLOUD_STATE_UNDEFINED_NORMAL')
end
`
menu
{
	name 'CloudSaveUpdateMenu'
	modal
	label -- Background
	{
		area 174 267 677 234
		mosaic GUIERR6 
	}
	label
	{
		area 214 287 600 120
		text lua "CheckCloudSaveStatus()"
		text style "label"
	}
	button
	{
		area		544 437 232 44
		bam			GUIOSTUR
		sequence	0
		text		"SKIP_BUTTON"
		text style	"button"
		on 			escape
		action
		"
			Infinity_PopMenu()
		"	
	}
}
`
messageBoxCurMessage = nil
messageBoxMessages = {}
function initMessageBox(message)
	messageBoxMessages[message] = 1
	if(messageBoxCurMessage ~= nil) then
		--message box already active
		return
	end
	getNextMessage()
	Infinity_PushMenu('LuaMessageBox',0,0)
end

function getNextMessage()
	i = 1
	while ( i <= messageBoxMessageCount ) do
		showMessage = messageBoxMessages[i]
		if ( showMessage ~= nil ) then
			messageBoxCurMessage = i
			return 1
		end
		i = i + 1
	end
	--whole table scanned, all messages have been displayed
	return 0
end
`
menu
{
	name 'LuaMessageBox'
	align center center
	modal
	label
	{
		area 0 0 657 234
		mosaic GUIERR6
	}
	label
	{
		area 29 21 580 126
		text lua "messages[messageBoxCurMessage]"
		text style	"label"
	}
	button
	{
		area 213 170 230 44
		bam GUIBUTNT
		text "DONE_BUTTON"
		text style	"button"
		action
		"
			messageBoxMessages[messageBoxCurMessage] = nil
			if(getNextMessage() == 0) then
				messageBoxCurMessage = nil
				Infinity_PopMenu()
			end
		"	
	}
}
`
	partyImport = {}
`
menu
{
	name 'IMPORTPARTY'
	align center center
	label 
	{
		mosaic 'GMPCARBD'
		area 0 0 1024 768
	}
	label
	{
		area 162 16 700 44
		text "CREATE_PARTY_TITLE"
		text style "title"
	}
	label
	{
		enabled		"game:GetMissionPackInfoTBP()"
		area 		54 584 902 62
		scrollbar	'GUISCRC'
		text style	"normal"
		text 			69563
	}

	--portraits
	label
	{
		area 67 180 64 90
		bam 'GUIRSP10'
		sequence 0
	}
	button
	{
		area 71 182 56 86
		bitmap lua "partyImport.character[1].portrait"
		clickable lua "partyImport.character[1].name ~= ''"
		action
		"
			createPartyScreen:OnPortraitButtonClick(0)
		"
	}
	label
	{
		area 67 315 64 90
		bam 'GUIRSP10'
		sequence 0
	}
	button
	{
		area 71 317 56 86
		bitmap lua "partyImport.character[2].portrait"
		clickable lua "partyImport.character[2].name ~= ''"
		action
		"
			createPartyScreen:OnPortraitButtonClick(1)
		"
	}
	label
	{
		area 67 454 64 90
		bam 'GUIRSP10'
		sequence 0
	}
	button
	{
		area 71 456 56 86
		bitmap lua "partyImport.character[3].portrait"
		clickable lua "partyImport.character[3].name ~= ''"
		action
		"
			createPartyScreen:OnPortraitButtonClick(2)
		"
	}
	label
	{
		area 557 180 64 90
		bam 'GUIRSP10'
		sequence 0
	}
	button
	{
		area 561 182 56 86
		bitmap lua "partyImport.character[4].portrait"
		clickable lua "partyImport.character[4].name ~= ''"
		action
		"
			createPartyScreen:OnPortraitButtonClick(3)
		"
	}
	label
	{
		area 557 315 64 90
		bam 'GUIRSP10'
		sequence 0
	}
	button
	{
		area 561 317 56 86
		bitmap lua "partyImport.character[5].portrait"
		clickable lua "partyImport.character[5].name ~= ''"
		action
		"
			createPartyScreen:OnPortraitButtonClick(4)
		"
	}
	label
	{
		area 557 454 64 90
		bam 'GUIRSP10'
		sequence 0
	}
	button
	{
		area 561 456 56 86
		bitmap lua "partyImport.character[6].portrait"
		clickable lua "partyImport.character[6].name ~= ''"
		action
		"
			createPartyScreen:OnPortraitButtonClick(5)
		"
	}

	button
	{
		area 527 710 200 44
		bam 'GUIBUTNT'
		sequence 1
		text "PLAY_IMPORT_BUTTON" -- Play
		text style 'button'
		clickable lua "partyImport.playbuttonclickable"
		action 
		"
			createPartyScreen:OnDoneButtonClick()
		"
	}
	button
	{
		on escape
		area 305 710 200 44
		bam 'GUIBUTNT'
		sequence 0
		text "BACK_BUTTON" -- Back
		text style 'button'
		action 
		"
			createPartyScreen:OnBackButtonClick()
		"
	}

	--delete/create buttons
	button
	{
		area 155 180 300 44
		bam 'GUIBUTWT'
		sequence 0
		text lua "partyImport.character[1].createdelete"
		text style "button"
		action
		"
			createPartyScreen:OnCreateDeleteButtonClick(0)
		"
	}
	button
	{
		area 155 317 300 44
		bam 'GUIBUTWT'
		sequence 2
		text lua "partyImport.character[2].createdelete"
		text style "button"
		action
		"
			createPartyScreen:OnCreateDeleteButtonClick(1)
		"
	}
	button
	{
		area 155 452 300 44
		bam 'GUIBUTWT'
		sequence 1
		text lua "partyImport.character[3].createdelete"
		text style "button"
		action
		"
			createPartyScreen:OnCreateDeleteButtonClick(2)
		"
	}
	button
	{
		area 645 180 300 44
		bam 'GUIBUTWT'
		sequence 0
		text lua "partyImport.character[4].createdelete"
		text style "button"
		action
		"
			createPartyScreen:OnCreateDeleteButtonClick(3)
		"
	}
	button
	{
		area 645 317 300 44
		bam 'GUIBUTWT'
		sequence 2
		text lua "partyImport.character[5].createdelete"
		text style "button"
		action
		"
			createPartyScreen:OnCreateDeleteButtonClick(4)
		"
	}
	button
	{
		area 645 452 300 44
		bam 'GUIBUTWT'
		sequence 1
		text lua "partyImport.character[6].createdelete"
		text style "button"
		action
		"
			createPartyScreen:OnCreateDeleteButtonClick(5)
		"
	}

	-- character labels
	label
	{
		area 155 228 314 50
		text lua "partyImport.character[1].name"
		text style "title"
	}
	label
	{
		area 155 365 314 50
		text lua "partyImport.character[2].name"
		text style "title"
	}
	label
	{
		area 155 500 314 50
		text lua "partyImport.character[3].name"
		text style "title"
	}
	label
	{
		area 645 228 314 50
		text lua "partyImport.character[4].name"
		text style "title"
	}
	label
	{
		area 645 365 314 50
		text lua "partyImport.character[5].name"
		text style "title"
	}
	label
	{
		area 645 500 314 50
		text lua "partyImport.character[6].name"
		text style "title"
	}
}
menu
{
	name 'START_CAMPAIGN_SELECT'
	align center center
	ignoreEsc
	modal
	
	label
	{
		area 0 0 672 672
		mosaic "RECENTEV"
	}
	label
	{
		area 158 52 354 46
		text style "title"
		text "SELECT_CAMPAIGN_TITLE"
	}
	label
	{
		area 136 120 406 258
		text style "normal"
		text "WELCOME_NORMAL"
	}
	button
	{
		area 198 408 300 45
		bam GUIBUTWT
		text style "button"
		text "SIEGE_OF_DRAGONSPEAR_BUTTON"
		action
		"
			startEngine:DismissChooseCampaignPopup()
			startEngine:OnCampaignButtonClick('SOD',true)
		"
	}
		button
	{
		area 198 458 300 45
		bam GUIBUTWT
		text style "button"
		text "BALDURS_GATE_BUTTON"
		action
		"
			--selected by default, just close this menu.
			startEngine:DismissChooseCampaignPopup()
		"
	}
	button
	{
		area 198 508 300 45
		bam GUIBUTWT
		text style "button"
		text "BLACK_PITS_BUTTON"
		action
		"
			startEngine:DismissChooseCampaignPopup()
			startEngine:OnTBPButtonClick(true)
		"
	}

}
`
	highlightedCampaign = nil

	--obviously theres some redundancy in this data but I dislike the idea of assuming what our frame/sequence will be.
	startCampaignData = { 
		{bigLogo = 0, icon = 0, tooltip = "TOOLTIP_CAMPAIGN_BG", background = 2, button = 2, sidebar = 2, importEnabled = false, tutorialEnabled = true}, 
		{bigLogo = 2, icon = 1, tooltip = "TOOLTIP_CAMPAIGN_TBP", background = 2, button = 2, sidebar = 2, importEnabled = false, tutorialEnabled = false}, 
		{bigLogo = 1, icon = 2, tooltip = "TOOLTIP_CAMPAIGN_SOD", background = 2, button = 2, sidebar = 2, importEnabled = true, tutorialEnabled = false}
	}
	startButtons = 
	{
		{const.START_CAMPAIGN_SOD, const.START_CAMPAIGN_BP}, --bg
		{const.START_CAMPAIGN_BG, const.START_CAMPAIGN_SOD}, --bp
		{const.START_CAMPAIGN_BG,const.START_CAMPAIGN_BP}, --sod
	}
	
	function getCampaignHighlight(selected)
		return selected == highlightedCampaign
	end
	
	function getBigLogo()
		local campaign = nil
		--return startCampaignData[campaign].bigLogo
		if startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 0 then
			campaign = 0
		elseif startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 1 then
			campaign = 1
		elseif startEngine:GetCampaign() == const.START_CAMPAIGN_BP then
			campaign = 2
		end
		return campaign
	end
	
	function getCampaignIcon(buttonNum)
		local campaign = startEngine:GetCampaign()
		return startCampaignData[startButtons[campaign][buttonNum]].icon
	end
	
	function getCampaignTooltip(buttonNum)
		local campaign = startEngine:GetCampaign()
		return t(startCampaignData[startButtons[campaign][buttonNum]].tooltip)
	end
	
	function getCampaignButtonSequence()
		local campaign = startEngine:GetCampaign()
		return startCampaignData[campaign].button
	end
	
	function onCampaignButton(buttonNum)
		local campaign = startEngine:GetCampaign()
		local clickedCampaign = startButtons[campaign][buttonNum]
		if(clickedCampaign == const.START_CAMPAIGN_SOD) then
			startEngine:OnCampaignButtonClick('SOD',true)
		elseif(clickedCampaign == const.START_CAMPAIGN_BP) then
			startEngine:OnTBPButtonClick(true)
		elseif(clickedCampaign == const.START_CAMPAIGN_BG) then
			startEngine:OnSoAButtonClick(true)
		end
	end
	function getCampaignImportEnabled()
		local campaign = startEngine:GetCampaign()
		return startCampaignData[campaign].importEnabled	
	end
	function getTutorialEnabled()
		--Tutorial and campaign import should never be enabled for the same campaign - the button uses the same space
		local campaign = startEngine:GetCampaign()
		return startCampaignData[campaign].tutorialEnabled	
	end
	function getSidebarFrame()
		local campaign = startEngine:GetCampaign()
		return startCampaignData[campaign].sidebar
	end
	function getMenuPanelArea()
	local screenWidth, screenHeight = Infinity_GetScreenSize()
	Infinity_SetArea('MenuPanel1', screenWidth-444, nil, nil, nil)
	Infinity_SetArea('MenuPanel1SP', screenWidth-444, nil, nil, nil)
	Infinity_SetArea('MenuPanel1OP', screenWidth-444, nil, nil, nil)
--	Infinity_SetArea('MenuPanel2', 72, screenHeight-188, nil, nil)
--	Infinity_SetArea('MenuLogo', screenWidth-410, nil, nil, nil)
--	Infinity_SetArea('MenuLogoSP', screenWidth-410, nil, nil, nil)
	Infinity_SetArea('MenuTitle1', screenWidth-510, nil, nil, nil)
	Infinity_SetArea('MenuTitle1SP', screenWidth-510, nil, nil, nil)
	Infinity_SetArea('MenuTitle1OP', screenWidth-510, nil, nil, nil)
	Infinity_SetArea('MenuTitle2', screenWidth-510, nil, nil, nil)
	Infinity_SetArea('MenuTitle2SP', screenWidth-510, nil, nil, nil)
	Infinity_SetArea('MenuTitle2OP', screenWidth-510, nil, nil, nil)
	Infinity_SetArea('MenuTitle3', screenWidth-532, nil, nil, nil)
	Infinity_SetArea('MenuTitle3SP', screenWidth-532, nil, nil, nil)
	Infinity_SetArea('MenuTitle3OP', screenWidth-532, nil, nil, nil)
	Infinity_SetArea('MenuButton1', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton1SP', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton2', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton2SP', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton3', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton3SP', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton4', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton4x', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton4SP', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton4xSP', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton5', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton5SP', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton6', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton6SP', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton7', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton7SP', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuButton5OP', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuOptionsArea', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuCampLabel1', 60, screenHeight-210, nil, nil)
	Infinity_SetArea('MenuCampLabel2', 58, screenHeight-212, nil, nil)
	Infinity_SetArea('MenuCampA1', 41, screenHeight-163, nil, nil)
	Infinity_SetArea('MenuCampA2', 175, screenHeight-163, nil, nil)
	Infinity_SetArea('MenuCampA3', 309, screenHeight-163, nil, nil)
	Infinity_SetArea('MenuCampB1', 56, screenHeight-148, nil, nil)
	Infinity_SetArea('MenuCampB2', 190, screenHeight-148, nil, nil)
	Infinity_SetArea('MenuCampB3', 324, screenHeight-148, nil, nil)
	Infinity_SetArea('MenuCChooser1', 58, screenHeight-146, nil, nil)
	Infinity_SetArea('MenuCChooser2', 192, screenHeight-146, nil, nil)
	Infinity_SetArea('MenuCChooser3', 326, screenHeight-146, nil, nil)
	Infinity_SetArea('flames', 324, nil, nil, nil)
--	Infinity_SetArea('flames2', screenWidth-420, nil, nil, nil)
--	Infinity_SetArea('flames3', screenWidth-420, nil, nil, nil)
	Infinity_SetArea('MenuVsLabel', screenWidth-132, screenHeight-41, nil, nil)
--	Infinity_SetArea('MenuVsLab1', 167, screenHeight-63, nil, nil)
	Infinity_SetArea('MenuOpLabel', screenWidth-384 , nil, nil, nil)
--	end
	end
--MenuCampA1 81 887  215 887  349 887
--MenuCampB1 96 902  230 902  364 902
--MenuCampLabel1 100 840  98 838

	usingSODStartMenu = 1
`
menu
{
	name 'FirstLoad'
	align center center
	modal
	ignoreEsc
	onopen
	"
	FLmenu = 'FLStartPage'
	"
	label
	{
		area 0 0 862 714
		mosaic "GUIHELP"
	}
	label
	{
		area 234 10 416 52
		text "SOD GUI Overhaul v2.2"
		text style "title"
		text align center center
	}
	label
	{
		enabled "FLmenu == 'FLStartPage'"
		area 108 92 650 52
		text "Select an option to explore the new features:"
		text point 22
		text style "button"
		text align left center
	}
	button
    {
        enabled "FLmenu == 'FLStartPage'"
        area 108 144 650 40
        text "Enhanced Inventory (v2.2)"
        text style "normal"
        text color 'R'
        text align center center
        action
        "
            FLmenu = 'newInventory'
        "
    }
	button
    {
        enabled "FLmenu == 'FLStartPage'"
        area 108 184 650 40
        text "Classic Dialog Option (v2.2)"
        text style "normal"
        text color 'R'
        text align center center
        action
        "
            FLmenu = 'newClassicDialog'
        "
    }
	button
	{
		enabled "FLmenu == 'FLStartPage'"
		area 108 224 650 40
		text "Graphics Overhaul"
		text style "normal"
		text color '$'
		text align center center
		action
		"
			FLmenu = 'newGraphics'
		"
	}
	button
	{
		enabled "FLmenu == 'FLStartPage'"
		area 108 264 650 40
		text "Two Journal Options"
		text style "normal"
		text color '$'
		text align center center
		action
		"
			FLmenu = 'newJournal'
		"
	}
	button
	{
		enabled "FLmenu == 'FLStartPage'"
		area 108 304 650 40
		text "Two Quickloot Options"
		text style "normal"
		text color '$'
		text align center center
		action
		"
			FLmenu = 'newQL'
		"
	}
	button
	{
		enabled "FLmenu == 'FLStartPage'"
		area 108 344 650 40
		text "Improved Dialog Window"
		text style "normal"
		text color '$'
		text align center center
		action
		"
			FLmenu = 'newDialog'
		"
	}
	button
	{
		enabled "FLmenu == 'FLStartPage'"
		area 108 384 650 40
		text "Restore Missing Portraits"
		text style "normal"
		text color '$'
		text align center center
		action
		"
			FLmenu = 'newPortraits'
		"
	}
	button
	{
		enabled "FLmenu == 'FLStartPage'"
		area 316 650 230 40
		bam GUIBUTMT
		text "CONTINUE_BUTTON"
		text style "normal"
		text align center center
		action
		"
			FLmenu = 'FLaccess'
		"
	}
	label
	{
		enabled "FLmenu == 'FLStartPage'"
		area 108 462 650 52
		text "Thanks to:"
		text point 22
		text style "button"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'FLStartPage'"
		area 108 514 650 124
		text lua "'Mr2150 (co-developer of this mod)\nlefreut (creator of the missing portraits and classic dialog components)\nAdul (creator of the store screen tweaks)\nAedan, Cahir, Etamin, rede9 (translators)'"
		text style "normal"
		text align center center
	}	

--new inventory
label
    {
        enabled "FLmenu == 'newInventory'"
        area 114 74 644 66
        text "Enhanced inventory now shows backpacks of all party members at the same time."
        text point 22
        text style "normal"
        text align left center
    }
    label
    {
        enabled "FLmenu == 'newInventory'"
        area 114 136 644 182
        text "You can shift between backpacks by clicking on portraits or any of their slots, after that, the respective character will be selected. However, you can transfer items only through portraits. After an item is transfered through portrait, a backpack of a non-selected character will be updated by either selecting it, or when mouse cursor leaves the portrait element of that character."
        text point 14
        text style "normal"
        text align left center
    }
    label
    {
        enabled "FLmenu == 'newInventory'"
        area 114 318 162 308
        text "An extended combat stats information, that was present in earlier versions is hidden under a tooltip of combat stat labels. If you hower over them, the information will be shown."
        text point 14
        text style "normal"
        text align left center
    }
    button
    {
        enabled "FLmenu == 'newInventory'"
        area 316 650 230 40
        bam GUIBUTMT
        text "BACK_BUTTON"
        text style "button"
        action
        "
            FLmenu = 'FLStartPage'
        "
    }
    label
    {
        enabled "FLmenu == 'newInventory'"
        area 286 312 478 276
        rectangle 6
    }
    label
    {
        enabled "FLmenu == 'newInventory'"
        area 292 318 466 262
        bitmap "RGSS07"
    }
--classic dialog
label
    {
        enabled "FLmenu == 'newClassicDialog'"
        area 114 106 644 66
        text "In the UI Settings screen, you can now toggle on a 'classic dialog' option, which displays the static dialog window in the bottom center of the screen."
        text point 22
        text style "normal"
        text align left center
    }
    label
    {
        enabled "FLmenu == 'newClassicDialog'"
        area 114 173 644 88
        text "This feature is based on lefreut's 'BGEE 1.3-ish dialog box' tweak, that allows to scroll up to see the dialog history."
        text point 14
        text style "normal"
        text align left center
    }
    button
    {
        enabled "FLmenu == 'newClassicDialog'"
        area 316 650 230 40
        bam GUIBUTMT
        text "BACK_BUTTON"
        text style "button"
        action
        "
            FLmenu = 'FLStartPage'
        "
    }
    label
    {
        enabled "FLmenu == 'newClassicDialog'"
        area 150 262 560 218
        rectangle 6
    }
    label
    {
        enabled "FLmenu == 'newClassicDialog'"
        area 158 268 546 206
        bitmap "RGSS08"
    }
-- newGraphics menu
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 74 650 96
		text "Several layouts were changed in this update. The most noticable is the main gameplay screen, which (aside from the new graphics) now has all the gameplay buttons at the bottom of the screen."
		text point 22
		text style "normal"
		text align left center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 212 50 50 
		bam RGGBUT
		sequence 0
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 174 212 142 50
		text "Map"
		text point 22
		text style "normal"
		text align left center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 262 50 50 
		bam RGGBUT
		sequence 2
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 174 262 142 50
		text "Journal"
		text point 22
		text style "normal"
		text align left center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 312 50 50 
		bam RGGBUT
		sequence 1
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 174 312 142 50
		text "Inventory"
		text point 22
		text style "normal"
		text align left center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 362 50 50 
		bam RGGBUT
		sequence 3
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 174 362 142 50
		text "Character Record"
		text point 22
		text style "normal"
		text align left center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 412 50 50 
		bam RGGBUT
		sequence 4
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 174 412 142 50
		text "Mage Spellbook"
		text point 22
		text style "normal"
		text align left center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 462 50 50 
		bam RGGBUT
		sequence 5
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 174 462 142 50
		text "Priest Scrollbook"
		text point 22
		text style "normal"
		text align left center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 688 212 50 50
		bam RGGBUT
		sequence 10
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 540 212 142 50
		text "Quicksave"
		text point 22
		text style "normal"
		text align right center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 688 262 50 50
		bam RGGBUT
		sequence 8
		frame lua "rggbuttHighlight2()"
	}	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 540 262 142 50
		text "Quickloot"
		text point 22
		text style "normal"
		text align right center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 688 312 50 50
		bam RGGBUT
		sequence 7
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 540 312 142 50
		text "Sleep"
		text point 22
		text style "normal"
		text align right center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 688 362 50 50
		bam RGGBUT
		sequence 6
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 540 362 142 50
		text "Reveal Details"
		text point 22
		text style "normal"
		text align right center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 688 412 50 50
		bam RGGBUT
		sequence 9
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 540 412 142 50
		text "Toggle AI"
		text point 22
		text style "normal"
		text align right center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 688 462 50 50
		bam RGGBUT
		sequence 11
		frame lua "rggbuttHighlight2()"
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 540 462 142 50
		text "Select All"
		text point 22
		text style "normal"
		text align right center
	}
	
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 173 208 39
		text "LEFT SIDEBAR"
		text point 22
		text style "normal"
		text color '$'
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 540 173 200 39
		text "RIGHT SIDEBAR"
		text point 22
		text style "normal"
		text color '$'
		text align right center
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 544 650 36
		text "Also, the In-game Options menu screen is now more stylish."
		text point 22
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newGraphics'"
		area 108 580 650 46
		text "Lastly, new chapters and dream sequences were overhauled. They will now fit to the entire screen with the text being shown on a darkened background above the artwork."
		text point 22
		text style "normal"
		text align left center
	}

	button	
	{
		enabled "FLmenu == 'newGraphics'"
		area 316 650 230 40
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action
		"
			FLmenu = 'FLStartPage'
		"
	}
	
-- newPortraits menu
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 108 74 650 110
		text "All available NPC portraits and portrait packs from BG:EE and BG2:EE will now appear in the Portrait Picker list. This includes for example portraits of Hexxat, New Imoen, or Yanner's portraits from BG2:EE."
		text point 22
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 265 197 113 173
		rectangle 0 
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 269 201 105 165
		bitmap "YANNER4L"
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 386 197 113 173
		rectangle 0 
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 390 201 105 165
		bitmap "YANNER1L"
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 506 197 113 173
		rectangle 0 
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 510 201 105 165
		bitmap "ohhexxl"
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 386 387 113 173
		rectangle 0 
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 390 391 105 165
		bitmap "YANNER6L"
	}	
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 265 387 113 173
		rectangle 0 
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 269 391 105 165
		bitmap "YANNER5L"
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 506 387 113 173
		rectangle 0 
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 510 391 105 165
		bitmap "bdimoenl"
	}
	label
	{
		enabled "FLmenu == 'newPortraits'"
		area 108 560 650 72
		text "This component is an inclusion of a mod 'Restore Missing Portraits' made by lefreut."
		text point 22
		text style "normal"
		text align left center
	}	
	button
	{
		enabled "FLmenu == 'newPortraits'"
		area 316 650 230 40
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action
		"
			FLmenu = 'FLStartPage'
		"
	}
-- newJournal menu
		label
	{
		enabled "FLmenu == 'newJournal'"
		area 108 74 650 40
		text "Two journal options are available:"
		text point 22
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newJournal'"
		area 108 118 70 40
		text "Large"
		text style "normal"
		text color '$'
		text align center center
	}
	label
	{
		enabled "FLmenu == 'newJournal'"
		area 118 158 622 96
		text "The Large journal fills the screen with a window the same size as the other windows.  It gives you access to all quests and filters these by Active (left) and Completed (right).  You can toggle between quests and notes.  Navigating, checking and adding notes, and getting a status update is simple with the large display."
		text point 14
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newJournal'"
		area 118 254 622 32
		text "Notes are pre-filtered by system and user notes (left and right respectively)."
		text point 14
		text style "normal"
		text align left center
	}
	button
	{
		enabled "FLmenu == 'newJournal'"
		area 316 650 230 40
		bam GUIBUTMT
		text "NEXT_BUTTON"
		text style "button"
		action
		"
			FLmenu = 'newJournal2'
		"
	}
	label
	{
		enabled "FLmenu == 'newJournal'"
		area 128 286 592 326
		rectangle 6
	}
	label
	{
		enabled "FLmenu == 'newJournal'"
		area 134 290 580 316
		bitmap "RGSS01"
	}
	
	-- Page 2
	label
	{
		enabled "FLmenu == 'newJournal2'"
		area 378 106 62 40
		text "Small"
		text style "normal"
		text color '$'
		text align center center
	}
	label
	{
		enabled "FLmenu == 'newJournal2'"
		area 386 140 314 110
		text "The small journal works much like the large journal however it doesn't fill the screen and can be dragged to a suitable position."
		text point 14
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newJournal2'"
		area 386 250 314 110
		text "It can be filtered by All, Active and Completed quests, and you can filter notes by just user created notes."
		text point 14
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newJournal2'"
		area 118 98 212 320
		rectangle 6
	}
	label
	{
		enabled "FLmenu == 'newJournal2'"
		area 122 102 204 312
		bitmap "RGSS02"
	}
	label
	{
		enabled "FLmenu == 'newJournal2'"
		area 114 526 632 96
		text "With both journals, you can close all opened quests by clicking Current Quests.  Clicking the journal update pop-up now takes you straight to the specific quest (where a matching quest is found)."
		text point 14
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newJournal2'"
		area 114 430 632 82
		text "Hitting the chapter button will toggle between journals but your preferred journal can be set to default in the settings."
		text point 14
		text style "normal"
		text align left center
	}
	button
	{
		enabled "FLmenu == 'newJournal2'"
		area 316 650 230 40
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action
		"
			FLmenu = 'FLStartPage'
		"
	}
	
-- newQL menu
	label
	{
		enabled "FLmenu == 'newQL'"
		area 108 74 650 40
		text "Two quickloot options are available:"
		text point 22
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newQL'"
		area 108 140 62 40
		text "Expert"
		text style "normal"
		text color '$'
		text align center center
	}
	label
	{
		enabled "FLmenu == 'newQL'"
		area 282 386 104 38
		text "Advanced"
		text style "normal"
		text color '$'
		text align center center
	}
		
	label
	{
		enabled "FLmenu == 'newQL'"
		area 114 173 385 113
		text "Expert arranges up to 60 items on the ground in a number of rows.  You can customise the number of rows.  This makes it easier to see multiple items and ensure you get the best loot."
		text point 14
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newQL'"
		area 296 418 462 110
		text "Advanced provides a scrollable list of all quickloot items.  You can filter the list, and reposition the menu down using the center of the tab, and left/right using the corners of the tab.  The E-key opens and closes the quickloot quickly."
		text point 14
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newQL'"
		area 134 572 612 60
		text lua "'Both quickloots will \'hide\' when there is nothing to pick-up.  You can configure the quickloot to start visible or hidden from the settings menu.'"
		text point 14
		text style "normal"
		text align left center
	}
	button
	{
		enabled "FLmenu == 'newQL'"
		area 316 650 230 40
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action
		"
			FLmenu = 'FLStartPage'
		"
	}
	label
	{
		enabled "FLmenu == 'newQL'"
		area 499 122 211 264
		rectangle 6
	}
	label
	{
		enabled "FLmenu == 'newQL'"
		area 134 300 138 254
		rectangle 6
	}
	label
	{
		enabled "FLmenu == 'newQL'"
		area 140 306 125 242
		bitmap "RGSS03"
	}
	label
	{
		enabled "FLmenu == 'newQL'"
		area 506 128 198 252
		bitmap "RGSS04"
	}
-- newDialog menu
	label
	{
		enabled "FLmenu == 'newDialog'"
		area 102 386 656 76
		text "The new dialog window automatically resizes to the size of the text being displayed so you can always see the full conversation and options without scrolling (depends on your text size and scaling option)."
		text point 14
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newDialog'"
		area 102 462 656 64
		text "The window can be moved left and right just by dragging the tab at the top.  A large picture** ensures it's clear who you are speaking to."
		text point 14
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newDialog'"
		area 102 526 656 46
		text "Convenient buttons allow you to open the Message Log history, shift the dialog position and copy the dialog text to your journal."
		text point 14
		text style "normal"
		text align left center
	}
	label
	{
		enabled "FLmenu == 'newDialog'"
		area 354 590 404 42
		text "** Works great with Minor NPC Portraits mod for BGEE."
		text point 14
		text style "normal"
		text align left center
	}
	button
	{
		enabled "FLmenu == 'newDialog'"
		area 310 650 230 40
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action
		"
			FLmenu = 'FLStartPage'
		"
	}
	label
	{
		enabled "FLmenu == 'newDialog'"
		area 246 98 390 278
		rectangle 6
	}
	label
	{
		enabled "FLmenu == 'newDialog'"
		area 252 106 380 264
		bitmap "RGSS05"
	}
	
-- FLaccess menu
	label
	{
		enabled "FLmenu == 'FLaccess'"
		area 196 100 482 112
		text lua "'All new features can be found under the\n      \'OPTIONS\' > \'GAMEPLAY\' > \'UI Settings\' menu.'"
		text style "button"
		text align left center
	}	
	label
	{
		enabled "FLmenu == 'FLaccess'"
		area 224 586 80 52
		text "Click"
		text style "normal"
		text align center center
	}
	label
	{
		enabled "FLmenu == 'FLaccess'"
		area 370 586 270 52
		text "to customise your settings now!"
		text style "normal"
		text align center center
	}	
	label
	{
		enabled "FLmenu == 'FLaccess'"
		area 224 212 426 342
		rectangle 6
	}
	label
	{
		enabled "FLmenu == 'FLaccess'"
		area 234 216 412 328
		bitmap "RGSS06"
	}
	button
	{
		enabled "FLmenu == 'FLaccess'"
		area 286 586 92 52
		text "HERE"
		text style "normal"
		text color '$'
		text align center center
		action
		"
			setCurrent()
			Infinity_PushMenu('UI_SETTINGS')
		"
	}
	button
	{
		enabled "FLmenu == 'FLaccess'"
		area 316 650 230 40
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		action
		"
			setCurrent()
		"
	}
}
`
function setCurrent()
	PWSMod = CurrentVer
	Infinity_SetINIValue('Game Options','PWSFirstLoad','2.21')
	Infinity_PopMenu('FirstLoad')
end
CurrentVer = "2.21" 		-- This is what you will call this version when you release it
OldVer = "2.2" 			-- This is the highest older version
`
menu
{
	name 'START'
	align top left
	size 1024 768
	ignoreesc
	onOpen "
		if isTob == nil then
			isTob = 0
		end
		campaignsString = ''
		PWSMod = Infinity_GetINIString('Game Options','PWSFirstLoad',1)
		if PWSMod ~= CurrentVer then
			PWSMod = OldVer
			Infinity_SetINIValue('Game Options','PWSFirstLoad',OldVer)
		end
		if PWSMod == OldVer then
			Infinity_PushMenu('FirstLoad')
		end
		QuicklootMode = Infinity_GetINIString('Game Options','QuicklootMode',1)
		if QuicklootMode ~= UIStrings.UI_Advanced then
			QuicklootMode = UIStrings.UI_Expert
			Infinity_SetINIValue('Game Options','QuicklootMode',UIStrings.UI_Expert)
		end
		QuicklootENum = Infinity_GetINIString('Game Options','QuicklootENumber',1)
		if QuicklootENum ~= 'Two' and QuicklootENum ~= 'Three' and QuicklootENum ~= 'Four' and QuicklootENum ~= 'Five' and QuicklootENum ~= 'Six' then
			QuicklootENum = 'Ten'
			Infinity_SetINIValue('Game Options','QuicklootENumber','Ten')
		end
		QuicklootStartPref = Infinity_GetINIString('Game Options','QuicklootStartPreference',1)
		groundItemsButtonToggle = 1
		if QuicklootStartPref ~= UIStrings.UI_Visible then
			QuicklootStartPref = UIStrings.UI_Hidden
			Infinity_SetINIValue('Game Options','QuicklootStartPreference',UIStrings.UI_Hidden)
			groundItemsButtonToggle = 0
		end
		JournalSize = Infinity_GetINIString('Game Options','SelectedJournalSize',1)
		if JournalSize ~= UIStrings.UI_Small then
			JournalSize = UIStrings.UI_Large
			Infinity_SetINIValue('Game Options','SelectedJournalSize',UIStrings.UI_Large)
		end
		canContinue = startEngine:HasGameToContinue()
		Infinity_PlayMovie('flames','flames')
		LeftSideMenu = Infinity_GetINIValue('Game Options','LeftSideMenu',0)
		ClassicDialog = Infinity_GetINIValue('Game Options','ClassicDialog',0)
		if ClassicDialog ~= 1 then
			ClassicDialog = 0
			Infinity_SetINIValue('Game Options','ClassicDialog',0)
		end
		MultiPortraitPicker = Infinity_GetINIValue('Game Options','MultiPortraitPicker',1)
		if MultiPortraitPicker ~= 0 then
			MultiPortraitPicker = 1
			Infinity_SetINIValue('Game Options','MultiPortraitPicker',1)
		end
		LargePortraits = Infinity_GetINIValue('Game Options','LargePortraits',0)
		if LargePortraits ~= 1 then
			LargePortraits = 0
			Infinity_SetINIValue('Game Options','LargePortraits',0)
		end
		Infinity_SetINIValue('Keymap Action','Thieving',102)
		PermThief = Infinity_GetINIValue('Game Options','PermThief',0)
		if PermThief ~= 1 then
			PermThief = 0
			Infinity_SetINIValue('Game Options','PermThief',0)
		end
		getMenuPanelArea()
		e:CheckGUISong()
		local state = startEngine:GetEngineState()
		if lastStartMenu and lastStartMenu ~= 'START' then
			Infinity_PopMenu('START')
			Infinity_PushMenu(lastStartMenu)
			lastStartMenu = nil
		elseif state == 1 or state == 3 then
			Infinity_PopMenu('START')
			Infinity_PushMenu('START_SP')
		elseif state == 2 then
			Infinity_PopMenu('START')
			Infinity_PushMenu('START_MP')
		end
		Infinity_SetBackground('BACKGROUND')
		
		--If we're coming back from the tutorial make sure we're set to our actual campaign.
		--if(startEngine:GetCampaign() == const.START_CAMPAIGN_BG) then
		--	startEngine:OnSoAButtonClick(false)
		--end
	"
	onClose "
		local state = startEngine:GetEngineState()
		if state == 1 then
			Infinity_PopMenu('START_SP')
		elseif state == 2 then
			Infinity_PopMenu('START_MP')
		end

	"
	label
	{
		name "MenuPanel1"
		area 922 190 368 470
		mosaic "RGMMENU"
	}
	movie
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_SOD"
		name "flames"
		area 324 124 404 564
		loop
	}
	label
	{
		name "MenuTitle1"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 0"
		area 856 78 488 96
		bam 'RGTITLE'
		sequence 0
		frame 0
	}
	label
	{
		name "MenuTitle2"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 1"
		area 856 78 488 96
		bam 'RGTITLE'
		sequence 0
		frame 1
	}
	label
	{
		name "MenuTitle3"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BP"
		area 834 78 488 96
		bam 'RGTITLE'
		sequence 0
		frame 2
		--ScaleToClip
	}

	button
	{
		name "MenuButton1"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 250 249 45
		pad 10 8 10 8
		text style "button"
		--text 9372
		text "CONTINUE_BUTTON"
		clickable lua "canContinue"
		action "startEngine:OnContinueGame()"
	}
	button
	{
		name "MenuButton2"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 300 249 45	
		pad 10 8 10 8
		text style "button"
		text "NEW_GAME_BUTTON"
		action "Infinity_PopMenu(); startEngine:OnNewGameButtonClick();"
	}
	button
	{
		name "MenuButton3"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 350 249 45
		pad 10 8 10 8
		text style "button"
		text "LOAD_GAME_BUTTON"
		action "Infinity_PopMenu(); startEngine:OnLoadGameButtonClick()"
	}
	button
	{
		name "MenuButton4"
		bam 'STARTBUT'
		enabled "getTutorialEnabled()"
		sequence lua "getCampaignButtonSequence()"
		area 982 400 249 45
		pad 10 8 10 8
		text style "button"
		text "TUTORIAL_BUTTON"
		action 
		"
			Infinity_PopMenu();
			startEngine:OnTutorialButtonClick()
		"
	}
	button
	{
		name "MenuButton4x"
		bam 'STARTBUT'
		enabled "getCampaignImportEnabled()"
		sequence lua "getCampaignButtonSequence()"
		area 982 400 249 45
		pad 10 8 10 8
		text style "button"
		text "IMPORT_GAME_BUTTON"
		action 
		"
			Infinity_PopMenu();
			startEngine:OnImportCharacterButtonClick();
		"
	}
	button
	{
		name "MenuButton5"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 450 249 45
		pad 10 8 10 8
		text style "button"
		text "MULTIPLAYER_BUTTON"
		action 
		"
			startEngine:OnMultiPlayerButtonClick()
		"
	}
	button
	{
		name "MenuButton6"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 500 249 45
		pad 10 8 10 8
		text style "button"
		text "OPTIONS_BUTTON"
		action "
			Infinity_TransitionMenu('START_OPTIONS')
			optionsScreen:SetEngineState(1)
			startEngine:OnOptionsButtonClick()
			lastStartMenu = 'START'
		"
	}
	button
	{
		name "MenuButton7"
		area 982 550 249 45
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		pad 10 8 10 8
		text style "button"
		text "QUIT_GAME_BUTTON"
		action 
		"
			startEngine:OnQuitButtonClick()
		"
	}

	label
	{
		name "MenuCampA1"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 0"
		area 41 605 160 160
		mosaic 'rgopt4'
	}
	label
	{
		name "MenuCampA2"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 1"
		area 175 605 160 160
		mosaic 'rgopt4'
	}
	label
	{
		name "MenuCampA3"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BP"
		area 309 605 160 160
		mosaic 'rgopt4'
	}
	label
	{
		name "MenuCampB1"
		area 56 620 130 132
		mosaic 'rgopt3'
	}
	label
	{
		name "MenuCampB2"
		area 190 620 134 132
		mosaic 'rgopt3'
	}
	label
	{
		name "MenuCampB3"
		area 324 620 134 132
		mosaic 'rgopt3'
	}
	
	text
	{
		name "MenuCChooser1"
		bam "CMPGSML"
		sequence 3
		frame lua "getCampaignHighlight(1)"
		area 58 622 116 116
		align center center
		--tooltip lua "getCampaignTooltip(1)"
		action 
		"
			if startEngine:GetCampaign() ~= const.START_CAMPAIGN_BG or isTob ~= 0 then
			startEngine:OnSoAButtonClick(true);
			isTob = 0
			end
			
		"
		actionEnter
		"
			if startEngine:GetCampaign() ~= const.START_CAMPAIGN_BG or isTob ~= 0 then
			highlightedCampaign = 1;
			end
			campaignsString = t('RG_MENU_CAMPAIGN1')
		"
		actionExit
		"
			highlightedCampaign = nil;
			campaignsString = ''
		"
	}
	text
	{
		name "MenuCChooser2"
		bam "CMPGSML"
		sequence 2
		frame lua "getCampaignHighlight(2)"
		area 192 622 116 116
		align center center
		--tooltip lua "getCampaignTooltip(2)"
		action 
		"
			if startEngine:GetCampaign() ~= const.START_CAMPAIGN_BG or isTob ~= 1 then
			startEngine:OnToBButtonClick(true);
			isTob = 1
			end
			
		"
		actionEnter
		"
			if startEngine:GetCampaign() ~= const.START_CAMPAIGN_BG or isTob ~= 1 then
			highlightedCampaign = 2;
			end
			campaignsString = t('RG_MENU_CAMPAIGN2')
		"
		actionExit
		"
			highlightedCampaign = nil;
			campaignsString = ''
		"
	}
	text
	{
		name "MenuCChooser3"
		bam "CMPGSML"
		sequence 1
		frame lua "getCampaignHighlight(3)"
		area 326 622 116 116
		align center center
		--tooltip lua "getCampaignTooltip(3)"
		action 
		"
			if startEngine:GetCampaign() ~= const.START_CAMPAIGN_BP then
			startEngine:OnTBPButtonClick(true);
			isTob = 0
			end
			
		"
		actionEnter
		"
			if startEngine:GetCampaign() ~= const.START_CAMPAIGN_BP then
			highlightedCampaign = 3;
			end
			campaignsString = t('RG_MENU_CAMPAIGN3')
		"
		actionExit
		"
			highlightedCampaign = nil;
			campaignsString = ''
		"
	}
	
	label
	{
		name "MenuVsLabel"
		area 1234 727 132 41
		text style "normal"
		text align center center
		text lua "CBaldurChitin:GetVersionString()"
	}
	
	label
	{
		name "MenuCampLabel1"
		area 60 558 750 35
		text style "title"
		text color '5'
		text align left center
		text lua "t('RG_MENU_CAMPAIGN') .. ': ' .. campaignsString"
	}
	label
	{
		name "MenuCampLabel2"
		area 58 556 750 35
		text style "title"
		--text shadow 5
		text color '$'
		text align left center
		text lua "t('RG_MENU_CAMPAIGN') .. ': ' .. campaignsString"
	}
}
menu
{
	name 'START_SP'
	align top left
	size 1024 768
	ignoreEsc
	onopen
	"
	--Infinity_PlayMovie('flames','flames2')
	getMenuPanelArea()
	startEngine:SetEngineState(0)
	Infinity_TransitionMenu('START')
	"

	label
	{
		name "MenuPanel1SP"
		area 922 190 368 470
		mosaic "RGMMENU"
	}
	button
	{
		name "MenuButton1SP"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 250 249 45
		pad 10 8 10 8
		text style "button"
		--text 9372
		text "CONTINUE_BUTTON"
		clickable lua "canContinue"
	}
	button
	{
		name "MenuButton2SP"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 300 249 45	
		pad 10 8 10 8
		text style "button"
		text "NEW_GAME_BUTTON"
	}
	button
	{
		name "MenuButton3SP"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 350 249 45
		pad 10 8 10 8
		text style "button"
		text "LOAD_GAME_BUTTON"
	}
	button
	{
		name "MenuButton4SP"
		bam 'STARTBUT'
		enabled "getTutorialEnabled()"
		sequence lua "getCampaignButtonSequence()"
		area 982 400 249 45
		pad 10 8 10 8
		text style "button"
		text "TUTORIAL_BUTTON"
	}
	button
	{
		name "MenuButton4xSP"
		bam 'STARTBUT'
		enabled "getCampaignImportEnabled()"
		sequence lua "getCampaignButtonSequence()"
		area 982 400 249 45
		pad 10 8 10 8
		text style "button"
		text "IMPORT_GAME_BUTTON"
	}
	button
	{
		name "MenuButton5SP"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 450 249 45
		pad 10 8 10 8
		text style "button"
		text "MULTIPLAYER_BUTTON"
	}
	button
	{
		name "MenuButton6SP"
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		area 982 500 249 45
		pad 10 8 10 8
		text style "button"
		text "OPTIONS_BUTTON"
	}
	button
	{
		name "MenuButton7SP"
		area 982 550 249 45
		bam 'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
		pad 10 8 10 8
		text style "button"
		text "QUIT_GAME_BUTTON"
	}
}
`
OptionsButtons = 
{
	{text = "CREDITS_BUTTON", menu = "CREDITS", sequence = 0}, 
	{text = "GAMEPLAY_BUTTON", menu = "OPTIONS_GAMEPLAY", sequence = 0}, 
	{text = "GRAPHICS_BUTTON", menu = "OPTIONS_GRAPHICS", sequence = 1}, 
	{text = "LANGUAGE_BUTTON", menu = "OPTIONS_LANGUAGE", sequence = 0}, 
	{text = "MOVIES_BUTTON", menu = "", sequence = 2}, 
	{text = "SOUND_BUTTON", menu = "OPTIONS_SOUND", sequence = 1}, 
}
function onStartOptionClick()
	Infinity_PlaySound('GAM_09')
	if(selectedMenuOpt == 1 and startEngine:GetCampaign() == const.START_CAMPAIGN_SOD) then
		--If in SOD, display the end credits
		Infinity_PopMenu('START_OPTIONS')
		chapterScreen:StartTextScreen( "25ecred" )
		e:SelectEngine(chapterScreen)
		selectedMenuOpt = NIL
		return
	end
	
	if OptionsButtons[selectedMenuOpt].menu ~= '' then
		Infinity_PushMenu( OptionsButtons[selectedMenuOpt].menu )
	else
		e:SelectEngine(moviesScreen)
	end
	selectedMenuOpt = NIL
end
`
menu
{
	name 'START_OPTIONS'
	align top left
	ignoreEsc
	onopen
	"
--	Infinity_PlayMovie('flames','flames3')
	getMenuPanelArea()
	"
	size 1024 768
	
	label
	{
		name "MenuPanel1OP"
		area 922 190 368 470
		mosaic "RGMMENU"
	}
	label
	{
		name "MenuOpLabel"
		area 982 205 249 40
		text "OPTIONS_TITLE"
		text style "title"
	}
	label
	{
		name "MenuTitle1OP"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 0"
		area 856 78 488 96
		bam 'RGTITLE'
		sequence 0
		frame 0
	}
	label
	{
		name "MenuTitle2OP"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 1"
		area 856 78 488 96
		bam 'RGTITLE'
		sequence 0
		frame 1
	}
	label
	{
		name "MenuTitle3OP"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BP"
		area 834 78 488 96
		bam 'RGTITLE'
		sequence 0
		frame 2
	}

	list
	{
		
		column 
		{ 
			width 100
			label
			{
				area 0 0 -1 40
				text lua "t( OptionsButtons[rowNumber].text )"
				text style "button"
				bam STARTBUT
				sequence lua "getCampaignButtonSequence()"
				frame lua "selectedMenuOpt == rowNumber"
				align center center
			}
		}

		area 982 250 268 300
		
		name "MenuOptionsArea"
		rowheight	50
		table		"OptionsButtons"
		var			selectedMenuOpt
		scrollbar	'GUISCRC'
		hidehighlight

		action		
		"
			onStartOptionClick()
		"
	}
	
		button
	{
		name "MenuButton5OP"
		on escape
		sequence lua "getCampaignButtonSequence()"
		area 982 550 249 45
		bam STARTBUT
		pad 10 8 10 8
		text style "button"
		text "BACK_BUTTON"
		action
		"
			Infinity_PopMenu()
			e:SelectEngine(startEngine)
		"
	}
}
`

function magePageInfo()
	if bookMode == 0 then -- Regular
		if characters[id].hasSorcererBook then
			return t("SPELLS_CAN_CAST_LABEL") .. ": " .. characters[id].mageDetails[currentSpellLevel].slotsRemaining .. "/" .. characters[id].mageDetails[currentSpellLevel].maxMemorized
		else
			return t("MEMORIZED_LABEL") .. ": " .. #bottomSpells .. "/" .. characters[id].mageDetails[currentSpellLevel].maxMemorized
		end
	elseif bookMode == 1 then -- Sequencer/Contingency
		return t("SPELLS_LABEL") .. " :" .. #bottomSpells .. "/" .. #bottomSpellsPlaceHolder

	end
	return ""
end

mageBookStrings = {
	SPWI908 = {tip = 24615, title = 'CHAIN_CONTINGENCY_TITLE', action = "ADD_SPELLS_CONTINGENCY_LABEL"},
	SPWI617 = {tip = 24615, title = 'CONTINGENCY_TITLE', action = "ADD_SPELLS_CONTINGENCY_LABEL"},
	SPWI809 = {tip = 24617, title = 'SPELL_TRIGGER_TITLE', action = "ADD_SPELLS_TRIGGER_LABEL"},
	SPWI710 = {tip = 24616, title = 'SPELL_SEQUENCER_TITLE', action = "ADD_SPELLS_SEQUENCER_LABEL"},
	SPWI420 = {tip = 24616, title = 'MINOR_SEQUENCER_TITLE', action = "ADD_SPELLS_SEQUENCER_LABEL"},
	}
	
contingencyDescription = 0

function mageBookDescription()
	if mageBookEnabled == true then
		if bookMode == 0 then
			if characters[id].mageSpells[currentSpellLevel][currentBookSpell] then
				return Infinity_FetchString(characters[id].mageSpells[currentSpellLevel][currentBookSpell].description)
			else
				return t('SPELL_MEMORIZATION_HELP')
			end
		elseif bookMode == 1 then
			if contingencyDescription == 0 and currentBookSpell ~= 0 then
				return Infinity_FetchString(bookSpells[currentBookSpell].description)
			else
				lastCurrentBookSpell = 0
				if contingencyDescription == 0 then
					contingencyDescription = mageBookStrings[contingencyResRef].tip
				end
				return Infinity_FetchString(contingencyDescription)
			end
		end
	end
	return ""
end
function mageBookTitle()
	if bookMode == 1 and mageBookStrings[contingencyResRef] then
		return t(mageBookStrings[contingencyResRef].title)
	else
		return t('MAGE_BOOK_LABEL')
	end
end
function mageBookAction()
	if bookMode == 1 and mageBookStrings[contingencyResRef] then
		return t(mageBookStrings[contingencyResRef].action)
	else
		return t(characters[id].name)
	end
end


function makeBlankTable(num)
	local out = {}
	for i = 1,num do
		table.insert(out, {})
	end
	return out
end

function contingencyComplete()
	if showContingency then
		return #bottomSpells == #bottomSpellsPlaceHolder and (currentContingencyCondition or 0) > 0 and (currentContingencyTarget or 0) > 0
	else
		return #bottomSpells == #bottomSpellsPlaceHolder
	end
end

function contingencyDoneButtonText()
	if contingencyComplete() then
		return t("DONE_BUTTON")
	else
		return t("CANCEL_BUTTON")
	end
end

function filterMemorizedMageSpells(level)
	local out = {}
	currentSpellLevel = math.min(currentSpellLevel, 9)
	level = level or currentSpellLevel

	for k,v in pairs(characters[id].mageSpells[level]) do
		for i=v.memorizedCount, 1, -1 do
			local spell = deepcopy(v)
			if(i <= v.castableCount) then
				spell.castable = 1
			else
				spell.castable = 0
			end
			table.insert(out, spell)
		end
	end
	return out
end

function tableInsert(out, v)
	if mageScreen:SpellSwappedInContingency(v.resref) then
		for key,value in pairs(contingencySwapTable) do
			value.castableCount = v.castableCount
			table.insert(out, value)
		end
	else
		table.insert(out, v)
	end
end

function filterContingencyMageSpells()
	local out = {}
	if characters[id].mageSpells ~= nil and characters[id].mageSpells[currentSpellLevel] ~= nil then
		for k,v in pairs(characters[id].mageSpells[currentSpellLevel]) do
			if v.castableCount > 0 and mageScreen:SpellAllowedForContingency(v.level, v.resref) then
				tableInsert(out, v)
			end
		end
	end
	if characters[id].priestSpells ~= nil and characters[id].priestSpells[currentSpellLevel] ~= nil then
		for k,v in pairs(characters[id].priestSpells[currentSpellLevel]) do
			if v.castableCount > 0 and mageScreen:SpellAllowedForContingency(v.level, v.resref) then
				tableInsert(out, v)
			end
		end
	end
	return out
end

function findFirstDifferenceInSpellList(oldList, newList)
	local ret = -1
	local spellIndex = 1

	if oldList ~= nil and newList ~= nil then
		while oldList[spellIndex] ~= nil do
			if newList[spellIndex] == nil then
				print("New list empty at point "..spellIndex)
				ret = spellIndex
				break
			end
			if oldList[spellIndex].icon ~= newList[spellIndex].icon then
				print("Lists differ at point "..spellIndex.." "..oldList[spellIndex].icon.." vs "..newList[spellIndex].icon)
				ret = spellIndex
				break
			end
			spellIndex = spellIndex + 1
		end
		if oldList[spellIndex] == nil and newList[spellIndex] ~= nil then
			print("New list has a new spell at point "..spellIndex)
			ret = spellIndex
		end
	end

	return ret
end

showMageMemorizationFlash = false

function refreshMageBook()
	if currentSpellLevel == nil then
		currentSpellLevel = 1
	end
	if bookMode == 0 then
		if characters[id].hasMageBook then
			bookSpells = characters[id].mageSpells[currentSpellLevel]
			local spells = { current = filterMemorizedMageSpells() }
			for i = 1, 9 do
				spells[i] = filterMemorizedMageSpells(i)
			end
			
			if showMageMemorizationFlash == true then
				createMageMemorizationSparkle(0,0,36,36,"memorizedListMage", findFirstDifferenceInSpellList(bottomSpells, spells.current))
				showMageMemorizationFlash = false
			end

			bottomSpells = spells.current
			bottomSpellsPlaceHolder = makeBlankTable(characters[id].mageDetails[currentSpellLevel].maxMemorized)
			for i = 1, 9 do
				_G['bottomSpells' .. i] = spells[i]
				_G['bottomSpellsPlaceHolder' .. i] = makeBlankTable(characters[id].mageDetails[i].maxMemorized)
			end
		else
			bookSpells = characters[id].mageSpells[currentSpellLevel]
			bottomSpells = {}
			bottomSpellsPlaceHolder = {}
			for i = 1, 9 do
				_G['bottomSpells' .. i] = {}
				_G['bottomSpellsPlaceHolder' .. i] = {}
			end
		end
	elseif bookMode == 1 then
		bookSpells = filterContingencyMageSpells()
		bottomSpells = sequencerSpells
		bottomSpellsPlaceHolder = makeBlankTable(contingencyMaxSpells) 
		contingencyDescription = mageBookStrings[contingencyResRef].tip
	end
end

function setMageBookLevel(num)
	currentBookSpell = 0
	currentSpellLevel = num
	mageScreen:SetSpellLevel(num-1)
	refreshMageBook()
end

function addMageBookLevel(value)
	local level = currentSpellLevel + value

	if level >= 1 and level <= 9 then
		setMageBookLevel(level)
		currentBookSpell = 0
		currentSpellLevel = level
		mageScreen:SetSpellLevel(level - 1)
		getSpellButtHighlight(level)
		refreshMageBook()
	end
end

function incrementMageBookLevel()
	addMageBookLevel(1)
        Infinity_PlaySound('GAM_05')
end

function decrementMageBookLevel()
	addMageBookLevel(-1)
        Infinity_PlaySound('GAM_05')
end

currentAnimationID = 1
updateCounterMemorizationSparkles = 1

function updateMemorizationSparkles()
	local sparkleNumber = 1
	updateCounterMemorizationSparkles = updateCounterMemorizationSparkles + 1
	if updateCounterMemorizationSparkles > 2 then
		updateCounterMemorizationSparkles = 1
		for sparkleNumber = 1, #(memorizationFlashes), 1 do
			if memorizationFlashes[sparkleNumber][1] == true then
				memorizationFlashes[sparkleNumber][2] = memorizationFlashes[sparkleNumber][2] + 1
				if memorizationFlashes[sparkleNumber][2] > 7 then
					memorizationFlashes[sparkleNumber][1] = false
					memorizationFlashes[sparkleNumber][2] = 0
					memorizationFlashes[sparkleNumber][3] = true
				end
			end
		end
	end
end

function destroyMemorizationSparkle(instanceId)
	local ret = memorizationFlashes[instanceId][3]
	memorizationFlashes[instanceId][3] = false
	return ret
end

function showMemorizationSparkle(instanceId)
	updateMemorizationSparkles()
	return memorizationFlashes[instanceId][1]
end

function createMageMemorizationSparkle(x,y,w,h, fromList, listIndex)
	Infinity_InstanceAnimation("TEMPLATE_mageMemorizationSparkle","FLASHBR",x,y,w,h,fromList,listIndex)
	memorizationFlashes[currentAnimationID][1] = true
	memorizationFlashes[currentAnimationID][3] = false
	currentAnimationID = currentAnimationID + 1
	if currentAnimationID > #(memorizationFlashes) then
		currentAnimationID = 1
	end
end

function unmemorizingMageSpell(resref)
	local index = 1
	local sparkle = -1
	for index = 1, #(bottomSpells), 1 do
		if bottomSpells[index].resref == resref then
			sparkle = index
			if bottomSpells[index].castable == 0 then
				break
			end
		end
	end

--	createMageMemorizationSparkle(0, 0, 36, 36, 'memorizedListMage', sparkle)
end

function getSpellButtHighlight(num)
	if currentSpellLevel == num then
		return 2
	else return 0
	end
end

memorizationFlashes = 
{
	{false, 0, false},
	{false, 0, false},
	{false, 0, false},
	{false, 0, false},
	{false, 0, false},
	{false, 0, false},
	{false, 0, false},
	{false, 0, false},
	{false, 0, false},
	{false, 0, false}
}

Mage = {}

function Mage:unmemorizeSpell(level, index)
	setMageBookLevel(level)
	local spell = _G['bottomSpells' .. level][index]

	if bookMode ~= 0 or not spell then
		return
	end

	createMageMemorizationSparkle(0, 0, 36, 36, 'memorizedListMage' .. level, index)
	mageScreen:UnmemorizeSpell(spell.level, spell.memorizedIndex)
	Infinity_PlaySound('GAM_24')
end

function Mage:eraseSpell(index)
	local spell = bookSpells[index]

	if spell and bookMode == 0 and characters[id].hasSorcererBook == false then
		popup2Button('63745', 'REMOVE_BUTTON', function()
			mageScreen:EraseKnownSpell(spell.resref)
			spellDescString = nil
		end)
	end
end

`
menu
{
	name 'MAGE'
	align center center
	greyscale lua "mageBookEnabled == false"
	modal lua "bookMode == 1"

	onopen "
		showMageMemorizationFlash = false
		mgpage = nil
		setMageBookLevel(1)
		helpString = ''
--		if showContingency then
--			Infinity_SetArea('bookListMage', nil, 374, nil, 200)
--			Infinity_SetArea('bookDescription', nil, 374, nil, 200)
--		else
--			Infinity_SetArea('bookListMage', nil, 174, nil, 400)
--			Infinity_SetArea('bookDescription', nil, 174, nil, 400)
--		end
		currentContingencyCondition = 0
		currentContingencyTarget = 0
		currentAnimationID = 1
		updateCounterMemorizationSparkles = 1
		Infinity_PopMenu('WORLD_QUICKLOOT');
		pushSidebars()
		"
	onclose "
		spellDescString = nil
		popSidebars()
	"

	button
	{
		enabled 	"CurrentlyInGame()"
		on escape
		action
		"
			--Return to world screen on escape 
			e:SelectEngine(worldScreen)
		"
	}

	template
	{
		label
		{
			enabled "showMemorizationSparkle(instanceId)"
			ignoreEvents
			area 0 0 45 42
			bam "FLASHBR"
			usealpha lua "true"
			frame lua "memorizationFlashes[instanceId][2]"
			align center center
		}
		name "TEMPLATE_mageMemorizationSparkle"
	}


	label
	{
		area 0 0 1364 756
		mosaic "GUIMGB2"
	}
	label
	{
		area		210 34 944 40
		text lua	"mageBookTitle()"
		text style	"title"
	}
	label
	{
		area 		295 106 774 16
		text lua	"mageBookAction()"
		text style	"label"
	}
	
	button
	{
		area		691 184 47 45
		--bam		RGSPNUM
--		highlightgroup	mgpage
		--sequence	0
		--text "1"
		--text align center center
		--frame lua "getSpellButtHighlight(1)"
		text '1'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 0"
		action		"setMageBookLevel(1)
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		691 239 49 45
		--bam		RGSPNUM
--		highlightgroup	mgpage
		--sequence	0
		--text "2"
		--text align center center
		--frame lua "getSpellButtHighlight(2)"
		text '2'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 1"
		action		"setMageBookLevel(2)
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		691 294 48 45
		--bam		RGSPNUM
--		--highlightgroup	mgpage
		--sequence	0
		--text "3"
		--text align center center
		--frame lua "getSpellButtHighlight(3)"
		text '3'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 2"
		action		"setMageBookLevel(3)
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		691 349 48 45
		--bam		RGSPNUM
--		--highlightgroup	mgpage
		--sequence	0
		--text "4"
		--text align center center
		--frame lua "getSpellButtHighlight(4)"
		text '4'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 3"
		action		"setMageBookLevel(4)
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		691 404 48 45
		--bam		RGSPNUM
--		--highlightgroup	mgpage
		--sequence	0
		--text "5"
		--text align center center
		--frame lua "getSpellButtHighlight(5)"
		text '5'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 4"
		action		"setMageBookLevel(5)
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		691 459 48 45
		--bam		RGSPNUM
--		--highlightgroup	mgpage
		--sequence	0
		--text "6"
		--text align center center
		--frame lua "getSpellButtHighlight(6)"
		text '6'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 5"
		action		"setMageBookLevel(6)
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		691 514 48 45
		--bam		RGSPNUM
--		--highlightgroup	mgpage
		--sequence	0
		--text "7"
		--text align center center
		--frame lua "getSpellButtHighlight(7)"
		text '7'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 6"
		action		"setMageBookLevel(7)
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		691 569 48 45
		--bam		RGSPNUM
--		--highlightgroup	mgpage
		--sequence	0
		--text "8"
		--text align center center
		--frame lua "getSpellButtHighlight(8)"
		text '8'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 7"
		action		"setMageBookLevel(8)
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		691 624 48 45
		--bam		RGSPNUM
--		--highlightgroup	mgpage
		--sequence	0
		--text "9"
		--text align center center
		--frame lua "getSpellButtHighlight(9)"
		text '9'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage >= 8"
		action		"setMageBookLevel(9)
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		491 168 34 44
		bam		RGSPARR
		sequence	1
		enabled		"bookMode == 0"
		action		"incrementMageBookLevel()
                                 Infinity_PlaySound('GAM_05')"
	}
	button
	{
		area		280 168 38 44
		bam		RGSPARR
		sequence	0
		enabled		"bookMode == 0"
		action		"decrementMageBookLevel()
                                 Infinity_PlaySound('GAM_05')"
	}
	label
	{
		area 		318 171 152 29
		text lua	"Infinity_FetchString(7192) .. '  ' .. currentSpellLevel"
		text style "rg_trajan"
		--text color lua "parchment"
		text align center center
	}

	list
	{
		column 
		{ 
			width 100
			label
			{
				area	0 0 -1 -1
				bam	lua "bookSpells[rowNumber].icon"
				align	center center
			}
		}

		
		name 		"bookListMage"
		rowwidth	40
		table		"bookSpells"
		var		currentBookSpell
		scrollbar	'GUISCRC'
		action		"

			if cellNumber == 1 then
				if bookMode == 0 then
					if #bottomSpells < #bottomSpellsPlaceHolder then
						createMageMemorizationSparkle(1, 0, 40, 40, 'bookListMage', -1)
						Infinity_PlaySound('GAM_24')
						showMageMemorizationFlash = true
					end
					mageScreen:MemorizeSpell( bookSpells[currentBookSpell].level, bookSpells[currentBookSpell].index )
				elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then
					mageScreen:SequenceSpell( bookSpells[currentBookSpell].resref, bookSpells[currentBookSpell].masterResref )
				end
			end
			if lastCurrentBookSpell == currentBookSpell and cellNumber == 2 then
				currentBookSpell = 0
			end
			lastCurrentBookSpell = currentBookSpell
		"
		actionalt
		"
			if cellNumber == 1 and bookMode == 0 and characters[id].hasSorcererBook == false then
				popup2Button(24485, 'REMOVE_BUTTON', function() mageScreen:EraseKnownSpell(bookSpells[currentBookSpell].resref) end)
			end
		"

	}


	
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 188 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder1" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 243 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder2" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 298 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder3" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 353 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder4" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 408 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder5" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 463 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder6" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 518 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder7" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 573 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder8" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 628 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder9" enabled "spellDescString == nil"
	}
		
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells1[rowNumber].icon" align	center center greyscale lua "bottomSpells1[rowNumber].castable == 0" } }
		area 740 188 512 36 
		name "memorizedListMage1" enabled 	"#bottomSpells1 ~= 0" rowwidth	36 table		"bottomSpells1" var		currentBottomSpell1 enabled "spellDescString == nil"
		action "Mage:unmemorizeSpell(1, currentBottomSpell1)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells2[rowNumber].icon" align	center center greyscale lua "bottomSpells2[rowNumber].castable == 0" } }
		area 740 243 512 36 
		name "memorizedListMage2" enabled 	"#bottomSpells2 ~= 0" rowwidth	36 table		"bottomSpells2" var		currentBottomSpell2 enabled "spellDescString == nil"
		action "Mage:unmemorizeSpell(2, currentBottomSpell2)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells3[rowNumber].icon" align	center center greyscale lua "bottomSpells3[rowNumber].castable == 0" } }
		area 740 298 512 36 
		name "memorizedListMage3" enabled 	"#bottomSpells3 ~= 0" rowwidth	36 table		"bottomSpells3" var		currentBottomSpell3 enabled "spellDescString == nil"
		action "Mage:unmemorizeSpell(3, currentBottomSpell3)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells4[rowNumber].icon" align	center center greyscale lua "bottomSpells4[rowNumber].castable == 0" } }
		area 740 353 512 36 
		name "memorizedListMage4" enabled 	"#bottomSpells4 ~= 0" rowwidth	36 table		"bottomSpells4" var		currentBottomSpell4 enabled "spellDescString == nil"
		action "Mage:unmemorizeSpell(4, currentBottomSpell4)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells5[rowNumber].icon" align	center center greyscale lua "bottomSpells5[rowNumber].castable == 0" } }
		area 740 408 512 36 
		name "memorizedListMage5" enabled 	"#bottomSpells5 ~= 0" rowwidth	36 table		"bottomSpells5" var		currentBottomSpell5 enabled "spellDescString == nil"
		action "Mage:unmemorizeSpell(5, currentBottomSpell5)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells6[rowNumber].icon" align	center center greyscale lua "bottomSpells6[rowNumber].castable == 0" } }
		area 740 463 512 36 
		name "memorizedListMage6" enabled 	"#bottomSpells6 ~= 0" rowwidth	36 table		"bottomSpells6" var		currentBottomSpell6 enabled "spellDescString == nil"
		action "Mage:unmemorizeSpell(6, currentBottomSpell6)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells7[rowNumber].icon" align	center center greyscale lua "bottomSpells7[rowNumber].castable == 0" } }
		area 740 518 512 36 
		name "memorizedListMage7" enabled 	"#bottomSpells7 ~= 0" rowwidth	36 table		"bottomSpells7" var		currentBottomSpell7 enabled "spellDescString == nil"
		action "Mage:unmemorizeSpell(7, currentBottomSpell7)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells8[rowNumber].icon" align	center center greyscale lua "bottomSpells8[rowNumber].castable == 0" } }
		area 740 573 512 36
		name "memorizedListMage8" enabled 	"#bottomSpells8 ~= 0" rowwidth	36 table		"bottomSpells8" var		currentBottomSpell8 enabled "spellDescString == nil"
		action "Mage:unmemorizeSpell(8, currentBottomSpell8)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells9[rowNumber].icon" align	center center greyscale lua "bottomSpells9[rowNumber].castable == 0" } }
		area 740 628 512 36 
		name "memorizedListMage9" enabled 	"#bottomSpells9 ~= 0" rowwidth	36 table		"bottomSpells9" var		currentBottomSpell9 enabled "spellDescString == nil"
		action "Mage:unmemorizeSpell(9, currentBottomSpell9)"
	}
	--list
	--{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells[rowNumber].icon" align	center center greyscale lua "bottomSpells[rowNumber].castable == 0" } }
	--	area 598 270 470 36 
	--	name "memorizedListMage"  rowwidth	36 table		"bottomSpells" var		currentBottomSpell
	--	action "
	--		mageScreen:UnSequenceSpell( bottomSpells[currentBottomSpell].resref )	table.remove(sequencerSpells, currentBottomSpell)	bottomSpells = sequencerSpells	currentBottomSpell = 1	end	"	
	--}	
	list
	{
		column 
		{ 
			width 100
			label
			{
				area	0 0 -1 -1
				bam	lua "bottomSpells[rowNumber].icon"
				align	center center
				greyscale lua "bottomSpells[rowNumber].castable == 0"
			}
		}

		area 225 454 353 36
		
		name 		"memorizedListMage"
		enabled 	"bookMode == 1"
		rowwidth	36
		table		"bottomSpells"
		var		currentBottomSpell
		action		
		"
			if bookMode == 0 then
				showMageMemorizationFlash = false
				mageScreen:UnmemorizeSpell( bottomSpells[currentBottomSpell].level, bottomSpells[currentBottomSpell].memorizedIndex )
				Infinity_PlaySound('GAM_44')
			elseif bookMode == 1 then
				mageScreen:UnSequenceSpell( bottomSpells[currentBottomSpell].resref, bottomSpells[currentBottomSpell].masterResref )
				table.remove(sequencerSpells, currentBottomSpell)
				bottomSpells = sequencerSpells
				currentBottomSpell = 0
			end
		"
	}


	label
	{
		area 1050 144 186 36
		--text "ZAPAMATOVANÁ KOUZLA" --lua "priestPageInfo()"  .. ' ' .. Infinity_FetchString(8624)
		text lua "Infinity_FetchString(11944)"
		text style "rg_trajan"
--		text color '5'
		enabled "spellDescString == nil"
		text align right center
	}
	label
	{
		area 130 144 156 36
		--text "ZNÁMÁ KOUZLA" --lua "Infinity_FetchString(11945)"  .. ' ' .. Infinity_FetchString(8624)
		text lua "Infinity_FetchString(11945)"
		text style "rg_trajan"
--		text color '5'
		text align left center
	}
	
	text
	{
		area		740 154 508 545
		text		lua "Infinity_FetchString(spellDescString)"
		text style	"normal_parchment"
		scrollbar	'RGSCR3' --GUISCRP
		enabled 	"spellDescString ~= nil"
		--mosaic "RGPRDESC"
		--action "spellDescString = null"
	}
	
	button
	{
		area 1194 148 32 40
		enabled "spellDescString ~= nil"
		text "X"
		text style "rg_trajan"
		--text shadow 1
		--text color lua "parchment"
		action "spellDescString = nil"
	}

	button
	{
		area 1154 148 33 40
		enabled "spellDescString ~= nil"
		text "Ø"
		text style "rg_trajan"
		--text shadow 1
		--text color lua "parchment"
		action "Mage:eraseSpell(spellDescIndex)"
	}
	
	list
	{
		column 
		{ 
			width 0
			label
			{
				area	0 0 -1 -1
				bam	"SPELFRMS"
				sequence 0
				align	center center
			}
		}

--		area 162 324 694 36
		
		enabled "#bottomSpellsPlaceHolder ~= 0 or bookMode == 1"
		rowwidth	36
		table		"bottomSpellsPlaceHolder"
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area	0 0 -1 -1
				bam	lua "bottomSpells[rowNumber].icon"
				align	center center
				greyscale lua "bottomSpells[rowNumber].castable == 0"
			}
		}

--		area 162 324 694 36
		
		name 		"memorizedListMage"
		enabled 	"#bottomSpells ~= 0"
		rowwidth	36
		table		"bottomSpells"
		var		currentBottomSpell
		action		
		"
			if bookMode == 0 then
				showMageMemorizationFlash = false
				mageScreen:UnmemorizeSpell( bottomSpells[currentBottomSpell].level, bottomSpells[currentBottomSpell].memorizedIndex )
				Infinity_PlaySound('GAM_44')
			elseif bookMode == 1 then
				mageScreen:UnSequenceSpell( bottomSpells[currentBottomSpell].resref, bottomSpells[currentBottomSpell].masterResref )
				table.remove(sequencerSpells, currentBottomSpell)
				bottomSpells = sequencerSpells
				currentBottomSpell = 0
			end
		"
	}

	button
	{
		area 1026 84 230 44
		enabled "bookMode == 0 and (#characters[id].contingencySpells > 0 or #characters[id].sequencerSpells > 0)"
		bam GUIBUTMT
		text "CONTINGENCY_BUTTON"
		text style "button"
		--text color '5'
		action "Infinity_PushMenu('MAGE_CONTINGENCY')"
		
	}
	label
	{
		area 0 0 1364 756
		enabled "bookMode == 1"
		mosaic "RGCONTI"
	}
	
	button
	{
		area		156 175 49 45
		bam		RGSPNUM
		sequence	0
		text align center center
		frame lua "getSpellButtHighlight(1)"
		text '1'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 0 and bookMode == 1"
		action		"setMageBookLevel(1)"
	}
	button
	{
		area		210 175 49 45
		bam		RGSPNUM
		sequence	0
		text align center center
		frame lua "getSpellButtHighlight(2)"
		text '2'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 1 and bookMode == 1"
		action		"setMageBookLevel(2)"
	}
	button
	{
		area		264 175 49 45
		bam		RGSPNUM
		sequence	0
		text align center center
		frame lua "getSpellButtHighlight(3)"
		text '3'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 2 and bookMode == 1"
		action		"setMageBookLevel(3)"
	}
	button
	{
		area		318 175 49 45
		bam		RGSPNUM
		sequence	0
		text align center center
		frame lua "getSpellButtHighlight(4)"
		text '4'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 3 and bookMode == 1"
		action		"setMageBookLevel(4)"
	}
	button
	{
		area		372 175 49 45
		bam		RGSPNUM
		sequence	0
		text align center center
		frame lua "getSpellButtHighlight(5)"
		text '5'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 4 and bookMode == 1"
		action		"setMageBookLevel(5)"
	}
	button
	{
		area		426 175 49 45
		bam		RGSPNUM
		sequence	0
		text align center center
		frame lua "getSpellButtHighlight(6)"
		text '6'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 5 and bookMode == 1"
		action		"setMageBookLevel(6)"
	}
	button
	{
		area		480 175 49 45
		bam		RGSPNUM
		sequence	0
		text align center center
		frame lua "getSpellButtHighlight(7)"
		text '7'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 6 and bookMode == 1"
		action		"setMageBookLevel(7)"
	}
	button
	{
		area		534 175 49 45
		bam		RGSPNUM
		sequence	0
		text align center center
		frame lua "getSpellButtHighlight(8)"
		text '8'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage > 7 and bookMode == 1"
		action		"setMageBookLevel(8)"
	}
	button
	{
		area		588 175 49 45
		bam		RGSPNUM
		sequence	0
		text align center center
		frame lua "getSpellButtHighlight(9)"
		text '9'
		text style "rg_trajan"
		text align center center
		enabled		"maxMagePage >= 8 and bookMode == 1"
		action		"setMageBookLevel(9)"
	}
	
	label
	{
		area 126 144 358 36
		text lua "Infinity_FetchString(11941) .. ' ' .. Infinity_FetchString(8624)"
		text style "normal_parchment"
		enabled "bookMode == 1"
		text align left center
	}
	
	label
	{
		area 130 494 354 40
		text lua "magePageInfo()"
		text style "normal_parchment"
		enabled "bookMode == 1"
--		text color '5'
		text align left center
	}
	
	label
	{
		area 734 159 164 34
		enabled "showContingency"
		text "CONDITION_NORMAL"
		text style "normal"
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area		10 0 -1 -1
				text lua "Infinity_FetchString( contingencyConditions[rowNumber].strref)"
				text style "normal"
				text align left center
			}
		}

		area 734 201 232 461
		
		enabled 	"showContingency"
		rowheight	25
		table		"contingencyConditions"
		var		currentContingencyCondition
		scrollbar	'GUISCRC'

	}
	label
	{
		area 991 159 163 34
		enabled "showContingency"
		text "TARGET_NORMAL"
		text style "normal"
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area		10 0 -1 -1
				text lua "Infinity_FetchString( contingencyTargets[rowNumber].strref)"
				text style "normal"
				text align left center
			}
		}

		area 991 201 241 461
		
		enabled 	"showContingency"
		rowheight	25
		table		"contingencyTargets"
		var		currentContingencyTarget
		scrollbar	'GUISCRC'

	}

	button
	{
		area 558 679 300 43
		enabled "bookMode == 1"
		bam GUIBUTWT
		text lua "contingencyDoneButtonText()"
		text style "button"
		--text color '5'
		action 
		"
			if contingencyComplete() then
				mageScreen:DoneSequencingSpells()
			else
				mageScreen:CancelSequencingSpells()
			end
			e:SelectEngine(worldScreen)
		"
		
	}
	
	label { area 134 225 36 36 bam	lua "bookSpells[1].icon" align center center }
	label { area 396 225 36 36 bam	lua "bookSpells[2].icon" align center center }
	label { area 134 263 36 36 bam	lua "bookSpells[3].icon" align center center }
	label { area 396 263 36 36 bam	lua "bookSpells[4].icon" align center center }
	label { area 134 301 36 36 bam	lua "bookSpells[5].icon" align center center }
	label { area 396 301 36 36 bam	lua "bookSpells[6].icon" align center center }
	label { area 134 339 36 36 bam	lua "bookSpells[7].icon" align center center }
	label { area 396 339 36 36 bam	lua "bookSpells[8].icon" align center center }
	label { area 134 377 36 36 bam	lua "bookSpells[9].icon" align center center }
	label { area 396 377 36 36 bam	lua "bookSpells[10].icon" align center center }
	label { area 134 415 36 36 bam	lua "bookSpells[11].icon" align center center }
	label { area 396 415 36 36 bam	lua "bookSpells[12].icon" align center center }
	label { area 134 453 36 36 bam	lua "bookSpells[13].icon" align center center }
	label { area 396 453 36 36 bam	lua "bookSpells[14].icon" align center center }
	label { area 134 491 36 36 bam	lua "bookSpells[15].icon" align center center }
	label { area 396 491 36 36 bam	lua "bookSpells[16].icon" align center center }
	label { area 134 529 36 36 bam	lua "bookSpells[17].icon" align center center }
	label { area 396 529 36 36 bam	lua "bookSpells[18].icon" align center center }
	label { area 134 567 36 36 bam	lua "bookSpells[19].icon" align center center }
	label { area 396 567 36 36 bam	lua "bookSpells[20].icon" align center center }
	label { area 134 605 36 36 bam	lua "bookSpells[21].icon" align center center }
	label { area 396 605 36 36 bam	lua "bookSpells[22].icon" align center center }
	label { area 134 643 36 36 bam	lua "bookSpells[23].icon" align center center }
	label { area 396 643 36 36 bam	lua "bookSpells[24].icon" align center center }
	
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[1].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[1].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 225 260 36	name	"bookSpellSlot1"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot1', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[1].level, bookSpells[1].index )	helpString = bookSpells[1].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[1].resref, bookSpells[1].masterResref )	helpString = bookSpells[1].description	end	"
		actionEnter	"helpTextString = bookSpells[1].name" actionExit "helpTextString = ''" actionAlt "spellDescString = bookSpells[1].description spellDescIndex = 1"		}
	
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[2].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[2].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 225 260 36	name	"bookSpellSlot2"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot2', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[2].level, bookSpells[2].index )	helpString = bookSpells[2].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[2].resref, bookSpells[2].masterResref  )	helpString = bookSpells[2].description	end	"
		actionEnter	"helpTextString = bookSpells[2].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[2].description spellDescIndex = 2"	}

	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[3].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[3].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 263 260 36	name	"bookSpellSlot3"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot3', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[3].level, bookSpells[3].index )	helpString = bookSpells[3].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[3].resref, bookSpells[3].masterResref  )	helpString = bookSpells[3].description	end	"
		actionEnter	"helpTextString = bookSpells[3].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[3].description	spellDescIndex = 3"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[4].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[4].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 263 260 36	name	"bookSpellSlot4"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot4', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[4].level, bookSpells[4].index )	helpString = bookSpells[4].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[4].resref, bookSpells[4].masterResref  )	helpString = bookSpells[4].description	end	"
		actionEnter	"helpTextString = bookSpells[4].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[4].description	spellDescIndex = 4"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[5].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[5].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 301 260 36	name	"bookSpellSlot5"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot5', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[5].level, bookSpells[5].index )	helpString = bookSpells[5].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[5].resref, bookSpells[5].masterResref  )	helpString = bookSpells[5].description	end	"
		actionEnter	"helpTextString = bookSpells[5].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[5].description	spellDescIndex = 5"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[6].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[6].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 301 260 36	name	"bookSpellSlot6"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot6', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[6].level, bookSpells[6].index )	helpString = bookSpells[6].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[6].resref, bookSpells[6].masterResref  )	helpString = bookSpells[6].description	end	"
		actionEnter	"helpTextString = bookSpells[6].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[6].description	spellDescIndex = 6"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[7].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[7].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 339 260 36	name	"bookSpellSlot7"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot7', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[7].level, bookSpells[7].index )	helpString = bookSpells[7].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[7].resref, bookSpells[7].masterResref  )	helpString = bookSpells[7].description	end	"
		actionEnter	"helpTextString = bookSpells[7].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[7].description	spellDescIndex = 7"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[8].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[8].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 339 260 36	name	"bookSpellSlot8"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot8', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[8].level, bookSpells[8].index )	helpString = bookSpells[8].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[8].resref, bookSpells[8].masterResref  )	helpString = bookSpells[8].description	end	"
		actionEnter	"helpTextString = bookSpells[8].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[8].description	spellDescIndex = 8"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[9].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[9].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 377 260 36	name	"bookSpellSlot9"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot9', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[9].level, bookSpells[9].index )	helpString = bookSpells[9].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[9].resref, bookSpells[9].masterResref  )	helpString = bookSpells[9].description	end	"
		actionEnter	"helpTextString = bookSpells[9].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[9].description	spellDescIndex = 9"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[10].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[10].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 377 260 36	name	"bookSpellSlot10"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot10', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[10].level, bookSpells[10].index )	helpString = bookSpells[10].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[10].resref, bookSpells[10].masterResref  )	helpString = bookSpells[10].description	end	"
		actionEnter	"helpTextString = bookSpells[10].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[10].description	spellDescIndex = 10"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[11].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[11].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 415 260 36	name	"bookSpellSlot11"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot11', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[11].level, bookSpells[11].index )	helpString = bookSpells[11].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[11].resref, bookSpells[11].masterResref  )	helpString = bookSpells[11].description	end	"
		actionEnter	"helpTextString = bookSpells[11].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[11].description	spellDescIndex = 11"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[12].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[12].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 415 260 36	name	"bookSpellSlot12"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot12', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[12].level, bookSpells[12].index )	helpString = bookSpells[12].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[12].resref, bookSpells[12].masterResref  )	helpString = bookSpells[12].description	end	"
		actionEnter	"helpTextString = bookSpells[12].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[12].description	spellDescIndex = 12"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[13].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[13].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 453 260 36	name	"bookSpellSlot13"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot13', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[13].level, bookSpells[13].index )	helpString = bookSpells[13].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[13].resref, bookSpells[13].masterResref  )	helpString = bookSpells[13].description	end	"
		actionEnter	"helpTextString = bookSpells[13].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[13].description	spellDescIndex = 13"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[14].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[14].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 453 260 36	name	"bookSpellSlot14"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot14', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[14].level, bookSpells[14].index )	helpString = bookSpells[14].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[14].resref, bookSpells[14].masterResref  )	helpString = bookSpells[14].description	end	"
		actionEnter	"helpTextString = bookSpells[14].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[14].description	spellDescIndex = 14"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[15].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[15].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 491 260 36	name	"bookSpellSlot15"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot15', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[15].level, bookSpells[15].index )	helpString = bookSpells[15].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[15].resref, bookSpells[15].masterResref  )	helpString = bookSpells[15].description	end	"
		actionEnter	"helpTextString = bookSpells[15].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[15].description	spellDescIndex = 15"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[16].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[16].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 491 260 36	name	"bookSpellSlot16"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot16', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[16].level, bookSpells[16].index )	helpString = bookSpells[16].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[16].resref, bookSpells[16].masterResref  )	helpString = bookSpells[16].description	end	"
		actionEnter	"helpTextString = bookSpells[16].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[16].description	spellDescIndex = 16"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[17].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[17].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 529 260 36	name	"bookSpellSlot17"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot17', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[17].level, bookSpells[17].index )	helpString = bookSpells[17].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[17].resref, bookSpells[17].masterResref  )	helpString = bookSpells[17].description	end	"
		actionEnter	"helpTextString = bookSpells[17].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[17].description	spellDescIndex = 17"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[18].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[18].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 529 260 36	name	"bookSpellSlot18"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot18', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[18].level, bookSpells[18].index )	helpString = bookSpells[18].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[18].resref, bookSpells[18].masterResref  )	helpString = bookSpells[18].description	end	"
		actionEnter	"helpTextString = bookSpells[18].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[18].description	spellDescIndex = 18"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[19].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[19].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 567 260 36	name	"bookSpellSlot19"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot19', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[19].level, bookSpells[19].index )	helpString = bookSpells[19].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[19].resref, bookSpells[19].masterResref  )	helpString = bookSpells[19].description	end	"
		actionEnter	"helpTextString = bookSpells[19].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[19].description	spellDescIndex = 19"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[20].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[20].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 567 260 36	name	"bookSpellSlot20"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot20', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[20].level, bookSpells[20].index )	helpString = bookSpells[20].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[20].resref, bookSpells[20].masterResref  )	helpString = bookSpells[20].description	end	"
		actionEnter	"helpTextString = bookSpells[20].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[20].description	spellDescIndex = 20"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[21].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[21].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 605 260 36	name	"bookSpellSlot21"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot21', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[21].level, bookSpells[21].index )	helpString = bookSpells[21].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[21].resref, bookSpells[21].masterResref  )	helpString = bookSpells[21].description	end	"
		actionEnter	"helpTextString = bookSpells[21].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[21].description	spellDescIndex = 21"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[22].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[22].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 605 260 36	name	"bookSpellSlot22"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot22', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[22].level, bookSpells[22].index )	helpString = bookSpells[22].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[22].resref, bookSpells[22].masterResref  )	helpString = bookSpells[22].description	end	"
		actionEnter	"helpTextString = bookSpells[22].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[22].description	spellDescIndex = 22"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[23].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[23].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	134 643 260 36	name	"bookSpellSlot23"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot23', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[23].level, bookSpells[23].index )	helpString = bookSpells[23].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[23].resref, bookSpells[23].masterResref  )	helpString = bookSpells[23].description	end	"
		actionEnter	"helpTextString = bookSpells[23].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[23].description	spellDescIndex = 23"	}
    
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "bookSpells[24].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( bookSpells[24].name)" pad 37 0 0 0 text style "normal_parchment" text align left center } }
		area	396 643 260 36	name	"bookSpellSlot24"	rowwidth	260	table		"bookSpells"	align	center center	hideHighlight
		action		"
			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot24', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[24].level, bookSpells[24].index )	helpString = bookSpells[24].description
			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[24].resref, bookSpells[24].masterResref  )	helpString = bookSpells[24].description	end	"
		actionEnter	"helpTextString = bookSpells[24].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[24].description	spellDescIndex = 24"	}

--	list {	column 	{ 	width 100	label	{		area	0 0 -1 -1	bam "SPELFRMS"	sequence 0	align	center center	enabled "bookSpells[25].icon ~= null"	}	label	{	area	0 0 -1 -1	bam	lua "bookSpells[25].icon"	align	center center	}	}
--	area	208 592 200 36	name	"bookSpellSlot25"	rowheight	50	table		"bookSpells"	align	center center	tooltip lua "Infinity_FetchString( bookSpells[25].name)"
--		action		"
--			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot25', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[25].level, bookSpells[25].index )	helpString = bookSpells[25].description
--			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[25].resref, bookSpells[25].masterResref  )	helpString = bookSpells[25].description	end	"
--		actionEnter	"helpTextString = bookSpells[25].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[25].description	spellDescIndex = 25"	}
--
--	list {	column 	{ 	width 100	label	{		area	0 0 -1 -1	bam "SPELFRMS"	sequence 0	align	center center	enabled "bookSpells[26].icon ~= null"	}	label	{	area	0 0 -1 -1	bam	lua "bookSpells[26].icon"	align	center center	}	}
--	area	274 592 200 36	name	"bookSpellSlot26"	rowheight	50	table		"bookSpells"	align	center center	tooltip lua "Infinity_FetchString( bookSpells[26].name)"
--		action		"
--			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot26', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[26].level, bookSpells[26].index )	helpString = bookSpells[26].description
--			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[26].resref, bookSpells[26].masterResref  )	helpString = bookSpells[26].description	end	"
--		actionEnter	"helpTextString = bookSpells[26].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[26].description	spellDescIndex = 26"	}
--
--	list {	column 	{ 	width 100	label	{		area	0 0 -1 -1	bam "SPELFRMS"	sequence 0	align	center center	enabled "bookSpells[27].icon ~= null"	}	label	{	area	0 0 -1 -1	bam	lua "bookSpells[27].icon"	align	center center	}	}
--	area	340 592 200 36	name	"bookSpellSlot27"	rowheight	50	table		"bookSpells"	align	center center	tooltip lua "Infinity_FetchString( bookSpells[27].name)"
--		action		"
--			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot27', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[27].level, bookSpells[27].index )	helpString = bookSpells[27].description
--			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[27].resref, bookSpells[27].masterResref  )	helpString = bookSpells[27].description	end	"
--		actionEnter	"helpTextString = bookSpells[27].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[27].description	spellDescIndex = 27"	}
--
--	list {	column 	{ 	width 100	label	{		area	0 0 -1 -1	bam "SPELFRMS"	sequence 0	align	center center	enabled "bookSpells[28].icon ~= null"	}	label	{	area	0 0 -1 -1	bam	lua "bookSpells[28].icon"	align	center center	}	}
--	area	404 592 200 36	name	"bookSpellSlot28"	rowheight	50	table		"bookSpells"	align	center center	tooltip lua "Infinity_FetchString( bookSpells[28].name)"
--		action		"
--			if bookMode == 0 then	if #bottomSpells < #bottomSpellsPlaceHolder then	createMageMemorizationSparkle(1, 0, 40, 40, 'bookSpellSlot28', -1)	Infinity_PlaySound('GAM_24')	end	mageScreen:MemorizeSpell( bookSpells[28].level, bookSpells[28].index )	helpString = bookSpells[28].description
--			elseif bookMode == 1 and #bottomSpells < #bottomSpellsPlaceHolder then	mageScreen:SequenceSpell( bookSpells[28].resref, bookSpells[28].masterResref  )	helpString = bookSpells[28].description	end	"
--		actionEnter	"helpTextString = bookSpells[28].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = bookSpells[28].description	spellDescIndex = 28"	}

	list
	{
		column 
		{ 
			width 100
			label
			{
				area	0 0 -1 -1
				bam	"RGSPSLO1"
				sequence 0
				align	center center
			}
		}

		area 130 545 460 36
		
		enabled "bookMode == 1"
		rowwidth	36
		table		"bottomSpellsPlaceHolder"
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area	0 0 -1 -1
				bam	lua "bottomSpells[rowNumber].icon"
				align	center center
				greyscale lua "bottomSpells[rowNumber].castable == 0"
			}
		}

		area 130 545 460 36
		
		name 		"memorizedListMage"
		enabled 	"bookMode == 1"
		rowwidth	36
		table		"bottomSpells"
		var		currentBottomSpell
		action		
		"
			if bookMode == 0 then
				showMageMemorizationFlash = false
				mageScreen:UnmemorizeSpell( bottomSpells[currentBottomSpell].level, bottomSpells[currentBottomSpell].memorizedIndex )
				Infinity_PlaySound('GAM_44')
			elseif bookMode == 1 then
				mageScreen:UnSequenceSpell( bottomSpells[currentBottomSpell].resref, bottomSpells[currentBottomSpell].masterResref )
				table.remove(sequencerSpells, currentBottomSpell)
				bottomSpells = sequencerSpells
				currentBottomSpell = 0
			end
		"
	}
		
}

`
function refreshMageContingency()
	preparedSpells = {}
	for k, v in pairs(characters[id].contingencySpells) do
		table.insert(preparedSpells, v)
	end
	for k, v in pairs(characters[id].sequencerSpells) do
		table.insert(preparedSpells, v)
	end

end
`
menu
{
	name 'MAGE_CONTINGENCY'

	align center center
	modal

	onopen "refreshMageContingency()"
	
	label
	{
		area 0 0 864 710 
		mosaic "GUIPOPF"
	}
	label --Title
	{
		area 40 104 790 106
		text "SPELLS_PREPARED_LABEL"
		text style "label"
		text align left top
	}
	label
	{
		area 60 37 744 44
		text "CONTINGENCY_TITLE"
		text style "title"
	}
	label
	{
		area 238 258 190 36
		text "CONDITION_LABEL"
		text style "label"
		text align left center
	}
	label
	{
		area 428 258 200 36
		text "TARGET_LABEL"
		text style "label"
		text align left center
	}

	label
	{
		area 628 258 196 36
		text "SPELL_LABEL"
		text style "label"
		text align left center
	}

	list
	{
		column
		{
			width 25
			label
			{
				area	0 0 -1 -1
				text lua "t(mageBookStrings[preparedSpells[rowNumber].resref].title)"
				text style "label"
				align	left center
			}

		}
		column
		{
			width 25
			label
			{
				area	0 0 -1 -1
				text lua "Infinity_FetchString(preparedSpells[rowNumber].condition)"
				text style "label"
				align	left center
			}

		}
		column
		{
			width 25
			label
			{
				area	0 0 -1 -1
				text lua "Infinity_FetchString(preparedSpells[rowNumber].target)"
				text style "label"
				align	left center
			}

		}

		column 
		{ 
			width 5
			label
			{
				enabled "preparedSpells[rowNumber].spells[1] ~= nil"
				area	0 0 -1 -1
				bam	lua "preparedSpells[rowNumber].spells[1].icon"
				align	center center
			}
		}
		column 
		{ 
			width 5
			label
			{
				enabled "preparedSpells[rowNumber].spells[2] ~= nil"
				area	0 0 -1 -1
				bam	lua "preparedSpells[rowNumber].spells[2].icon"
				align	center center
			}
		}
		column 
		{ 
			width 5
			label
			{
				enabled "preparedSpells[rowNumber].spells[3] ~= nil"
				area	0 0 -1 -1
				bam	lua "preparedSpells[rowNumber].spells[3].icon"
				align	center center
			}
		}
		column 
		{ 
			width 5
			label
			{
				area	0 0 -1 -1
				bam	"GUISTMPC"
				sequence 2
				align	center center
				enabled "preparedSpells[rowNumber].dispellable"
			}
		}

		area 44 294 780 300
		
		rowheight	56
		table		"preparedSpells"
		var		"currentContingencySpell"
		action		"
			if (cellNumber == 7) and preparedSpells[currentContingencySpell].dispellable then
				popup2Button(24398, 'YES_BUTTON', function() mageScreen:OnDispellButtonClick(currentContingencySpell) end, 'NO_BUTTON')
			end
		"
	}
	

	button
	{
		area 316 650 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		action "Infinity_PopMenu('MAGE_CONTINGENCY')"
	}
}
menu
{
	name "POPUP_DETAILS"
	align center center
	modal

	label
	{
		area 0 0 1364 756
		mosaic "GUIINVHI"
	}
	label
	{
		area 329 31 700 44
		text lua "Infinity_FetchString(PopupDetails.title)"
		text style "title"
	}
	label
	{
		area 525 82 300 50
		text lua "Infinity_FetchString(PopupDetails.name)"
		text style "label"
	}
	text
	{
		area 156 200 1043 439
		text lua "Infinity_FetchString(PopupDetails.description)"
		text style "parchment"
		scrollbar 'GUISCRC'
	}
	label
	{
		area 338 89 52 52
		bam lua "PopupDetails.icon"
		align center center
		sequence 0
	}
	button
	{
		area 561 676 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		
		on escape
		action
		"
			Infinity_PopMenu('POPUP_DETAILS')
		"
	}

}
`
function priestPageInfo()
	if characters[id].hasShamanBook then
		return t("SPELLS_CAN_CAST_LABEL") .. ": " .. characters[id].priestDetails[currentSpellLevel].slotsRemaining .. "/" .. characters[id].priestDetails[currentSpellLevel].maxMemorized
	else
		return t("MEMORIZED_LABEL") .. ": " .. #bottomSpells .. "/" .. characters[id].priestDetails[currentSpellLevel].maxMemorized
	end
end

function priestBookDescription()
	if priestBookEnabled == true then
		if characters[id].priestSpells[currentSpellLevel][currentBookSpell] then
			return Infinity_FetchString(characters[id].priestSpells[currentSpellLevel][currentBookSpell].description)
		else
			return t('SPELL_MEMORIZATION_HELP')
		end
	end
	return ""
end

function filterMemorizedPriestSpells(level)
	local out = {}
	currentSpellLevel = math.min(currentSpellLevel, 7)
	level = level or currentSpellLevel

	for k,v in pairs(characters[id].priestSpells[level]) do
		for i=v.memorizedCount, 1, -1 do
			local spell = deepcopy(v)
			if(i <= v.castableCount) then
				spell.castable = 1
			else
				spell.castable = 0
			end
			table.insert(out, spell)
		end
	end
	return out
end


showPriestMemorizationFlash = false

function refreshPriestBook()
	if currentSpellLevel == nil then
		currentSpellLevel = 1
	end
	if characters[id].hasClericBook then
		local spells = { current = filterMemorizedPriestSpells() }
		for i = 1, 7 do
			spells[i] = filterMemorizedPriestSpells(i)
		end

		if showPriestMemorizationFlash == true then
			createPriestMemorizationSparkle(0,0,36,36,"memorizedListPriest", findFirstDifferenceInSpellList(bottomSpells, spells.current))
			showPriestMemorizationFlash = false
		end

		bottomSpells = spells.current
		bottomSpellsPlaceHolder = makeBlankTable(characters[id].priestDetails[currentSpellLevel].maxMemorized)
		for i = 1, 7 do
			_G['bottomSpells' .. i] = spells[i]
			_G['bottomSpellsPlaceHolder' .. i] = makeBlankTable(characters[id].priestDetails[i].maxMemorized)
		end
	else
		bottomSpells = {}
		bottomSpellsPlaceHolder = {}
		for i = 1, 7 do
			_G['bottomSpells' .. i] = {}
			_G['bottomSpellsPlaceHolder' .. i] = {}
		end
	end
end

function setPriestBookLevel(num)
	currentBookSpell = 0
	currentSpellLevel = num
	refreshPriestBook()
end

function addPriestBookLevel(value)
	local level = currentSpellLevel + value

	if level >= 1 and level <= 7 then
		setPriestBookLevel(level)
		currentBookSpell = 0
		currentSpellLevel = level
		priestScreen:SetSpellLevel(level-1)
		getPrSpellButtHighlight(level)
		refreshPriestBook()
	end
end

function incrementPriestBookLevel()
	addPriestBookLevel(1)
        Infinity_PlaySound('GAM_06')
end

function decrementPriestBookLevel()
	addPriestBookLevel(-1)
        Infinity_PlaySound('GAM_06')
end

function createPriestMemorizationSparkle(x,y,w,h, fromList, listIndex)
	Infinity_InstanceAnimation("TEMPLATE_priestMemorizationSparkle","FLASHBR",x,y,w,h,fromList,listIndex)
	memorizationFlashes[currentAnimationID][1] = true
	memorizationFlashes[currentAnimationID][3] = false
	currentAnimationID = currentAnimationID + 1
	if currentAnimationID > #(memorizationFlashes) then
		currentAnimationID = 1
	end
end

function unmemorizingPriestSpell(resref)
	local index = 1
	local sparkle = -1
	for index = 1, #(bottomSpells), 1 do
		if bottomSpells[index].resref == resref then
			sparkle = index
			if bottomSpells[index].castable == 0 then
				break
			end
		end
	end

--	createPriestMemorizationSparkle(0, 0, 36, 36, 'memorizedListPriest', sparkle)
end

function getPrSpellButtHighlight(num)
	if currentSpellLevel == num then
		return 2
	else return 0
	end
end

Priest = {}

function Priest:unmemorizeSpell(level, index)
	setPriestBookLevel(level)
	local spell = _G['bottomSpells' .. level][index]

	if not spell then
		return
	end

	createPriestMemorizationSparkle(0, 0, 36, 36, 'memorizedListPriest' .. level, index)
	priestScreen:UnmemorizeSpell(spell.level, spell.memorizedIndex)
	Infinity_PlaySound('GAM_44')
end

`
menu
{
	name 'PRIEST'
	align center center
	greyscale lua "priestBookEnabled == false"

	onopen 
	"
		showPriestMemorizationFlash = false
		pushSidebars()
		prpage = nil
		setPriestBookLevel(1)
		helpTextString = ''
		--spellDescString = ''
		currentAnimationID = 1
		updateCounterMemorizationSparkles = 1
		Infinity_PopMenu('WORLD_QUICKLOOT');
	"
	onclose 
	"
		popSidebars()
		spellDescString = nil
	"

	button
	{
		on escape
		action
		"
			--Return to world screen on escape 
			e:SelectEngine(worldScreen)
		"
	}

	template
	{
		label
		{
			enabled "showMemorizationSparkle(instanceId)"
			ignoreEvents
			area 0 0 45 42
			bam "FLASHBR"
			usealpha lua "true"
			frame lua "memorizationFlashes[instanceId][2]"
			align center center
		}
		name "TEMPLATE_priestMemorizationSparkle"
	}


	label
	{
		area 0 0 1364 756
		mosaic "GUIPRB2"
	}
	label
	{
		area		210 34 944 40
		text		"PRIEST_SCROLL_TITLE" 
		text style	"title"
	}
	label
	{
		area		295 90 774 32
		text lua	"characters[id].name" 
		text style	"label"
		text align center center
	}
	label
	{
		area 		295 74 774 106
		text lua	"priestName"
		text style	"label"
	}
	button
	{
		area		691 184 47 45
		--bam		GUIPRTC
--		--highlightgroup	prpage
		--sequence	0
		--frame lua "getPrSpellButtHighlight(1)"
		--enabled		"maxPriestPage > 0"
		text '1'
		text style "rg_trajan"
		text align center center
		action		"setPriestBookLevel(1)
                                 Infinity_PlaySound('GAM_06')"
	}
	button
	{
		area		691 239 49 45
		--bam		GUIPRTC
--		--highlightgroup	prpage
		--sequence	1
		--frame lua "getPrSpellButtHighlight(2)"
		--enabled		"maxPriestPage > 1"
		text '2'
		text style "rg_trajan"
		text align center center
		action		"setPriestBookLevel(2)
                                 Infinity_PlaySound('GAM_06')"
	}
	button
	{
		area		691 294 48 45
		--bam		GUIPRTC
--		--highlightgroup	prpage
		--sequence	2
		--frame lua "getPrSpellButtHighlight(3)"
		--enabled		"maxPriestPage > 2"
		text '3'
		text style "rg_trajan"
		text align center center
		action		"setPriestBookLevel(3)
                                 Infinity_PlaySound('GAM_06')"
	}
	button
	{
		area		691 349 48 45
		--bam		GUIPRTC
--		--highlightgroup	prpage
		--sequence	3
		--frame lua "getPrSpellButtHighlight(4)"
		--enabled		"maxPriestPage > 3"
		text '4'
		text style "rg_trajan"
		text align center center
		action		"setPriestBookLevel(4)
                                 Infinity_PlaySound('GAM_06')"
	}
	button
	{
		area		691 404 48 45
		--bam		GUIPRTC
--		--highlightgroup	prpage
		--sequence	4
		--frame lua "getPrSpellButtHighlight(5)"
		--enabled		"maxPriestPage > 4"
		text '5'
		text style "rg_trajan"
		text align center center
		action		"setPriestBookLevel(5)
                                 Infinity_PlaySound('GAM_06')"
	}
	button
	{
		area		691 459 48 45
		--bam		GUIPRTC
--		--highlightgroup	prpage
		--sequence	5
		--frame lua "getPrSpellButtHighlight(6)"
		--enabled		"maxPriestPage > 5"
		text '6'
		text style "rg_trajan"
		text align center center
		action		"setPriestBookLevel(6)
                                 Infinity_PlaySound('GAM_06')"
	}
	button
	{
		area		691 514 48 45
		--bam		GUIPRTC
--		--highlightgroup	prpage
		--sequence	6
		--frame lua "getPrSpellButtHighlight(7)"
		--enabled		"maxPriestPage > 6"
		text '7'
		text style "rg_trajan"
		text align center center
		action		"setPriestBookLevel(7)
                                 Infinity_PlaySound('GAM_06')"
	}
	button
	{
		area		491 168 34 44
		bam		RGSPARR
		sequence	1
		action		"incrementPriestBookLevel()
                                 Infinity_PlaySound('GAM_06')"
	}
	button
	{
		area		280 168 34 44
		bam		RGSPARR
		sequence	0
		action		"decrementPriestBookLevel()
                                 Infinity_PlaySound('GAM_06')"
	}
	label
	{
		area 		318 171 152 29
		text lua	"Infinity_FetchString(7192) .. '  ' .. currentSpellLevel"
		text style "rg_trajan"
		--text color lua "parchment"
		text align center center
	}

	list
	{
		column 
		{ 
			width 100
			label
			{
				area	0 0 -1 -1
				bam	lua "characters[id].priestSpells[currentSpellLevel][rowNumber].icon"
				align	center center
			}
		}
		name "bookListPriest"
		rowwidth	40
		table		"characters[id].priestSpells[currentSpellLevel]"
		var		currentBookSpell
		scrollbar	'GUISCRC'
		action		"
			if cellNumber == 1 then
				if #bottomSpells < #bottomSpellsPlaceHolder then
					createPriestMemorizationSparkle(3, 0, 40, 40, 'bookListPriest', -1)
					Infinity_PlaySound('GAM_24')
					showPriestMemorizationFlash = true
				end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][currentBookSpell].level, characters[id].priestSpells[currentSpellLevel][currentBookSpell].index )
			end
			if lastCurrentBookSpell == currentBookSpell and cellNumber == 2 then
				currentBookSpell = 0
			end
			lastCurrentBookSpell = currentBookSpell
		"

	}
	label { area 134 225 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][1].icon" align center center }
	label { area 396 225 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][2].icon" align center center }
	label { area 134 263 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][3].icon" align center center }
	label { area 396 263 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][4].icon" align center center }
	label { area 134 301 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][5].icon" align center center }
	label { area 396 301 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][6].icon" align center center }
	label { area 134 339 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][7].icon" align center center }
	label { area 396 339 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][8].icon" align center center }
	label { area 134 377 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][9].icon" align center center }
	label { area 396 377 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][10].icon" align center center }
	label { area 134 415 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][11].icon" align center center }
	label { area 396 415 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][12].icon" align center center }
	label { area 134 453 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][13].icon" align center center }
	label { area 396 453 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][14].icon" align center center }
	label { area 134 491 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][15].icon" align center center }
	label { area 396 491 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][16].icon" align center center }
	label { area 134 529 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][17].icon" align center center }
	label { area 396 529 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][18].icon" align center center }
	label { area 134 567 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][19].icon" align center center }
	label { area 396 567 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][20].icon" align center center }
	label { area 134 605 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][21].icon" align center center }
	label { area 396 605 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][22].icon" align center center }
	label { area 134 643 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][23].icon" align center center }
	label { area 396 643 36 36 bam	lua "characters[id].priestSpells[currentSpellLevel][24].icon" align center center }
	
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][1].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][1].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 225 260 36	name	"bookPriestSlot1"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot1', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][1].level, characters[id].priestSpells[currentSpellLevel][1].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][1].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][1].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][1].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][2].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][2].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 225 260 36	name	"bookPriestSlot2"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot2', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][2].level, characters[id].priestSpells[currentSpellLevel][2].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][2].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][2].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][2].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][3].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][3].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 263 260 36	name	"bookPriestSlot3"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot3', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][3].level, characters[id].priestSpells[currentSpellLevel][3].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][3].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][3].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][3].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][4].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][4].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 263 260 36	name	"bookPriestSlot4"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot4', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][4].level, characters[id].priestSpells[currentSpellLevel][4].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][4].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][4].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][4].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][5].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][5].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 301 260 36	name	"bookPriestSlot5"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot5', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][5].level, characters[id].priestSpells[currentSpellLevel][5].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][5].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][5].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][5].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][6].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][6].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 301 260 36	name	"bookPriestSlot6"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot6', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][6].level, characters[id].priestSpells[currentSpellLevel][6].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][6].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][6].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][6].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][7].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][7].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 339 260 36	name	"bookPriestSlot7"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot7', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][7].level, characters[id].priestSpells[currentSpellLevel][7].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][7].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][7].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][7].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][8].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][8].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 339 260 36	name	"bookPriestSlot8"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot8', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][8].level, characters[id].priestSpells[currentSpellLevel][8].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][8].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][8].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][8].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][9].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][9].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 377 260 36	name	"bookPriestSlot9"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot9', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][9].level, characters[id].priestSpells[currentSpellLevel][9].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][9].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][9].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][9].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][10].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][10].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 377 260 36	name	"bookPriestSlot10"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot10', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][10].level, characters[id].priestSpells[currentSpellLevel][10].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][10].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][10].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][10].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][11].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][11].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 415 260 36	name	"bookPriestSlot11"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot11', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][11].level, characters[id].priestSpells[currentSpellLevel][11].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][11].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][11].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][11].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][12].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][12].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 415 260 36	name	"bookPriestSlot12"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot12', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][12].level, characters[id].priestSpells[currentSpellLevel][12].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][12].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][12].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][12].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][13].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][13].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 453 260 36	name	"bookPriestSlot13"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot13', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][13].level, characters[id].priestSpells[currentSpellLevel][13].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][13].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][13].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][13].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][14].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][14].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 453 260 36	name	"bookPriestSlot14"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot14', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][14].level, characters[id].priestSpells[currentSpellLevel][14].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][14].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][14].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][14].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][15].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][15].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 491 260 36	name	"bookPriestSlot15"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot15', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][15].level, characters[id].priestSpells[currentSpellLevel][15].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][15].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][15].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][15].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][16].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][16].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 491 260 36	name	"bookPriestSlot16"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot16', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][16].level, characters[id].priestSpells[currentSpellLevel][16].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][16].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][16].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][16].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][17].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][17].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 529 260 36	name	"bookPriestSlot17"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot17', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][17].level, characters[id].priestSpells[currentSpellLevel][17].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][17].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][17].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][17].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][18].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][18].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 529 260 36	name	"bookPriestSlot18"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot18', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][18].level, characters[id].priestSpells[currentSpellLevel][18].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][18].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][18].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][18].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][19].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][19].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 567 260 36	name	"bookPriestSlot19"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot19', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][19].level, characters[id].priestSpells[currentSpellLevel][19].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][19].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][19].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][19].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][20].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][20].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 567 260 36	name	"bookPriestSlot20"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot20', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][20].level, characters[id].priestSpells[currentSpellLevel][20].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][20].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][20].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][20].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][21].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][21].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 605 260 36	name	"bookPriestSlot21"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot21', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][21].level, characters[id].priestSpells[currentSpellLevel][21].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][21].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][21].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][21].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][22].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][22].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 605 260 36	name	"bookPriestSlot22"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot22', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][22].level, characters[id].priestSpells[currentSpellLevel][22].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][22].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][22].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][22].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][23].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][23].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	134 643 260 36	name	"bookPriestSlot23"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot23', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][23].level, characters[id].priestSpells[currentSpellLevel][23].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][23].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][23].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][23].description"	}
		
	list { column { width 100 label { area		0 0 -1 -1 bam "RGKNSLOT" align left center enabled "characters[id].priestSpells[currentSpellLevel][24].icon ~= null" } label { area		5 0 -1 -1 text lua "Infinity_FetchString( characters[id].priestSpells[currentSpellLevel][24].name)" pad 37 0 0 0  text style "normal_parchment" text align left center } }
	area	396 643 260 36	name	"bookPriestSlot24"	rowwidth	260	table		"characters[id].priestSpells[currentSpellLevel]"	align	center center	hideHighlight
		action		"
			if true then	if #bottomSpells < #bottomSpellsPlaceHolder then	createPriestMemorizationSparkle(1, 0, 40, 40, 'bookPriestSlot24', -1)	Infinity_PlaySound('GAM_24')	end
				priestScreen:MemorizeSpell( characters[id].priestSpells[currentSpellLevel][24].level, characters[id].priestSpells[currentSpellLevel][24].index )	helpTextString = characters[id].priestSpells[currentSpellLevel][24].name	end	"
		actionEnter	"helpTextString = characters[id].priestSpells[currentSpellLevel][24].name" actionExit "helpTextString = ''" actionAlt 	"spellDescString = characters[id].priestSpells[currentSpellLevel][24].description"	}
		

	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 188 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder1" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 243 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder2" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 298 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder3" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 353 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder4" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 408 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder5" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 463 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder6" enabled "spellDescString == nil"
	}
	list
	{ column {  width 100 label { area	0 0 -1 -1 bam	"RGSPSLO1" sequence 0 align	center center } }
		area 740 518 512 36
		rowwidth	36 table		"bottomSpellsPlaceHolder7" enabled "spellDescString == nil"
	}

	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells1[rowNumber].icon" align	center center greyscale lua "bottomSpells1[rowNumber].castable == 0" } }
		area 740 188 512 36  
		name "memorizedListPriest1" enabled 	"#bottomSpells1 ~= 0" rowwidth	36 table		"bottomSpells1" var		currentBottomSpell1 enabled "spellDescString == nil"
		action "Priest:unmemorizeSpell(1, currentBottomSpell1)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells2[rowNumber].icon" align	center center greyscale lua "bottomSpells2[rowNumber].castable == 0" } }
		area 740 243 512 36
		name "memorizedListPriest2" enabled 	"#bottomSpells2 ~= 0" rowwidth	36 table		"bottomSpells2" var		currentBottomSpell2 enabled "spellDescString == nil"
		action "Priest:unmemorizeSpell(2, currentBottomSpell2)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells3[rowNumber].icon" align	center center greyscale lua "bottomSpells3[rowNumber].castable == 0" } }
		area 740 298 512 36 
		name "memorizedListPriest3" enabled 	"#bottomSpells3 ~= 0" rowwidth	36 table		"bottomSpells3" var		currentBottomSpell3 enabled "spellDescString == nil"
		action "Priest:unmemorizeSpell(3, currentBottomSpell3)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells4[rowNumber].icon" align	center center greyscale lua "bottomSpells4[rowNumber].castable == 0" } }
		area 740 353 512 36 
		name "memorizedListPriest4" enabled 	"#bottomSpells4 ~= 0" rowwidth	36 table		"bottomSpells4" var		currentBottomSpell4 enabled "spellDescString == nil"
		action "Priest:unmemorizeSpell(4, currentBottomSpell4)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells5[rowNumber].icon" align	center center greyscale lua "bottomSpells5[rowNumber].castable == 0" } }
		area 740 408 512 36 
		name "memorizedListPriest5" enabled 	"#bottomSpells5 ~= 0" rowwidth	36 table		"bottomSpells5" var		currentBottomSpell5 enabled "spellDescString == nil"
		action "Priest:unmemorizeSpell(5, currentBottomSpell5)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells6[rowNumber].icon" align	center center greyscale lua "bottomSpells6[rowNumber].castable == 0" } }
		area 740 463 512 36 
		name "memorizedListPriest6" enabled 	"#bottomSpells6 ~= 0" rowwidth	36 table		"bottomSpells6" var		currentBottomSpell6 enabled "spellDescString == nil"
		action "Priest:unmemorizeSpell(6, currentBottomSpell6)"
	}
	list
	{ column  {  width 100 label { area	0 0 -1 -1 bam	lua "bottomSpells7[rowNumber].icon" align	center center greyscale lua "bottomSpells7[rowNumber].castable == 0" } }
		area 740 518 512 36 
		name "memorizedListPriest7" enabled 	"#bottomSpells7 ~= 0" rowwidth	36 table		"bottomSpells7" var		currentBottomSpell7 enabled "spellDescString == nil"
		action "Priest:unmemorizeSpell(7, currentBottomSpell7)"
	}


	label
	{
		area 1050 144 186 36
		text lua "Infinity_FetchString(11944)"
		text style "rg_trajan"
--		text color '5'
		enabled "spellDescString == nil"
		text align right center
	}
	label
	{
		area 130 144 156 36
		text lua "Infinity_FetchString(11945)"
		text style "rg_trajan"
--		text color '5'
		text align left center
	}

	text
	{
		area		740 154 508 545
		text		lua "Infinity_FetchString(spellDescString)"
		text style	"normal_parchment"
		scrollbar	'RGSCR3'
		enabled 	"spellDescString ~= nil"
		--mosaic "RGPRDESC"
		--action "spellDescString = null"
	}
	
	button
	{
		area 1194 148 32 40
		enabled "spellDescString ~= nil"
		text "X"
		text style "rg_trajan"
		--text shadow 1
		--text color lua "parchment"
		action "spellDescString = nil"
	}


}

`
	versionString = ""
	function canClickSaveLoad()
		return game:IsClient() == false
	end
	
	function getEscMenuArea()
	local screenWidth, screenHeight = Infinity_GetScreenSize()
	Infinity_SetArea('RGOPT1', nil, nil, screenWidth, screenHeight)
	Infinity_SetArea('RGOPT2', (screenWidth-628)/2, (screenHeight-628)/2, nil, nil)
	Infinity_SetArea('RGVERSTRING', (screenWidth-145)/2, screenHeight-33, nil, nil)
	Infinity_SetArea('RGBUT_GAMEPLAY', (screenWidth/2)+354, (screenHeight/2)-270, nil, nil)
	Infinity_SetArea('RGBUT_GRAPHICS', (screenWidth/2)+394, (screenHeight/2)-70, nil, nil)
	Infinity_SetArea('RGBUT_SOUND', (screenWidth/2)+354, (screenHeight/2)+130, nil, nil)
	Infinity_SetArea('RGBUT_LOAD', (screenWidth/2)-510, (screenHeight/2)-270, nil, nil)
	Infinity_SetArea('RGBUT_QUIT', (screenWidth/2)-550, (screenHeight/2)-70, nil, nil)
	Infinity_SetArea('RGBUT_SAVE', (screenWidth/2)-510, (screenHeight/2)+130, nil, nil)
	if startEngine:GetCampaign() == const.START_CAMPAIGN_BG then
	Infinity_SetArea('RGESCLOGO', (screenWidth-589)/2, (screenHeight-580)/2, nil, nil)
	else
	Infinity_SetArea('RGESCLOGO', (screenWidth-586)/2, (screenHeight-582)/2, nil, nil)
	end
	end
`
menu
{
	name "ESC_MENU"
	ignoreesc
	align top left
	onOpen "
		getEscMenuArea()
		versionString = CBaldurChitin:GetVersionString()
		pushSidebars()
		rgEscPortrait = 1
		Infinity_PopMenu('WORLD_QUICKLOOT');
	"
	onClose "
		popSidebars()
		rgEscPortrait = 0
	"
	movie
	{
		name "RGOPT1"
		area 0 0 1366 768
                mosaic ESC
	}
	label
	{
		name "RGOPT2"
		area 369 70 628 628
		mosaic RGOPT2
	}	
	label
	{
		name "RGESCLOGO"
		area		388 94 587 587
		bam 		BIGLOGO
		sequence 1
		frame lua "getBigLogo()"
	}
	button
	{
		area		665 250 587 587
		action
		"
			e:SelectEngine( worldScreen );
		"
	}
--	label
--	{
--		area 260 92 350 44
--		text "OPTIONS_TITLE"
--		text style "title"
--	}
	label
	{
		name "RGVERSTRING"
		area 610 735 145 29
		text lua "versionString"
		text style "normal"
		text align center center
	}
	button
	{
		name "RGBUT_GAMEPLAY"
		area		1037 114 156 156
		bam			RGOPTBT
		text 		"GAMEPLAY_BUTTON"
		text style	"button"
		
		action
		"
			Infinity_PushMenu( 'OPTIONS_GAMEPLAY' )

		"
	}
	button
	{
		name "RGBUT_GRAPHICS"
		area		1077 314 156 156
		bam			RGOPTBT
		text 		"GRAPHICS_BUTTON"
		text style	"button"
		
		action
		"
			Infinity_PushMenu( 'OPTIONS_GRAPHICS' )

		"
	}
	button
	{
		name "RGBUT_SOUND"
		area		1037 514 156 156
		bam			RGOPTBT
		text 		"SOUND_BUTTON"
		text style	"button"
		
		action
		"
			Infinity_PushMenu( 'OPTIONS_SOUND' )

		"
	}
--	button
--	{
--		area 284 615 300 45
--		bam GUIBUTWT
--		text "RETURN_GAME_BUTTON"
--		text style "button"
--		action
--		"
--			e:SelectEngine( worldScreen );
--		"
--	}
	button
	{
		name "RGBUT_LOAD"
		area		173 114 156 156
		bam			RGOPTBT
		text style "button"
		text "LOAD_GAME_BUTTON"
		clickable lua "canClickSaveLoad()"
		action
		"
			popup2Button(19531, 'LOAD_BUTTON', function() optionsScreen:LoadGame() end)
		"
	}
	button
	{
		name "RGBUT_QUIT"
		area		133 314 156 156
		bam			RGOPTBT
		text style "button"
		text "QUIT_GAME_BUTTON"
		action
		"
			popup4Button(16456, 
			'CANCEL_BUTTON', nil, 
			'MAIN_MENU_BUTTON', function() optionsScreen:QuitGame() end, 
			'QUIT_BUTTON', function() Infinity_ShutdownGame() end, 
			'SAVE_BUTTON', function() optionsScreen:SaveGame(0) end
			) 
		"
	}
	button
	{
		name "RGBUT_SAVE"
		area		173 514 156 156
		bam			RGOPTBT
		text style "button"
		text "SAVE_GAME_BUTTON"
		clickable lua "canClickSaveLoad()"
		action
		"
			optionsScreen:SaveGame(0)
		"
	}
}
`
mapnoteSettings = {}
showNotes = 1
function showNote(instanceId)
	if(mapScreen:IsNoteVisible(mapnoteSettings[instanceId].worldCoord.x, mapnoteSettings[instanceId].worldCoord.y)
	and mapnoteSettings[instanceId].screenCoord.x >= 0
	and mapnoteSettings[instanceId].screenCoord.y >= 0) then
		return showNotes
	else
		return false
	end
end
notesAlpha = 0
function getAndIncrementNotesAlpha()
	if(notesAlpha < .99) then
		notesAlpha = notesAlpha + 0.075
	end
	if(notesAlpha > 1) then
		notesAlpha = 1
	end
	return notesAlpha
end
`
menu
{
	name 'AREA_MAP_TITLE'
	align center top
	opacity lua "notesAlpha"
	ignoreEsc
	label
	{
		name "AREA_MAP_BACKGROUND"
		area 66 0 662 92
		rectangle 0
	}
	label
	{
		area 74 8 184 74
		name "AREA_MAP_TITLE"
		text "AREA_MAP_TITLE"
		text style title
	}
		label
	{
		area 300 8 170 36
		action "mapScreen:ToggleDisplayExploredMap()"
		text "WORLDMAP_HIGHLIGHT_LABEL"
		text style "label"
		text align left center

	}
	button
	{
		area 264 8 206 36
		bam "4CHECK"
		sequence lua "mapScreen:DisplayExploredMap() and 0 or 1"
		action "mapScreen:ToggleDisplayExploredMap()"
	}

	label
	{
		area 300 42 170 40
		toggle showNotes
		text "WORLD_MAP_NOTES_LABEL"
		text style "label"
		text align left center

	}
	button
	{
		area 264 42 206 40
		bam "4CHECK"
		sequence lua "showNotes == 1 and 0 or 1"
		toggle showNotes
	}

	button
	{
		area 478 24 230 44
		bam GUIBUTMT
		sequence 0
		text style "button"
		text "WORLD_MAP_BUTTON"
		action
		"
			worldMapScreen:StartWorldMap(0)
			e:SelectEngine(worldMapScreen)
		"
	}

}
`
	areaMapHover = -1
	function showAreaMapNoteTooltip(id)
		if id == areaMapHover then
			return true
		else
			return false
		end
	end
`
menu
{
	name 'AREA_MAP'
	align left top
	ignoreesc
	onOpen "Infinity_PopMenu('WORLD_QUICKLOOT'); pushSidebars(); Infinity_PushMenu('AREA_MAP_TITLE'); notesAlpha = 0"
	onClose "popSidebars(); Infinity_PopMenu('AREA_MAP_TITLE');"
	opacity lua "getAndIncrementNotesAlpha()"
	template
	{
		button
		{
			enabled "showNote(instanceId)"
			area 0 0 45 42
			bam "FLAG1"
			sequence lua "mapnoteSettings[instanceId].sequence"
			tooltip force lua "showAreaMapNoteTooltip(instanceId)"
			tooltip force top
			tooltip lua "Infinity_FetchString(mapnoteSettings[instanceId].text)"
			tooltip position 3
			actionAlt
			"
				mapScreen:OnUserNoteClick(instanceId, mapnoteSettings[instanceId].worldCoord.x, mapnoteSettings[instanceId].worldCoord.y)
				Infinity_PushMenu('NOTE_ADD',0,0)
			"
			actionEnter
			"
				areaMapHover = instanceId
			"
			actionExit
			"
				areaMapHover = -1
			"
		}
		name "TEMPLATE_mapnote"
	}
}
`
	colorChoice = nil
`
menu
{
	name 'NOTE_ADD'
	align center center
	onOpen "colorChoice = mapScreen:GetColorChoice()"
	modal
	label
	{
		area 0 0 657 234
		mosaic GUIERR6
	}
	label
	{
		area	 32 24 596 68
		rectangle	0
	}
	edit
	{
		name 		"mapNoteEditArea"
		area		40 32 584 56
		var			mapNoteEdit
		scrollbar	'GUISCRC'
		text style	"edit"
		fill            112 111 111 64
	}
	button
	{
		area 440 170 200 44
		bam GUIBUTNT
		text style "button"
		text "DONE_BUTTON"
		action
		"
			mapScreen:OnUserNoteDoneButtonClick()
			Infinity_PopMenu('NOTE_ADD',0,0)
		"
	}
	button
	{
		area 228 170 200 44
		bam GUIBUTNT
		text style "button"
		text "CANCEL_BUTTON"
		action
		"
			Infinity_PopMenu('NOTE_ADD',0,0)
		"
	}
	button
	{
		area 18 170 200 44
		bam GUIBUTNT
		text style "button"
		text "DELETE_BUTTON"
		action
		"
			mapScreen:OnUserNoteDeleteButtonClick()
			Infinity_PopMenu('NOTE_ADD',0,0)
		"
	}
	
	button
	{
		area 29 98 45 42
		bam "FLAG1"
		highlightgroup colorChoice
		sequence 0
		action
		"
			mapScreen:OnColorChoice(0)
		"
	}
	button
	{
		area 108 98 45 42
		bam "FLAG1"
		highlightgroup colorChoice
		sequence 1
		action
		"
			mapScreen:OnColorChoice(1)
		"
	}
	button
	{
		area 187 98 45 42
		bam "FLAG1"
		highlightgroup colorChoice
		sequence 2
		action
		"
			mapScreen:OnColorChoice(2)
		"
	}
	button
	{
		area 266 98 45 42
		bam "FLAG1"
		highlightgroup colorChoice
		sequence 3
		action
		"
			mapScreen:OnColorChoice(3)
		"
	}
	button
	{
		area 345 98 45 42
		bam "FLAG1"
		highlightgroup colorChoice
		sequence 4
		action
		"
			mapScreen:OnColorChoice(4)
		"
	}
	button
	{
		area 424 98 45 42
		bam "FLAG1"
		highlightgroup colorChoice
		sequence 5
		action
		"
			mapScreen:OnColorChoice(5)
		"
	}
	button
	{
		area 503 98 45 42
		bam "FLAG1"
		highlightgroup colorChoice
		sequence 6
		action
		"
			mapScreen:OnColorChoice(6)
		"
	}
	button
	{
		area 582 98 45 42
		bam "FLAG1"
		highlightgroup colorChoice
		sequence 7
		action
		"
			mapScreen:OnColorChoice(7)
		"
	}
}
menu
{
	name "WORLD_MAP"
	align center center
	label
	{
		area 0 0 1026 726
		mosaic RGWMAP1
	}
	--label
	--{
	--	area 211 22 583 44
	--	text "WORLD_MAP_TITLE"
	--	text style "title"
	--}
	button
	{
		on escape
		area 0 0 0 0 --51 35 66 58
		bam "MAPBUT"
		action
		"
			worldMapScreen:OnCancelButtonClick()
--			e:GetActiveEngine():OnLeftPanelButtonClick(0)
		"
	}
	map
	{
		area 14 12 1000 700
		worldmap
		action
		"
			worldMapScreen:OnMapMouseDown(eventXCoord,eventYCoord)
		"
		actionDbl
		"
			worldMapScreen:TravelToSelected()
		"
		actionDrag
		"
			worldMapScreen:OnMapMouseMove(eventXCoord,eventYCoord)
		"
	}
--	button
--	{
--		area 783 715 230 44
--		enabled "worldMapScreen:IsTravelButtonVisible()"
--		bam GUIBUTMT
--		text "TRAVEL_BUTTON"
--		text style "button"
--		clickable lua "worldMapScreen:IsTravelButtonClickable()"
--		action "
--			worldMapScreen:TravelToSelected()
--		"	
--	}
}
`

chapterBackground = ""

text_CHAPTERSCROLL = ""
text_CHAPTERSCROLL_timeStart = 0
text_CHAPTERSCROLL_auto = 1
function UpdateChapterScroll(top, height, contentHeight)
	if(text_CHAPTERSCROLL_auto == 0) then
		--defer to default scrolling
		return nil
	end
	local dT = Infinity_GetClockTicks() - text_CHAPTERSCROLL_timeStart
	local timerCrawl = dT * -0.009
	if megacredits ~= '' then
		timerCrawl = dT * -0.09
	end
	local newTop = timerCrawl + height
	if(newTop + contentHeight + height < height) then
		return top
	end
	return newTop
end
function setChapterBackground(id)
	chapterBackground = chapterBackgrounds[id]
end
function rgChapterNumber()
	chapter = Infinity_GetMaxChapterPage()
	if chapterBackground == chapterBackgrounds[0]
	or chapterBackground == chapterBackgrounds[1]
	or chapterBackground == chapterBackgrounds[2]
	or chapterBackground == chapterBackgrounds[3]
	or chapterBackground == chapterBackgrounds[4]
	or chapterBackground == chapterBackgrounds[5]
	or chapterBackground == chapterBackgrounds[6]
	or chapterBackground == chapterBackgrounds[7]then	
	return Infinity_FetchString(16202 + chapter)
	elseif chapterBackground == chapterBackgrounds[8]
	or chapterBackground == chapterBackgrounds[9]
	or chapterBackground == chapterBackgrounds[10]
	or chapterBackground == chapterBackgrounds[11]
	or chapterBackground == chapterBackgrounds[12] then
	return Infinity_FetchString(70004 + chapter)
	end
end
function getChapterArea()
	local screenWidth, screenHeight = Infinity_GetScreenSize()
	Infinity_SetArea('chpBottomLeft', nil, screenHeight-355, nil, nil)
	Infinity_SetArea('chpTopRight', screenWidth-287, nil, nil, nil)
	Infinity_SetArea('chpBottomRight', screenWidth-287, screenHeight-359, nil, nil)
	Infinity_SetArea('chpImage', 25, 65, screenWidth-48, screenHeight-133)
	Infinity_SetArea('chpTextRect', screenWidth-565, 139, nil, nil)
	Infinity_SetArea('chpNumber', (screenWidth-600)/2, 10, nil, nil)
	Infinity_SetArea('chpText', screenWidth-552, 146, nil, nil)
--	Infinity_SetArea('text_CHAPTERSCROLL_item', screenWidth-552, 146, nil, nil)
	Infinity_SetArea('chpDoneButt', (screenWidth/2)+5, screenHeight-58, nil, nil)
	Infinity_SetArea('chpReplayButt', (screenWidth/2)-235, screenHeight-58, nil, nil)
end
`
menu
{
	name 'CHAPTER'
	align top left
	ignoreEsc
	onopen "getChapterArea()"
	label
	{
		name "chpImage"
		area 25 65 1872 947
		bam lua "chapterBackground"
		ScaleToClip
	}
	label
	{
		name "chpTopLeft"
		area 0 0 3840 2160
		mosaic 'RGCHPB1'
		align top left
	}
	label
	{
		name "chpBottomLeft"
		area 0 725 3840 355
		mosaic 'RGCHPB2'
		align bottom left
	}
	label
	{
		name "chpTopRight"
		area 1633 0 287 2160
		mosaic 'RGCHPB3'
		align top right
	}
	label
	{
		name "chpBottomRight"
		area 1633 721 287 359
		mosaic 'RGCHPB4'
		align bottom right
	}
	label
	{
		name "chpTextRect"
		area 1355 139 455 536
		rectangle 0
		rectangle opacity 150
	}
	text
	{
		name "chpNumber"
		area 660 10 600 50
		text lua "rgChapterNumber()"
		text style title
	}
	text
	{
--		name "text_CHAPTERSCROLL_item"
		name "chpText"
		area 1368 146 436 522
		text lua "text_CHAPTERSCROLL"
		text style normal
		scrollbar 'GUISCRC'
		scrollbar func 'UpdateChapterScroll'
		scrollbar hide lua 'text_CHAPTERSCROLL_auto == 1'
		action
		"
			text_CHAPTERSCROLL_auto = 0
		"
	}
	button
	{
		name "chpDoneButt"
		area 965 1022 230 40
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "chapterScreen:IsDoneButtonClickable()"
		action
		"
			chapterScreen:OnDoneButtonClick()
		"
	}
	button
	{
		name "chpReplayButt"
		area 725 1022 230 40
		bam GUIBUTMT
		text "REPLAY_BUTTON"
		text style "button"
		clickable lua "chapterScreen:IsReplayButtonClickable()"
		action
		"
			chapterScreen:OnReplayButtonClick()
		"
	}
}
menu
{
	name 'CHAPTER_WAITING_FOR_PROVIDER'
	modal
	align center center

	label
	{
		area 0 0 406 418
		mosaic GUIERR
	}
	label --Title
	{
		area 74 82 254 80
		text "WAITING_FOR_OTHER_PLAYERS"
		text style	"label"
	}
}
`
store = {}
storeGroupItemsVar = 0
storeItemsVar = 0
function getStoreSlotHighlight(highlight)
	if(highlight == 0) then 
		return 0
	else
		return 2 
	end
end
function storeSplitStack(count)
	storeScreen:SelectStoreItem(storeItemsVar-1, true);
	storeScreen:SetStoreItemCount(storeItemsVar-1, count);
end
function groupSplitStack(count)
	storeScreen:SelectGroupItem(storeGroupItemsVar-1, true);
	storeScreen:SetGroupItemCount(storeGroupItemsVar-1, count);
end
function checkContainerText(normalStr, containerStr)
	if(storeScreen:IsContainer()) then
		return t(containerStr)
	else
		return t(normalStr)
	end
end
function canSteal()
	local nb = 0
	for _, v in pairs(store.storeItems) do
		if v.highlight == 1 then
			nb = nb + 1
		end
	end
	return nb > 0 and nb + #store.groupItems <= 16
end
function getStoreItemCount(row)
	local count = store.storeItems[rowNumber].item.count
	if(count ~= 0xFFFF)  then 
		return count
	else
		-- maxword, infinite count.
		return nil
	end
end
StoreSearchString = ""
function StoreContainsSearchString(rowNumber)
	
	if(StoreSearchString == nil or StoreSearchString == "") then return 1 end --no search string, do nothing
	
	local text = store.storeItems[rowNumber].label
	if(string.find(string.lower(text),string.lower(StoreSearchString))) then
		return 1
	else
		return nil --does not contain search string
	end
end
GroupSearchString = ""
function GroupContainsSearchString(rowNumber)
	
	if(GroupSearchString == nil or GroupSearchString == "") then return 1 end --no search string, do nothing
	
	local text = store.groupItems[rowNumber].label
	if(string.find(string.lower(text),string.lower(GroupSearchString))) then
		return 1
	else
		return nil --does not contain search string
	end
end
`
menu
{
	name 'STORE_BUYSELL'
	align center center
	onOpen
	"
	storeScreen:UpdateBuySellPanel()
	StoreSearchString = ''
	GroupSearchString = ''
	"
	ignoreEsc
	label
	{
		area 0 0 864 756
		mosaic GUISTBSC
	}
	label
	{
		area 0 32 864 44
		text lua "checkContainerText('BUY_SELL_TITLE','CONTAINER_TITLE')"
		text style "title"
	}
	label
	{
		area 0 76 864 36
		text lua "Infinity_FetchString(storeScreen:GetStoreName())"
		text style "label"
	}
	edit
	{
		area	20 644 220 18
		var StoreSearchString
		placeholder "..."
		text style "edit"
		text color 'D'
		maxlines 1
		align left center
		fill		112 111 111 64
	}
	edit
	{
		area	446 644 220 18
		var GroupSearchString
		placeholder "..."
		text style "edit"
		text color 'D'
		maxlines 1
		align left center
		fill		112 111 111 64
	}
	button
	{
		area 666 645 15 17
		enabled "GroupSearchString ~= ''"
		mosaic RGXBUT
		action
		"
			StoreSearchString = ''
			GroupSearchString = ''
		"
	}
	button
	{
		area 240 645 15 17
		enabled "StoreSearchString ~= ''"
		mosaic RGXBUT
		action
		"
			StoreSearchString = ''
			GroupSearchString = ''
		"
	}
--	label
--	{
--		area 719 112 108 30
--		enabled "not storeScreen:IsContainer()"
--		text lua "game:GetPartyGold()"
--		text style "gold"
--		align right center
--	}
	label
	{
		area 268 637 47 30
		enabled "not storeScreen:IsContainer()"
		text "COST_LABEL"
		text style "label"
		align right center
	}
	label
	{
		area 315 637 93 30
		enabled "not storeScreen:IsContainer()"
		text lua "storeScreen:GetStoreCost()"
		text style "normal"
		align right center
	}
	label
	{
		area 696 637 47 30
		enabled "not storeScreen:IsContainer()"
		text "PRICE_LABEL"
		text style "label"
		align right center
	}
	label
	{
		area 743 637 93 30
		enabled "not storeScreen:IsContainer()"
		text lua "storeScreen:GetGroupCost()"
		text style "normal"
		align right center
	}
	
	label
	{
		area 28 122 386 34
		text "STORE_LABEL"
		text style "label"
		align left center
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 		0 56 407 -1
				enabled	"StoreContainsSearchString(rowNumber)"
				mosaic	RGSLINE
				respectClipping 
				align		center center
			}
			label
			{
				enabled	"StoreContainsSearchString(rowNumber)"
				area 0 0 64 60
				bam STONSL10
				frame lua "getStoreSlotHighlight(store.storeItems[rowNumber].highlight)"
				icon lua "store.storeItems[rowNumber].item.icon"
				tint lua "store.storeItems[rowNumber].item.tint"
				usages lua "store.storeItems[rowNumber].amountSelected" --how many selected
				count lua "store.storeItems[rowNumber].item.stackSize" --How many to a stack
				align center center
			}
			label
			{
				enabled	"StoreContainsSearchString(rowNumber)"
				area 75 0 240 60
				text lua "store.storeItems[rowNumber].label"
				text style "normal"
				text align left center
			}
			label
			{
				enabled	"StoreContainsSearchString(rowNumber) and not storeScreen:IsContainer()"
				area 315 0 91 60
				text lua "store.storeItems[rowNumber].value"
				text style "gold"
			}
			label
			{
				enabled "store.storeItems[rowNumber].valid == 0 and store.storeItems[rowNumber].highlight == 0 and StoreContainsSearchString(rowNumber)"
				area 0 0 436 56
				fill 0 0 0 150
			}
		}
		area 15 157 407 480
		hidehighlight
		rowheight	dynamic
		table		"store.storeItems"
		var			"storeItemsVar"
--		rowbackground	 GUISTBK2
		scrollbar 'GUISCRC'
		action
		"
			if not storeScreen:IsContainer() then
				if not storeScreen:IsCloseBagButtonClickable() or store.storeItems[storeItemsVar].valid == 1 then
					local highlight = true
					if(store.storeItems[storeItemsVar].highlight == 1) then highlight = false end
					storeScreen:SelectStoreItem(storeItemsVar - 1,  highlight)
				end
			elseif (store.storeItems[storeItemsVar].highlight == 1) then
				storeScreen:SelectStoreItem(storeItemsVar - 1,  false)
			else
				storeScreen:SelectStoreItem(storeItemsVar - 1,  true)
				local count = store.storeItems[storeItemsVar].item.count
				local stock = store.storeItems[storeItemsVar].numInStock
				if (count > 1) then
					storeScreen:SetStoreItemCount(storeItemsVar - 1, count)
				elseif (stock > 1) then
					storeScreen:SetStoreItemCount(storeItemsVar - 1, stock)
				end	
			end
		"
		actionalt
		"
			showItemDescription(store.storeItems[storeItemsVar].item, 1)
		"
		actionDbl
		"
			if not storeScreen:IsCloseBagButtonClickable() or store.storeItems[storeItemsVar].valid == 1 then
				local maxCount = store.storeItems[storeItemsVar].maxCount
				if(maxCount > 1) then
					popupRequester(maxCount, storeSplitStack, false)
					storeScreen:SelectStoreItem(storeItemsVar - 1, false)
				end
			end
		"
	}
	
	label
	{
		area 455 122 385 34
		text "INVENTORY_TITLE"
		text style "label"
		align left center
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 		0 56 407 -1
				enabled	"GroupContainsSearchString(rowNumber)"
				mosaic	RGSLINE
				respectClipping 
				align		center center
			}
			label
			{
				enabled	"GroupContainsSearchString(rowNumber)"
				area 0 0 64 60
				bam STONSL10
				frame lua "getStoreSlotHighlight(store.groupItems[rowNumber].highlight)"
				tint lua "store.groupItems[rowNumber].item.tint"
				icon lua "store.groupItems[rowNumber].item.icon"
				count lua "store.groupItems[rowNumber].count"
				usages lua "store.groupItems[rowNumber].item.usages"
				align center center
			}
			label
			{
				enabled	"GroupContainsSearchString(rowNumber)"
				area 75 0 240 60
				text lua "store.groupItems[rowNumber].label"
				text style "normal"
				text align left center
			}
			label
			{
				area 315 0 62 60
				enabled "not storeScreen:IsContainer() and GroupContainsSearchString(rowNumber)"
				text lua "store.groupItems[rowNumber].value"
				text style "gold"
			}
			label
			{
				--#21242 We don't grey out bags, even though they're not selectable, because we can open them.
				enabled "store.groupItems[rowNumber].valid == 0  and store.groupItems[rowNumber].item.isBag ~= 1 and GroupContainsSearchString(rowNumber)"
				area 0 0 436 56
				fill 0 0 0 150
			}
		}
		area 442 157 407 480
		enabled "not storeScreen:IsCloseBagButtonClickable()"
		hidehighlight
		rowheight	dynamic
		table		"store.groupItems"
		var			"storeGroupItemsVar"
--		rowbackground	 GUISTBK2
		scrollbar 'GUISCRC'
		action
		"
			if store.groupItems[storeGroupItemsVar].valid ~= 0 then
				if (store.groupItems[storeGroupItemsVar].highlight == 1) then
					storeScreen:SelectGroupItem(storeGroupItemsVar - 1,  false)
				else
					storeScreen:SelectGroupItem(storeGroupItemsVar - 1,  true)
					local count = store.groupItems[storeGroupItemsVar].item.count
					local stock = store.groupItems[storeGroupItemsVar].numInStock
					if (count > 1) then
						storeScreen:SetGroupItemCount(storeGroupItemsVar - 1, count)
					elseif (stock > 1) then
						storeScreen:SetGroupItemCount(storeGroupItemsVar - 1, stock)
					end
				end
			end
		"
		actionalt
		"
			showItemDescription(store.groupItems[storeGroupItemsVar].item, 1)
		"
		actionDbl
		"
			if(store.groupItems[storeGroupItemsVar].item.isBag == 1) then
				showItemDescription(store.groupItems[storeGroupItemsVar].item, 1)
				itemDescLeftButtonAction()
			else
				if store.groupItems[storeGroupItemsVar].valid ~= 0 then
					local count = store.groupItems[storeGroupItemsVar].item.count
					local stock = store.groupItems[storeGroupItemsVar].numInStock
					if(count > 1) then
						popupRequester(count, groupSplitStack, false)
					elseif stock > 1 then
						popupRequester(stock, groupSplitStack, false)
					end
					storeScreen:SelectGroupItem(storeGroupItemsVar - 1, false)
				end
			end
		"
	}

	list
	{
		column 
		{ 
			width 100
			label
			{
				area 		0 56 407 -1
				enabled	"GroupContainsSearchString(rowNumber)"
				mosaic	RGSLINE
				respectClipping 
				align		center center
			}
			label
			{
				enabled	"GroupContainsSearchString(rowNumber)"
				area 0 0 64 60
				bam STONSL10
				frame lua "getStoreSlotHighlight(store.groupItems[rowNumber].highlight)"
				tint lua "store.groupItems[rowNumber].item.tint"
				icon lua "store.groupItems[rowNumber].item.icon"
				count lua "store.groupItems[rowNumber].item.count"
				usages lua "store.groupItems[rowNumber].count"
				align center center
			}
			label
			{
				enabled	"GroupContainsSearchString(rowNumber)"
				area 75 0 240 60
				text lua "store.groupItems[rowNumber].label"
				text style "normal"
				text align left center
			}
			label
			{
				area 315 0 62 60
				enabled "not storeScreen:IsContainer() and GroupContainsSearchString(rowNumber)"
				text lua "store.groupItems[rowNumber].value"
				text style "gold"
			}
			label
			{
				enabled "store.groupItems[rowNumber].valid == 0 and GroupContainsSearchString(rowNumber)"
				area 0 0 436 56
				fill 0 0 0 150
			}
		}
		area 442 157 407 480
		enabled "storeScreen:IsCloseBagButtonClickable()"
		hidehighlight
		rowheight	dynamic
		table		"store.groupItems"
		var			"storeGroupItemsVar"
--		rowbackground	 GUISTBK2
		scrollbar 'GUISCRC'
		action
		"
			if store.groupItems[storeGroupItemsVar].valid ~= 0 then
				if (store.groupItems[storeGroupItemsVar].highlight == 1) then
					storeScreen:SelectGroupItem(storeGroupItemsVar - 1,  false)
				else
					storeScreen:SelectGroupItem(storeGroupItemsVar - 1,  true)
					local count = store.groupItems[storeGroupItemsVar].item.count
					local stock = store.groupItems[storeGroupItemsVar].numInStock
					if (count > 1) then
						storeScreen:SetGroupItemCount(storeGroupItemsVar - 1, count)
					elseif (stock > 1) then
						storeScreen:SetGroupItemCount(storeGroupItemsVar - 1, stock)
					end
				end
			end
		"
		actionalt
		"
			showItemDescription(store.groupItems[storeGroupItemsVar].item, 1)
		"
		actionDbl
		"
			if store.groupItems[storeGroupItemsVar].valid ~= 0 then
				local count = store.groupItems[storeGroupItemsVar].item.count
				local stock = store.groupItems[storeGroupItemsVar].numInStock
				if(count > 1) then
					popupRequester(count, groupSplitStack, false)
				elseif stock > 1 then
					popupRequester(stock, groupSplitStack, false)
				end
				storeScreen:SelectGroupItem(storeGroupItemsVar - 1, false)
			end
		"
	}
	
	
	button
	{
		area 118 676 201 43
		bam GUIBUTNT
		text lua "checkContainerText('BUY_BUTTON', 'TO_BACKPACK_BUTTON')"
		text style "button"
		clickable lua "storeScreen:IsBuyItemButtonClickable()"
		action
		"
			storeScreen:OnBuyItemButtonClick()
		"
	}
	button
	{
		area 546 676 201 43
		bam GUIBUTNT
		text lua "checkContainerText('SELL_BUTTON','TO_CONTAINER_BUTTON')"
		text style "button"
		clickable lua "storeScreen:IsSellItemButtonClickable()"
		action
		"
			storeScreen:OnSellItemButtonClick()
		"
	}
	button
	{
		area 332 676 201 43
		enabled "(not storeScreen:IsContainer()) and storeScreen:IsStealEnabled()"
		bam GUIBUTNT
		text "STEAL_BUTTON"
		text style "button"
		clickable lua "canSteal()"
		action
		"
			local toSteal = {}
			for k, v in pairs(store.storeItems) do
				if v.highlight == 1 then
					table.insert(toSteal, v.label)
					storeScreen:SelectStoreItem(k - 1,  false)
				end
			end
		
			for _, label in pairs(toSteal) do
				local steal = 0
				for k, v in pairs(store.storeItems) do
					if v.highlight == 1 then
						steal = 0
						break
					end
					if v.label == label then
						steal = k
					end
				end
            
				if steal == 0 then
					break
				end

				storeScreen:SelectStoreItem(steal - 1,  true)
				storeScreen:OnStealItemButtonClick()
			end
		"
	}
	button
	{
		area 332 676 201 43
		enabled "storeScreen:IsCloseBagButtonClickable()"
		bam GUIBUTNT
		text "CLOSE_CONTAINER_BUTTON"
		text style "button"
		action
		"
			storeScreen:OnCloseBagButtonClick()
		"
	}
--	button
--	{
--		area 16 629 68 90
--		encumbrance
--	}

}
`
	identifyItemsVar = 0
	
function filter(t)
	local out = {}
	for k, v in pairs(t) do
		if v.valid == 1 then
			table.insert(out, v)
		end
	end
	return out
end
function getIdx(t, i)
	local o = 0
	for k, v in pairs(t) do
		o = o + 1
		if v.valid == 1 then i = i - 1 end
		if i == 0 then break end
	end
	return o
end
`
menu
{
	name 'STORE_IDENTIFY'
	align center center
	onOpen
	"
		storeScreen:UpdateIdentifyPanel()
		store.identifyText = ''
		
	"
	ignoreEsc
	
	label
	{
		area 0 0 864 756
		mosaic GUISTIDB
	}
	label
	{
		area 0 32 864 44
		text "IDENTIFY_TITLE"
		text style "title"
	}
	label
	{
		area 0 76 864 36
		text lua "Infinity_FetchString(storeScreen:GetStoreName())"
		text style "label"
	}
--	label
--	{
--		area 719 70 110 48
--		text lua "game:GetPartyGold()"
--		text style "gold"
--	}
	label
	{
		area 26 122 252 34
		text "COST_LABEL"
		text style "label"
		text align left center
	}
	label
	{
		area 324 126 102 30
		text lua "storeScreen:GetIdentifyCost()"
		text style "gold"
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 64 60
				bam STONSL10
				frame lua "getStoreSlotHighlight(filter(store.identifyItems)[rowNumber].highlight)"
				icon lua "filter(store.identifyItems)[rowNumber].item.icon"
				tint lua "filter(store.identifyItems)[rowNumber].item.tint"
				align center center
			}
			label
			{
				area 75 0 304 60
				text lua "filter(store.identifyItems)[rowNumber].label"
				text style "normal"
				text align left center
			}
--			label
--			{
--				enabled "store.identifyItems[rowNumber].valid == 0"
--				area 0 0 379 60
--				rectangle 1
--				rectangle opacity 150
--			}
		}
		area 15 157 407 480
		hidehighlight
		rowheight	60
		table		"filter(store.identifyItems)"
		var			"identifyItemsVar"
		rowbackground	 GUISTBK2
		scrollbar 'GUISCRC'
		action
		"
			local highlight = true
			local idx = getIdx(store.identifyItems, identifyItemsVar)
			if (store.identifyItems[idx].highlight == 1) then highlight = false end
			storeScreen:SelectIdentifyItem(idx - 1,  highlight)
		"
	}
	button
	{
		area 118 676 200 44	
		bam GUIBUTNT
		text "IDENTIFY_BUTTON"
		text style "button"
		clickable lua "storeScreen:IsIdentifyItemButtonClickable()"
		action
		"
			storeScreen:OnIdentifyItemButtonClick()
		"
	}
	text
	{
		area 464 157 372 493
		text lua "store.identifyText"
		text style "normal_parchment"
		scrollbar 'GUISCRP'
	}
}
`
function getDonationFrame()
	if(store.hasDonated ~= nil and store.hasDonated == 1) then
		return 1
	else
		return 0
	end
end
storeDonateAmountEdit = 0 --no longer used in ui, but the engine needs it.
function changeDonationAmount(amount)
	if (amt == nil) then
		amt = 0
	end
	amt = amt + amount

	if (amt > 0) then
		storeDonateAmountEdit = tostring(amt)
	else
		storeDonateAmountEdit = '0'
	end
end	
`
menu
{
	name 'STORE_DONATE'
	align center center
	onOpen "storeScreen:UpdateDonatePanel()"
	ignoreEsc
	label
	{
		area 0 0 864 756
		mosaic GUISTDOB
	}
	label
	{
		area 0 32 864 44
		text "DONATE_TITLE"
		text style "title"
	}
	label
	{
		area 0 76 864 36
		text lua "Infinity_FetchString(storeScreen:GetStoreName())"
		text style "label"
	}
	label
	{
		area 68 151 311 267
		bam "DONATE"
		frame lua "getDonationFrame()"
	}
	label
	{
		area 51 431 346 38
		text "ENTER_DONATION_LABEL"
		text style "label"
	}
	edit
	{
		name		"storeDonateAmountEditArea"
		area		106 476 122 48
		var			storeDonateAmountEdit
		text style	"edit"
		text align left center
		maxlines	1
		fill            112 111 111 64
	}
	button
	{
		bam GUIOSW
		area 244 481 44 44
		sequence 0
		action
		"
			changeDonationAmount(1)
		"
		actionHold
		"
			changeDonationAmount(1)
		"
	}
	button
	{
		bam GUIOSW
		area 288 481 44 44
		sequence 1
		clickable lua "tonumber(storeDonateAmountEdit) > 0"
		action
		"
			changeDonationAmount(-1)
		"
		actionHold
		"
			changeDonationAmount(-1)
		"
	}
	button
	{
		area 118 676 200 44
		bam GUIBUTNT
		text "DONATE_BUTTON"
		text style "button"
		clickable lua "storeScreen:IsDonateButtonClickable()"
		action
		"
			storeScreen:OnDonateButtonClick()
		"
	}
--	label
--	{
--		area 700 73 110 48
--		text lua "game:GetPartyGold()"
--		text style "gold"
--	}
	text
	{
		area 473 151 345 489
		text lua "store.donateText"
		text style "normal_parchment"
		scrollbar 'GUISCRP'
	}
}
`
	function storeRest()
		storeScreen:RestParty()
	end
`
menu
{
	name 'STORE_ROOMS'
	align center center
	onOpen 
	"
		storeScreen:SetRoomType(0)
		storeScreen:UpdateRentRoomPanel()
	"
	ignoreEsc
	
	label
	{
		area 0 0 864 756
		mosaic GUISTROB
	}
	label
	{
		area 0 32 864 44
		text "ROOMS_TITLE"
		text style "title"
	}
	label
	{
		area 0 76 864 36
		text lua "Infinity_FetchString(storeScreen:GetStoreName())"
		text style "label"
	}
--	label
--	{
--		area 724 67 110 48
--		text lua "game:GetPartyGold()"
--		text style "gold"
--	}
	
	button
	{
		area 26 176 245 161
		bam "INNROOMS"
		sequence 0
		clickable lua "storeScreen:IsRoomTypeClickable(1)"
		action
		"
			storeScreen:SetRoomType(1)
			selectedRoom = Infinity_FindUIItemByName('BUTTON_room_peasant')
		"
	}
	button
	{
		name "BUTTON_room_peasant"
		area 34 346 230 44
		bam GUIBUTMT
		text "PEASANT_BUTTON"
		text style "button"
		glow lua "storeScreen:GetRoomType() == 1"
		clickable lua "storeScreen:IsRoomTypeClickable(1)"
		action
		"
			storeScreen:SetRoomType(1)
		"
	}
	
	button
	{
		area 338 176 245 161
		bam "INNROOMS"
		sequence 1
		clickable lua "storeScreen:IsRoomTypeClickable(2)"
		action
		"
			storeScreen:SetRoomType(2)
			selectedRoom = Infinity_FindUIItemByName('BUTTON_room_merchant')
		"
	}
	button
	{
		name "BUTTON_room_merchant"
		area 345 346 230 44
		bam GUIBUTMT
		text "MERCHANT_BUTTON"
		text style "button"
		glow lua "storeScreen:GetRoomType() == 2"
		clickable lua "storeScreen:IsRoomTypeClickable(2)"
		action
		"
			storeScreen:SetRoomType(2)
		"
	}
	
	button
	{
		area 26 422 245 161
		bam "INNROOMS"
		sequence 2
		clickable lua "storeScreen:IsRoomTypeClickable(3)"
		frame 0
		action
		"
			storeScreen:SetRoomType(3)
			selectedRoom = Infinity_FindUIItemByName('BUTTON_room_noble')
		"
	}
	button
	{
		name "BUTTON_room_noble"
		area 34 592 230 44
		bam GUIBUTMT
		text "NOBLE_BUTTON"
		text style "button"
		glow lua "storeScreen:GetRoomType() == 3"
		clickable lua "storeScreen:IsRoomTypeClickable(3)"
		action
		"
			storeScreen:SetRoomType(3)
		"
	}
	
	button
	{
		area 338 422 245 161
		bam "INNROOMS"
		sequence 3
		clickable lua "storeScreen:IsRoomTypeClickable(4)"
		action
		"
			storeScreen:SetRoomType(4)
			selectedRoom = Infinity_FindUIItemByName('BUTTON_room_royal')
		"
	}
	button
	{
		name "BUTTON_room_royal"
		area 345 592 230 44
		bam GUIBUTMT
		text "ROYAL_BUTTON"
		text style "button"
		glow lua "storeScreen:GetRoomType() == 4"
		clickable lua "storeScreen:IsRoomTypeClickable(4)"
		action
		"
			storeScreen:SetRoomType(4)
		"
	}
	label
	{
		area 634 543 70 38
		text "COST_LABEL"
		text style "label"
	}
	text
	{
		area 634 176 202 330
		text lua "store.roomText"
		text style "normal"
	}
	label
	{
		area 710 543 126 40
		text lua "storeScreen:GetRoomCost()"
		text style "gold"
	}
	button
	{
		area 332 676 200 44
		bam GUIBUTNT
		text "RENT_BUTTON"
		text style "button"
		action
		"
			storeScreen:OnRentRoomButtonClick()
		"
	}
}
menu
{
	name 'STORE_HEALING'
	align center center
	onOpen "storeScreen:UpdateBuySpellPanel()"
	ignoreEsc
	label
	{
		area 0 0 864 756
		mosaic GUISTIDB
	}
	label
	{
		area 0 32 864 44
		text "HEALING_TITLE"
		text style "title"
	}
	label
	{
		area 0 76 864 36
		text lua "Infinity_FetchString(storeScreen:GetStoreName())"
		text style "label"
	}
--	label
--	{
--		area 719 70 110 48
--		text lua "game:GetPartyGold()"
--		text style "gold"
--	}
	label
	{
		area 26 122 144 35
		text "COST_LABEL"
		text style "label"
		align left center
	}
	label
	{
		area 328 125 94 32
		text lua "storeScreen:GetSpellCost()"
		text style "gold"
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 64 60
				bam STONSL10
				frame lua "getStoreSlotHighlight(store.healingSpells[rowNumber].highlight)"
				icon lua "store.healingSpells[rowNumber].icon"
				tint lua "store.healingSpells[rowNumber].tint"
				align center center
			}
			label
			{
				area 75 0 240 60
				text lua "Infinity_FetchString(store.healingSpells[rowNumber].name)"
				text style "normal"
				text align left center
			}
			label
			{
				area 315 0 91 60
				text style "gold"
				text align center center
				text lua "store.healingSpells[rowNumber].value"
			}
			label
			{
				enabled "store.healingSpells[rowNumber].valid == 0"
				area 0 0 304 56
				fill 0 0 0 150
			}
		}
		area 15 157 407 507
		hidehighlight
		rowheight	60
		table		"store.healingSpells"
		var			"healingSpellsVar"
		rowbackground	 GUISTBK2
		scrollbar 'GUISCRC'
		action
		"
			local highlight = true
			if(store.healingSpells[healingSpellsVar].highlight == 1) then highlight = false end
			if(highlight == true and store.healingSpells[healingSpellsVar].valid == 0) then return end
			storeScreen:SelectSpellItem( healingSpellsVar - 1,  highlight)
		"
		actionAlt
		"
			local spell = store.healingSpells[healingSpellsVar]
			popupDetails(16189, spell.name, spell.description,spell.icon)
		"
	}
	button
	{
		area 118 676 200 44
		bam GUIBUTNT
		text "BUY_BUTTON"
		text style "button"
		action
		"
			storeScreen:OnBuySpellButtonClick()
		"
	}
	text
	{
		area 461 166 371 484
		text lua "store.spellText"
		text style "normal_parchment"
		scrollbar 'GUISCRP'
	}
}
menu
{
	name 'STORE_DRINKS'
	align center center
	onOpen "storeScreen:UpdateBuyDrinksPanel()"
	ignoreEsc
	
	label
	{
		area 0 0 864 756
		mosaic GUISTIDB
	}
	label
	{
		area 0 32 864 44
		text "DRINKS_TITLE"
		text style "title"
	}
	label
	{
		area 0 76 864 36
		text lua "Infinity_FetchString(storeScreen:GetStoreName())"
		text style "label"
	}
--	label
--	{
--		area 719 70 110 48
--		text lua "game:GetPartyGold()"
--		text style "gold"
--	}
	label
	{
		area 18 127 70 30
		text "DRINK_LABEL"
		text style "label"
	}
	label
	{
		area 300 127 118 31
		text "COST_LABEL"
		text style "label"
		text align center center
	}
	label
	{
		area 18 157 0 0
		rectangle 1
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 5 0 200 60
				text lua "store.drinks[rowNumber].name"
				text style "normal"
				text align left center
			}
			label
			{
				area 310 0 64 60
				text lua "store.drinks[rowNumber].value"
				text style "gold"
				text align center center
			}
			label
			{
				enabled "store.drinks[rowNumber].valid == 0"
				area 0 0 308 60
				fill 0 0 0 150
			}
		}
		area 18 161 408 503
		rowheight	60
		table		"store.drinks"
		var			"storeDrinksVar"
		scrollbar 'GUISCRC'
	}
	button
	{
		area 118 676 201 43
		bam GUIBUTNT
		text "BUY_BUTTON"
		text style "button"
		clickable lua "storeDrinksVar ~= nil and storeDrinksVar ~= 0"
		action
		"
			storeScreen:OnBuyDrinkButtonClick(storeDrinksVar - 1)
		"
	}
	label
	{
		area 629 142 127 93
		bam lua "store.qualityIcon"
	}
	label
	{
		area 466 142 155 93
		text "RUMORS_LABEL"
		text style "label_parchment"
	}
	text
	{
		area 466 240 368 404
		text lua "store.drinkText"
		text style "normal_parchment"
		scrollbar 'GUISCRP'
	}
	
}
`
	storePanelButtonHighlightGroup = nil
	function setStoreMainPanel(buttonId)
		local oldMenu  = storeScreen:GetMenuName(storeCurMenuId)
		Infinity_PopMenu(oldMenu)
		storeCurMenuId = storeScreen:GetPanelButtonPanelId(buttonId)
		Infinity_PushMenu(storeScreen:GetMenuName(storeCurMenuId))
	end
	function getBuySellTooltip()
		if(storeScreen:IsContainer()) then
			return t('TRANSFER_ITEMS_TOOLTIP')
		else
			return Infinity_FetchString(storeScreen:GetPanelButtonToolTip(0))
		end
	end
`
menu
{
	name 'STORE_CHOOSER'
	align center center
	onOpen
	"
		local menuName = storeScreen:GetMenuName(storeCurMenuId)
		Infinity_PushMenu(menuName)
		pushSidebars()
		local buttonId = storeScreen:GetPanelButtonId(storeCurMenuId)
		storePanelButtonHighlightGroup = Infinity_FindUIItemByName('BUTTON_storechooser_' .. buttonId)
		Infinity_PopMenu('WORLD_QUICKLOOT')
	"
	onClose 
	"
		local menuName = storeScreen:GetMenuName(storeCurMenuId)
		Infinity_PopMenu(menuName)
		popSidebars()
	"
	ignoreEsc
	
	label
	{
		area 0 0 1364 756
		mosaic RGSTORE
	}
	label
	{
		area 131 172 91 70
		bam lua "store.icon"
	}
	button
	{
		on escape
		area 1132 674 140 44
		bam RGSTBT
		text "DONE_BUTTON"
		text style "button"
		action
		"
			storeScreen:OnMainDoneButtonClick()
		"
	}
	button
	{
		name 'BUTTON_storechooser_0'
		area 132 254 70 64
		enabled "storeScreen:GetPanelButtonEnabled(0)"
		bam GUISTBBC
		highlightgroup storePanelButtonHighlightGroup
		sequence lua "storeScreen:GetPanelButtonSequence(0)"
		tooltip lua "getBuySellTooltip()"
		action
		"
			setStoreMainPanel(0)
		"
	}
	button
	{
		name 'BUTTON_storechooser_1'
		area 132 328 70 64
		enabled "storeScreen:GetPanelButtonEnabled(1)"
		bam GUISTBBC
		highlightgroup storePanelButtonHighlightGroup
		sequence lua "storeScreen:GetPanelButtonSequence(1)"
		tooltip lua "Infinity_FetchString(storeScreen:GetPanelButtonToolTip(1))"
		action
		"
			setStoreMainPanel(1)
		"
	}
	button
	{
		name 'BUTTON_storechooser_2'
		area 132 402 70 64
		enabled "storeScreen:GetPanelButtonEnabled(2)"
		bam GUISTBBC
		highlightgroup storePanelButtonHighlightGroup
		sequence lua "storeScreen:GetPanelButtonSequence(2)"
		tooltip lua "Infinity_FetchString(storeScreen:GetPanelButtonToolTip(2))"
		action
		"
			setStoreMainPanel(2)
		"
	}
	button
	{
		name 'BUTTON_storechooser_3'
		area 132 476 62 64
		enabled "storeScreen:GetPanelButtonEnabled(3)"
		bam GUISTBBC
		highlightgroup storePanelButtonHighlightGroup
		sequence lua "storeScreen:GetPanelButtonSequence(3)"
		tooltip lua "Infinity_FetchString(storeScreen:GetPanelButtonToolTip(3))"
		action
		"
			setStoreMainPanel(3)
		"
	}
	label
	{
		area 1154 226 94 36
--		enabled "not storeScreen:IsContainer()"
		text lua "game:GetPartyGold()"
		text style "gold"
		align center center
	}
	button
	{
		area 1166 339 68 90
		encumbrance
	}
}
`
	function worldDeathLoadClickable()
		if(e:IsMultiplayer() and not e:IsHosting()) then
			return false
		end
		return not worldScreen:GetHardPaused()
	end
	function worldDeathQuitClickable()
		return not worldScreen:GetHardPaused()
	end
	function worldDeathText()
		if(e:IsMultiplayer()) then
			if(e:IsHosting()) then
				return Infinity_FetchString(19377)
			else
				return Infinity_FetchString(11331)
			end
		else
			if(worldDeathStr == nil) then
				return Infinity_FetchString(16498)
			else
				return Infinity_FetchString(worldDeathStr)
			end
		end
	end
	function worldDeathQuitText()
		if(e:IsMultiplayer()) then
			return t('LOGOUT_BUTTON')
		else
			return t('QUIT_BUTTON')
		end
	end
	worldChatEdit = ""
`
menu
{
	name "WORLD_DEATH"
	align center center
	ignoreEsc
	modal
	label
	{
		area 0 0 657 234
		mosaic GUIERR6
	}
	label
	{
		area 29 21 580 126
		text lua "worldDeathText()"
		text style	"label"
		text align center center
	}
	button
	{
		area 79 170 230 44
		bam GUIBUTMT
		text "LOAD_BUTTON"
		text style	"button"
		clickable lua "worldDeathLoadClickable()"
		action 
		"
			Infinity_PopMenu()
			worldScreen:OnDeathLoad()
		"
	}
	button
	{
		area 343 170 230 44
		bam GUIBUTMT
		text style	"button"
		text lua "worldDeathQuitText()"
		clickable lua "worldDeathQuitClickable()"
		action 
		"
			Infinity_PopMenu()
			worldScreen:OnDeathQuit()
		"
	}
}
`
	actionBarTooltip = {}
	FirstTime = 0
`
menu
{
	name "WORLD_ACTIONBAR"
	align center bottom
	onOpen 
	"
		QuicklootMode = Infinity_GetINIString('Game Options','QuicklootMode',1)
		QuicklootStartPref = Infinity_GetINIString('Game Options','QuicklootStartPreference',1)
		toolbarTop = 50
		Infinity_PushMenu('WORLD_MESSAGES')
--		Infinity_PushMenu('WORLD_QUICKLOOT')
	"
	onClose 
	"
		Infinity_PopMenu('WORLD_QUICKLOOT');
		Infinity_PopMenu('WORLD_MESSAGES');
	"
	ignoreEsc
	label
	{
		area 0 0 650 57
		mosaic GUWBTP10
	}
	button
	{
		area 2 5 52 52
		actionBar 0
		enabled "buttonArray:GetButtonEnabled(0)"
		tooltip lua "actionBarTooltip[0]"
		action "buttonArray:OnLButtonPressed(0)"
		actionAlt "buttonArray:OnRButtonPressed(0)"
		actionHold "buttonArray:OnLButtonPressed(0)"
	}
	button
	{
		area 56 5 52 52
		actionBar 1
		enabled "buttonArray:GetButtonEnabled(1)"
		tooltip lua "actionBarTooltip[1]"
		action "buttonArray:OnLButtonPressed(1)"
		actionAlt "buttonArray:OnRButtonPressed(1)"
	}
	button
	{
		area 110 5 52 52
		actionBar 2
		enabled "buttonArray:GetButtonEnabled(2)"
		tooltip lua "actionBarTooltip[2]"
		action "buttonArray:OnLButtonPressed(2)"
		actionAlt "buttonArray:OnRButtonPressed(2)"
	}
	button
	{
		area 164 5 52 52
		actionBar 3
		enabled "buttonArray:GetButtonEnabled(3)"
		tooltip lua "actionBarTooltip[3]"
		action "buttonArray:OnLButtonPressed(3)"
		actionAlt "buttonArray:OnRButtonPressed(3)"
	}
	button
	{
		area 218 5 52 52
		actionBar 4
		enabled "buttonArray:GetButtonEnabled(4)"
		tooltip lua "actionBarTooltip[4]"
		action "buttonArray:OnLButtonPressed(4)"
		actionAlt "buttonArray:OnRButtonPressed(4)"
	}
	button
	{
		area 272 5 52 52
		actionBar 5
		enabled "buttonArray:GetButtonEnabled(5)"
		tooltip lua "actionBarTooltip[5]"
		action "buttonArray:OnLButtonPressed(5)"
		actionAlt "buttonArray:OnRButtonPressed(5)"
	}
	button
	{
		area 326 5 52 52
		actionBar 6
		enabled "buttonArray:GetButtonEnabled(6)"
		tooltip lua "actionBarTooltip[6]"
		action "buttonArray:OnLButtonPressed(6)"
		actionAlt "buttonArray:OnRButtonPressed(6)"
	}
	button
	{
		area 380 5 52 52
		actionBar 7
		enabled "buttonArray:GetButtonEnabled(7)"
		tooltip lua "actionBarTooltip[7]"
		action "buttonArray:OnLButtonPressed(7)"
		actionAlt "buttonArray:OnRButtonPressed(7)"
	}
	
	button
	{
		area 434 5 52 52
		actionBar 8
		enabled "buttonArray:GetButtonEnabled(8)"
		tooltip lua "actionBarTooltip[8]"
		action "buttonArray:OnLButtonPressed(8)"
		actionAlt "buttonArray:OnRButtonPressed(8)"
	}
	button
	{
		area 488 5 52 52
		actionBar 9
		enabled "buttonArray:GetButtonEnabled(9)"
		tooltip lua "actionBarTooltip[9]"
		action "buttonArray:OnLButtonPressed(9)"
		actionAlt "buttonArray:OnRButtonPressed(9)"
	}
	button
	{
		area 542 5 52 52
		actionBar 10
		enabled "buttonArray:GetButtonEnabled(10)"
		tooltip lua "actionBarTooltip[10]"
		action "buttonArray:OnLButtonPressed(10)"
		actionAlt "buttonArray:OnRButtonPressed(10)"
	}
	button
	{
		area 596 5 52 52
		actionBar 11
		enabled "buttonArray:GetButtonEnabled(11)"
		tooltip lua "actionBarTooltip[11]"
		action "buttonArray:OnLButtonPressed(11)"
		actionAlt "buttonArray:OnRButtonPressed(11)"
		actionHold "buttonArray:OnLButtonPressed(11)"
	}
}
`
	loot = 
	{
		containerItems = {},
		groupItems = {},
		groundItems = {}
	}
	function getContainerItemProperty(index, property)
		local idxScrolled = index + worldScreen:GetTopContainerItem()
		if(loot.containerItems[idxScrolled] == nil or loot.containerItems[idxScrolled].item == nil) then
			return nil
		end
		return loot.containerItems[idxScrolled].item[property]
	end
	function getGroupItemProperty(index, property)
		local idxScrolled = index + worldScreen:GetTopGroupItem()
		if(loot.groupItems[idxScrolled] == nil or loot.groupItems[idxScrolled].item == nil) then
			return nil
		end
		return loot.groupItems[idxScrolled].item[property]
	end
	function scrollContainerItems()
		if scrollDirection > 0 then
			if worldScreen:ContainerScrollEnabled(-1) then
				worldScreen:OnContainerScroll(-1)
			end
		elseif scrollDirection < 0 then
			if worldScreen:ContainerScrollEnabled(1) then
				worldScreen:OnContainerScroll(1)
			end
		end
	end
	function scrollGroupItems()
		if scrollDirection > 0 then
			if worldScreen:GroupScrollEnabled(-1) then
				worldScreen:OnGroupScroll(-1)
			end
		elseif scrollDirection < 0 then
			if worldScreen:GroupScrollEnabled(1) then
				worldScreen:OnGroupScroll(1)
			end
		end
	end
	function showContainerItemDescription(index)
		local idxScrolled = index + worldScreen:GetTopContainerItem()
		if(loot.containerItems[idxScrolled] == nil or loot.containerItems[idxScrolled].item == nil) then
			return nil
		end
		Infinity_GetContainerItemDescription(idxScrolled)
		showItemDescription(loot.containerItems[idxScrolled].item, 2)
	end
	function showGroupItemDescription(index)
		local idxScrolled = index + worldScreen:GetTopGroupItem()
		if(loot.groupItems[idxScrolled] == nil or loot.groupItems[idxScrolled].item == nil) then
			return nil
		end
		Infinity_GetGroupItemDescription(idxScrolled)
		showItemDescription(loot.groupItems[idxScrolled].item, 2)
	end

`
menu
{
	name "WORLD_CONTAINER"
	align center bottom
	offset -24 0
	ignoreesc
	onClose 
	"
		if groundItemsButtonToggle == 1 then
			Infinity_PushMenu('WORLD_QUICKLOOT')
		end
	"
	label
	{
		area 0 0 653 130
		mosaic gmpwmsg0
	}
	label
	{
		area 16 10 83 100
		bam lua "loot.containerIcon"
	}
	button
	{
		area 104 2 209 116
		actionScroll "scrollContainerItems()"
	}
	button
	{
		area 108 8 52 52
		bam STONSL10
		tooltip lua	"getContainerItemProperty(0,'name')"
		tint lua	"getContainerItemProperty(0,'tint')"
		icon lua	"getContainerItemProperty(0,'icon')"
		count lua	"getContainerItemProperty(0,'count')"
		usages lua	"getContainerItemProperty(0,'usages')"
		action		"worldScreen:OnContainerButtonClick(0)"
		actionAlt	"showContainerItemDescription(0)"
		actionScroll "scrollContainerItems()"
	}
	button
	{
		area 162 8 52 52
		bam STONSL10
		tooltip lua	"getContainerItemProperty(1,'name')"
		tint lua	"getContainerItemProperty(1,'tint')"
		icon lua	"getContainerItemProperty(1,'icon')"
		count lua	"getContainerItemProperty(1,'count')"
		usages lua	"getContainerItemProperty(1,'usages')"
		action		"worldScreen:OnContainerButtonClick(1)"
		actionAlt	"showContainerItemDescription(1)"
		actionScroll "scrollContainerItems()"
	}
	button
	{
		area 216 8 52 52
		bam STONSL10
		tooltip lua	"getContainerItemProperty(2,'name')"
		tint lua	"getContainerItemProperty(2,'tint')"
		icon lua	"getContainerItemProperty(2,'icon')"
		count lua	"getContainerItemProperty(2,'count')"
		usages lua	"getContainerItemProperty(2,'usages')"
		action		"worldScreen:OnContainerButtonClick(2)"
		actionAlt	"showContainerItemDescription(2)"
		actionScroll "scrollContainerItems()"
	}
	button
	{
		area 108 62 52 52
		bam STONSL10
		tooltip lua	"getContainerItemProperty(3,'name')"
		tint lua	"getContainerItemProperty(3,'tint')"
		icon lua	"getContainerItemProperty(3,'icon')"
		count lua	"getContainerItemProperty(3,'count')"
		usages lua	"getContainerItemProperty(3,'usages')"
		action		"worldScreen:OnContainerButtonClick(3)"
		actionAlt	"showContainerItemDescription(3)"
		actionScroll "scrollContainerItems()"
	}
	button
	{
		area 162 62 52 52
		bam STONSL10
		tooltip lua	"getContainerItemProperty(4,'name')"
		tint lua	"getContainerItemProperty(4,'tint')"
		icon lua	"getContainerItemProperty(4,'icon')"
		count lua	"getContainerItemProperty(4,'count')"
		usages lua	"getContainerItemProperty(4,'usages')"
		action		"worldScreen:OnContainerButtonClick(4)"
		actionAlt	"showContainerItemDescription(4)"
		actionScroll "scrollContainerItems()"
	}
	button
	{
		area 216 62 52 52
		bam STONSL10
		tooltip lua	"getContainerItemProperty(5,'name')"
		tint lua	"getContainerItemProperty(5,'tint')"
		icon lua	"getContainerItemProperty(5,'icon')"
		count lua	"getContainerItemProperty(5,'count')"
		usages lua	"getContainerItemProperty(5,'usages')"
		action		"worldScreen:OnContainerButtonClick(5)"
		actionAlt	"showContainerItemDescription(5)"
		actionScroll "scrollContainerItems()"
	}
	button
	{
		area 268 8 44 44
		enabled "worldScreen:ContainerScrollEnabled(-1)"
		bam guisv10
		sequence 0
		action
		"
			worldScreen:OnContainerScroll(-1)
		"
		actionScroll "scrollContainerItems()"
	}
	button
	{
		area 268 70 44 44
		enabled "worldScreen:ContainerScrollEnabled(1)"
		bam guisv10
		sequence 1
		action
		"
			worldScreen:OnContainerScroll(1)
		"
		actionScroll "scrollContainerItems()"
	}
	label
	{
		area 313 12 68 100
		encumbrance
	}
	button
	{
		area 406 2 162 116
		actionScroll "scrollGroupItems()"
	}
	button
	{
		area 411 8 52 52
		bam STONSL10
		tooltip lua	"getGroupItemProperty(0,'name')"
		tint lua	"getGroupItemProperty(0,'tint')"
		icon lua	"getGroupItemProperty(0,'icon')"
		count lua	"getGroupItemProperty(0,'count')"
		usages lua	"getGroupItemProperty(0,'usages')"
		action		"worldScreen:OnContainerButtonClick(10)"
		actionAlt	"showGroupItemDescription(0)"
		actionScroll "scrollGroupItems()"
	}
	button
	{
		area 465 8 52 52
		bam STONSL10
		tooltip lua	"getGroupItemProperty(1,'name')"
		tint lua	"getGroupItemProperty(1,'tint')"
		icon lua	"getGroupItemProperty(1,'icon')"
		count lua	"getGroupItemProperty(1,'count')"
		usages lua	"getGroupItemProperty(1,'usages')"
		action		"worldScreen:OnContainerButtonClick(11)"
		actionAlt	"showGroupItemDescription(1)"
		actionScroll "scrollGroupItems()"
	}
	button
	{
		area 411 62 52 52
		bam STONSL10
		tooltip lua	"getGroupItemProperty(2,'name')"
		tint lua	"getGroupItemProperty(2,'tint')"
		icon lua	"getGroupItemProperty(2,'icon')"
		count lua	"getGroupItemProperty(2,'count')"
		usages lua	"getGroupItemProperty(2,'usages')"
		action		"worldScreen:OnContainerButtonClick(12)"
		actionAlt	"showGroupItemDescription(2)"
		actionScroll "scrollGroupItems()"
	}
	button
	{
		area 465 62 52 52
		bam STONSL10
		tooltip lua	"getGroupItemProperty(3,'name')"
		tint lua	"getGroupItemProperty(3,'tint')"
		icon lua	"getGroupItemProperty(3,'icon')"
		count lua	"getGroupItemProperty(3,'count')"
		usages lua	"getGroupItemProperty(3,'usages')"
		action		"worldScreen:OnContainerButtonClick(13)"
		actionAlt	"showGroupItemDescription(3)"
		actionScroll "scrollGroupItems()"
	}
	button
	{
		area 517 8 44 44
		enabled "worldScreen:GroupScrollEnabled(-1)"
		bam guisv10
		sequence 0
		action
		"
			worldScreen:OnGroupScroll(-1)
		"
		actionScroll "scrollGroupItems()"
	}
	button
	{
		area 517 70 44 44
		enabled "worldScreen:GroupScrollEnabled(1)"
		bam guisv10
		sequence 1
		action
		"
			worldScreen:OnGroupScroll(1)
		"
		actionScroll "scrollGroupItems()"
	}
	label
	{
		area 568 20 78 50
		bam GUIGOLD
	}
	label
	{
		area 575 76 71 28
		text lua "game:GetPartyGold()"
		text style "gold"
	}
	button
	{
		area 40 82 32 32
		bam "ROUNDBUT"
		scaleToClip
		action
		"
			worldScreen:TakeAllFromContainer()
		"
	}
}

`
	function getSlotContainerId(index)
		local idxScrolled = index + worldScreen:GetTopGroundItem()
		if(loot.groundItems[idxScrolled] == nil) then
			return nil
		end
		return loot.groundItems[idxScrolled].containerId
	end
	function hideQuicklootSlot()
		if QuicklootENum == "Ten" then
			QLrows = 10
		elseif QuicklootENum == "Six" then
			QLrows = 6
		elseif QuicklootENum == "Five" then
			QLrows = 5
		elseif QuicklootENum == "Four" then
			QLrows = 4
		elseif QuicklootENum == "Three" then
			QLrows = 3
		elseif QuicklootENum == "Two" then
			QLrows = 2
		end
		QLcols = 60 / QLrows
		QLrows = QLrows - 1
		for j = 0,QLrows,1 do
			for i = QLcols,0,-1 do
				if not getSlotContainerId(j*QLcols + i) then
					Infinity_SetArea('quicklootSlot' .. (j*QLcols + i), (i*54)+76, (j*54)+5, 0, 0)
				elseif getSlotContainerId(j*QLcols + i) then
					Infinity_SetArea('quicklootSlot' .. (j*QLcols + i), (i*54)+76, (j*54)+5, 52, 52)
				end
			end
		end
		if worldScreen:GroundScrollEnabled(-6) or worldScreen:GroundScrollEnabled(6) then
			Infinity_SetArea('quicklootArrowL', 8, 5, 34, 53)
			Infinity_SetArea('quicklootArrowR', 42, 5, 34, 53)
		else
			Infinity_SetArea('quicklootArrowL', 8, 5, 0, 0)
			Infinity_SetArea('quicklootArrowR', 42, 5, 0, 0)
		end
	end

	function getGroundItemProperty(index, property)
		local idxScrolled = index + worldScreen:GetTopGroundItem()
		if(loot.groundItems[idxScrolled] == nil or loot.groundItems[idxScrolled].item == nil) then
			return nil
		end
		return loot.groundItems[idxScrolled].item[property]
	end
	
	function groundItemClick(slotId)
		local slot = loot.groundItems[slotId]
		if(slot and slot.item) then
			worldScreen:OnGroundButtonClick(slot.slotId, slot.containerId, slot.item.res)
		end
	end
	function groundItemClick2(slotId)
		local slot = loot.groundItems[slotId + worldScreen:GetTopGroundItem()]
		if(slot and slot.item) then
			worldScreen:OnGroundButtonClick(slot.slotId, slot.containerId, slot.item.res)
		end
	end
	function dragQLX(newX)
		--do a quick bounds check.
		local area = {Infinity_GetArea("QLhandle")}
		if(area[1] + newX) < 66 then
			newX = 66 - area[1]
		elseif (area[1] + newX) > 1577 then
			newX = 1577 - area[1]
		end

		adjustItemGroup({"QLeditboxbackground","QLeditbox","QLeditboxX"}, newX, 0, 0, 0)
		adjustItemGroup({"QLdisplaybackground"}, newX, 0, 0, 0)
		adjustItemGroup({"QLdisplayrows"}, newX, 0, 0, 0)
		adjustItemGroup({"QLhandle","QLhandleMid","QLhandleL","QLhandleR"}, newX, 0, 0, 0)
		adjustItemGroup({"QLreset"}, newX, 0, 0, 0)
		
	end
	
	function dragQLY(newY)
		--do a quick bounds check.
		
		local area = {Infinity_GetArea("QLdisplaybackground")}
		if(area[4] + newY <= -40) then newY = 0 - area[4] - 40 end
		
		area = {Infinity_GetArea("QLhandle")}
		local screenWidth, screenHeight = Infinity_GetScreenSize()
		if(area[2] + area[4] + newY > screenHeight - 120) then newY = screenHeight - area[2] - area[4] - 120 end
		
		adjustItemGroup({"QLeditboxbackground","QLeditbox","QLeditboxX"}, 0, newY, 0, 0)
		adjustItemGroup({"QLdisplaybackground"}, 0, 0, 0, newY)
		adjustItemGroup({"QLdisplayrows"}, 0, 0, 0, newY)
		adjustItemGroup({"QLhandle","QLhandleMid","QLhandleL","QLhandleR"}, 0, newY, 0, 0)
		adjustItemGroup({"QLreset"}, 0, newY, 0, 0)
	end
	
	function QLfilter(rowNumber)
		if(QLSearchString == nil or QLSearchString == "") then return 1 end --no search string, do nothing
		local QLtext = loot.groundItems[rowNumber].item['name']
		if(string.find(string.lower(QLtext),string.lower(QLSearchString))) then
			return 1 --does contain search string
		else
			return nil
		end
	end
	
	function PickUpItem()
		if selectedLootItem == #loot.groundItems + 1 then selectedLootItem = 0 end
		groundItemClick(selectedLootItem)
	end

	function repositionQuickloot()
		Infinity_SetArea('QLdisplaybackground', 0, 0, 328, -40)
		Infinity_SetArea('QLeditboxbackground', 0, -40, 328, 40)
		Infinity_SetArea('QLeditbox', 0, -40, 328, 40)
		Infinity_SetArea('QLeditboxX', 298, -40, 30, 40)
		Infinity_SetArea('QLdisplayrows', 4, 10, 318, -60)
		Infinity_SetArea('QLhandle', 66, 0, 195, 28)
		Infinity_SetArea('QLhandleL', 66, 0, 50, 28)
		Infinity_SetArea('QLhandleR', 211, 0, 50, 28)
		Infinity_SetArea('QLhandleMid', 116, 0, 95, 28)
		Infinity_SetArea('QLreset', 114, 0, -1, -1)			
	end
	
	function getHeight()
		local area = {Infinity_GetArea("QLdisplaybackground")}
		if area[4] < 100 then
			return 1
		else
			return nil
		end
	end
`
menu
{
	name 'WORLD_QUICKLOOT'
	align left top
	ignoreEsc
	onOpen
	"
		QLSearchString = ''
	"
	button
	{
		area 114 172 -1 -1
		name "QLreset"
		on e
		enabled "getSlotContainerId(0,'containerId') and QuicklootMode == UIStrings.UI_Advanced"
		action
		"
			local x,y,w,h = Infinity_GetArea('QLdisplaybackground')
			if h < 1 then
				dragQLY((#loot.groundItems * 52) + 124)
			elseif h > 0 then
				dragQLY(-h-40)
			end
			toggleY = 0
		"
	}
	button
	{
		area 0 0 328 -40
		enabled "getSlotContainerId(0,'containerId') and QuicklootMode == UIStrings.UI_Advanced"
		name "QLdisplaybackground"
		rectangle 6
		rectangle opacity 160
	}
	label
	{
		area 0 -40 328 40
		enabled "getSlotContainerId(0,'containerId') and QuicklootMode == UIStrings.UI_Advanced"
		name "QLeditboxbackground"
		rectangle 6
	}
	edit
	{
		area 30 -40 268 40
		enabled "getSlotContainerId(0,'containerId') and QuicklootMode == UIStrings.UI_Advanced"
		name "QLeditbox"
		var QLSearchString
		placeholder "..."
		text style "edit"
		text align center center
		maxlines	1
		
	}
	button
	{
		enabled "QLSearchString ~= '' and QuicklootMode == UIStrings.UI_Advanced"
		area 298 -40 30 40
		name "QLeditboxX"
		text "X"
		text style "button"
		action
		"
			QLSearchString = ''
		"
	}
	list
	{
		column 
		{ 
			width 310
			button
			{
				area 5 0 52 52
				bam STONSLOT
				enabled "QLfilter(rowNumber) and QuicklootMode == UIStrings.UI_Advanced"
				frame lua "loot.groundItems[rowNumber].item['frame']"
				icon lua "loot.groundItems[rowNumber].item['icon']"
				tint lua "loot.groundItems[rowNumber].item['tint']"
				usages lua "loot.groundItems[rowNumber].item['usages']" --how many selected
				count lua "loot.groundItems[rowNumber].item['count']" --How many to a stack
				align center center
			}
			button
			{
				area 79 0 230 52
				enabled "QLfilter(rowNumber) and QuicklootMode == UIStrings.UI_Advanced"
				text lua "loot.groundItems[rowNumber].item['name']"
				text style "normal"
				text align left center
			}
		}
		area 			4 10 318 -60
		enabled 		"getSlotContainerId(0,'containerId') and QuicklootMode == UIStrings.UI_Advanced"
		name 			"QLdisplayrows"
		rowheight		dynamic
		hidehighlight
		table			"loot.groundItems"
		var				"selectedLootItem"
		scrollbar 		'GUISCRC'
		scrollbar hide lua "getHeight()"
		action
		"
			PickUpItem()
			if #loot.groundItems == 0 then repositionQuickloot() end
		"
	}
	label
	{
		name "QLhandle"
		enabled "getSlotContainerId(0,'containerId') and QuicklootMode == UIStrings.UI_Advanced"
		area 66 0 195 28
		mosaic "RGTAB1"
		text lua "#loot.groundItems + 1"
		text style "parchment"
		text color 255 255 255 255
		text point 14
		text align center center
	}
	handle
	{
		name "QLhandleL"
		enabled "getSlotContainerId(0,'containerId') and QuicklootMode == UIStrings.UI_Advanced"
		area 66 0 50 28
		actionDrag
		"
			dragQLX(motionX)
		"
	}	
	handle
	{
		name "QLhandleMid"
		enabled "getSlotContainerId(0,'containerId') and QuicklootMode == UIStrings.UI_Advanced"
		area 116 0 95 28
		actionDrag
		"
			dragQLY(motionY)
		"
	}
	handle
	{
		name "QLhandleR"
		enabled "getSlotContainerId(0,'containerId') and QuicklootMode == UIStrings.UI_Advanced"
		area 211 0 50 28
		actionDrag
		"
			dragQLX(motionX)
		"
	}
	
	button
	{
		area 0 0 0 0
		enabled "QuicklootMode == UIStrings.UI_Expert"
		text lua "hideQuicklootSlot()"
	}
	button
	{
		name "quicklootArrowL"
		area 8 5 0 0
		bam RGQAROW
		sequence 1
		enabled "(worldScreen:GroundScrollEnabled(-6) or worldScreen:GroundScrollEnabled(6)) and QuicklootMode == UIStrings.UI_Expert"
		action
		"
		worldScreen:OnGroundScroll(-6)
		"
	}
	button
	{
		name "quicklootArrowR"
		area 42 5 0 0
		bam RGQAROW
		sequence 0
		enabled "(worldScreen:GroundScrollEnabled(-6) or worldScreen:GroundScrollEnabled(6)) and QuicklootMode == UIStrings.UI_Expert"
		action
		"
		worldScreen:OnGroundScroll(6)
		"
	}
	
	button
	{
		name "quicklootSlot0"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(0)"	area 76 5 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(0,'name')"	tint lua	"getGroundItemProperty(0,'tint')"
		icon lua	"getGroundItemProperty(0,'icon')"	count lua	"getGroundItemProperty(0,'count')"	usages lua	"getGroundItemProperty(0,'usages')"
		action "groundItemClick2(0)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(0,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot1"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(1)"	area 130 5 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(1,'name')"	tint lua	"getGroundItemProperty(1,'tint')"
		icon lua	"getGroundItemProperty(1,'icon')"	count lua	"getGroundItemProperty(1,'count')"	usages lua	"getGroundItemProperty(1,'usages')"
		action "groundItemClick2(1)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(1,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot2"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(2)"	area 184 5 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(2,'name')"	tint lua	"getGroundItemProperty(2,'tint')"
		icon lua	"getGroundItemProperty(2,'icon')"	count lua	"getGroundItemProperty(2,'count')"	usages lua	"getGroundItemProperty(2,'usages')"
		action "groundItemClick2(2)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(2,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot3"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(3)"	area 238 5 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(3,'name')"	tint lua	"getGroundItemProperty(3,'tint')"
		icon lua	"getGroundItemProperty(3,'icon')"	count lua	"getGroundItemProperty(3,'count')"	usages lua	"getGroundItemProperty(3,'usages')"
		action "groundItemClick2(3)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(3,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot4"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(4)"	area 292 5 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(4,'name')"	tint lua	"getGroundItemProperty(4,'tint')"
		icon lua	"getGroundItemProperty(4,'icon')"	count lua	"getGroundItemProperty(4,'count')"	usages lua	"getGroundItemProperty(4,'usages')"
		action "groundItemClick2(4)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(4,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot5"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(5)"	area 346 5 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(5,'name')"	tint lua	"getGroundItemProperty(5,'tint')"
		icon lua	"getGroundItemProperty(5,'icon')"	count lua	"getGroundItemProperty(5,'count')"	usages lua	"getGroundItemProperty(5,'usages')"
		action "groundItemClick2(5)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(5,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot6"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(6)"	area 76 59 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(6,'name')"	tint lua	"getGroundItemProperty(6,'tint')"
		icon lua	"getGroundItemProperty(6,'icon')"	count lua	"getGroundItemProperty(6,'count')"	usages lua	"getGroundItemProperty(6,'usages')"
		action "groundItemClick2(6)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(6,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot7"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(7)"	area 130 59 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(7,'name')"	tint lua	"getGroundItemProperty(7,'tint')"
		icon lua	"getGroundItemProperty(7,'icon')"	count lua	"getGroundItemProperty(7,'count')"	usages lua	"getGroundItemProperty(7,'usages')"
		action "groundItemClick2(7)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(7,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot8"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(8)"	area 184 59 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(8,'name')"	tint lua	"getGroundItemProperty(8,'tint')"
		icon lua	"getGroundItemProperty(8,'icon')"	count lua	"getGroundItemProperty(8,'count')"	usages lua	"getGroundItemProperty(8,'usages')"
		action "groundItemClick2(8)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(8,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot9"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(9)"	area 238 59 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(9,'name')"	tint lua	"getGroundItemProperty(9,'tint')"
		icon lua	"getGroundItemProperty(9,'icon')"	count lua	"getGroundItemProperty(9,'count')"	usages lua	"getGroundItemProperty(9,'usages')"
		action "groundItemClick2(9)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(9,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot10"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(10)"	area 292 59 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(10,'name')"	tint lua	"getGroundItemProperty(10,'tint')"
		icon lua	"getGroundItemProperty(10,'icon')"	count lua	"getGroundItemProperty(10,'count')"	usages lua	"getGroundItemProperty(10,'usages')"
		action "groundItemClick2(10)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(10,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot11"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(11)"	area 346 59 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(11,'name')"	tint lua	"getGroundItemProperty(11,'tint')"
		icon lua	"getGroundItemProperty(11,'icon')"	count lua	"getGroundItemProperty(11,'count')"	usages lua	"getGroundItemProperty(11,'usages')"
		action "groundItemClick2(11)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(11,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot12"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(12)"	area 76 113 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(12,'name')"	tint lua	"getGroundItemProperty(12,'tint')"
		icon lua	"getGroundItemProperty(12,'icon')"	count lua	"getGroundItemProperty(12,'count')"	usages lua	"getGroundItemProperty(12,'usages')"
		action "groundItemClick2(12)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(12,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot13"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(13)"	area 130 113 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(13,'name')"	tint lua	"getGroundItemProperty(13,'tint')"
		icon lua	"getGroundItemProperty(13,'icon')"	count lua	"getGroundItemProperty(13,'count')"	usages lua	"getGroundItemProperty(13,'usages')"
		action "groundItemClick2(13)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(13,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot14"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(14)"	area 184 113 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(14,'name')"	tint lua	"getGroundItemProperty(14,'tint')"
		icon lua	"getGroundItemProperty(14,'icon')"	count lua	"getGroundItemProperty(14,'count')"	usages lua	"getGroundItemProperty(14,'usages')"
		action "groundItemClick2(14)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(14,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot15"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(15)"	area 238 113 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(15,'name')"	tint lua	"getGroundItemProperty(15,'tint')"
		icon lua	"getGroundItemProperty(15,'icon')"	count lua	"getGroundItemProperty(15,'count')"	usages lua	"getGroundItemProperty(15,'usages')"
		action "groundItemClick2(15)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(15,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot16"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(16)"	area 292 113 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(16,'name')"	tint lua	"getGroundItemProperty(16,'tint')"
		icon lua	"getGroundItemProperty(16,'icon')"	count lua	"getGroundItemProperty(16,'count')"	usages lua	"getGroundItemProperty(16,'usages')"
		action "groundItemClick2(16)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(16,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot17"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(17)"	area 346 113 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(17,'name')"	tint lua	"getGroundItemProperty(17,'tint')"
		icon lua	"getGroundItemProperty(17,'icon')"	count lua	"getGroundItemProperty(17,'count')"	usages lua	"getGroundItemProperty(17,'usages')"
		action "groundItemClick2(17)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(17,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot18"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(18)"	area 76 167 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(18,'name')"	tint lua	"getGroundItemProperty(18,'tint')"
		icon lua	"getGroundItemProperty(18,'icon')"	count lua	"getGroundItemProperty(18,'count')"	usages lua	"getGroundItemProperty(18,'usages')"
		action "groundItemClick2(18)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(18,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot19"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(19)"	area 130 167 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(19,'name')"	tint lua	"getGroundItemProperty(19,'tint')"
		icon lua	"getGroundItemProperty(19,'icon')"	count lua	"getGroundItemProperty(19,'count')"	usages lua	"getGroundItemProperty(19,'usages')"
		action "groundItemClick2(19)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(19,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot20"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(20)"	area 184 167 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(20,'name')"	tint lua	"getGroundItemProperty(20,'tint')"
		icon lua	"getGroundItemProperty(20,'icon')"	count lua	"getGroundItemProperty(20,'count')"	usages lua	"getGroundItemProperty(20,'usages')"
		action "groundItemClick2(20)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(20,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot21"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(21)"	area 238 167 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(21,'name')"	tint lua	"getGroundItemProperty(21,'tint')"
		icon lua	"getGroundItemProperty(21,'icon')"	count lua	"getGroundItemProperty(21,'count')"	usages lua	"getGroundItemProperty(21,'usages')"
		action "groundItemClick2(21)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(21,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot22"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(22)"	area 292 167 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(22,'name')"	tint lua	"getGroundItemProperty(22,'tint')"
		icon lua	"getGroundItemProperty(22,'icon')"	count lua	"getGroundItemProperty(22,'count')"	usages lua	"getGroundItemProperty(22,'usages')"
		action "groundItemClick2(22)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(22,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot23"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(23)"	area 346 167 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(23,'name')"	tint lua	"getGroundItemProperty(23,'tint')"
		icon lua	"getGroundItemProperty(23,'icon')"	count lua	"getGroundItemProperty(23,'count')"	usages lua	"getGroundItemProperty(23,'usages')"
		action "groundItemClick2(23)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(23,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot24"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(24)"	area 76 221 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(24,'name')"	tint lua	"getGroundItemProperty(24,'tint')"
		icon lua	"getGroundItemProperty(24,'icon')"	count lua	"getGroundItemProperty(24,'count')"	usages lua	"getGroundItemProperty(24,'usages')"
		action "groundItemClick2(24)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(24,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot25"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(25)"	area 130 221 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(25,'name')"	tint lua	"getGroundItemProperty(25,'tint')"
		icon lua	"getGroundItemProperty(25,'icon')"	count lua	"getGroundItemProperty(25,'count')"	usages lua	"getGroundItemProperty(25,'usages')"
		action "groundItemClick2(25)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(25,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot26"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(26)"	area 184 221 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(26,'name')"	tint lua	"getGroundItemProperty(26,'tint')"
		icon lua	"getGroundItemProperty(26,'icon')"	count lua	"getGroundItemProperty(26,'count')"	usages lua	"getGroundItemProperty(26,'usages')"
		action "groundItemClick2(26)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(26,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot27"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(27)"	area 238 221 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(27,'name')"	tint lua	"getGroundItemProperty(27,'tint')"
		icon lua	"getGroundItemProperty(27,'icon')"	count lua	"getGroundItemProperty(27,'count')"	usages lua	"getGroundItemProperty(27,'usages')"
		action "groundItemClick2(27)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(27,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot28"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(28)"	area 292 221 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(28,'name')"	tint lua	"getGroundItemProperty(28,'tint')"
		icon lua	"getGroundItemProperty(28,'icon')"	count lua	"getGroundItemProperty(28,'count')"	usages lua	"getGroundItemProperty(28,'usages')"
		action "groundItemClick2(28)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(28,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot29"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(29)"	area 346 221 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(29,'name')"	tint lua	"getGroundItemProperty(29,'tint')"
		icon lua	"getGroundItemProperty(29,'icon')"	count lua	"getGroundItemProperty(29,'count')"	usages lua	"getGroundItemProperty(29,'usages')"
		action "groundItemClick2(29)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(29,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot30"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(30)"	area 76 275 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(30,'name')"	tint lua	"getGroundItemProperty(30,'tint')"
		icon lua	"getGroundItemProperty(30,'icon')"	count lua	"getGroundItemProperty(30,'count')"	usages lua	"getGroundItemProperty(30,'usages')"
		action "groundItemClick2(30)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(30,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot31"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(31)"	area 130 275 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(31,'name')"	tint lua	"getGroundItemProperty(31,'tint')"
		icon lua	"getGroundItemProperty(31,'icon')"	count lua	"getGroundItemProperty(31,'count')"	usages lua	"getGroundItemProperty(31,'usages')"
		action "groundItemClick2(31)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(31,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot32"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(32)"	area 184 275 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(32,'name')"	tint lua	"getGroundItemProperty(32,'tint')"
		icon lua	"getGroundItemProperty(32,'icon')"	count lua	"getGroundItemProperty(32,'count')"	usages lua	"getGroundItemProperty(32,'usages')"
		action "groundItemClick2(32)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(32,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot33"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(33)"	area 238 275 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(33,'name')"	tint lua	"getGroundItemProperty(33,'tint')"
		icon lua	"getGroundItemProperty(33,'icon')"	count lua	"getGroundItemProperty(33,'count')"	usages lua	"getGroundItemProperty(33,'usages')"
		action "groundItemClick2(33)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(33,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot34"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(34)"	area 292 275 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(34,'name')"	tint lua	"getGroundItemProperty(34,'tint')"
		icon lua	"getGroundItemProperty(34,'icon')"	count lua	"getGroundItemProperty(34,'count')"	usages lua	"getGroundItemProperty(34,'usages')"
		action "groundItemClick2(34)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(34,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot35"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(35)"	area 346 275 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(35,'name')"	tint lua	"getGroundItemProperty(35,'tint')"
		icon lua	"getGroundItemProperty(35,'icon')"	count lua	"getGroundItemProperty(35,'count')"	usages lua	"getGroundItemProperty(35,'usages')"
		action "groundItemClick2(35)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(35,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot36"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(36)"	area 76 329 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(36,'name')"	tint lua	"getGroundItemProperty(36,'tint')"
		icon lua	"getGroundItemProperty(36,'icon')"	count lua	"getGroundItemProperty(36,'count')"	usages lua	"getGroundItemProperty(36,'usages')"
		action "groundItemClick2(36)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(36,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot37"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(37)"	area 130 329 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(37,'name')"	tint lua	"getGroundItemProperty(37,'tint')"
		icon lua	"getGroundItemProperty(37,'icon')"	count lua	"getGroundItemProperty(37,'count')"	usages lua	"getGroundItemProperty(37,'usages')"
		action "groundItemClick2(37)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(37,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot38"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(38)"	area 184 329 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(38,'name')"	tint lua	"getGroundItemProperty(38,'tint')"
		icon lua	"getGroundItemProperty(38,'icon')"	count lua	"getGroundItemProperty(38,'count')"	usages lua	"getGroundItemProperty(38,'usages')"
		action "groundItemClick2(38)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(38,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot39"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(39)"	area 238 329 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(39,'name')"	tint lua	"getGroundItemProperty(39,'tint')"
		icon lua	"getGroundItemProperty(39,'icon')"	count lua	"getGroundItemProperty(39,'count')"	usages lua	"getGroundItemProperty(39,'usages')"
		action "groundItemClick2(39)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(39,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot40"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(40)"	area 292 329 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(40,'name')"	tint lua	"getGroundItemProperty(40,'tint')"
		icon lua	"getGroundItemProperty(40,'icon')"	count lua	"getGroundItemProperty(40,'count')"	usages lua	"getGroundItemProperty(40,'usages')"
		action "groundItemClick2(40)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(40,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot41"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(41)"	area 346 329 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(41,'name')"	tint lua	"getGroundItemProperty(41,'tint')"
		icon lua	"getGroundItemProperty(41,'icon')"	count lua	"getGroundItemProperty(41,'count')"	usages lua	"getGroundItemProperty(41,'usages')"
		action "groundItemClick2(41)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(41,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot42"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(42)"	area 76 383 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(42,'name')"	tint lua	"getGroundItemProperty(42,'tint')"
		icon lua	"getGroundItemProperty(42,'icon')"	count lua	"getGroundItemProperty(42,'count')"	usages lua	"getGroundItemProperty(42,'usages')"
		action "groundItemClick2(42)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(42,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot43"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(43)"	area 130 383 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(43,'name')"	tint lua	"getGroundItemProperty(43,'tint')"
		icon lua	"getGroundItemProperty(43,'icon')"	count lua	"getGroundItemProperty(43,'count')"	usages lua	"getGroundItemProperty(43,'usages')"
		action "groundItemClick2(43)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(43,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot44"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(44)"	area 184 383 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(44,'name')"	tint lua	"getGroundItemProperty(44,'tint')"
		icon lua	"getGroundItemProperty(44,'icon')"	count lua	"getGroundItemProperty(44,'count')"	usages lua	"getGroundItemProperty(44,'usages')"
		action "groundItemClick2(44)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(44,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot45"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(45)"	area 238 383 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(45,'name')"	tint lua	"getGroundItemProperty(45,'tint')"
		icon lua	"getGroundItemProperty(45,'icon')"	count lua	"getGroundItemProperty(45,'count')"	usages lua	"getGroundItemProperty(45,'usages')"
		action "groundItemClick2(45)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(45,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot46"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(46)"	area 292 383 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(46,'name')"	tint lua	"getGroundItemProperty(46,'tint')"
		icon lua	"getGroundItemProperty(46,'icon')"	count lua	"getGroundItemProperty(46,'count')"	usages lua	"getGroundItemProperty(46,'usages')"
		action "groundItemClick2(46)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(46,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot47"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(47)"	area 346 383 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(47,'name')"	tint lua	"getGroundItemProperty(47,'tint')"
		icon lua	"getGroundItemProperty(47,'icon')"	count lua	"getGroundItemProperty(47,'count')"	usages lua	"getGroundItemProperty(47,'usages')"
		action "groundItemClick2(47)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(47,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot48"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(48)"	area 76 437 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(48,'name')"	tint lua	"getGroundItemProperty(48,'tint')"
		icon lua	"getGroundItemProperty(48,'icon')"	count lua	"getGroundItemProperty(48,'count')"	usages lua	"getGroundItemProperty(48,'usages')"
		action "groundItemClick2(48)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(48,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot49"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(49)"	area 130 437 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(49,'name')"	tint lua	"getGroundItemProperty(49,'tint')"
		icon lua	"getGroundItemProperty(49,'icon')"	count lua	"getGroundItemProperty(49,'count')"	usages lua	"getGroundItemProperty(49,'usages')"
		action "groundItemClick2(49)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(49,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot50"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(50)"	area 184 437 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(50,'name')"	tint lua	"getGroundItemProperty(50,'tint')"
		icon lua	"getGroundItemProperty(50,'icon')"	count lua	"getGroundItemProperty(50,'count')"	usages lua	"getGroundItemProperty(50,'usages')"
		action "groundItemClick2(50)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(50,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot51"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(51)"	area 238 437 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(51,'name')"	tint lua	"getGroundItemProperty(51,'tint')"
		icon lua	"getGroundItemProperty(51,'icon')"	count lua	"getGroundItemProperty(51,'count')"	usages lua	"getGroundItemProperty(51,'usages')"
		action "groundItemClick2(51)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(51,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot52"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(52)"	area 292 437 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(52,'name')"	tint lua	"getGroundItemProperty(52,'tint')"
		icon lua	"getGroundItemProperty(52,'icon')"	count lua	"getGroundItemProperty(52,'count')"	usages lua	"getGroundItemProperty(52,'usages')"
		action "groundItemClick2(52)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(52,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot53"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(53)"	area 346 437 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(53,'name')"	tint lua	"getGroundItemProperty(53,'tint')"
		icon lua	"getGroundItemProperty(53,'icon')"	count lua	"getGroundItemProperty(53,'count')"	usages lua	"getGroundItemProperty(53,'usages')"
		action "groundItemClick2(53)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(53,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot54"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(54)"	area 76 491 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(54,'name')"	tint lua	"getGroundItemProperty(54,'tint')"
		icon lua	"getGroundItemProperty(54,'icon')"	count lua	"getGroundItemProperty(54,'count')"	usages lua	"getGroundItemProperty(54,'usages')"
		action "groundItemClick2(54)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(54,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot55"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(55)"	area 130 491 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(55,'name')"	tint lua	"getGroundItemProperty(55,'tint')"
		icon lua	"getGroundItemProperty(55,'icon')"	count lua	"getGroundItemProperty(55,'count')"	usages lua	"getGroundItemProperty(55,'usages')"
		action "groundItemClick2(55)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(55,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot56"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(56)"	area 184 491 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(56,'name')"	tint lua	"getGroundItemProperty(56,'tint')"
		icon lua	"getGroundItemProperty(56,'icon')"	count lua	"getGroundItemProperty(56,'count')"	usages lua	"getGroundItemProperty(56,'usages')"
		action "groundItemClick2(56)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(56,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot57"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(57)"	area 238 491 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(57,'name')"	tint lua	"getGroundItemProperty(57,'tint')"
		icon lua	"getGroundItemProperty(57,'icon')"	count lua	"getGroundItemProperty(57,'count')"	usages lua	"getGroundItemProperty(57,'usages')"
		action "groundItemClick2(57)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(57,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot58"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(58)"	area 292 491 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(58,'name')"	tint lua	"getGroundItemProperty(58,'tint')"
		icon lua	"getGroundItemProperty(58,'icon')"	count lua	"getGroundItemProperty(58,'count')"	usages lua	"getGroundItemProperty(58,'usages')"
		action "groundItemClick2(58)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(58,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}
	button
	{
		name "quicklootSlot59"	enabled "QuicklootMode == UIStrings.UI_Expert and getSlotContainerId(59)"	area 346 491 0 0	bam STONSLOT	tooltip lua	"getGroundItemProperty(59,'name')"	tint lua	"getGroundItemProperty(59,'tint')"
		icon lua	"getGroundItemProperty(59,'icon')"	count lua	"getGroundItemProperty(59,'count')"	usages lua	"getGroundItemProperty(59,'usages')"
		action "groundItemClick2(59)"	actionEnter "mouseOverQuicklootContainer = getSlotContainerId(59,'containerId')"	actionExit "mouseOverQuicklootContainer = nil"
	}	
}
menu
{
	name 'WORLD_PICKPARTY'
	align center bottom
	ignoreEsc
	label
	{
		area 0 0 845 160
		mosaic GUWPKPC0
	}
	label
	{
		area 14 11 431 32
		text "REMOVE_MEMBERS_LABEL"
		text style "label"
		align left center
	}
	button
	{
		area 13 54 61 91
		bitmap lua "worldScreen:GetPickPartyPortrait(0)"
		glow lua "worldScreen:GetPickPartyCharacterId(0) == worldScreen:GetPickPartyRemoveCharacterId()"
		action
		"
			worldScreen:OnPickPartyPortraitButtonClick(0)
		"
	}
	button
	{
		area 75 54 61 91
		bitmap lua "worldScreen:GetPickPartyPortrait(1)"
		glow lua "worldScreen:GetPickPartyCharacterId(1) == worldScreen:GetPickPartyRemoveCharacterId()"
		action
		"
			worldScreen:OnPickPartyPortraitButtonClick(1)
		"
	}
	button
	{
		area 137 54 61 91
		bitmap lua "worldScreen:GetPickPartyPortrait(2)"
		glow lua "worldScreen:GetPickPartyCharacterId(2) == worldScreen:GetPickPartyRemoveCharacterId()"
		action
		"
			worldScreen:OnPickPartyPortraitButtonClick(2)
		"
	}
	button
	{
		area 199 54 61 91
		bitmap lua "worldScreen:GetPickPartyPortrait(3)"
		glow lua "worldScreen:GetPickPartyCharacterId(3) == worldScreen:GetPickPartyRemoveCharacterId()"
		action
		"
			worldScreen:OnPickPartyPortraitButtonClick(3)
		"
	}
	button
	{
		area 261 54 61 91
		bitmap lua "worldScreen:GetPickPartyPortrait(4)"
		glow lua "worldScreen:GetPickPartyCharacterId(4) == worldScreen:GetPickPartyRemoveCharacterId()"
		action
		"
			worldScreen:OnPickPartyPortraitButtonClick(4)
		"
	}
	button
	{
		area 323 54 61 91
		bitmap lua "worldScreen:GetPickPartyPortrait(5)"
		glow lua "worldScreen:GetPickPartyCharacterId(5) == worldScreen:GetPickPartyRemoveCharacterId()"
		action
		"
			worldScreen:OnPickPartyPortraitButtonClick(5)
		"
	}
	button
	{
		area 385 54 61 91
		bitmap lua "worldScreen:GetPickPartyPortrait(6)"
		glow lua "worldScreen:GetPickPartyCharacterId(6) == worldScreen:GetPickPartyRemoveCharacterId()"
		action
		"
			worldScreen:OnPickPartyPortraitButtonClick(6)
		"
	}
	label
	{
		area 747 11 91 32
		text lua "game:GetCharacterOverflowCount()"
		text style "normal"
		align center center
	}
	button
	{
		area 638 54 200 44
		bam guibutnt
		text "REMOVE_BUTTON"
		text style "button"
		clickable lua "worldScreen:IsPickPartyRemoveButtonClickable()"
		action
		"
			popup2Button(17518, 'REMOVE_BUTTON', function() worldScreen:RemoveCharacterFromParty() end)
		"
	}
	button
	{
		area 638 101 200 44
		bam guibutnt
		text "DONE_BUTTON"
		text style "button"
		clickable lua "worldScreen:IsPickPartyDoneButtonClickable()"
		on esc
		action
		"
			worldScreen:OnPickPartyDoneButtonClick()
		"
	}
}
`
currentSave = 0
function getSaveBackground(row)
	if(row == currentSave) then
		return "RGSAVEB"
	else
		return "RGSAVEA"
	end
end

function getLoadArea()
	local screenWidth, screenHeight = Infinity_GetScreenSize()
	if screenWidth <= 1372 and LeftSideMenu == 0 then
	Infinity_SetArea('SaveArea', 0, 0, screenWidth-444, screenHeight)
	Infinity_SetArea('SaveAreaPanel', -50, 0, screenWidth-394, 2160)
	elseif screenWidth > 1372 and screenWidth <= 1552 and LeftSideMenu == 0 then
	Infinity_SetArea('SaveArea', 0, 0, 928, screenHeight)
	Infinity_SetArea('SaveAreaPanel', -42, 0, 1012, 2160)
	elseif screenWidth > 1552 and LeftSideMenu == 0 then
	Infinity_SetArea('SaveArea', screenWidth-1552, 0, 928, screenHeight)
	Infinity_SetArea('SaveAreaPanel', screenWidth-1594, 0, 1012, 2160)
	
	elseif screenWidth <= 1372 and LeftSideMenu == 1 then
	Infinity_SetArea('SaveArea', 444, 0, screenWidth-444, screenHeight)
	Infinity_SetArea('SaveAreaPanel', 444, 0, screenWidth-444, 2160)
	elseif screenWidth > 1372 and screenWidth <= 1552 and LeftSideMenu == 1 then
	Infinity_SetArea('SaveArea', 444, 0, 928, screenHeight)
	Infinity_SetArea('SaveAreaPanel', 444, 0, 1012, 2160)
	elseif screenWidth > 1552 and LeftSideMenu == 1 then
	Infinity_SetArea('SaveArea', 624, 0, 928, screenHeight)
	Infinity_SetArea('SaveAreaPanel', 582, 0, 1012, 2160)
	end
	if LeftSideMenu == 1 then
	Infinity_SetArea('LoadPanel', 76, nil, nil, nil)
	Infinity_SetArea('LoadTitle1', 33, nil, nil, nil)
	Infinity_SetArea('LoadTitle2', 16, nil, nil, nil)
	Infinity_SetArea('LoadTitle3', 18, nil, nil, nil)
	Infinity_SetArea('LoadButton1', 135, nil, nil, nil)
	Infinity_SetArea('LoadButton2', 135, nil, nil, nil)
	Infinity_SetArea('LoadButton3', 135, nil, nil, nil)
	Infinity_SetArea('MenuLoadLabel', 135 , nil, nil, nil)
	Infinity_SetArea('LoadFilter1', 149, nil, nil, nil)
	Infinity_SetArea('LoadFilter2', 149, nil, nil, nil)
	Infinity_SetArea('LoadFilter3', 149, nil, nil, nil)
	Infinity_SetArea('LoadFilterLabel1', 135, nil, nil, nil)
	Infinity_SetArea('LoadFilterLabel2', 135, nil, nil, nil)
	Infinity_SetArea('LoadFilterLabel3', 135, nil, nil, nil)
	else
	Infinity_SetArea('LoadPanel', screenWidth-444, nil, nil, nil)
	Infinity_SetArea('LoadTitle1', screenWidth-510, nil, nil, nil)
	Infinity_SetArea('LoadTitle2', screenWidth-510, nil, nil, nil)
	Infinity_SetArea('LoadTitle3', screenWidth-532, nil, nil, nil)
	Infinity_SetArea('LoadButton1', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('LoadButton2', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('LoadButton3', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('MenuLoadLabel', screenWidth-384 , nil, nil, nil)
	Infinity_SetArea('LoadFilter1', screenWidth-370, nil, nil, nil)
	Infinity_SetArea('LoadFilter2', screenWidth-370, nil, nil, nil)
	Infinity_SetArea('LoadFilter3', screenWidth-370, nil, nil, nil)
	Infinity_SetArea('LoadFilterLabel1', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('LoadFilterLabel2', screenWidth-384, nil, nil, nil)
	Infinity_SetArea('LoadFilterLabel3', screenWidth-384, nil, nil, nil)
	end
end
	
LoadSearchString = ""
function LoadContainsSearchString(rowNumber)
	
	if(LoadSearchString == nil or LoadSearchString == "") then return 1 end --no search string, do nothing
	
	local text = gameSaves.files[rowNumber].sName
	if(string.find(string.lower(text),string.lower(LoadSearchString))) then
		return 1
	else
		return nil --does not contain search string
	end
end
LoadSearchString1 = ""
function LoadContainsSearchString1(rowNumber)
	
	if(LoadSearchString1 == nil or LoadSearchString1 == "") then return 1 end --no search string, do nothing
	
	local text = string.sub(gameSaves.files[rowNumber].fileName,10)
	if(string.find(string.lower(text),string.lower(LoadSearchString1))) then
		return 1
	else
		return nil --does not contain search string
	end
end
LoadSearchString2 = ""
function LoadContainsSearchString2(rowNumber)
	
	if(LoadSearchString2 == nil or LoadSearchString2 == "") then return 1 end --no search string, do nothing
	
	local text = gameSaves.files[rowNumber].chapter
	if(string.find(string.lower(text),string.lower(LoadSearchString2))) then
		return 1
	else
		return nil --does not contain search string
	end
end
`
menu
{
	name 'LOAD'
	align top left
	ignoreEsc
	onOpen
	"
		LeftSideMenu = Infinity_GetINIValue('Game Options','LeftSideMenu',0)
		getLoadArea()
	"
	button
	{
		area	0 0 1024 768
--		mosaic	GUISMBM --GUISRSVB
		action 
		"
			currentSave = nil
		"
	}
--	label
--	{
		--center this under the menu
		--(2160/2) - (768/2) = 696
--		area 1500 0 390 1080
--		bam "STRTSIDE"
--		frame lua "getSidebarFrame()"
--	}
	label
	{
		name "LoadPanel"
		area 922 190 368 470
		mosaic "RGMMENU"
	}
	label
	{
		name "SaveAreaPanel"
		area -50 0 972 2160
		mosaic "RGLOAD"
	}
	label
	{
		name "LoadFilterLabel1"
		area 982 300 249 45
		bam		'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
	}
	label
	{
		name "LoadFilterLabel2"
		area 982 250 249 45
		bam		'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
	}
	label
	{
		name "LoadFilterLabel3"
		area 982 350 249 45
		bam		'STARTBUT'
		sequence lua "getCampaignButtonSequence()"
	}
	edit
	{
		name "LoadFilter1"
		area	996 300 225 45
		var LoadSearchString
		placeholder 'RG_FILTER1'
		text style "edit"
		maxlines 1
		align left center
	}
	edit
	{
		name "LoadFilter2"
		area	996 250 225 45
		var LoadSearchString1
		placeholder 'RG_FILTER2'
		text style "edit"
		maxlines 1
		align left center
	}
	edit
	{
		name "LoadFilter3"
		area	996 350 225 45
		var LoadSearchString2
		placeholder 'RG_FILTER3'
		text style "edit"
		maxlines 1
		align left center
	}
	label
	{
		name "LoadTitle1"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 0"
		area 856 78 488 96
		bam 'RGTITLE'
		sequence 0
		frame 0
	}
	label
	{
		name "LoadTitle2"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 1"
		area 856 78 488 96
		bam 'RGTITLE'
		sequence 0
		frame 1
	}
	label
	{
		name "LoadTitle3"
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BP"
		area 834 78 488 96
		bam 'RGTITLE'
		sequence 0
		frame 2
	}
	label
	{
		name"MenuLoadLabel"
		area 982 205 249 40
		text "LOAD_TITLE"
		text style "title"
	}
	list
	{
		column 
		{ 
			width	100
			label
			{
				area 		0,0,928,-1
				enabled	"LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber)"
				mosaic lua	'getSaveBackground(rowNumber)'
				respectClipping 
				align		center center
				}
			button
			{
				enabled		"LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasScreenShot"
				area		0 0 60 60
				bitmap res 	"gameSaves.files[rowNumber].screenshot"
				bitmap area	8 8 130 82 
				align		center center
			}

			label
			{
				area	416 21 298 30
				enabled	"LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber)"
				text	lua "gameSaves.files[rowNumber].slotName"
				text style "label"
				align	left top
			}
	
			label
			{
				area	414 57 468 30
				enabled	"LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber)"
				text	lua "gameSaves.files[rowNumber].chapter .. ' ' .. gameSaves.files[rowNumber].time"
				text style "label"
				align	right top
			--	pad		0 0 -200 0				
			}
			label
			{
				area	714 21 168 30
				enabled	"LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber)"
				text	lua "gameSaves.files[rowNumber].sName"
				text style "label"
				align	right top
			}
			button
			{
				enabled		 "LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait0"
				area	163 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait0"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait1"
				area	198 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait1"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait2"
				area	234 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait2"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait3"
				area	269 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait3"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait4"
				area	304 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait4"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber) and LoadContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait5"
				area	339 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait5"
				bitmap area	0 0 30 48 
				align	center center
			}
		}
--		column 
--		{ 
--			width	25
--			label
--			{
--				area 		-684,0,928,-1
--				enabled	"LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber)"
--				mosaic lua	'getSaveBackground(rowNumber)'
--				respectClipping 
--				align		center center
--			}
--			label
--			{
--				area	8 20 195 100
--				enabled	"LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber)"
--				text	lua "gameSaves.files[rowNumber].sName"
--				text style "label_loadname"
--				align	center center
--			}
--		}

		actionDbl
		"
			Infinity_PlaySound('GAM_09')
			loadScreen:LoadGame(gameSaves.files[currentSave].fileName)
		"
		
		name "SaveArea"
		area 0 0 922 768
		rowheight	dynamic
		hidehighlight
		table		"gameSaves.files"
		var		currentSave
		scrollbar	'GUISCRC'
--		seperator	"LoadContainsSearchString(rowNumber) and LoadContainsSearchString1(rowNumber)"
	}

	button
	{
		name "LoadButton1"
		area		982 450 249 45
		bam			'STARTBUT'
		clickable	lua	"currentSave"		
		text		"LOAD_BUTTON"
		text style	"button"
		sequence lua "getCampaignButtonSequence()"
		action
		"
			Infinity_PlaySound('GAM_09')
			loadScreen:LoadGame(gameSaves.files[currentSave].fileName)
		"
	}
	button
	{
		name "LoadButton2"
		enabled 	"gameSaves.isImporting ~= 1"
		area		982 500 249 45
		bam			'STARTBUT'
		clickable	lua	"currentSave"		
		text		"DELETE_BUTTON"
		text style	"button"
		sequence lua "getCampaignButtonSequence()"
		action
		"
			popup2Button(15305, 'DELETE_BUTTON',
			 function() loadScreen:DeleteGame(gameSaves.files[currentSave].slotIndex) end)
		"
	}
	button
	{
		name "LoadButton3"
		area		982 550 249 45
		bam			'STARTBUT'
		text		"BACK_BUTTON"
		text style	"button"
		sequence lua "getCampaignButtonSequence()"
		on escape
		action
		"
				LoadSearchString = ''
				LoadSearchString1 = ''
				LoadSearchString2 = ''
				
				loadScreen:OnMainCancelButtonClick()
		"
	}
}
`
function compareSaves(s1,s2)
		--return true if s1 comes before s2
		--show the most recent saves first
		return s1.fileTime > s2.fileTime
	end
	function sortSaves()
		table.sort(gameSaves.files,compareSaves)
end
	
SaveSearchString = ""
function SaveContainsSearchString(rowNumber)
	
	if(SaveSearchString == nil or SaveSearchString == "") then return 1 end --no search string, do nothing
	
	local text = gameSaves.files[rowNumber].sName
	if(string.find(string.lower(text),string.lower(SaveSearchString))) then
		return 1
	else
		return nil --does not contain search string
	end
end
SaveSearchString1 = ""
function SaveContainsSearchString1(rowNumber)
	
	if(SaveSearchString1 == nil or SaveSearchString1 == "") then return 1 end --no search string, do nothing
	
	local text = gameSaves.files[rowNumber].fileName
	if(string.find(string.lower(text),string.lower(SaveSearchString1))) then
		return 1
	else
		return nil --does not contain search string
	end
end
SaveSearchString2 = ""
function SaveContainsSearchString2(rowNumber)
	
	if(SaveSearchString2 == nil or SaveSearchString2 == "") then return 1 end --no search string, do nothing
	
	local text = gameSaves.files[rowNumber].chapter
	if(string.find(string.lower(text),string.lower(SaveSearchString2))) then
		return 1
	else
		return nil --does not contain search string
	end
end
`
menu
{
	name 'SAVE'
	align center center
	ignoreEsc
	label
	{
		area	0 0 1444 818
		mosaic	RGSAVE --GUISRSVB
		action 
		"
			currentSave = nil
		"
	}
	label
	{
		area 250 32 944 44
		text "SAVE_TITLE"
		text style "title"
	}
	label
	{
		name "SaveFilterLabel1"
		area 1092 482 230 44
		bam			GUIBUTMT
	}
	label
	{
		name "SaveFilterLabel2"
		area 1092 428 230 44
		bam			GUIBUTMT
	}
	label
	{
		name "SaveFilterLabel3"
		area 1092 374 230 44
		bam			GUIBUTMT
	}
	edit
	{
		name "SaveFilter1"
		area	1102 428 215 44
		var SaveSearchString
		placeholder 'RG_FILTER1'
		text style "edit"
		maxlines 1
		align left center
	}
	edit
	{
		name "SaveFilter2"
		area	1102 374 215 44
		var SaveSearchString1
		placeholder 'RG_FILTER2'
		text style "edit"
		maxlines 1
		align left center
	}
	edit
	{
		name "SaveFilter3"
		area	1102 482 215 44
		var SaveSearchString2
		placeholder 'RG_FILTER3'
		text style "edit"
		maxlines 1
		align left center
	}

	list
	{
		column 
		{ 
			width	75
			label
			{
				area 		0,0,928,-1
				enabled	"SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber)"
				mosaic lua	'getSaveBackground(rowNumber)'
				respectClipping 
				align		center center
				}
			button
			{
				enabled		"SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasScreenShot"
				area		0 0 60 60
				bitmap res 	"gameSaves.files[rowNumber].screenshot"
				bitmap area	8 8 130 82 
				align		center center
			}

			label
			{
				area	416 21 298 30
				enabled	"SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber)"
				text	lua "gameSaves.files[rowNumber].slotName"
				text style "label"
				align	left top
			}
	
			label
			{
				area	416 57 280 30
				enabled	"SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber)"
				text	lua "gameSaves.files[rowNumber].chapter .. ' ' .. gameSaves.files[rowNumber].time"
				text style "label"
				align	left top
			--	pad		0 0 -200 0				
			}			
			
			button
			{
				enabled		 "SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait0"
				area	163 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait0"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait1"
				area	198 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait1"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait2"
				area	234 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait2"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait3"
				area	269 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait3"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait4"
				area	304 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait4"
				bitmap area	0 0 30 48 
				align	center center
			}
			button
			{
				enabled		 "SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber) and gameSaves.files[rowNumber].hasPortrait5"
				area	339 34 30 64
				bitmap res "gameSaves.files[rowNumber].portrait5"
				bitmap area	0 0 30 48 
				align	center center
			}
		}
		column
		{
			width	25
			label
			{
				area 		-684,0,928,-1
				enabled	"SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber)"
				mosaic lua	'getSaveBackground(rowNumber)'
				respectClipping 
				align		center center
			}
			label
			{
				area	10 21 195 30
				enabled	"SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber)"
				text	lua "gameSaves.files[rowNumber].sName"
				text style "label"
				align	center top
			}
			label
			{
				area		10 47 195 40
				enabled	"SaveContainsSearchString(rowNumber) and SaveContainsSearchString1(rowNumber) and SaveContainsSearchString2(rowNumber)"
				bam 		GUIBUTNT
				frame lua 	"currentCellCheck(2)"
				sequence 	0
				text		"SAVE_BUTTON"
				text style	"button"
			}
		}

		action 
		"
			if cellNumber == 1 then
				cellNumber = nil
			elseif cellNumber == 2 then
				cellNumber = nil
				Infinity_PlaySound('GAM_09')
				Infinity_PushMenu( 'SAVE_NEWSAVE' );
			end
		"

		actionDbl
		"
			Infinity_PlaySound('GAM_09')
			Infinity_PushMenu( 'SAVE_NEWSAVE' );
		"
		
		area 98 84 928 690
		rowheight	dynamic
		table		"gameSaves.files"
		hidehighlight
		var		currentSave
		scrollbar	'GUISCRC'
	}
--	button 
--	{
--		area	48 108 928 148
--		mosaic		GUISAVEB
--	}
--	label
--	{
--		area	248 120 300 30
--		text	'NEW_SAVE_LABEL'
--		text style "label"
--		text align left center
--	}
	button
	{
		area		1092 196 230 44
		bam			GUIBUTMT
		text		"NEW_SAVE_LABEL"
		text style	"button"
		action
		"
			--saveScreen:SaveGame(#saveFiles, 'Test Save ' .. #saveFiles)
			currentSave = 0
			Infinity_PushMenu( 'SAVE_NEWSAVE' );
		"
	}

	button
	{
		area		1092 590 230 44
		bam			GUIBUTMT
		clickable	lua	"currentSave"		
		text		"DELETE_BUTTON"
		text style	"button"
		action
		"
			popup2Button(15305, 'DELETE_BUTTON',
			 function() saveScreen:DeleteGame(gameSaves.files[currentSave].slotIndex) end)
		"
	}
	button
	{
		area		1092 644 230 44
		bam			GUIBUTMT
		text		"BACK_BUTTON"
		text style	"button"
		action
		"
			saveScreen:OnMainCancelButtonClick()
		"
	}
}
`
	newSaveName = ''
	function completeSave()
		Infinity_Log('not overwrite')
		Infinity_PopMenu('SAVE_NEWSAVE')
		saveScreen:SaveGame(#gameSaves.files, newSaveName)
	end
	function completeOverwrite()
		Infinity_Log('overwrite')
		Infinity_PopMenu('SAVE_NEWSAVE')
		saveScreen:SaveGame(gameSaves.files[currentSave].slotIndex,newSaveName)
	end

`
menu
{
	name 'SAVE_NEWSAVE'
	align center center
	modal
	onOpen
	"
		bitmapbools = 
		{
			hasScreenShot = 0,
			hasPortrait0 = 0,
			hasPortrait1 = 0,
			hasPortrait2 = 0,
			hasPortrait3 = 0,
			hasPortrait4 = 0,
			hasPortrait5 = 0,
		}
		newSaveName = ''
		if currentSave ~= 0 then
			newSaveName = gameSaves.files[currentSave].slotName
			bitmapbools = 
			{
			hasScreenShot = gameSaves.files[currentSave].hasScreenShot,
			hasPortrait0 = gameSaves.files[currentSave].hasPortrait0,
			hasPortrait1 = gameSaves.files[currentSave].hasPortrait1,
			hasPortrait2 = gameSaves.files[currentSave].hasPortrait2,
			hasPortrait3 = gameSaves.files[currentSave].hasPortrait3,
			hasPortrait4 = gameSaves.files[currentSave].hasPortrait4,
			hasPortrait5 = gameSaves.files[currentSave].hasPortrait5,
			}
		end
		Infinity_FocusTextEdit('newSaveNameArea')
	"
	label
	{
		area	0 0 786 341
		mosaic	GUISRRQB
	}
	label
	{
		area	42 20 300 30
		text	"ENTER_SAVE_LABEL"
		text style "label"
		text align left center
	}
	edit
	{
		name        "newSaveNameArea"
		area		246 66 466 32
		var			newSaveName	
		text style	"edit"
		maxlines	1
		fill        112 111 111 64
		action
		"
			--On return pressed
			if (key_pressed == 13) then
				if(currentSave ~= 0) then
					completeOverwrite()
				else
					completeSave()
				end
				return -1
			end
			return 1
		"
	}
	label
	{
		area	252 110 424 34
		text	lua "gameSaves.currentGameInfo.chapter .. ' ' .. gameSaves.currentGameInfo.time"
		text style "label"
		text align left center
	}
	button
	{
		enabled		 "bitmapbools.hasScreenShot"
		area	64 70 160 138
		bitmap res "gameSaves.files[currentSave].screenshot"
		align	center center
	}
	button
	{
		enabled		 "bitmapbools.hasPortrait0"
		area	338 164 30 48
		bitmap res "gameSaves.files[currentSave].portrait0"
		align	center center
	}
	button
	{
		enabled		 "bitmapbools.hasPortrait1"
		area	402 164 30 48
		bitmap res "gameSaves.files[currentSave].portrait1"
		align	center center
	}
	button
	{
		enabled		 "bitmapbools.hasPortrait2"
		area	462 164 30 48
		bitmap res "gameSaves.files[currentSave].portrait2"	
		align	center center
	}
	button
	{
		enabled		 "bitmapbools.hasPortrait3"
		area	524 164 30 48
		bitmap res "gameSaves.files[currentSave].portrait3"
		align	center center
	}
	button
	{
		enabled		 "bitmapbools.hasPortrait4"
		area	592 164 30 48
		bitmap res "gameSaves.files[currentSave].portrait4"
		align	center center
	}
	button
	{
		enabled		 "bitmapbools.hasPortrait5"
		area	654 164 30 48
		bitmap res "gameSaves.files[currentSave].portrait5"
		align	center center
	}
	button
	{
		area	528 254 200 44
		bam		GUIBUTNT
		text	"SAVE_BUTTON"
		text style "button"
		action
		"
			completeSave()
		"
	}
	button
	{
		enabled	currentSave
		area	528 254 200 44
		bam		GUIBUTNT
		text	"OVERWRITE_BUTTON"
		text style "button"
		action
		"
			completeOverwrite()
		"
	}
	button
	{
		area	228 254 200 44
		bam		GUIBUTNT
		text	"CANCEL_BUTTON"
		text style "button"
		action
		"
			Infinity_PopMenu('SAVE_NEWSAVE')			
		"
	}
}
menu
{
	name 'CHARACTER_SELECT'
	align center center
	onopen "selectedCharacter = 0"
	ignoreesc
	label
	{
		mosaic GUICGPR
		area 0 0 1024 768
	}
	label
	{
		area 170 16 690 44
		text "CHARGEN_TITLE"
		text style "title"
	}
	label
	{
		area 26 64 978 622
		rectangle 3
	}
	list
	{
		column
		{
			width 8
			label
			{
				area 0 0 0 100 --hack to pad the portrait on the bottom by forcing a min rowheight
			}
			label
			{
				area 10 8 54 84
				bitmap lua "character_select[rowNumber].portrait"
			}
		}
		column
		{
			width 92
			label
			{
				area 20 4 -1 -1
				text lua "character_select[rowNumber].name .. '\n' .. character_select[rowNumber].desc" 
				text style "label"
				text align left top
			}
		}

		area 50 84 932 586
		rowheight dynamic
		table "character_select"
		var selectedCharacter
		scrollbar GUISCRC
	}
	button
	{
		area 520 686 237 66
		text "DONE_BUTTON" 
		text style "button"
		bam GUIBUTST
		clickable lua "selectedCharacter ~= 0"
		action "
			createCharScreen:OnPrerollCharacterPick(character_select[selectedCharacter].id)
			Infinity_PopMenu('CHARACTER_SELECT')
			"
	}
	button
	{
		on escape
		bam GUIBUTST
		area 268 686 237 66
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu('CHARACTER_SELECT');"
	}

}
`
chargen = {

	races = {},
	kits = {},

}
function chargenAcceptOrExport()
	if createCharScreen:GetEngineState() == 4 then
		return t("EXPORT_BUTTON")
	else
		return t("ACCEPT_BUTTON")

	end
end


`
menu
{
	name 'CHARGEN'
	align center center
	ignoreesc
	onopen "randomCharacter = 0;"
	label
	{
		area 0 0 1444 818
		mosaic 'RGCGB'
	}
	label
	{
		area 376 32 690 44
		text "CHARGEN_TITLE"
		text style "title"
	}
	text
	{
		area 358 184 342 512
		text lua "chargen.information"
		scrollbar 'GUISCRC'
		text style "normal"
	}
	text
	{
		enabled "createCharScreen:GetCurrentStep() >= 17"
		area 748 184 342 512
		text lua "createBioEdit"
		scrollbar 'GUISCRC'
		text style "normal"
	}
	label
	{
		area 1142 248 210 330
		bitmap lua "chargen.portrait"
	}

	button
	{
		area 90 243 212 33
		bam RGCGBUT
		sequence 0
		clickable lua "createCharScreen:GetCurrentStep() == 0"
		glow lua "createCharScreen:GetCurrentStep() == 0"
		text "GENDER_BUTTON"
		text style "button"
		pad 8 2 8 2
		action "createCharScreen:OnMenuButtonClick()"
	}
	button
	{
		area 90 278 212 33
		bam RGCGBUT
		sequence 1
		clickable lua "createCharScreen:GetCurrentStep() == 3"
		glow lua "createCharScreen:GetCurrentStep() == 3"
		text "RACE_BUTTON"
		text style "button"
		pad 8 2 8 2
		action "createCharScreen:OnMenuButtonClick()"
	}
	button
	{
		area 90 313 212 33
		bam RGCGBUT
		sequence 2
		clickable lua "createCharScreen:GetCurrentStep() == 4"
		glow lua "createCharScreen:GetCurrentStep() == 4"
		text "CLASS_TITLE"
		text style "button"
		pad 8 2 8 2
		action "createCharScreen:OnMenuButtonClick()"
	}
	button
	{
		area 90 348 212 33
		bam RGCGBUT
		sequence 1
		clickable lua "createCharScreen:GetCurrentStep() == 7"
		glow lua "createCharScreen:GetCurrentStep() == 7"
		text "ALIGNMENT_BUTTON"
		text style "button"
		pad 8 2 8 2
		action "createCharScreen:OnMenuButtonClick()"
	}

	button
	{
		area 90 383 212 33
		bam RGCGBUT
		sequence 0
		clickable lua "createCharScreen:GetCurrentStep() == 8"
		glow lua "createCharScreen:GetCurrentStep() == 8"
		text "ABILITIES_BUTTON"
		text style "button"
		pad 8 2 8 2
		action "createCharScreen:OnMenuButtonClick()"
	}
	button
	{
		area 90 418 212 33
		bam RGCGBUT
		sequence 1
		clickable lua "createCharScreen:GetCurrentStep() == 9"
		glow lua "createCharScreen:GetCurrentStep() == 9"
		text "SKILLS_BUTTON"
		text style "button"
		pad 8 2 8 2
		action "createCharScreen:OnMenuButtonClick()"
	}
	button
	{
		area 90 453 212 33
		bam RGCGBUT
		sequence 2
		clickable lua "createCharScreen:GetCurrentStep() == 15"
		glow lua "createCharScreen:GetCurrentStep() == 15"
		text "APPEARANCE_BUTTON"
		text style "button"
		pad 8 2 8 2
		action "createCharScreen:OnMenuButtonClick()"
	}
	button
	{
		area 90 488 212 33
		bam RGCGBUT
		sequence 0
		clickable lua "createCharScreen:GetCurrentStep() == 17"
		glow lua "createCharScreen:GetCurrentStep() == 17"
		text "BIOGRAPHY_BUTTON"
		text style "button"
		pad 8 2 8 2
		action "createCharScreen:OnBiographyButtonClick()"
	}
	button
	{
		area 90 523 212 33
		bam RGCGBUT
		sequence 1
		clickable lua "createCharScreen:GetCurrentStep() == 17"
		glow lua "createCharScreen:GetCurrentStep() == 17"
		text "NAME_BUTTON"
		text style "button"
		pad 8 2 8 2
		action "createCharScreen:OnMenuButtonClick()"
	}

	button
	{
		area 1134 604 230 44
		text "IMPORT_BUTTON"
		text style "button"
		bam GUIBUTMT
		action "createCharScreen:OnImportCharacterButtonClick()"
	}
	button
	{
		enabled "createCharScreen:GetCurrentStep() == 0"
		area 82 604 230 44
		text "RG_RANDOM"
		text style "button"
		pad 8 2 8 2
		bam GUIBUTMT
		action "randChar()"
	}
	button
	{
		enabled "randomCharacter == 1 and createCharScreen:GetCurrentStep() == 15"
		area 82 604 230 44
		text "RG_RANDOM"
		text style "button"
		pad 8 2 8 2
		bam GUIBUTMT
		action "
			chargen.information = nil
			randomCharacter = 0
			for i=1,5,1 do
				createCharScreen:OnMainBackButtonClick()
			end
			randomCharacter = 1
			randChar()
		"
	}
	button
	{
		on escape
		area 352 732 230 44
		text "BACK_BUTTON"
		text style "button"
		bam GUIBUTMT
		clickable lua "createCharScreen:IsMainBackButtonClickable()"
		action
		"
		createCharScreen:OnMainBackButtonClick()
		randomCharacter = 0
		"
	}
	button
	{
		on escape
		area 352 732 232 44
		text "CANCEL_BUTTON"
		text style "button"
		bam GUIBUTMT
		enabled "not createCharScreen:IsMainBackButtonClickable()"
		action "createCharScreen:OnMainCancelButtonClick()"
	}
	button
	{
		area 610 732 230 44
		text lua "chargenAcceptOrExport()"
		text style "button"
		bam GUIBUTMT
		clickable lua "createCharScreen:IsChargenComplete()"
		action "createCharScreen:AcceptCharacter(-1)"
	}
	button
	{
		area 866 732 230 44
		text "CREATE_PARTY_BUTTON"
		text style "button"
		bam GUIBUTMT
		clickable lua "createCharScreen:IsAdvancedButtonClickable() == true"
		action "createCharScreen:OnAdvancedButtonClick()"
	}
}
`
createCharGenderHelp = 24313
`
menu
{
	name 'CHARGEN_GENDER'
--	modal
	align center center
	ignoreesc
	onOpen "toggleMale = 0; toggleFemale = 0"
	
	label
	{
		area 0 0 1444 818
		mosaic 'RGCGGEN'
	}
	label
	{
		area 476 86 500 38
		text lua "Infinity_FetchString(11990)"
		text style "title"
	}
	label
	{
		area 526 454 392 210
		text lua "Infinity_FetchString(createCharGenderHelp)" 
		text style "normal"
	}
	button
	{
		area 526 248 188 166
		bam GUIGEND
		sequence 0
		toggle toggleMale
		action "toggleFemale = 0; createCharScreen:OnGenderSelectButtonClick(1)"
	}
	button
	{
		area 730 248 188 166
		bam GUIGEND
		sequence 1
		toggle toggleFemale
		action "toggleMale = 0; createCharScreen:OnGenderSelectButtonClick(2)"
	}

	button
	{
		on escape
		area 484 724 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 730 724 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "Infinity_PopMenu(); createCharScreen:OnDoneButtonClick()"
	}
}
`
CurrentImage = ""
CImage = ""
charactergender = ""
toggleSex = ""
toggleSort = 0
faNot = 0
fbNot = 0
tSort = ""

function PortraitContainsSearchString(rowNumber)
	
	if(PortraitSearchString == nil or PortraitSearchString == "") then return 1 end --no search string, do nothing
	
	local Portraittext = PortraitPicker[rowNumber][1]
	if fbNot == 1 then
		if(string.find(string.lower(Portraittext),string.lower(PortraitSearchString))) then
			return nil --does not contain search string
		else
			return 1
		end
	else
		if(string.find(string.lower(Portraittext),string.lower(PortraitSearchString))) then
			return 1
		else
			return nil --does not contain search string
		end
	end
end

function PortContainsSearchString(rowNumber)
	
	if(PortSearchString == nil or PortSearchString == "") then return 1 end --no search string, do nothing
	
	local Porttext = PortraitPicker[rowNumber][1]
	if faNot == 1 then
		if(string.find(string.lower(Porttext),string.lower(PortSearchString))) then
			return nil --does not contain search string
		else
			return 1
		end
	else
		if(string.find(string.lower(Porttext),string.lower(PortSearchString))) then
			return 1
		else
			return nil --does not contain search string
		end
	end
end

function SexFilter(rowNumber)
	if (toggleSex == nil or toggleSex == "") then return 1 end --no sex selected

	local Sex = PortraitPicker[rowNumber][2]
	if(string.find(string.lower(Sex),string.lower(toggleSex))) or (string.find(string.lower(Sex),string.lower('d'))) then
		return 1
	else	
		return nil --does not contain search string
	end
end

function compare2(a,b)
	if toggleSort == 0 or toggleSort == 1 then
		UpdatePortraitPicker()
	elseif toggleSort == 2 then
		tSort = PPStrings.PP_SORTAZ
		return string.lower(a[1]) < string.lower(b[1])
	elseif toggleSort == 3 then
		tSort = PPStrings.PP_SORTZA
		return string.lower(a[1]) > string.lower(b[1])
	end
end

function UpdatePortraitPicker()
	PortraitPicker = {}
	if toggleSort == 0 then
		AddBGImages()
		Addportraits()
		tSort = PPStrings.PP_SORTDC
	elseif toggleSort == 1 then
		Addportraits()
		AddBGImages()
		tSort = PPStrings.PP_SORTCD
	end
end

function AddBGImages()
	for i=1,#BGImages,1 do
		local name = BGImages[i][1]
		local fname = BGImages[i][3]
		if BGImages[i][2] == 'F' then 
			BGgender = 'F'
		elseif BGImages[i][2] == 'M' then
			BGgender = 'M'
		elseif BGImages[i][2] == 'D' then
			BGgender = 'D'
		end
		
		table.insert(PortraitPicker, i, {name,BGgender,string.lower(fname)})
	end
end

function Addportraits()
	for i=1,#portraits,1 do
		local name = portraits[i][1] 
		local fname = name .. 'L'
		if nicks[name] ~= nil then
			name = nicks[name]
		end
		if portraits[i][2] == 2 then 
			BGgender = 'F'
		elseif portraits[i][2] == 1 then
			BGgender = 'M'
		end
		
		table.insert(PortraitPicker, i, {name,BGgender,fname})
	end
end

function GetMediumPortrait()
	HasMediumPortrait = ""
	if (PortraitPicker[CImage][3]) == "" or (PortraitPicker[CImage][3]) == nil then
		HasMediumPortrait = ""
	end
	
	if string.sub(PortraitPicker[CImage][3],-1) == "l" then
		HasMediumPortrait = string.sub(PortraitPicker[CImage][3], 1, (string.len(PortraitPicker[CImage][3])-1)) .. 'm'
	end

end

function getPortraitBackground(row)
	if(row == CImage) then
		return "RGCPBUT"
	else
		return "RGCPBUT1"
	end
end

portraitArray = {}

function ZeroToggleArray()
    togglePort1 = 0
    togglePort2 = 0
    togglePort3 = 0
    togglePort4 = 0
    togglePort5 = 0
    togglePort6 = 0
    togglePort7 = 0
    togglePort8 = 0
    togglePort9 = 0
    togglePort10 = 0  
    togglePort11 = 0
    togglePort12 = 0
    togglePort13 = 0
    togglePort14 = 0
    togglePort15 = 0
    togglePort16 = 0
    togglePort17 = 0
    togglePort18 = 0
    togglePort19 = 0
    togglePort20 = 0  
    togglePort21 = 0
    togglePort22 = 0
    togglePort23 = 0
    togglePort24 = 0
    togglePort25 = 0
    togglePort26 = 0
    togglePort27 = 0
    togglePort28 = 0 
end

function togglePortrait1()
    tempTog = togglePort1
    ZeroToggleArray()
    togglePort1 = tempTog
end

function togglePortrait2()  
    tempTog = togglePort2
    ZeroToggleArray()
    togglePort2 = tempTog
end

function togglePortrait3()
    tempTog = togglePort3
    ZeroToggleArray()
    togglePort3 = tempTog
end

function togglePortrait4()
    tempTog = togglePort4
    ZeroToggleArray()
    togglePort4 = tempTog
end

function togglePortrait5()
    tempTog = togglePort5
    ZeroToggleArray()
    togglePort5 = tempTog
end

function togglePortrait6()
    tempTog = togglePort6
    ZeroToggleArray()
    togglePort6 = tempTog
end

function togglePortrait7()
    tempTog = togglePort7
    ZeroToggleArray()
    togglePort7 = tempTog
end

function togglePortrait8()
    tempTog = togglePort8
    ZeroToggleArray()
    togglePort8 = tempTog
end

function togglePortrait9()
    tempTog = togglePort9
    ZeroToggleArray()
    togglePort9 = tempTog
end

function togglePortrait10()
    tempTog = togglePort10
    ZeroToggleArray()
    togglePort10 = tempTog
end

function togglePortrait11()  tempTog = togglePort11 ZeroToggleArray() togglePort11 = tempTog end
function togglePortrait12()  tempTog = togglePort12 ZeroToggleArray() togglePort12 = tempTog end
function togglePortrait13()  tempTog = togglePort13 ZeroToggleArray() togglePort13 = tempTog end
function togglePortrait14()  tempTog = togglePort14 ZeroToggleArray() togglePort14 = tempTog end
function togglePortrait15()  tempTog = togglePort15 ZeroToggleArray() togglePort15 = tempTog end
function togglePortrait16()  tempTog = togglePort16 ZeroToggleArray() togglePort16 = tempTog end
function togglePortrait17()  tempTog = togglePort17 ZeroToggleArray() togglePort17 = tempTog end
function togglePortrait18()  tempTog = togglePort18 ZeroToggleArray() togglePort18 = tempTog end
function togglePortrait19()  tempTog = togglePort19 ZeroToggleArray() togglePort19 = tempTog end
function togglePortrait20()  tempTog = togglePort20 ZeroToggleArray() togglePort20 = tempTog end
function togglePortrait21()  tempTog = togglePort21 ZeroToggleArray() togglePort21 = tempTog end
function togglePortrait22()  tempTog = togglePort22 ZeroToggleArray() togglePort22 = tempTog end
function togglePortrait23()  tempTog = togglePort23 ZeroToggleArray() togglePort23 = tempTog end
function togglePortrait24()  tempTog = togglePort24 ZeroToggleArray() togglePort24 = tempTog end
function togglePortrait25()  tempTog = togglePort25 ZeroToggleArray() togglePort25 = tempTog end
function togglePortrait26()  tempTog = togglePort26 ZeroToggleArray() togglePort26 = tempTog end
function togglePortrait27()  tempTog = togglePort27 ZeroToggleArray() togglePort27 = tempTog end
function togglePortrait28()  tempTog = togglePort28 ZeroToggleArray() togglePort28 = tempTog end

function OnPortraitArrayClick(thisOne)
    if portraitChoice == thisOne then
        portraitChoice = -1
    else
        portraitChoice = thisOne
    end
end

function IncPortraitArray()
    for index = 1, 28, 1 do
        portraitArray[index] = createCharScreen:GetCurrentPortrait()
        createCharScreen:IncCurrentPortrait()
    end
    ZeroToggleArray()
    portraitChoice = -1
end

function DecPortraitArray()
    for index = 1, 56, 1 do
        createCharScreen:DecCurrentPortrait()
    end
    IncPortraitArray()
    ZeroToggleArray()
    portraitChoice = -1
end

function GetPortrait(portraitIndex)
    return portraitArray[portraitIndex]
end

function ChoosePortrait()
    if portraitChoice == -1 then
        Infinity_PopMenu()
        createCharScreen:OnCancelButtonClick()
    else
        for index = 29, portraitChoice+1, -1 do
            createCharScreen:DecCurrentPortrait()
        end
    end
end

function IsPortraitChosen()
    if portraitChoice == -1 then
        return 0
    else
        return 1
    end
end

`
menu
{
	name 'CHARGEN_PORTRAIT'
	align center center
	ignoreesc
	onopen "
		MultiPortraitPicker = Infinity_GetINIValue('Game Options','MultiPortraitPicker',0)
		if MultiPortraitPicker == 1 then
			IncPortraitArray()
		end
		PortraitSearchString = ''
		PortSearchString = ''
		toggleSex = ''
		CurrentImage = ''
		togs = ''
		toggleSort = 0
		CImage = 0
		faNot = 0
		fbNot = 0
		if toggleMale == 1 then
			toggleSex = 'M'
		elseif toggleFemale == 1 then
			toggleSex = 'F'
		elseif Infinity_FetchString(characters[currentID].gender) == 'Male' then
				toggleSex = 'M'
		elseif Infinity_FetchString(characters[currentID].gender) == 'Female' then
				toggleSex = 'F'
		end
		if toggleSex == 'F' then
			togS = PPStrings.PP_CHAR_FEMALE
		else
			togS = PPStrings.PP_CHAR_MALE
		end
		UpdatePortraitPicker()
	"
	
	label
	{
		enabled "MultiPortraitPicker == 1"
		area 0 0 1444 818
		mosaic 'RGCNAME'
	}
	label
	{
		area 474 84 500 42
		text "APPEARANCE_TITLE"
		text style "title"
	}
	
    button
    {
		enabled "MultiPortraitPicker == 1"
        area 336 362 52 132
        bam GUIPRC
        sequence 0
        action "DecPortraitArray()"
    }
    button
    {
		enabled "MultiPortraitPicker == 1"
        area 1059 362 52 132
        bam GUIPRC
        sequence 1
        action "IncPortraitArray()"
    }
    
    label { enabled "MultiPortraitPicker == 1" area 400 156 80 125 bitmap lua "GetPortrait(1)" }
    label { enabled "MultiPortraitPicker == 1" area 494 156 80 125 bitmap lua "GetPortrait(2)" }
    label { enabled "MultiPortraitPicker == 1" area 588 156 80 125 bitmap lua "GetPortrait(3)" }
    label { enabled "MultiPortraitPicker == 1" area 682 156 80 125 bitmap lua "GetPortrait(4)" }
    label { enabled "MultiPortraitPicker == 1" area 776 156 80 125 bitmap lua "GetPortrait(5)" }
    label { enabled "MultiPortraitPicker == 1" area 870 156 80 125 bitmap lua "GetPortrait(6)" }
    label { enabled "MultiPortraitPicker == 1" area 964 156 80 125 bitmap lua "GetPortrait(7)" }
    label { enabled "MultiPortraitPicker == 1" area 400 295 80 125 bitmap lua "GetPortrait(8)" }
    label { enabled "MultiPortraitPicker == 1" area 494 295 80 125 bitmap lua "GetPortrait(9)" }
    label { enabled "MultiPortraitPicker == 1" area 588 295 80 125 bitmap lua "GetPortrait(10)" }
    label { enabled "MultiPortraitPicker == 1" area 682 295 80 125 bitmap lua "GetPortrait(11)" }
    label { enabled "MultiPortraitPicker == 1" area 776 295 80 125 bitmap lua "GetPortrait(12)" }
    label { enabled "MultiPortraitPicker == 1" area 870 295 80 125 bitmap lua "GetPortrait(13)" }
    label { enabled "MultiPortraitPicker == 1" area 964 295 80 125 bitmap lua "GetPortrait(14)" }
    label { enabled "MultiPortraitPicker == 1" area 400 434 80 125 bitmap lua "GetPortrait(15)" }
    label { enabled "MultiPortraitPicker == 1" area 494 434 80 125 bitmap lua "GetPortrait(16)" }
    label { enabled "MultiPortraitPicker == 1" area 588 434 80 125 bitmap lua "GetPortrait(17)" }
    label { enabled "MultiPortraitPicker == 1" area 682 434 80 125 bitmap lua "GetPortrait(18)" }
    label { enabled "MultiPortraitPicker == 1" area 776 434 80 125 bitmap lua "GetPortrait(19)" }
    label { enabled "MultiPortraitPicker == 1" area 870 434 80 125 bitmap lua "GetPortrait(20)" }
    label { enabled "MultiPortraitPicker == 1" area 964 434 80 125 bitmap lua "GetPortrait(21)" }
    label { enabled "MultiPortraitPicker == 1" area 400 573 80 125 bitmap lua "GetPortrait(22)" }
    label { enabled "MultiPortraitPicker == 1" area 494 573 80 125 bitmap lua "GetPortrait(23)" }
    label { enabled "MultiPortraitPicker == 1" area 588 573 80 125 bitmap lua "GetPortrait(24)" }
    label { enabled "MultiPortraitPicker == 1" area 682 573 80 125 bitmap lua "GetPortrait(25)" }
    label { enabled "MultiPortraitPicker == 1" area 776 573 80 125 bitmap lua "GetPortrait(26)" }
    label { enabled "MultiPortraitPicker == 1" area 870 573 80 125 bitmap lua "GetPortrait(27)" }
    label { enabled "MultiPortraitPicker == 1" area 964 573 80 125 bitmap lua "GetPortrait(28)" }
    
    button { enabled "MultiPortraitPicker == 1" area 395 151 90 135 bam "rgcfram" toggle togglePort1 action "togglePortrait1(); OnPortraitArrayClick(1)" }
    button { enabled "MultiPortraitPicker == 1" area 489 151 90 135 bam "rgcfram" toggle togglePort2 action "togglePortrait2(); OnPortraitArrayClick(2)" }
    button { enabled "MultiPortraitPicker == 1" area 583 151 90 135 bam "rgcfram" toggle togglePort3 action "togglePortrait3(); OnPortraitArrayClick(3)" }
    button { enabled "MultiPortraitPicker == 1" area 677 151 90 135 bam "rgcfram" toggle togglePort4 action "togglePortrait4(); OnPortraitArrayClick(4)" }
    button { enabled "MultiPortraitPicker == 1" area 771 151 90 135 bam "rgcfram" toggle togglePort5 action "togglePortrait5(); OnPortraitArrayClick(5)" }
    button { enabled "MultiPortraitPicker == 1" area 865 151 90 135 bam "rgcfram" toggle togglePort6 action "togglePortrait6(); OnPortraitArrayClick(6)" }
    button { enabled "MultiPortraitPicker == 1" area 959 151 90 135 bam "rgcfram" toggle togglePort7 action "togglePortrait7(); OnPortraitArrayClick(7)" }
    button { enabled "MultiPortraitPicker == 1" area 395 290 90 135 bam "rgcfram" toggle togglePort8 action "togglePortrait8(); OnPortraitArrayClick(8)" }
    button { enabled "MultiPortraitPicker == 1" area 489 290 90 135 bam "rgcfram" toggle togglePort9 action "togglePortrait9(); OnPortraitArrayClick(9)" }
    button { enabled "MultiPortraitPicker == 1" area 583 290 90 135 bam "rgcfram" toggle togglePort10 action "togglePortrait10(); OnPortraitArrayClick(10)" }
    button { enabled "MultiPortraitPicker == 1" area 677 290 90 135 bam "rgcfram" toggle togglePort11 action "togglePortrait11(); OnPortraitArrayClick(11)" }
    button { enabled "MultiPortraitPicker == 1" area 771 290 90 135 bam "rgcfram" toggle togglePort12 action "togglePortrait12(); OnPortraitArrayClick(12)" }
    button { enabled "MultiPortraitPicker == 1" area 865 290 90 135 bam "rgcfram" toggle togglePort13 action "togglePortrait13(); OnPortraitArrayClick(13)" }
    button { enabled "MultiPortraitPicker == 1" area 959 290 90 135 bam "rgcfram" toggle togglePort14 action "togglePortrait14(); OnPortraitArrayClick(14)" }
    button { enabled "MultiPortraitPicker == 1" area 395 429 90 135 bam "rgcfram" toggle togglePort15 action "togglePortrait15(); OnPortraitArrayClick(15)" }
    button { enabled "MultiPortraitPicker == 1" area 489 429 90 135 bam "rgcfram" toggle togglePort16 action "togglePortrait16(); OnPortraitArrayClick(16)" }
    button { enabled "MultiPortraitPicker == 1" area 583 429 90 135 bam "rgcfram" toggle togglePort17 action "togglePortrait17(); OnPortraitArrayClick(17)" }
    button { enabled "MultiPortraitPicker == 1" area 677 429 90 135 bam "rgcfram" toggle togglePort18 action "togglePortrait18(); OnPortraitArrayClick(18)" }
    button { enabled "MultiPortraitPicker == 1" area 771 429 90 135 bam "rgcfram" toggle togglePort19 action "togglePortrait19(); OnPortraitArrayClick(19)" }
    button { enabled "MultiPortraitPicker == 1" area 865 429 90 135 bam "rgcfram" toggle togglePort20 action "togglePortrait20(); OnPortraitArrayClick(20)" }
    button { enabled "MultiPortraitPicker == 1" area 959 429 90 135 bam "rgcfram" toggle togglePort21 action "togglePortrait21(); OnPortraitArrayClick(21)" }
    button { enabled "MultiPortraitPicker == 1" area 395 568 90 135 bam "rgcfram" toggle togglePort22 action "togglePortrait22(); OnPortraitArrayClick(22)" }
    button { enabled "MultiPortraitPicker == 1" area 489 568 90 135 bam "rgcfram" toggle togglePort23 action "togglePortrait23(); OnPortraitArrayClick(23)" }
    button { enabled "MultiPortraitPicker == 1" area 583 568 90 135 bam "rgcfram" toggle togglePort24 action "togglePortrait24(); OnPortraitArrayClick(24)" }
    button { enabled "MultiPortraitPicker == 1" area 677 568 90 135 bam "rgcfram" toggle togglePort25 action "togglePortrait25(); OnPortraitArrayClick(25)" }
    button { enabled "MultiPortraitPicker == 1" area 771 568 90 135 bam "rgcfram" toggle togglePort26 action "togglePortrait26(); OnPortraitArrayClick(26)" }
    button { enabled "MultiPortraitPicker == 1" area 865 568 90 135 bam "rgcfram" toggle togglePort27 action "togglePortrait27(); OnPortraitArrayClick(27)" }
    button { enabled "MultiPortraitPicker == 1" area 959 568 90 135 bam "rgcfram" toggle togglePort28 action "togglePortrait28(); OnPortraitArrayClick(28)" }
    
    label
    {
        enabled "IsPortraitChosen() and MultiPortraitPicker == 1"
        area 1142 248 210 330
        bitmap lua "GetPortrait(portraitChoice)"
    }
    label
    {
		enabled "IsPortraitChosen() and MultiPortraitPicker == 1"
        area 1134 604 230 44
        text lua "GetPortrait(portraitChoice)"
        text style "button"
    }
    button
    {
        on escape
		enabled "MultiPortraitPicker == 1"
        area 484 724 230 44
        bam GUIBUTMT
        text "BACK_BUTTON"
        text style "button"
        action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
    }
    button
    {
        on return
		enabled "MultiPortraitPicker == 1"
        area 730 724 230 44
        bam GUIBUTMT
        text "DONE_BUTTON"
        text style "button"
        clickable lua "IsPortraitChosen()"
        action "ChoosePortrait(); Infinity_PopMenu(); createCharScreen:OnDoneButtonClick()"
    }
	label
	{
		enabled "MultiPortraitPicker == 0"
		area 0 0 1444 818
		mosaic 'RGCGAPP'
	}
--	label
--	{
--		area 82 90 178 44
--		text lua "Infinity_FetchString(32297) .. ': ' .. t(togS)"
--		text style "label"
--		align left center
--	}
	label
	{
		enabled "MultiPortraitPicker == 0"
		area 356 177 346 85
		text 'RG_PP_TOOLTIP'
		text style "label"
		align left center
	}
	label
	{
		enabled "MultiPortraitPicker == 0"
		area 356 498 346 82
		text lua "t(PPStrings.PP_TOTAL) .. '\n' .. t(PPStrings.PP_DEFAULT) ..  t(#portraits) .. '\n' .. t(PPStrings.PP_CUSTOM) .. t(#BGImages)"
		text style "label"
		align left center
	}
	button
	{
		enabled "MultiPortraitPicker == 0"
		area 0 0 0 0
		bam GUIPRC
		sequence 0
		action "createCharScreen:DecCurrentPortrait()"
	}
	button
	{
		enabled "MultiPortraitPicker == 0"
		area 0 0 0 0
		bam GUIPRC
		sequence 1
		action "createCharScreen:IncCurrentPortrait()"
	}
	label
	{
		enabled "CurrentImage ~= '' and MultiPortraitPicker == 0"
		area 1142 248 210 330
		bitmap lua "createCharScreen:GetCurrentPortrait()"
	}
	label
	{
		enabled "CurrentImage == '' and MultiPortraitPicker == 0"
		area 1142 248 210 330
		bitmap "NOPORTMD"
	}
	button
	{
--		enabled "CurrentImage ==''"
		enabled "MultiPortraitPicker == 0"
		area 1134 604 230 44
		bam GUIBUTMT
		text "CUSTOM_BUTTON"
		text style "button"
		action "
--			TEXT_popup_big = 17188
			Infinity_PushMenu('RG_PP_POPUP')
			"
	}
	label
	{
--		area 1120 618 234 78
		enabled "createCharScreen:GetCurrentPortrait() == CurrentImage or string.lower(createCharScreen:GetCurrentPortrait()) == string.lower(CurrentImage) and MultiPortraitPicker == 0"
		rectangle 4
	}
	label
	{
		area 356 372 346 60
		enabled "(createCharScreen:GetCurrentPortrait() == CurrentImage or string.lower(createCharScreen:GetCurrentPortrait()) == string.lower(CurrentImage)) and HasMediumPortrait == '' and MultiPortraitPicker == 0"
		text lua "string.upper(t(PortraitPicker[CImage][1])) .. '\n' .. string.upper(t(PPStrings.PP_FILENAME)) .. t(PortraitPicker[CImage][3])"
		text style "label"
		align left center
	}
	label
	{
		area 356 372 346 60
		enabled "(createCharScreen:GetCurrentPortrait() == CurrentImage or string.lower(createCharScreen:GetCurrentPortrait()) == string.lower(CurrentImage)) and HasMediumPortrait ~= '' and MultiPortraitPicker == 0"
		text lua "string.upper(t(PortraitPicker[CImage][1])) .. '\n' .. string.upper(t(PPStrings.PP_FILENAME)) .. t(PortraitPicker[CImage][3]) .. ' & ' .. t(HasMediumPortrait)"
		text style "label"
		align left center
	}
	label
	{
		enabled "HasMediumPortrait ~= '' and CurrentImage ~= '' and MultiPortraitPicker == 0"
		area 1206 108 76 108
		rectangle 0
	}
	label
	{
		enabled "HasMediumPortrait ~= '' and CurrentImage ~= '' and MultiPortraitPicker == 0"
		area 1217 120 54 85
		bitmap lua "HasMediumPortrait"
	}
	label
	{
		enabled "MultiPortraitPicker == 0"
		area 356 446 346 36
		text lua "t(PPStrings.PP_SORT) .. t(tSort)"
		text style "label"
		align left center
	}
	button
	{
		on escape
		enabled "MultiPortraitPicker == 0"
		area 420 726 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu()
			createCharScreen:OnCancelButtonClick()
			PortraitSearchString = ''
			PortSearchString = ''
			toggleSex = ''
			toggleMale = 0
			toggleFemale = 0
			PortraitPicker = {}
			faNot = 0
			fbNot = 0
		"
	}
	button
	{
		on return
		enabled "MultiPortraitPicker == 0"
		area 806 726 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable() and CurrentImage ~=''"
		action "
			Infinity_PopMenu();
			createCharScreen:OnDoneButtonClick()
			PortraitSearchString = ''
			PortSearchString = ''
			toggleSex = ''
			toggleMale = 0
			toggleFrame = 0
			PortraitPicker = {}
			faNot = 0
			fbNot = 0
		"
	}
	edit
	{
		area	392 668 274 32
		enabled "fbNot == 0 and MultiPortraitPicker == 0"
		var PortraitSearchString
		placeholder "..."
		text style "edit"
		text color 'D'
		maxlines 1
		align left center
		glow lua "PortraitSearchString ~= ''"
		fill 112 111 111 64
	}
	edit
	{
		area	392 668 274 32
		enabled "fbNot == 1 and MultiPortraitPicker == 0"
		var PortraitSearchString
		placeholder "..."
		text style "edit"
		text color 180 0 0 255
		maxlines 1
		align left center
		fill 112 111 111 64
	}
	button
	{
		enabled "PortraitSearchString ~= '' and MultiPortraitPicker == 0"
		area 674 664 34 40
		text "X"
		text style "button"
		action
		"
			PortraitSearchString = ''
			fbNot = 0
		"
	}
	button
	{
		enabled "MultiPortraitPicker == 0"
		area 352 668 36 32
		bam ROUNDBUT
		glow lua "fbNot == 0"
		action
		"
			if fbNot == 0 then
				fbNot = 1
			else
				fbNot = 0
			end
		"
	}
	edit
	{
		area	392 628 274 32
		enabled "faNot == 0 and MultiPortraitPicker == 0"
		var PortSearchString
		placeholder "..."
		text style "edit"
		text color 'D'
		maxlines 1
		align left center
		glow lua "PortSearchString ~= ''"
		fill 112 111 111 64
	}
	edit
	{
		area	392 628 274 32
		enabled "faNot == 1 and MultiPortraitPicker == 0"
		var PortSearchString
		placeholder "..."
		text style "edit"
		text color 180 0 0 255
		maxlines 1
		align left center
		fill 112 111 111 64
	}
	button
	{
		enabled "PortSearchString ~= '' and MultiPortraitPicker == 0"
		area 674 624 34 40
		text "X"
		text style "button"
		action
		"
			PortSearchString = ''
			faNot = 0
		"
	}
	button
	{
		enabled "MultiPortraitPicker == 0"
		area 352 628 36 32
		bam ROUNDBUT
		glow lua "faNot == 0"
		action
		"
			if faNot == 0 then
				faNot = 1
			else
				faNot = 0
			end
		"
	}
	list
	{
		column
		{ 
			width	350
			label
			{
				enabled "PortraitContainsSearchString(rowNumber) and PortContainsSearchString(rowNumber) and SexFilter(rowNumber) and string.lower(string.sub(PortraitPicker[rowNumber][3],-1)) ~='m' and string.lower(string.sub(PortraitPicker[rowNumber][3],-1)) ~= 's'"
				area		0 0 329 90
				mosaic lua 	'getPortraitBackground(rowNumber)'
				respectClipping
				align		center center
			}
			label
			{
				enabled "PortraitContainsSearchString(rowNumber) and PortContainsSearchString(rowNumber) and SexFilter(rowNumber) and string.lower(string.sub(PortraitPicker[rowNumber][3],-1)) ~='m' and string.lower(string.sub(PortraitPicker[rowNumber][3],-1)) ~= 's'"
				area		0 0 255 90
				text lua	"string.upper(PortraitPicker[rowNumber][1])"
				text style	"label"
				align		right center
			}
			button
			{
				enabled "PortraitContainsSearchString(rowNumber) and PortContainsSearchString(rowNumber) and SexFilter(rowNumber) and string.lower(string.sub(PortraitPicker[rowNumber][3],-1)) ~='m' and string.lower(string.sub(PortraitPicker[rowNumber][3],-1)) ~= 's'"
				area		270 2 54 85
				bitmap lua 	'string.lower(PortraitPicker[rowNumber][3])'
				respectClipping
				align		center center
			}
		}
		enabled "MultiPortraitPicker == 0"
		name		'Portrait_Picker'
		area		742 178 350 522
		rowheight	dynamic
		hideHighlight
		table		"PortraitPicker"
		var			CImage
		scrollbar	'GUISCRC'
		action
		"
			if CurrentImage == string.lower(PortraitPicker[CImage][3]) then
				CImage = 0
				CurrentImage = ''
			else
				CurrentImage = string.lower(PortraitPicker[CImage][3])
				GetMediumPortrait()
				while string.lower(createCharScreen:GetCurrentPortrait()) ~= string.lower(CurrentImage) do
					createCharScreen:IncCurrentPortrait()
				end
			end
		"
	}
	button
	{
		enabled "MultiPortraitPicker == 0"
		area 1010 146 68 35
--		text lua "PPStrings.PP_SORT_LABEL"
--		text style "button"
		bam RGCSORT
		action "
			if toggleSort == 0 then
				toggleSort = 1
			elseif toggleSort == 1 then
				toggleSort = 2
			elseif toggleSort == 2 then
				toggleSort = 3
			elseif toggleSort == 3 then
				toggleSort = 0
			end
			CurrentImage = ''
			table.sort(PortraitPicker, compare2)
		"
	}
	

}
`
function raceOrGeneralHelp()
	race = chargen.races[currentChargenRace]
	if race then
		return Infinity_FetchString(race.desc)
	else
		return Infinity_FetchString(17237)
	end
end

currentChargenRace = 0
function getRaceBackground(row)
	if(row == currentChargenRace) then
		return "RGCGBT2"
	else
		return "RGCGBT1"
	end
end
`
menu
{
	name 'CHARGEN_RACE'
--	modal
	align center center
	ignoreesc
	onopen "currentChargenRace = nil"
	label
	{
		area 0 0 1444 818
		mosaic RGCGWDE
	}
	label
	{
		area 342 82 744 44
		text "RACE_TITLE"
		text style "title"
	}
	list
	{
		column
		{
			width 100
			label
			{
				area 		0 0 310 42
				mosaic lua  'getRaceBackground(rowNumber)'
				respectClipping 
				align		center center
			}
			label
			{
				area 0 0 310 42
				text lua "Infinity_FetchString(chargen.races[rowNumber].name)"
				text style "list"
				text align center center
				pad -8 0 0 0
				text lower
				
			}
		}
		action "
			if chargen.races[currentChargenRace] then
				createCharScreen:OnRaceSelectButtonClick(chargen.races[currentChargenRace].id)
			end
			"
		rowheight 42
		hideHighlight
		area 376 180 318 518
		table "chargen.races"
		var currentChargenRace
		scrollbar	'GUISCRC'
	}
	text
	{
		area 748 180 344 518
		text lua "raceOrGeneralHelp()"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	button
	{
		on escape
		area 420 726 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 806 726 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "Infinity_PopMenu(); createCharScreen:OnDoneButtonClick(); chargen.selectedRace = chargen.races[ currentChargenRace ].id;"
	}

}
`
function classOrGeneralHelp()
	class = chargen.class[currentChargenClass]
	if class then
		return Infinity_FetchString(class.desc)
	else
		--only bit that may need to change for dual class! :)
		return Infinity_FetchString(17242)
	end
end

currentChargenClass = 0
function getClassBackground(row)
	if(row == currentChargenClass) then
		return "RGCGBT2"
	else
		return "RGCGBT1"
	end
end
`
menu
{
	name 'CHARGEN_CLASS'
--	modal
	align center center
	ignoreesc
	onopen "currentChargenClass = nil"
	label
	{
		area 0 0 1444 818
		mosaic RGCGWDE
	}
	label
	{
		area 350 84 744 44
		text "CLASS_TITLE"
		text style "title"
	}
	list
	{
		column
		{
			width 100
			label
			{
				area 		0 0 310 42
				mosaic lua  'getClassBackground(rowNumber)'
				respectClipping 
				align		center center
			}
			label
			{
				area 0 0 310 42
				text lua "Infinity_FetchString(chargen.class[rowNumber].name)"
				text style "list"
				text align center center
				pad -8 0 0 0
				text lower
				
			}
		}
		action "
			if chargen.class[currentChargenClass] then
				createCharScreen:OnClassSelectButtonClick(chargen.class[currentChargenClass].id)
			end
			"
		rowheight 42
		hideHighlight
		area 376 180 318 518
		table "chargen.class"
		var currentChargenClass
		scrollbar 'GUISCRC'
	}
	text
	{
		area 748 180 344 518
		text lua "classOrGeneralHelp()"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	button
	{
		on escape
		area 420 726 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "createCharScreen:OnCancelButtonClick(); Infinity_PopMenu('CHARGEN_CLASS');"
	}
	button
	{
		on return
		area 806 726 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "createCharScreen:OnDoneButtonClick(); Infinity_PopMenu('CHARGEN_CLASS'); chargen.selectedClass = chargen.class[ currentChargenClass ].id;"
	}

}
`
function kitOrGeneralHelp()
	kit = chargen.kit[currentChargenKit]
	if kit then
		return Infinity_FetchString(kit.desc)
	else
		return Infinity_FetchString(17242)
	end
end

currentChargenKit = 0
function getKitBackground(row)
	if(row == currentChargenKit) then
		return "RGCGBT2"
	else
		return "RGCGBT1"
	end
end
`
menu
{
	name 'CHARGEN_KIT'
--	modal
	align center center
	ignoreesc
	label
	{
		area 0 0 1444 818
		mosaic RGCGWDE
	}
	label
	{
		area 348 86 744 40
		text "CLASS_KIT_TITLE"
		text style "title"
	}
	list
	{
		column
		{
			width 100
			label
			{
				area 		0 0 310 42
				mosaic lua  'getKitBackground(rowNumber)'
				respectClipping 
				align		center center
			}
			label
			{
				area 0 0 310 42
				text lua "Infinity_FetchString(chargen.kit[rowNumber].name)"
				text style "list"
				text align center center
				pad -8 0 0 0
				text lower
				
			}
		}
		action "
			if chargen.kit[currentChargenKit] then
				createCharScreen:OnKitSelectButtonClick(chargen.kit[currentChargenKit].id)
			end
			"
			
		rowheight 42
		hideHighlight
		area 376 180 318 518
		table "chargen.kit"
		var currentChargenKit
	}
	text
	{
		area 748 180 344 518
		text lua "kitOrGeneralHelp()"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	button
	{
		on escape
		area 420 726 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 806 726 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "Infinity_PopMenu(); createCharScreen:OnDoneButtonClick()"
	}

}
`
function alignmentOrGeneralHelp()
	alignment = chargen.alignment[currentChargenAlignment]
	if alignment then
		return Infinity_FetchString(alignment.desc)
	else
		return Infinity_FetchString(9602)
	end
end

currentChargenAlignment = 0
function getAlignmentBackground(row)
	if(row == currentChargenAlignment) then
		return "RGCGBT2"
	else
		return "RGCGBT1"
	end
end
`
menu
{
	name 'CHARGEN_ALIGNMENT'
--	modal
	align center center
	ignoreesc
	onopen "currentChargenAlignment = nil"
	label
	{
		area 0 0 1444 818
		mosaic RGCGWDE
	}
	label
	{
		area 348 84 744 42
		text "ALIGNMENT_TITLE"
		text style "title"
	}
	list
	{
		column
		{
			width 100
			label
			{
				area 		0 0 310 42
				mosaic lua  'getAlignmentBackground(rowNumber)'
				respectClipping 
				align		center center
			}
			label
			{
				area 0 0 310 42
				text lua "Infinity_FetchString(chargen.alignment[rowNumber].name)"
				text style "list"
				text align center center
				pad -8 0 0 0
				text lower
				
			}
		}
		action "
			if chargen.alignment[currentChargenAlignment] then
				createCharScreen:OnAlignmentSelectButtonClick(chargen.alignment[currentChargenAlignment].id)
			end
			"
		rowheight 42
		hideHighlight
		area 376 180 318 518
		table "chargen.alignment"
		var currentChargenAlignment
		scrollbar	'GUISCRC'
	}
	text
	{
		area 748 180 344 518
		text lua "alignmentOrGeneralHelp()"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	button
	{
		on escape
		area 420 726 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 806 726 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "Infinity_PopMenu(); createCharScreen:OnDoneButtonClick()"
	}

}
`
RerollFrame = 0
storedTotalRoll = 0
ptflat = 0
MethodToggle = 0
MethDescToggle = 0
rolling = 0
fiftyStr = 0
seventyfiveStr = 0
ninetyStr = 0
ninetynineStr = 1
hundredStr = 2
minStr = 1
PBuy = 75
rollMinValue = 1
rollMaxValue = 108
downkeep = 0
arspeed = 1
arse = 1760

chargen.ability = {
	{name = 'STRENGTH_LABEL', desc = 9582},
	{name = 'DEXTERITY_LABEL', desc = 9584},
	{name = 'CONSTITUTION_LABEL', desc = 9583},
	{name = 'INTELLIGENCE_LABEL', desc = 9585},
	{name = 'WISDOM_LABEL', desc = 9586},
	{name = 'CHARISMA_LABEL', desc = 9587},
}

function abilityOrGeneralHelp()
	ability = chargen.ability[currentChargenAbility]
	if ability and ability.desc ~= -1 then
		createCharScreen:SetAbilityHelpInfo(currentChargenAbility)
		return Infinity_FetchString(ability.desc)
	else
		return Infinity_FetchString(17247)
	end
end

raceHasExceptionalStr = { 
	true, -- Human
	true, -- Elf
	true, -- Half-Elf
	true, -- Dwarf
	false, -- Halfling
	true, -- Gnome
	true -- Half-Orc
	}

classHasExceptionalStr = { 
	false, -- Mage
	true, -- Fighter
	false, -- Cleric
	false, -- Thief
	false, -- Bard
	true, -- Paladin
	true, -- Fighter / Mage
	true, -- Fighter / Cleric
	true, -- Fighter / Thief
	true, -- Fighter / Mage / Thief
	false, -- Druid
	true, -- Ranger
	false, -- Mage / Thief
	false, -- Cleric / Mage
	false, -- Cleric / Thief
	true, -- Fighter / Druid
	true, -- Fighter / Mage / Cleric
	true, -- Cleric / Ranger
	false, -- Sorcerer
	false, -- Monk
	false -- Shaman
	}

function HasExceptionalStrength( )
  return raceHasExceptionalStr[ chargen.selectedRace ] and classHasExceptionalStr[ chargen.selectedClass ]
end

function ShowExceptionalStrength( )
	local strength = tonumber( string.sub( chargen.ability[ 1 ].roll, 1, 2 ) )
	local abilityToDec = 2
	if strength ~= nil then
		while ( strength ~= nil ) and ( strength < 18 ) do
			createCharScreen:OnAbilityPlusMinusButtonClick( abilityToDec, false )
			abilityToDec = abilityToDec + 1
			if( abilityToDec == 7 ) then
				abilityToDec = 2
			end
			createCharScreen:OnAbilityPlusMinusButtonClick( 1, true )
			strength = tonumber( string.sub( chargen.ability[ 1 ].roll, 1, 2 ) )
		end
	end
end

function AutoRoll( )
	createCharScreen:OnAbilityReRollButtonClick()
	local MeetsCriteria = 0
	local exceptionalStrength = 0
	local MinValue = tonumber(rollMinValue)
	local MaxValue = tonumber(rollMaxValue)
	local minimumStr = tonumber(minStr)
	local foStr = tonumber(fiftyStr)
	local sfStr = tonumber(seventyfiveStr)
	local noStr = tonumber(ninetyStr)
	local nnStr = tonumber(ninetynineStr)
	local ohStr = tonumber(hundredStr)
	
	if( HasExceptionalStrength() ) then
		ShowExceptionalStrength( )
		exceptionalStrength = tonumber( string.sub( chargen.ability[ 1 ].roll, 4 ) )
		if exceptionalStrength ~= nil then
			if exceptionalStrength == 0 then
				exceptionalStrength = 100
			end	
		else
			exceptionalStrength = 0
		end
	end
	
	if MethodToggle == 1 then
		if ( storedTotalRoll == chargen.totalRoll ) then
			if ( chargen.ability[ 1 ].exceptional < exceptionalStrength ) then
				MeetsCriteria = 1
			end
		elseif ( storedTotalRoll < chargen.totalRoll ) then
			MeetsCriteria = 1
		end
	elseif MethodToggle == 2 then
		if ( storedTotalRoll == chargen.totalRoll ) then
			if ( chargen.ability[ 1 ].exceptional < exceptionalStrength ) then
				MeetsCriteria = 1
			end
		elseif ( storedTotalRoll < chargen.totalRoll ) then
			if ( MinValue <= chargen.totalRoll ) then
				if ( MaxValue >= chargen.totalRoll ) then
					MeetsCriteria = 1
				end
			end
		end
	elseif MethodToggle == 3 then
		if ( PBuy == chargen.totalRoll ) then
			if ( chargen.ability[ 1 ].exceptional < exceptionalStrength ) then
				MeetsCriteria = 1
			elseif ( PBuy ~= storedTotalRoll ) then
				MeetsCriteria = 1
			end
		end
	elseif MethodToggle == 4 then
		if ( minimumStr <= exceptionalStrength ) then
			if ( storedTotalRoll == chargen.totalRoll ) then
				if ( chargen.ability [ 1 ].exceptional < exceptionalStrength ) then
					MeetsCriteria = 1
				end
			elseif ( storedTotalRoll < chargen.totalRoll ) then
				MeetsCriteria = 1
			end
		end
	elseif MethodToggle == 5 then
		if ( storedTotalRoll == chargen.totalRoll ) then
			if ( chargen.ability[ 1 ].exceptional < exceptionalStrength ) then
				MeetsCriteria = 1
			end
		elseif ( storedTotalRoll < chargen.totalRoll ) then
			MeetsCriteria = 1
			if ( downkeep <= storedTotalRoll ) then downkeep = 0 end
		elseif ( chargen.ability [ 1 ].exceptional < exceptionalStrength ) then
			if ( chargen.totalRoll >= downkeep ) then
				if ( ( chargen.totalRoll + ohStr >= storedTotalRoll ) and ( exceptionalStrength == 100 ) ) then
					downkeep = storedTotalRoll + ohStr
					MeetsCriteria = 1
				elseif ( ( chargen.totalRoll + nnStr >= storedTotalRoll ) and ( exceptionalStrength >= 91 ) ) then
					downkeep = storedTotalRoll + nnStr
					MeetsCriteria = 1
				elseif ( ( chargen.totalRoll + noStr >= storedTotalRoll ) and ( exceptionalStrength >= 76 ) ) then
					downkeep = storedTotalRoll + noStr
					MeetsCriteria = 1
				elseif ( ( chargen.totalRoll + sfStr >= storedTotalRoll ) and ( exceptionalStrength >= 51 ) ) then
					downkeep = storedTotalRoll + sfStr
					MeetsCriteria = 1
				elseif ( ( chargen.totalRoll + foStr >= storedTotalRoll ) and ( exceptionalStrength >= 1 ) ) then
					downkeep = storedTotalRoll + foStr
					MeetsCriteria = 1
				end
			end
		end
		
	end
	
	if MeetsCriteria == 1 then
		storedTotalRoll = chargen.totalRoll
		chargen.ability[ 1 ].exceptional = exceptionalStrength
		chargen.ability[ 1 ].storedRoll = chargen.ability[ 1 ].roll
		chargen.ability[ 2 ].storedRoll = chargen.ability[ 2 ].roll
		chargen.ability[ 3 ].storedRoll = chargen.ability[ 3 ].roll
		chargen.ability[ 4 ].storedRoll = chargen.ability[ 4 ].roll
		chargen.ability[ 5 ].storedRoll = chargen.ability[ 5 ].roll
		chargen.ability[ 6 ].storedRoll = chargen.ability[ 6 ].roll
		createCharScreen:OnAbilityStoreButtonClick()
		MeetsCriteria = 0
	end
end

function UpdateAutoRoll()
	if rolling == 1 then
		RerollFrame = RerollFrame + 1
		if RerollFrame > 1 then
			RerollFrame = 0
		end
	
		if RerollFrame == 0 then
		  local index = 1
			for index = 1, arse, 1 do
				AutoRoll( )
			end
		end
	end
end

function PointReduction()
	local oldPoints
	for i = 1,6 do
		oldPoints = chargen.extraAbilityPoints + 1
		while oldPoints ~= chargen.extraAbilityPoints do
			oldPoints = chargen.extraAbilityPoints
			createCharScreen:OnAbilityPlusMinusButtonClick(i,false)						
		end		
	end
	StoreRoll()
	createCharScreen:OnAbilityStoreButtonClick()
end

function PointFlatten()
	local overAbility
	PointReduction()
	createCharScreen:OnAbilityRecallButtonClick()
	ptflat = math.floor(chargen.totalRoll/6)
	overAbility = 0
	for i = 1,6 do
		if tonumber(chargen.ability[i].roll) > ptflat then
			overAbility = overAbility + tonumber(chargen.ability[i].roll) - ptflat
		end
	end
	if overAbility > 0 then ptflat = math.floor((chargen.totalRoll - overAbility)/6) end
	for i = 1,6 do
		while ptflat > tonumber(chargen.ability[i].roll) do
			createCharScreen:OnAbilityPlusMinusButtonClick(i,true)						
		end
	end
	StoreRoll()
	createCharScreen:OnAbilityStoreButtonClick()
end

function StoreRoll()
	storedTotalRoll = chargen.totalRoll
	chargen.ability[ 1 ].storedRoll = chargen.ability[ 1 ].roll
	chargen.ability[ 2 ].storedRoll = chargen.ability[ 2 ].roll
	chargen.ability[ 3 ].storedRoll = chargen.ability[ 3 ].roll
	chargen.ability[ 4 ].storedRoll = chargen.ability[ 4 ].roll
	chargen.ability[ 5 ].storedRoll = chargen.ability[ 5 ].roll
	chargen.ability[ 6 ].storedRoll = chargen.ability[ 6 ].roll
end

function rgAbilityText()
	if cheatMode == 1 then
	Infinity_SetArea('abilityText', 724, 157, 388, 193)
	else
	Infinity_SetArea('abilityText', 724, 157, 388, 393)
	end
end
`
menu
{
	name 'CHARGEN_ABILITIES'
	align center center
	ignoreesc
	onopen
	"
		ticksPassed = 0
		ticksStarting = 0
		MethodToggle = 0
		MethDescToggle = 0
		cheatMode = Infinity_GetINIValue('Game Options','CheatMode','1')
		rgAbilityText()
	"
	label
	{
		area 0 0 1444 818
		mosaic RGCGROL
	}
	label
	{
		enabled "Infinity_GetINIValue('Game Options','CheatMode','1')"
		area 708 349 420 55
		mosaic RGCROLX
	}
	label
	{
		area 504 84 426 44
		text "ABILITIES_TITLE"
		text style "title"
	}
	list
	{
		column
		{
			width 18
			label
			{
				area 		0 0 50 55
				text lua 	"chargen.ability[rowNumber].storedRoll"
				text style 	"normal"
				text color 	'$'
				align 		center center
			}
		}
		column
		{
			width 34
			label
			{
				area 		0 0 125 55
				text lua 	"t(chargen.ability[rowNumber].name)"
				text style 	"normal"
				align 		right center
			}
		}
		column
		{
			width 20
			label
			{
				area 15 0 50 55
				text lua "chargen.ability[rowNumber].roll"
				text style "normal"
				align center center
			}
		}
		column
		{
			width 15
			label
			{
				area 11 6 45 42
				bam GUIOSW
				frame lua "currentCellCheck(4)"
				sequence 0
			}
		}
		column
		{
			width 15
			label
			{
				area 0 6 45 42
				bam GUIOSW
				frame lua "currentCellCheck(5)"
				sequence 1
			}
		}
		action 
		"
			if ticksStarting < 10 then 
				if cellNumber == 4 then
					createCharScreen:OnAbilityPlusMinusButtonClick(currentChargenAbility, true)
				elseif cellNumber == 5 then
					createCharScreen:OnAbilityPlusMinusButtonClick(currentChargenAbility, false)
				end
			end
			cellNumber = nil
			ticksPassed = 0
			ticksStarting = 0
		"
		actionUpdate 
		"
			ticksStarting = ticksStarting + 1
			if ticksStarting > 10 then
				ticksPassed = ticksPassed + 1
				if ticksPassed > 2 then
					if cellNumber == 4 then
						createCharScreen:OnAbilityPlusMinusButtonClick(currentChargenAbility, true)
					elseif cellNumber == 5 then
						createCharScreen:OnAbilityPlusMinusButtonClick(currentChargenAbility, false)
					end
					ticksPassed = 0
				end
			end
		"

		rowheight 54
		hidehighlight
		area 334 157 370 325
		table "chargen.ability"
		var currentChargenAbility
	}
	label
	{
		enabled 	"storedTotalRoll > 0"
		area 		384 488 72 54
		text 		"ACM_STORED_LABEL"
		text style 	"normal"
		text align 	left center
		text color 	'$'
	}
	label
	{
		area 		446 488 80 54
--		text 		"TOTAL_ROLL_NORMAL"
		text		'RG_TOTAL'
		text style 	"normal"
		text align 	right center
	}
	label
	{
		enabled 	"storedTotalRoll > 0"
		area 		336 488 48 54
		text lua 	"storedTotalRoll"
		text style 	"normal"
		text align 	center center
		text color 	'$'
	}
	label
	{
		area 		539 488 55 54
		text lua 	"chargen.totalRoll"
		text style 	"normal"
		text align 	center center
	}
	label
	{
		enabled 	"chargen.extraAbilityPoints > 0"
		area 		618 488 74 54
		text lua 	"chargen.extraAbilityPoints"
		text style 	"normal"
		text align 	center center
		text color 	'G'
	}
	text
	{
		name		'abilityText'
		area 		724 157 388 193
		text lua 	"abilityOrGeneralHelp()"
		text style 	"normal"
		scrollbar	'GUISCRC'
	}
--	label
--	{
--		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1')"
--		area 		696 358 444 366
--		Rectangle 	3
--	}
	label
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle > 0 and MethodToggle < 6"
		area 		714 543 400 37
		text		"ACM_ROLL_SPEED_LABEL"
		text style 	"label"
		text color 	'$'
		align 		center center
	}
	slider
	{
		enabled "Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle > 0 and MethodToggle < 6"
		area 806 586 212 22
		position "arspeed"
		bam	 'SLDRSTAR'
		mosaic RGSCALE
		sequence 0
		frame	 1
		settings 21
		pad 4 0 6 0
		action
		"
			arse = 2000 - ( arspeed * 80 ) + 80
		" 
	}

-- Cheat Method Submenu

	text
	{
		enabled 	"MethodToggle == 0 and Infinity_GetINIValue('Game Options','CheatMode','1')"
		area 		718 354 396 44
		text 		"ACM_CHEAT_METHOD"
		text style 	"normal"
		text align 	center center
		text color 	'$'
	}
	text
	{
		enabled 	"MethodToggle == 0 and MethDescToggle == 0 and Infinity_GetINIValue('Game Options','CheatMode','1')"
		area 		724 542 390 154
		text		"ACM_UF_DESCRIPTION"
		text style 	"normal"
		text align 	left top
		text color 	'$'
	}
	button
	{
		enabled 	"MethodToggle == 0 and Infinity_GetINIValue('Game Options','CheatMode','1')"
		area 		716 404 200 44
		bam 		GUIBUTNT
		text 		"ACM_AUTOROLL_BUTTON"
		text style 	"label"
		text color 	'$'
		action "
			MethodToggle = 1
		"
		actionenter "
			MethDescToggle = 1
		"
		actionexit "
			MethDescToggle = 0
		"
	}
	button
	{
		enabled 	"MethodToggle == 0 and Infinity_GetINIValue('Game Options','CheatMode','1')"
		area 		914 404 200 44
		bam 		GUIBUTNT
		text 		"ACM_RANGEROLL_BUTTON"
		text style 	"label"
		text color	'$'
		action "
			MethodToggle = 2
		"
		actionenter "
			MethDescToggle = 2
		"
		actionexit "
			MethDescToggle = 0
		"
	}
	button
	{
		enabled 	"MethodToggle == 0 and Infinity_GetINIValue('Game Options','CheatMode','1')"
		area 		716 448 200 44
		bam 		GUIBUTNT
		text 		"ACM_POINTBUY_BUTTON"
		text style 	"label"
		text color	'$'
		action "
			MethodToggle = 3
		"
		actionenter "
			MethDescToggle = 3
		"
		actionexit "
			MethDescToggle = 0
		"
	}
	button
	{
		enabled 	"MethodToggle == 0 and HasExceptionalStrength() and Infinity_GetINIValue('Game Options','CheatMode','1')"
		area 		716 492 200 44
		bam 		GUIBUTNT
		text 		"ACM_MINSTR_BUTTON"
		text style 	"label"
		text color	'$'
		action "
			MethodToggle = 4
		"
		actionenter "
			MethDescToggle = 4
		"
		actionexit "
			MethDescToggle = 0
		"
	}
	button
	{
		enabled 	"MethodToggle == 0 and HasExceptionalStrength() and Infinity_GetINIValue('Game Options','CheatMode','1')"
		area 		914 492 200 44
		bam			GUIBUTNT
		text 		"ACM_PRISTR_BUTTON"
		text style 	"label"
		text color	'$'
		action "
			MethodToggle = 5
		"
		actionenter "
			MethDescToggle = 5
		"
		actionexit "
			MethDescToggle = 0
		"
	}
	button
	{
		enabled 	"MethodToggle == 0 and Infinity_GetINIValue('Game Options','CheatMode','1')"
		area 		914 448 200 44
		bam 		GUIBUTNT
		text 		"ACM_MAXMAX_BUTTON"
		text style 	"label"
		text color 	'$'
		action "
			MethodToggle = 6
			Infinity_SetINIValue('Program Options','Debug Mode','1')
		"
		actionenter "
			MethDescToggle = 6
		"
		actionexit "
			MethDescToggle = 0
		"
	}
	
-- Method Descriptions

	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 0 and MethDescToggle == 1"
		area 		724 542 390 154
		text		"ACM_AUTOROLL_DESCRIPTION"
		text style 	"normal"
		text align 	left top
		text color 	'$'
	}
	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 0 and MethDescToggle == 2"
		area 		724 542 390 154
		text 		"ACM_RANGEROLL_DESCRIPTION"
		text style 	"normal"
		text align 	left top
		text color 	'$'
	}
	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 0 and MethDescToggle == 3"
		area 		724 542 390 154
		text	 	"ACM_POINTBUY_DESCRIPTION"
		text style 	"normal"
		text align 	left top
		text color 	'$'
	}
	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 0 and MethDescToggle == 4"
		area 		724 542 390 154
		text		"ACM_MINSTR_DESCRIPTION"
		text style 	"normal"
		text color 	'$'
		text align 	left top
	}
	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 0 and MethDescToggle == 5"
		area 		724 542 390 154
		text		"ACM_PRISTR_DESCRIPTION"
		text style 	"normal"
		text color 	'$'
		text align 	left top
	}
	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 0 and MethDescToggle == 6"
		area 		724 542 390 154
		text		"ACM_MAXMAX_DESCRIPTION"
		text style 	"normal"
		text color 	'$'
		text align 	left top
	}
	
-- Change Method and Reset

	button
	{
		enabled 		"MethodToggle > 0 and Infinity_GetINIValue('Game Options','CheatMode','1')"
		clickable lua	"rolling==0"
		area 			714 656 200 44
		bam 			GUIBUTNT
		text 			"ACM_CHANGEMETHOD_BUTTON"
		text style 		"label"
		text color 		'$'
		action "
			MethodToggle = 0
			MethDescToggle = 0
			downkeep = 0
			fiftyStr = 0
			seventyfiveStr = 0
			ninetyStr = 0
			ninetynineStr = 1
			hundredStr = 2
			minStr = 1
			PBuy = 75
			rollMinValue = 1
			rollMaxValue = 108
			createCharScreen:OnAbilityReRollButtonClick()
			StoreRoll()
			createCharScreen:OnAbilityStoreButtonClick()
		"
	}

-- Cheat Method Submenu end	

-- Method 1, Auto Roller
	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 1"
		area 		720 354 394 44
		text 		"ACM_SELMETHOD_AUTOROLL_TEXT"
		text style 	"normal"
		text color 	'$'
		text align 	center center
	}

-- METHOD 2 = RANGE ROLL
	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 2"
		area 		712 354 402 44
		text 		"ACM_SELMETHOD_RANGEROLL_TEXT"
		text style 	"normal"
		text color 	'$'
		text align 	center center
	}
	edit
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 2"
		clickable	"rolling == 0"
		area		810 478 64 44
		var			rollMinValue
		text style 	"edit"
		text color 	'$'
		align 		center center
		maxlines	1
		fill		112 111 111 64
		action
		"
			-- only permit numbers as letters.
			-- character limit of 3
			if((tonumber(letter_pressed) ~= nil and #tostring(rollMinValue) < 3) or not letter_pressed) then
				return 1
			else
				return 0
			end
		"
	}
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 2"
		area 		894 478 42 44
		text 		"ACM_SELMETHOD_RANGEROLL_TO_TEXT"
		text style	"normal"
		text color 	'$'
		text align 	center center
	}
	edit
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 2"
		clickable	"rolling == 0"
		area		958 478 64 44
		var			rollMaxValue
		text style	"edit"
		text color 	'$'
		text align	center center
		maxlines	1
		fill		112 111 111 64
		action
		"
			-- only permit numbers as letters.
			-- character limit of 3
			if((tonumber(letter_pressed) ~= nil and #tostring(rollMaxValue) < 3) or not letter_pressed) then
				return 1
			else
				return 0
			end
		"
	}
	
-- Method 3 = Point Buy
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 3"
		area 		712 354 406 44
		text 		"ACM_SELMETHOD_POINTBUY_TEXT"
		text style 	"normal"
		text color 	'$'
		text align 	center center
	}
	button
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 3"
		area 		760 414 142 44
		bam 		RGSTBT
		text 		"75"
		text style 	"normal"
		text color 	'$'
		text align 	center center
		glow lua 	"PBuy == 75"
		action "
			PBuy = 75
		"
	}
	button
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 3"
		area 		910 414 142 44
		bam 		RGSTBT
		text 		"80"
		text style 	"normal"
		text color 	'$'
		text align 	center center
		glow lua 	"PBuy == 80"
		action "
			PBuy = 80
		"
	}
	button
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 3"
		area 		760 462 142 44
		bam 		RGSTBT
		text 		"85"
		text style 	"normal"
		text color 	'$'
		text align 	center center
		glow lua 	"PBuy == 85"
		action "
			PBuy = 85
		"
	}
	button
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 3"
		area 		910 462 142 44
		bam 		RGSTBT
		text 		"90"
		text style 	"normal"
		text color 	'$'
		text align 	center center
		glow lua 	"PBuy == 90"
		action "
			PBuy = 90
		"
	}
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 3 and storedTotalRoll == PBuy and rolling == 1"
		area 		712 626 402 30
		text 		"ACM_SELMETHOD_POINTBUY_ACQUIRED"
		text color 	'$'
		text style 	"normal"
		text align 	center center
	}
	
-- Method 4 = MIN STR%
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 4"
		area 		720 354 394 44
		text 		"ACM_SELMETHOD_MINSTR_TEXT"
		text style 	"normal"
		text color 	'$'
		text align 	center center
	}
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 4"
		area 		810 430 118 38
		text		"ACM_SELMETHOD_MINSTR_MINSTR"
		text style 	"normal"
		text color 	'$'
		text align 	right center
	}
	edit
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 4"
		area		944 430 64 38
		var			minStr
		text style	"normal"
		text color	'$'
		align 		center center
		maxlines	1
		fill		112 111 111 64
		action "
			-- only permit numbers as letters.
			-- character limit of 3
			if((tonumber(letter_pressed) ~= nil and #tostring(minStr) < 3) or not letter_pressed) then
				return 1
			else
				return 0
			end
		"
	}

-- Method 5 = Priority Str%
	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area 		720 354 394 44
		text 		"ACM_SELMETHOD_PRISTR_TEXT"
		text style 	"normal"
		text color 	'$'
		text align 	center center
	}
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area 		738 414 86 38
		text 		"1% to 50%"
		text style 	"normal"
		text color 	'$'
		text align 	right center
	}
	edit
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area		836 414 64 38
		var			fiftyStr
		text style	"edit"
		text color	'$'
		align 		center center
		maxlines	1
		fill		112 111 111 64
		action
		"
			-- only permit numbers as letters.
			-- character limit of 1
			if((tonumber(letter_pressed) ~= nil and #tostring(fiftyStr) < 1) or not letter_pressed) then
				return 1
			else
				return 0
			end
		"
	}
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area 		734 452 90 40
		text 		"51% to 75%"
		text style 	"normal"
		text color 	'$'
		text align 	right center
	}
	edit
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area		836 452 64 40
		var			seventyfiveStr
		text style	"edit"
		text color	'$'
		align 		center center
		maxlines	1
		fill		112 111 111 64
		action
		"
			-- only permit numbers as letters.
			-- character limit of 1
			if((tonumber(letter_pressed) ~= nil and #tostring(seventyfiveStr) < 1) or not letter_pressed) then
				return 1
			else
				return 0
			end
		"
	}
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area 		910 414 98 38
		text 		"76% to 90%"
		text style 	"normal"
		text color 	'$'
		text align 	right center
	}
	edit
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area		1018 414 64 38
		var			ninetyStr
		text style	"edit"
		text color	'$'
		align		center center
		maxlines	1
		fill		112 111 111 64
		action
		"
			-- only permit numbers as letters.
			-- character limit of 1
			if((tonumber(letter_pressed) ~= nil and #tostring(ninetyStr) < 1) or not letter_pressed) then
				return 1
			else
				return 0
			end
		"
	}
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area 		910 452 98 40
		text 		"91% to 99%"
		text style 	"normal"
		text color 	'$'
		text align 	right center
	}
	edit
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area		1018 452 64 40
		var			ninetynineStr
		text style	"edit"
		text color	'$'
		align 		center center
		maxlines	1
		fill		112 111 111 64
		action
		"
			-- only permit numbers as letters.
			-- character limit of 1
			if((tonumber(letter_pressed) ~= nil and #tostring(ninetynineStr) < 1) or not letter_pressed) then
				return 1
			else
				return 0
			end
		"
	}
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area 		910 492 98 38
		text		"100%"
		text style 	"normal"
		text color 	'$'
		text align 	right center
	}
	edit
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 5"
		area		1018 492 64 38
		var			hundredStr
		text style	"edit"
		text color 	'$'
		align 		center center
		maxlines	1
		fill		112 111 111 64
		action
		"
			-- only permit numbers as letters.
			-- character limit of 1
			if((tonumber(letter_pressed) ~= nil and #tostring(hundredStr) < 1) or not letter_pressed) then
				return 1
			else
				return 0
			end
		"
	}
-- METHOD 6 = ALL 18s
	text
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 6"
		area 		720 354 394 44
		text 		"ACM_SELMETHOD_MAXMAX_TEXT"
		text style 	"normal"
		text color 	'$'
		text align 	center center
	}
	text
	{
		enabled		"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle == 6"
		area 		720 478 394 102
		text		"ACM_SELMETHOD_MAXMAX_MAXMAX"
		text style 	"normal"
		text color 	'$'
		text align 	center center
	}

-- Methods End


-- Start And Stop Buttons

	button
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle > 0 and MethodToggle < 6 and rolling == 0"
		area 914 656 200 44
		bam GUIBUTNT
		sequence 0
		text "ACM_START"
		text style "label"
		text color 	'$'
		action
		"
			if rollMinValue == nil then
				rollMinValue = 1
			end
			if rollMaxValue == nil then
				rollMaxValue = 108
			end
			if tonumber(rollMinValue) >= tonumber(rollMaxValue) then
				rollMaxValue = tonumber(rollMinValue)
				rollMinValue = tonumber(rollMaxValue) - 5
			end
			if minStr == nil then
				minStr = 1
			end
			if tonumber(minStr) <= 1 then
				minStr = 1
			elseif tonumber(minStr) > 100 then
				minStr = 100
			end

			if fiftyStr == nil then
				fiftyStr = 0
			elseif tonumber(fiftyStr) > 9 then
				fiftyStr = 9
			end
			if seventyfiveStr == nil then
				seventyfiveStr = 0
			elseif tonumber(seventyfiveStr) > 9 then
				seventyfiveStr = 9
			end
			if ninetyStr == nil then
				ninetyStr = 0
			elseif tonumber(ninetyStr) > 9 then
				ninetyStr = 9
			end
			if ninetynineStr == nil then
				ninetynineStr = 1
			elseif tonumber(ninetynineStr) > 9 then
				ninetynineStr = 9
			end
			if hundredStr == nil then
				hundredStr = 2
			elseif tonumber(hundredStr) > 9 then
				hundredStr = 9
			end
			
			chargen.ability[ 1 ].exceptional = tonumber( string.sub( chargen.ability[ 1 ].roll, 4 ) )
			if chargen.ability[ 1 ].exceptional ~= nil then
				if chargen.ability[ 1 ].exceptional == 0 then
					chargen.ability[ 1 ].exceptional = 100
				end	
			else
				chargen.ability[ 1 ].exceptional = 0
			end
			storedTotalRoll = chargen.totalRoll
			rolling = 1
		"
	}
	button
	{
		enabled 	"Infinity_GetINIValue('Game Options','CheatMode','1') and MethodToggle > 0 and MethodToggle < 6 and rolling == 1"
		area 914 656 200 44
		bam GUIBUTNT
		sequence 0
		text "ACM_STOP"
		text style "label"
		text color 	'$'
		action
		"
			rolling = 0
			createCharScreen:OnAbilityRecallButtonClick()
		"
	}
	
-- Start And Stop Buttons End

	button
	{
		mosaic lua "UpdateAutoRoll()"
		area 1 1 1 1
	}
--	label
--	{
--		area 550 564 152 136
--		Rectangle 5
--	}
	text
	{
		area 556 570 142 38
		text "ACM_VIEW"
		text style "normal"
		text align center center
	}
	button
	{
		clickable lua "rolling==0"
		area 556 608 142 44
		bam RGSTBT
		sequence 0
		text "ACM_FLATTEN"
		text style "normal"
		text align center center
		action "
			PointFlatten()
			"
	}
	button
	{
		clickable lua "rolling==0"
		area 556 652 142 44
		bam RGSTBT
		sequence 0
		text "ACM_MINIMUM"
		text style "normal"
		text align center center
		action "
			PointReduction()
			"
	}
	button
	{
		clickable lua "rolling==0"
		area 334 564 200 44
		bam GUIBUTNT
		sequence 0
		text "REROLL_BUTTON"
		text style "button"
		action "createCharScreen:OnAbilityReRollButtonClick()"
	}
	button
	{
		clickable lua "rolling==0"
		area 334 608 200 44
		bam GUIBUTNT
		sequence 0
		text "STORE_BUTTON"
		text style "button"
		action "
			local exceptionalStrength = tonumber( string.sub( chargen.ability[ 1 ].roll, 4 ) )
			if exceptionalStrength ~= nil then
				if exceptionalStrength == 0 then
					exceptionalStrength = 100
				end	
			else
				exceptionalStrength = 0
			end
			storedTotalRoll = chargen.totalRoll
			chargen.ability[ 1 ].exceptional = exceptionalStrength
			chargen.ability[ 1 ].storedRoll = chargen.ability[ 1 ].roll
			chargen.ability[ 2 ].storedRoll = chargen.ability[ 2 ].roll
			chargen.ability[ 3 ].storedRoll = chargen.ability[ 3 ].roll
			chargen.ability[ 4 ].storedRoll = chargen.ability[ 4 ].roll
			chargen.ability[ 5 ].storedRoll = chargen.ability[ 5 ].roll
			chargen.ability[ 6 ].storedRoll = chargen.ability[ 6 ].roll
			createCharScreen:OnAbilityStoreButtonClick()
		"
	}
	button
	{
		clickable lua "rolling==0 and createCharScreen:IsAbilityRecallButtonClickable()"
		area 334 652 200 44
		bam GUIBUTNT
		sequence 0
		text "RECALL_BUTTON"
		text style "button"
		action "createCharScreen:OnAbilityRecallButtonClick()"
	}

	button
	{
		on '8'
		action "createCharScreen:OnCheatyMcCheaterson()"
		
		
	}

	button
	{
		clickable lua "rolling==0"
		on escape
		area 410 728 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "
			Infinity_PopMenu()
			createCharScreen:OnCancelButtonClick()
			RerollFrame = 0
			storedTotalRoll = 0
			ptflat = 0
			MethodToggle = 0
			MethDescToggle = 0
			rolling = 0
			fiftyStr = 0
			seventyfiveStr = 0
			ninetyStr = 0
			ninetynineStr = 1
			hundredStr = 2
			minStr = 1
			PBuy = 75
			rollMinValue = 1
			rollMaxValue = 108
			downkeep = 0
		"
	}
	button
	{
		clickable lua "rolling==0 and createCharScreen:IsDoneButtonClickable()"
		on return
		area 814 728 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		action "Infinity_PopMenu()
			createCharScreen:OnDoneButtonClick()
			RerollFrame = 0
			storedTotalRoll = 0
			ptflat = 0
			MethodToggle = 0
			MethDescToggle = 0
			rolling = 0
			fiftyStr = 0
			seventyfiveStr = 0
			ninetyStr = 0
			ninetynineStr = 1
			hundredStr = 2
			minStr = 1
			PBuy = 75
			rollMinValue = 1
			rollMaxValue = 108
			downkeep = 0
		"
	}

}
`
function proficiencyOrGeneralHelp()
	local prof = chargen.proficiency[currentChargenProficiency]
	local skill = chargen.thief_skill[currentChargenThiefSkill]
	if prof and prof.desc ~= -1 then
		return Infinity_FetchString(prof.desc)
	elseif skill and skill.desc ~= -1 then
		return Infinity_FetchString(skill.description)
	else
		if(chargen.levelingUp) then
			if(levelUpInfoToggle == 1) then
				return chargen.charInfo
			else
				return chargen.levelInfo
			end
		else
		return Infinity_FetchString(24315)
	end
	end
end

function getProficienciesTitle()
	if(chargen.levelingUp) then
		return t("LEVEL_UP_TITLE")
	else
		return t("CHARGEN_TITLE")
	end
end

function isChargenProficienciesBackButtonClickable()
	return ((not chargen.levelingUp) and createCharScreen:GetCurrentStep() ~= const.STEP_DUALCLASS_PROFICIENCIES)
end
`
menu
{
	name 'CHARGEN_PROFICIENCIES'
--	modal
	align center center
	ignoreesc
	onopen "currentChargenProficiency = nil; currentChargenThiefSkill = nil; ticksPassed = 0; ticksStarting = 0"
	label
	{
		area 0 0 1444 818
		mosaic RGLEVEL
	}
	label
	{
		area 247 33 948 42
		text lua "getProficienciesTitle()"
		text style "title"
	}
	label
	{
		area 106 171 244 44
		text "PROF_SLOTS_LABEL"
		text style "label"
	}
	label
	{
		area 364 171 196 44
		text lua "chargen.extraProficiencySlots"
		text style "label"
	}
	label
	{
		area 592 171 198 44
		text "SKILLS_LABEL"
		text style "label"
	}
	label
	{
		area 800 171 157 44
		text lua "chargen.extraSkillPoints"
		text style "label"
	}

	list
	{
		column
		{
			width 60
			label
			{
				area 0 0 235 44
				text lua "Infinity_FetchString(chargen.proficiency[rowNumber].name)"
				text style "normal"
				align right center
				
			}
		}
		column
		{
			width 4
			label
			{
				bam GUIPFC
				area 0 13 16 16
				align center center
				enabled "chargen.proficiency[rowNumber].value > 4"
			}
		}
		column
		{
			width 4
			label
			{
				bam GUIPFC
				area 0 13 16 16
				align center center
				enabled "chargen.proficiency[rowNumber].value > 3"
			}
		}
		column
		{
			width 4
			label
			{
				bam GUIPFC
				area 0 13 16 16
				align center center
				enabled "chargen.proficiency[rowNumber].value > 2"
			}
		}
		column
		{
			width 4
			label
			{
				bam GUIPFC
				area 0 13 16 16
				align center center
				enabled "chargen.proficiency[rowNumber].value > 1"
			}
		}
		column
		{
			width 4
			label
			{
				bam GUIPFC
				area 0 13 16 16
				align center center
				enabled "chargen.proficiency[rowNumber].value > 0"
			}
		}

		column
		{
			width 10
			label
			{
				area 2 0 45 44
				bam GUIOSW
				frame lua "getPlusFrame(7)"
				sequence 0
				align center center
			}
		}
		column
		{
			width 10
			label
			{
				area 0 0 45 44
				bam GUIOSW
				sequence 1
				frame lua "getMinusFrame(8)"

				align center center
			}
		}

		action 
		"
			currentChargenThiefSkill = nil
			if ticksStarting < 10 then
				if cellNumber == 7 and plusButtonClickable(currentChargenProficiency) then
					createCharScreen:OnProficiencyPlusMinusButtonClick(chargen.proficiency[currentChargenProficiency].id, true)
				elseif cellNumber == 8 and minusButtonClickable(currentChargenProficiency) then
					createCharScreen:OnProficiencyPlusMinusButtonClick(chargen.proficiency[currentChargenProficiency].id, false)
				end
			end
			cellNumber = nil
			ticksPassed = 0
			ticksStarting = 0
		"
		actionUpdate 
		"
			currentChargenThiefSkill = nil
			ticksStarting = ticksStarting + 1
			if ticksStarting > 10 then
				ticksPassed = ticksPassed + 1
				if ticksPassed > 7 then
					if cellNumber == 7 and plusButtonClickable(currentChargenProficiency) then
						createCharScreen:OnProficiencyPlusMinusButtonClick(chargen.proficiency[currentChargenProficiency].id, true)
					elseif cellNumber == 8 and minusButtonClickable(currentChargenProficiency) then
						createCharScreen:OnProficiencyPlusMinusButtonClick(chargen.proficiency[currentChargenProficiency].id, false)
					end
					ticksPassed = 0
				end
			end
		"

		rowheight 44
		area 100 228 458 474
		table "chargen.proficiency"
		var currentChargenProficiency
		scrollbar	'GUISCRC'

	}
	list
	{
		column
		{
			width 63
			label
			{
				area 0 0 180 54
				text lua "Infinity_FetchString(chargen.thief_skill[rowNumber].name)"
				text style "normal"
				text align right center
				
			}
		}
		column
		{
			width 13
			label
			{
				area 0 0 60 54
				text lua "chargen.thief_skill[rowNumber].value"
				text style "normal"
				text align left center

			}
		}
		column
		{
			width 12
			label
			{
				area 0 6 45 42
				bam GUIOSW
				enabled "createCharScreen:IsThiefSkillPlusMinusButtonClickable()"
				frame lua "currentCellCheck(3)"
				sequence 0
			}
		}
		column
		{
			width 12
			label
			{
				area 0 6 45 42
				bam GUIOSW
				enabled "createCharScreen:IsThiefSkillPlusMinusButtonClickable()"
				frame lua "currentCellCheck(4)"
				sequence 1

			}
		}

		action 
		"
			currentChargenProficiency = nil
			if ticksStarting < 10 then
				if createCharScreen:IsThiefSkillPlusMinusButtonClickable() then
					if cellNumber == 3 then
						createCharScreen:OnThiefSkillPlusMinusButtonClick(chargen.thief_skill[currentChargenThiefSkill].id, true)
					elseif cellNumber == 4 then
						createCharScreen:OnThiefSkillPlusMinusButtonClick(chargen.thief_skill[currentChargenThiefSkill].id, false)
					end
				end
			end
			cellNumber = nil
			ticksPassed = 0
			ticksStarting = 0
		"
		actionUpdate 
		"
			currentChargenProficiency = nil
			if createCharScreen:IsThiefSkillPlusMinusButtonClickable() then
				ticksStarting = ticksStarting + 1
				if ticksStarting > 10 then
					ticksPassed = ticksPassed + 1
					if ticksPassed > 2 then
						if cellNumber == 3 then
							createCharScreen:OnThiefSkillPlusMinusButtonClick(chargen.thief_skill[currentChargenThiefSkill].id, true)
						elseif cellNumber == 4 then
							createCharScreen:OnThiefSkillPlusMinusButtonClick(chargen.thief_skill[currentChargenThiefSkill].id, false)
						end
						ticksPassed = 0
					end
				end
			end
		"

		rowheight 54
		area 592 228 365 474
		table "chargen.thief_skill"
		var currentChargenThiefSkill
		scrollbar	'GUISCRC'
	}

	text
	{
		area 996 166 342 536
		text lua "proficiencyOrGeneralHelp()"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	
	button
	{
		enabled "chargen.levelingUp"
		area 990 730 230 44
		bam GUIBUTMT
		text "INFORMATION_BUTTON"
		text style "button"
		toggle "levelUpInfoToggle"
		action
		"
			currentChargenProficiency = nil
		"
	}
	button
	{
		enabled "chargen.levelingUp"
		area 736 730 230 44
		bam GUIBUTMT
		text "HIGH_LEVEL_ABILITIES_BUTTON"
		text style "button"
		toggle "levelUpInfoToggle"
		clickable lua "createCharScreen:IsHighLevelAbilitiesButtonClickable()"
		action
		"
			createCharScreen:OnHighLevelAbilitiesButtonClick()
		"
	}
	button
	{
		on escape
		area 236 730 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
--		clickable lua "not chargen.levelingUp"
		action "createCharScreen:OnCancelButtonClick();"
	}
	button
	{
		on return
		area 486 730 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "createCharScreen:OnDoneButtonClick();"
	}
	label
	{
		area		332 86 778 40
		text		lua "characters[currentID].name"
		text style  	'normal'
		text align	center center
		enabled	"chargen.levelingUp"
	}
	label
	{
		area		1230 56 64 90
		bam GUIRSP10
		enabled	"chargen.levelingUp"
	}
	label
	{
		area		1235 59 54 85
		bitmap		lua "characters[currentID].portrait"
		enabled	"chargen.levelingUp"
	}

}
`
function specialistFrame(num)
	if spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[num].key].specialist then
		return 3
	end
	return 0
end
function spellLearnOrUnlearnText()
	if chargen.extraSpells > 0 then
		return t("BUTTON_LEARN")
	else
		return t("BUTTON_UNLEARN")
	end
end
function spellLearnOrUnlearnClickable()
	spl = chargen.choose_spell[currentChargenChooseMageSpell]
	if chargen.extraSpells == 0 and spl ~= nil and spl.enabled == false or spl == nil or spl.known then
		return false
	else
		return true 
	end
end


function chooseSpellOrGeneralHelp()
	local helpText = chargen.helpText
	spl = chargen.choose_spell[currentChargenChooseMageSpell]
	if spl == nil then
		return helpText
	end

	local desc = spellBook[chargen.currentSpellLevelChoice][spl.key].desc
	if currentChargenChooseMageSpell and desc ~= -1 then
		return Infinity_FetchString(desc)
	else
		return helpText
	end
end
function rgUnlearnDefault()
	if randomCharacter == 0 then
		if chargen.choose_spell[1].known or chargen.choose_spell[1].enabled then	createCharScreen:OnLearnMageSpellButtonClick(1) end
		if chargen.choose_spell[2].known or chargen.choose_spell[2].enabled then	createCharScreen:OnLearnMageSpellButtonClick(2) end
		if chargen.choose_spell[3].known or chargen.choose_spell[3].enabled then	createCharScreen:OnLearnMageSpellButtonClick(3) end
		if chargen.choose_spell[4].known or chargen.choose_spell[4].enabled then	createCharScreen:OnLearnMageSpellButtonClick(4) end
		if chargen.choose_spell[5].known or chargen.choose_spell[5].enabled then	createCharScreen:OnLearnMageSpellButtonClick(5) end
		if chargen.choose_spell[6].known or chargen.choose_spell[6].enabled then	createCharScreen:OnLearnMageSpellButtonClick(6) end
		if chargen.choose_spell[7].known or chargen.choose_spell[7].enabled then	createCharScreen:OnLearnMageSpellButtonClick(7) end
		if chargen.choose_spell[8].known or chargen.choose_spell[8].enabled then	createCharScreen:OnLearnMageSpellButtonClick(8) end
		if chargen.choose_spell[9].known or chargen.choose_spell[9].enabled then	createCharScreen:OnLearnMageSpellButtonClick(9) end
		if chargen.choose_spell[10].known or chargen.choose_spell[10].enabled then	createCharScreen:OnLearnMageSpellButtonClick(10) end
		if chargen.choose_spell[11].known or chargen.choose_spell[11].enabled then	createCharScreen:OnLearnMageSpellButtonClick(11) end
		if chargen.choose_spell[12].known or chargen.choose_spell[12].enabled then	createCharScreen:OnLearnMageSpellButtonClick(12) end
		if chargen.choose_spell[13].known or chargen.choose_spell[13].enabled then	createCharScreen:OnLearnMageSpellButtonClick(13) end
		if chargen.choose_spell[14].known or chargen.choose_spell[14].enabled then	createCharScreen:OnLearnMageSpellButtonClick(14) end
		if chargen.choose_spell[15].known or chargen.choose_spell[15].enabled then	createCharScreen:OnLearnMageSpellButtonClick(15) end
		if chargen.choose_spell[16].known or chargen.choose_spell[16].enabled then	createCharScreen:OnLearnMageSpellButtonClick(16) end
		if chargen.choose_spell[17].known or chargen.choose_spell[17].enabled then	createCharScreen:OnLearnMageSpellButtonClick(17) end
		if chargen.choose_spell[18].known or chargen.choose_spell[18].enabled then	createCharScreen:OnLearnMageSpellButtonClick(18) end
		if chargen.choose_spell[19].known or chargen.choose_spell[19].enabled then	createCharScreen:OnLearnMageSpellButtonClick(19) end
		if chargen.choose_spell[20].known or chargen.choose_spell[20].enabled then	createCharScreen:OnLearnMageSpellButtonClick(20) end
		if chargen.choose_spell[21].known or chargen.choose_spell[21].enabled then	createCharScreen:OnLearnMageSpellButtonClick(21) end
		if chargen.choose_spell[22].known or chargen.choose_spell[22].enabled then	createCharScreen:OnLearnMageSpellButtonClick(22) end
		if chargen.choose_spell[23].known or chargen.choose_spell[23].enabled then	createCharScreen:OnLearnMageSpellButtonClick(23) end
		if chargen.choose_spell[24].known or chargen.choose_spell[24].enabled then	createCharScreen:OnLearnMageSpellButtonClick(24) end
		if chargen.choose_spell[25].known or chargen.choose_spell[25].enabled then	createCharScreen:OnLearnMageSpellButtonClick(25) end
		if chargen.choose_spell[26].known or chargen.choose_spell[26].enabled then	createCharScreen:OnLearnMageSpellButtonClick(26) end
		if chargen.choose_spell[27].known or chargen.choose_spell[27].enabled then	createCharScreen:OnLearnMageSpellButtonClick(27) end
		if chargen.choose_spell[28].known or chargen.choose_spell[28].enabled then	createCharScreen:OnLearnMageSpellButtonClick(28) end
		if chargen.choose_spell[29].known or chargen.choose_spell[29].enabled then	createCharScreen:OnLearnMageSpellButtonClick(29) end
		if chargen.choose_spell[30].known or chargen.choose_spell[30].enabled then	createCharScreen:OnLearnMageSpellButtonClick(30) end
	end
end

function nextOrDone()
	if(createCharScreen:HasMoreMageLevels()) then
		return t('NEXT_BUTTON')
	else
		return t('DONE_BUTTON')
	end
end
`
menu
{
	name 'CHARGEN_CHOOSE_SPELLS'
	align center center
	ignoreesc
	onOpen "
		rgspelldesc = 0
		table.sort(chargen.choose_spell, sortBySpellName)
		currentChargenChooseMageSpell = nil
		rgUnlearnDefault()
		"
	label
	{
		area 0 0 1444 818
		mosaic RGCSPEL
	}
	label
	{
		area 378 80 686 52
		text lua "t(chargen.title) .. ': ' .. t('LEVEL_LABEL') .. ' ' .. chargen.currentSpellLevelChoice"
		text style "title"
	}
	list
	{
		column
		{
			width 16

			label
			{
				bam GUIPFC
				area 4 19 16 16
				align center center
				enabled "chargen.choose_spell[rowNumber].enabled or chargen.choose_spell[rowNumber].known"
			}
			label
			{
				bam GUIBTBUT
				area 20 0 52 52 
				align center center
				frame lua "specialistFrame(rowNumber)"
			}
			label
			{
				area 20 0 52 52
				greyscale lua "chargen.choose_spell[rowNumber].enabled == false"
				bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[rowNumber].key].groundicon"
				align center center
			}
		}
		column
		{
			width 84
			label
			{
				area 4 0 -1 -1
				text lua "Infinity_FetchString(spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[rowNumber].key].name)"
				text style "normal"

				glow lua "chargen.choose_spell[rowNumber].enabled"
				align left center
				
			}
		}

--		scrollbar	'GUISCRC'
		rowheight 52
--		area 256 174 480 438
		table "chargen.choose_spell"
		var currentChargenChooseMageSpell
		action "
			if cellNumber == 1 and not chargen.choose_spell[currentChargenChooseMageSpell].known then
				createCharScreen:OnLearnMageSpellButtonClick(currentChargenChooseMageSpell)
			end
		"
	}
	
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[1].enabled or chargen.choose_spell[1].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(1)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[1].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 347 178 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[1].known then	createCharScreen:OnLearnMageSpellButtonClick(1)	end	"
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[1].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[2].enabled or chargen.choose_spell[2].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(2)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[2].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 419 178 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[2].known then	createCharScreen:OnLearnMageSpellButtonClick(2)	end	"
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[2].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[3].enabled or chargen.choose_spell[3].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(3)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[3].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 491 178 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[3].known then	createCharScreen:OnLearnMageSpellButtonClick(3)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[3].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[4].enabled or chargen.choose_spell[4].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(4)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[4].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 563 178 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[4].known then	createCharScreen:OnLearnMageSpellButtonClick(4)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[4].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[5].enabled or chargen.choose_spell[5].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(5)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[5].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 635 178 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[5].known then	createCharScreen:OnLearnMageSpellButtonClick(5)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[5].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[6].enabled or chargen.choose_spell[6].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(6)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[6].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 347 258 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[6].known then	createCharScreen:OnLearnMageSpellButtonClick(6)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[6].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[7].enabled or chargen.choose_spell[7].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(7)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[7].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 419 258 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[7].known then	createCharScreen:OnLearnMageSpellButtonClick(7)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[7].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[8].enabled or chargen.choose_spell[8].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(8)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[8].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 491 258 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[8].known then	createCharScreen:OnLearnMageSpellButtonClick(8)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[8].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[9].enabled or chargen.choose_spell[9].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(9)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[9].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 563 258 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[9].known then	createCharScreen:OnLearnMageSpellButtonClick(9)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[9].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[10].enabled or chargen.choose_spell[10].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(10)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[10].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 635 258 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[10].known then	createCharScreen:OnLearnMageSpellButtonClick(10)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[10].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[11].enabled or chargen.choose_spell[11].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(11)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[11].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 347 338 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[1].known then	createCharScreen:OnLearnMageSpellButtonClick(11)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[11].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[12].enabled or chargen.choose_spell[12].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(12)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[12].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 419 338 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[12].known then	createCharScreen:OnLearnMageSpellButtonClick(12)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[12].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[13].enabled or chargen.choose_spell[13].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(13)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[13].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 491 338 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[13].known then	createCharScreen:OnLearnMageSpellButtonClick(13)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[13].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[14].enabled or chargen.choose_spell[14].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(14)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[14].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 563 338 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[14].known then	createCharScreen:OnLearnMageSpellButtonClick(14)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[14].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[15].enabled or chargen.choose_spell[15].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(15)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[15].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 635 338 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[15].known then	createCharScreen:OnLearnMageSpellButtonClick(15)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[15].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[16].enabled or chargen.choose_spell[16].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(16)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[16].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 347 418 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[16].known then	createCharScreen:OnLearnMageSpellButtonClick(16)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[16].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[17].enabled or chargen.choose_spell[17].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(17)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[17].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 419 418 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[17].known then	createCharScreen:OnLearnMageSpellButtonClick(17)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[17].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[18].enabled or chargen.choose_spell[18].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(18)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[18].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 491 418 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[18].known then	createCharScreen:OnLearnMageSpellButtonClick(18)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[18].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[19].enabled or chargen.choose_spell[19].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(19)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[19].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 563 418 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[19].known then	createCharScreen:OnLearnMageSpellButtonClick(19)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[19].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[20].enabled or chargen.choose_spell[20].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(20)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[20].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 635 418 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[20].known then	createCharScreen:OnLearnMageSpellButtonClick(20)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[20].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[21].enabled or chargen.choose_spell[21].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(21)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[21].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 347 498 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[21].known then	createCharScreen:OnLearnMageSpellButtonClick(21)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[21].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[22].enabled or chargen.choose_spell[22].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(22)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[22].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 419 498 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[22].known then	createCharScreen:OnLearnMageSpellButtonClick(22)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[22].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[23].enabled or chargen.choose_spell[23].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(23)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[23].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 491 498 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[23].known then	createCharScreen:OnLearnMageSpellButtonClick(23)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[23].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[24].enabled or chargen.choose_spell[24].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(24)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[24].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 563 498 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[24].known then	createCharScreen:OnLearnMageSpellButtonClick(24)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[24].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[25].enabled or chargen.choose_spell[25].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(25)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[25].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 635 498 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[25].known then	createCharScreen:OnLearnMageSpellButtonClick(25)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[25].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[26].enabled or chargen.choose_spell[26].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(26)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[26].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 347 578 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[26].known then	createCharScreen:OnLearnMageSpellButtonClick(26)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[26].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[27].enabled or chargen.choose_spell[27].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(27)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[27].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 419 578 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[27].known then	createCharScreen:OnLearnMageSpellButtonClick(27)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[27].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[28].enabled or chargen.choose_spell[28].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(28)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[28].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 491 578 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[28].known then	createCharScreen:OnLearnMageSpellButtonClick(28)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[28].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[29].enabled or chargen.choose_spell[29].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(29)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[29].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 563 578 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[29].known then	createCharScreen:OnLearnMageSpellButtonClick(29)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[29].key].desc	rgspelldesc = 1"}
	list	{	column	{	width 100	label	{	bam RGCMHI	area 0 0 72 72	align center center	enabled "chargen.choose_spell[30].enabled or chargen.choose_spell[30].known"	}
			label	{	bam GUIBTBUT	area 10 10 52 52 	align center center	frame lua "specialistFrame(30)"	}
			label	{	area 10 10 52 52	bam lua "spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[30].key].groundicon"	align center center	}	}
		rowwidth 72	hideHighlight	area 635 578 72 72	table "chargen.choose_spell"	var currentChargenChooseMageSpell
		action "	if cellNumber == 1 and not chargen.choose_spell[30].known then	createCharScreen:OnLearnMageSpellButtonClick(30)	end	"		
		actionEnter	"desc = spellBook[chargen.currentSpellLevelChoice][chargen.choose_spell[30].key].desc	rgspelldesc = 1"}

	text
	{
		enabled "rgspelldesc == 1"
		area 748 180 344 517
		text lua "Infinity_FetchString(desc)"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled "rgspelldesc ~= 1"
		area 748 180 344 517
		text lua "chargen.helpText"
		text style "normal"
		scrollbar	'GUISCRC'
	}

	label
	{
		area 474 654 192 48
		text "SPELLS_REMAINING_NORMAL"
		text style "normal"
		text align right center
	}
	label
	{
		area 666 654 36 48
		text lua "chargen.extraSpells"
		text style "normal"
		text align center center
	}

	button
	{
--		area 240 654 230 44
		bam GUIBUTMT
		text lua "spellLearnOrUnlearnText()"
		text style "button"
--		clickable lua "spellLearnOrUnlearnClickable()"
--		action "createCharScreen:OnLearnMageSpellButtonClick(currentChargenChooseMageSpell)"
--		action "rgUnlearnDefault()"
	}

	button
	{
		on escape
		area 408 724 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		clickable lua "not chargen.levelingUp"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 806 724 230 44
		bam GUIBUTMT
		text lua "nextOrDone()"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "createCharScreen:OnDoneButtonClick()"
	}

}
`

function mageMemorizeSpellOrGeneralHelp()
	spl = chargen.choose_spell[currentChargenMemorizeMageSpell]
	if spl == nil then
		return Infinity_FetchString(17253)
	end

	local desc = mageSpells[chargen.currentSpellLevelChoice][spl.key].desc
	if currentChargenMemorizeMageSpell and desc ~= -1 then
		return Infinity_FetchString(desc)
	else
		return Infinity_FetchString(17253)
	end
end

`
menu
{
	name 'CHARGEN_MEMORIZE_MAGE'
	align center center
	ignoreesc
	onOpen "
		table.sort(chargen.choose_spell, sortByMageSpellName)
		currentChargenMemorizeMageSpell = nil
		"
	label
	{
		area 0 0 1444 818
		mosaic RGCGWDE
	}
	label
	{
		area 378 78 686 52
		text lua "chargen.title"
		text style "title"
	}
	list
	{
		column
		{
			width 18

			label
			{
				bam GUIBTBUT
				area 0 0 52 52 
				align center center
				icon lua "mageSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[rowNumber].key].groundicon"
				frame lua "specialistFrame(rowNumber)"
				count lua "chargen.choose_spell[rowNumber].count"
			}
		}
		column
		{
			width 56
			label
			{
				area 4 0 -1 -1
				text lua "Infinity_FetchString(mageSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[rowNumber].key].name)"
				text style "normal"

				glow lua "chargen.choose_spell[rowNumber].enabled"
				align left center
				
			}
		}
		column
		{
			width 13
			label
			{
				area 0 4 45 42
				bam GUIOSW
				frame lua "currentCellCheck(3)"
				sequence 0
			}
		}
		column
		{
			width 13
			label
			{
				area 0 4 45 42
				bam GUIOSW
				frame lua "currentCellCheck(4)"
				sequence 1

			}
		}


		scrollbar	'GUISCRC'
		rowheight 52
		hideHighlight
		area 352 182 352 438
		table "chargen.choose_spell"
		var currentChargenMemorizeMageSpell
		action "
			if cellNumber == 3 then
				createCharScreen:OnMemorizeMageSpellButtonClick(currentChargenMemorizeMageSpell, 1)
			elseif cellNumber == 4 then
				createCharScreen:OnMemorizeMageSpellButtonClick(currentChargenMemorizeMageSpell, -1)
			end
			cellNumber = nil
		"
	}
	text
	{
		area 748 182 342 515
		text lua "mageMemorizeSpellOrGeneralHelp()"
		text style "normal"
		scrollbar	'GUISCRC'
	}

	label
	{
		area 480 649 176 48
		text "SPELLS_REMAINING_NORMAL"
		text style "normal"
		text align right center
	}
	label
	{
		area 664 649 36 48
		text lua "chargen.extraSpells"
		text style "normal"
		text align center center
	}

	button
	{
		on escape
		area 416 724 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 808 724 230 44
		bam GUIBUTMT
		text lua "nextOrDone()"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "createCharScreen:OnDoneButtonClick()"
	}

}
`

function priestMemorizeSpellOrGeneralHelp()
	spl = chargen.choose_spell[currentChargenMemorizePriestSpell]
	if spl == nil then
		return Infinity_FetchString(17253)
	end

	local desc = priestSpells[chargen.currentSpellLevelChoice][spl.key].desc
	if currentChargenMemorizePriestSpell and desc ~= -1 then
		return Infinity_FetchString(desc)
	else
		return Infinity_FetchString(17253)
	end
end

`
menu
{
	name 'CHARGEN_MEMORIZE_PRIEST'
	align center center
	ignoreesc
	onOpen "
		rgprspelldesc = 0
		table.sort(chargen.choose_spell, sortByPriestSpellName)
		currentChargenMemorizePriestSpell = nil
		"
	label
	{
		area 0 0 1444 818
		mosaic RGCSPEL
	}
	label
	{
		area 378 78 686 52
		text lua "chargen.title"
		text style "title"
	}
	list
	{
		column
		{
			width 12

			label
			{
				bam GUIBTBUT
				area 0 0 52 52 
				align center center
				icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[rowNumber].key].groundicon"
				frame 0
				count lua "chargen.choose_spell[rowNumber].count"
			}
		}
		column
		{
			width 68
			label
			{
				area 4 0 -1 -1
				text lua "Infinity_FetchString(priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[rowNumber].key].name)"
				text style "normal"

				glow lua "chargen.choose_spell[rowNumber].enabled"
				align left center
				
			}
		}
		column
		{
			width 10
			label
			{
				area 0 4 45 42
				bam GUIOSW
				sequence 0
			}
		}
		column
		{
			width 10
			label
			{
				area 0 4 45 42
				bam GUIOSW
				sequence 1

			}
		}


--		scrollbar	'GUISCRC'
		rowheight 52
--		area 234 180 466 462
		table "chargen.choose_spell"
		var currentChargenMemorizePriestSpell
		action "
			if cellNumber == 3 then
				createCharScreen:OnMemorizePriestSpellButtonClick(currentChargenMemorizePriestSpell, 1)
			elseif cellNumber == 4 then
				createCharScreen:OnMemorizePriestSpellButtonClick(currentChargenMemorizePriestSpell, -1)
			end
		"
	}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[1].key].groundicon"	frame 0	count lua "chargen.choose_spell[1].count"	}	}
		rowwidth 52	area 347 178 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(1, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(1, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[1].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[2].key].groundicon"	frame 0	count lua "chargen.choose_spell[2].count"	}	}
		rowwidth 52	area 419 178 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(2, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(2, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[2].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[3].key].groundicon"	frame 0	count lua "chargen.choose_spell[3].count"	}	}
		rowwidth 52	area 491 178 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(3, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(3, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[3].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[4].key].groundicon"	frame 0	count lua "chargen.choose_spell[4].count"	}	}
		rowwidth 52	area 563 178 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(4, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(4, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[4].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[5].key].groundicon"	frame 0	count lua "chargen.choose_spell[5].count"	}	}
		rowwidth 52	area 635 178 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(5, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(5, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[5].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[6].key].groundicon"	frame 0	count lua "chargen.choose_spell[6].count"	}	}
		rowwidth 52	area 347 258 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(6, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(6, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[6].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[7].key].groundicon"	frame 0	count lua "chargen.choose_spell[7].count"	}	}
		rowwidth 52	area 419 258 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(7, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(7, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[7].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[8].key].groundicon"	frame 0	count lua "chargen.choose_spell[8].count"	}	}
		rowwidth 52	area 491 258 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(8, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(8, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[8].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[9].key].groundicon"	frame 0	count lua "chargen.choose_spell[9].count"	}	}
		rowwidth 52	area 563 258 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(9, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(9, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[9].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[10].key].groundicon"	frame 0	count lua "chargen.choose_spell[10].count"	}	}
		rowwidth 52	area 635 258 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(10, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(10, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[10].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[11].key].groundicon"	frame 0	count lua "chargen.choose_spell[11].count"	}	}
		rowwidth 52	area 347 338 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(11, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(11, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[11].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[12].key].groundicon"	frame 0	count lua "chargen.choose_spell[12].count"	}	}
		rowwidth 52	area 419 338 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(12, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(12, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[12].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[13].key].groundicon"	frame 0	count lua "chargen.choose_spell[13].count"	}	}
		rowwidth 52	area 491 338 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(13, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(13, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[13].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[14].key].groundicon"	frame 0	count lua "chargen.choose_spell[14].count"	}	}
		rowwidth 52	area 563 338 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(14, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(14, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[14].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[15].key].groundicon"	frame 0	count lua "chargen.choose_spell[15].count"	}	}
		rowwidth 52	area 635 338 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(15, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(15, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[15].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[16].key].groundicon"	frame 0	count lua "chargen.choose_spell[16].count"	}	}
		rowwidth 52	area 347 418 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(16, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(16, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[16].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[17].key].groundicon"	frame 0	count lua "chargen.choose_spell[17].count"	}	}
		rowwidth 52	area 419 418 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(17, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(17, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[17].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[18].key].groundicon"	frame 0	count lua "chargen.choose_spell[18].count"	}	}
		rowwidth 52	area 491 418 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(18, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(18, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[18].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[19].key].groundicon"	frame 0	count lua "chargen.choose_spell[19].count"	}	}
		rowwidth 52	area 563 418 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(19, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(19, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[19].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[20].key].groundicon"	frame 0	count lua "chargen.choose_spell[20].count"	}	}
		rowwidth 52	area 635 418 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(20, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(20, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[20].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[21].key].groundicon"	frame 0	count lua "chargen.choose_spell[21].count"	}	}
		rowwidth 52	area 347 498 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(21, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(21, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[21].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[22].key].groundicon"	frame 0	count lua "chargen.choose_spell[22].count"	}	}
		rowwidth 52	area 419 498 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(22, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(22, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[22].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[23].key].groundicon"	frame 0	count lua "chargen.choose_spell[23].count"	}	}
		rowwidth 52	area 491 498 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(23, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(23, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[23].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[24].key].groundicon"	frame 0	count lua "chargen.choose_spell[24].count"	}	}
		rowwidth 52	area 563 498 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(24, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(24, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[24].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[25].key].groundicon"	frame 0	count lua "chargen.choose_spell[25].count"	}	}
		rowwidth 52	area 635 498 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(25, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(25, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[25].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[26].key].groundicon"	frame 0	count lua "chargen.choose_spell[26].count"	}	}
		rowwidth 52	area 347 578 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(26, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(26, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[26].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[27].key].groundicon"	frame 0	count lua "chargen.choose_spell[27].count"	}	}
		rowwidth 52	area 419 578 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(27, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(27, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[27].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[28].key].groundicon"	frame 0	count lua "chargen.choose_spell[28].count"	}	}
		rowwidth 52	area 491 578 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(28, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(28, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[28].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[29].key].groundicon"	frame 0	count lua "chargen.choose_spell[29].count"	}	}
		rowwidth 52	area 563 578 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(29, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(29, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[29].key].desc	rgprspelldesc = 1"}
	list	{	column	{	width 52	label	{	bam GUIBTBUT	area 0 0 52 52 	align center center	icon lua "priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[30].key].groundicon"	frame 0	count lua "chargen.choose_spell[30].count"	}	}
		rowwidth 52	area 635 578 52 52	table "chargen.choose_spell"	action "createCharScreen:OnMemorizePriestSpellButtonClick(30, 1)"	actionAlt "createCharScreen:OnMemorizePriestSpellButtonClick(30, -1)"
		actionEnter	"desc = priestSpells[chargen.currentSpellLevelChoice][chargen.choose_spell[30].key].desc	rgprspelldesc = 1"}
	
	text
	{
		enabled "rgprspelldesc == 1"
		area 748 180 344 517
		text lua "Infinity_FetchString(desc)"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled "rgprspelldesc ~= 1"
		area 748 180 344 517
		text lua "Infinity_FetchString(17253)"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	text
	{
		enabled "rgprspelldesc ~= 1"
		area 748 580 344 117
		text 'RG_SPELL_TOOLTIP'
		text style "normal"
		scrollbar	'GUISCRC'
	}
--	text
--	{
--		area 744 180 348 517
--		text lua "priestMemorizeSpellOrGeneralHelp()"
--		text style "normal"
--		scrollbar	'GUISCRC'
--	}

	label
	{
		area 434 654 224 48
		text "SPELLS_REMAINING_NORMAL"
		text style "normal"
		text align right center
	}
	label
	{
		area 664 654 36 48
		text lua "chargen.extraSpells"
		text style "normal"
		text align center center
	}

	button
	{
		on escape
		area 410 722 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 806 722 230 44
		bam GUIBUTMT
		text lua "nextOrDone()"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "createCharScreen:OnDoneButtonClick()"
	}

}
`
currentChargenCustomSound = 0

`
menu
{
	name 'CHARGEN_CUSTOMSOUNDS'
	align center center
	ignoreesc
	label
	{
		area 0 0 1444 818
		mosaic 'RGCGWDE'
	}
	label
	{
		area	338 82 772 44
		text	"SOUND_TITLE"
		text style	title
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 384 20
				text lua "getFileNameStringRef(rowNumber, chargen.customSound)"
				text style	"normal"
				pad 8 0 0 0
			}
		}
		area 358 232 340 464
		rowheight	20
		table		"chargen.customSound"
		var			"currentChargenCustomSound"
		scrollbar	'GUISCRC'
		action
		"
			createCharScreen:OnSoundItemSelect(currentChargenCustomSound-1)
		"
	}
	text
	{
		area 746 180 342 516
		text "SOUND_DESCRIPTION"
		scrollbar 'GUISCRC'
		text style	normal
	}
	button
	{
		area 374 184 300 44
		bam GUIBUTWT
		text "PLAY_SOUND_BUTTON"
		text style "button"
		action "createCharScreen:OnPlayButtonClick()"
	}
	button
	{
		on escape
		area 420 724 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 802 724 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "Infinity_PopMenu(); createCharScreen:OnDoneButtonClick()"
	}
}
`
function hatedRaceOrGeneralHelp()
	race = chargen.hatedRace[currentChargenHatedRace]
	if race then
		return Infinity_FetchString(race.desc)
	else
		return Infinity_FetchString(17256)
	end
end

currentChargenHatedRace = 0
function getHatedRaceBackground(row)
	if(row == currentChargenHatedRace) then
		return "RGCGBT2"
	else
		return "RGCGBT1"
	end
end
`
menu
{
	name 'CHARGEN_HATEDRACE'
	align center center
	ignoreesc
	onopen "currentChargenHatedRace = nil"
	label
	{
		area 0 0 1444 818
		mosaic RGCGWDE
	}
	label
	{
		area 354 84 744 44
		text "HATED_RACE_TITLE"
		text style "title"
	}
	list
	{
		column
		{
			width 100
			label
			{
				area 		0 0 310 42
				mosaic lua  'getHatedRaceBackground(rowNumber)'
				respectClipping 
				align		center center
			}
			label
			{
				area 0 0 310 42
				text lua "Infinity_FetchString(chargen.hatedRace[rowNumber].name)"
				text style "list"
				text align center center
				pad -8 0 0 0
				text lower
			}
		}
		action "
			if chargen.hatedRace[currentChargenHatedRace] then
				createCharScreen:OnRacialEnemySelectButtonClick(chargen.hatedRace[currentChargenHatedRace].id)
			end
			"
		rowheight 42
		hideHighlight
		area 376 180 318 518
		table "chargen.hatedRace"
		var currentChargenHatedRace
		scrollbar	'GUISCRC'
	}
	text
	{
		area 748 180 344 518
		text lua "hatedRaceOrGeneralHelp()"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	button
	{
		on escape
		area 420 726 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 806 726 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "Infinity_PopMenu(); createCharScreen:OnDoneButtonClick()"
	}

}
`
charNameEdit = ""
`
menu
{
	name 'CHARGEN_NAME'
	align center center
	ignoreesc
	onopen 
	"
		Infinity_FocusTextEdit('charNameEditArea')
		if chargen.name then
			charNameEdit = chargen.name
		else
			charNameEdit = ''
		end
	"
	label
	{
		area 0 0 1444 818
		mosaic 'RGCNAME'

	}
	label
	{
		area 394 344 656 166
		rectangle 3

	}
	label
	{
		area 422 374 602 38
		text "ENTER_NAME_LABEL"
		text style "label"
	}
	label
	{
		area 422 428 598 36
		fill            112 111 111 64
	}
	edit
	{
		name		"charNameEditArea"
		area		422 432 586 52
		var			charNameEdit
		text style	"edit"
		maxlines	1
		maxchars	20
	}
	button
	{
		on escape
		area 410 720 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu(); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 812 720 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action "Infinity_PopMenu(); createCharScreen:OnDoneButtonClick()"
	}

}
`
createBioEdit = ""
`
menu
{
	name 'CHARGEN_BIO'
	align center center
	ignoreesc
	label
	{
		area 0 0 1444 818
		mosaic 'RGCBIOG'
	}
	label
	{
		area 350 84 744 44
		text "BIOGRAPHY_TITLE"
		text style "title"
	}
	label
	{
		area		334 160 776 538
		fill        112 111 111 64
	}
	edit
	{
		name		"createBioEditArea"
		area		342 168 760 522
		var			createBioEdit
		scrollbar	'GUISCRC'
		text style	"edit"
	}
	button
	{
		on escape
		area 354 724 230 44
		text "BACK_BUTTON"
		text style "button"
		bam GUIBUTMT
		action "createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		area 606 724 230 44
		text "CLEAR_BUTTON"
		text style "button"
		bam GUIBUTMT
		action "createBioEdit = ''"
	}
	button
	{
		on return
		area 860 724 230 44
		text "DONE_BUTTON"
		text style "button"
		bam GUIBUTMT
		action "createCharScreen:OnDoneButtonClick()"
	}

}
`
list_GUICG_20_2_idx = 0
function NextOrDone()
	if createCharScreen:GetImportState() == 1 then
		return t("NEXT_BUTTON")
	else
		return t("DONE_BUTTON")
	end
end
`
menu
{
	name 'CHARGEN_IMPORT'
	modal
	align center center
	ignoreesc
	onOpen
	"
		list_GUICG_20_2_idx = 0
	"
	label
	{
		area 0 0 864 710
		mosaic 'GUIPOP46'
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 -1 -1
				text lua "list_GUICG_20_2[rowNumber]"
				text style "list"
				pad 8 0 0 0
			}
		}
		area 36 96 312 498
		rowheight	34
		table		"list_GUICG_20_2"
		var			"list_GUICG_20_2_idx"
		scrollbar	'GUISCRC'
		action
		"
			Infinity_OnCharacterImportItemSelect(list_GUICG_20_2_idx - 1)
		"
	}
	text
	{
		area 364 96 440 490
		text 10963
		text style normal
		scrollbar 'GUISCRC'
	}
	button
	{
		on escape
		area 196 650 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu('CHARGEN_IMPORT'); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 438 650 230 44
		bam GUIBUTMT
		text lua "NextOrDone()"
		text style "button"
		clickable lua "list_GUICG_20_2_idx ~= 0"
		action "Infinity_PopMenu('CHARGEN_IMPORT'); createCharScreen:OnDoneButtonClick()"
	}

}
`
chargenExportCharacterEdit = ""
list_GUICG_21_2_idx = 0
`
menu
{
	name 'CHARGEN_EXPORT'
	modal
	align center center
	ignoreesc
	onopen "chargenExportListId = 0"
	label
	{
		area 0 0 864 710
		mosaic 'GUIPOP46'
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 -1 -1
				text lua "list_GUICG_21_2[rowNumber]"
				text style "list"
				pad 8 0 0 0
			}
		}
		area 42 100 312 282
		rowheight	18
		table		"list_GUICG_21_2"
		var			"chargenExportListId"
		scrollbar	'GUISCRC'
		action
		"
			createCharScreen:OnCharacterExportItemSelect(chargenExportListId - 1)
		"
	}
	text
	{
		area 362 100 466 498
		text 24461
		text style "normal"

	}
	label
	{
		area		42 382 312 23
		text		"EXPORT_FILENAME_LABEL"
		text style	"label"
		text color 3
	}
	label
	{
		area		42 405 312 51
		rectangle	0
	}
	edit
	{
		name		"chargenExportCharacterEditArea"
		area		48 416 298 30
		var			chargenExportCharacterEdit
		text style	"edit"
		maxlines	1
		fill            112 111 111 64
	}
	button
	{
		on escape
		area 196 650 230 44
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action "Infinity_PopMenu('CHARGEN_EXPORT'); createCharScreen:OnCancelButtonClick()"
	}
	button
	{
		on return
		area 438 650 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		action "Infinity_PopMenu('CHARGEN_EXPORT'); createCharScreen:OnDoneButtonClick()"
	}
	
}
menu
{
	name 'CHARGEN_DUALCLASS'
	align center center
	ignoreesc
	label
	{
		area 0 0 864 710
		mosaic guidcx
	}
	label
	{
		area 82 10 700 44
		text "DUALCLASS_TITLE"
		text style "title"
	}
	label
	{
		area 62 124 363 37
		text lua "characters[currentID].name"
		text style "label"
	}
	label
	{
		area 459 124 363 37
		text lua "characters[currentID].class"
		text style "label"
	}
	label
	{
		area 136 191 177 243
		bitmap		lua "characters[currentID].portrait"
	}
	text
	{
		area 481 194 336 407
		text 10811 --dual class info
		text style "normal"
		scrollbar	'GUISCRC'
	}
	button
	{
		area 57 495 340 32
		clickable lua "createCharScreen:GetCurrentStep() == const.STEP_DUALCLASS_CLASS"
		bam GUIBUTWS
		text "CLASS_BUTTON"
		text style "button"
		action
		"
			createCharScreen:OnMenuButtonClick()
		"
	}
	button
	{
		area 57 528 340 32
		clickable lua "createCharScreen:GetCurrentStep() == const.STEP_DUALCLASS_PROFICIENCIES"
		bam GUIBUTWS
		text "SKILLS_BUTTON"
		text style "button"
		action
		"
			createCharScreen:OnMenuButtonClick()
		"
	}
	button
	{
		area 438 653 230 44
		bam GUIBUTMT
		clickable lua "createCharScreen:GetCurrentStep() == const.STEP_DUALCLASS_DONE"
		text "DONE_BUTTON"
		text style "button"
		action
		"
			createCharScreen:OnDoneButtonClick()
		"
	}
	button
	{
		area 196 653 230 44
		clickable false
		bam GUIBUTMT
		text "BACK_BUTTON"
		text style "button"
		action
		"
			createCharScreen:OnCancelButtonClick()
		"
	}
}
`
difficulties = 
{
	{icon = "COLRSPRY", name = "DIFFICULTY_LABEL_STORYMODE", 		description = "DIFFICULTY_DESCRIPTION_STORYMODE"},
	{icon = "CONTSHLF", name = "DIFFICULTY_LABEL_EASY", 			description = "DIFFICULTY_DESCRIPTION_EASY"},
	{icon = "CONTSACK", name = "DIFFICULTY_LABEL_NORMAL", 			description = "DIFFICULTY_DESCRIPTION_NORMAL"},
	{icon = "CONTGRND", name = "DIFFICULTY_LABEL_CORERULES", 		description = "DIFFICULTY_DESCRIPTION_CORERULES"},
	{icon = "CONTBODY", name = "DIFFICULTY_LABEL_HARD", 			description = "DIFFICULTY_DESCRIPTION_HARD"},
	{icon = "CONTSKL1", name = "DIFFICULTY_LABEL_INSANE", 			description = "DIFFICULTY_DESCRIPTION_INSANE"},
	{icon = "CONTSKL2", name = "DIFFICULTY_LABEL_LEGACYOFBHAAL", 	description = "DIFFICULTY_DESCRIPTION_LEGACYOFBHAAL"},
}
fromSinglePlayer = false
fromMultiPlayer = false
function WhoYouGonnaCall()	
	fromSinglePlayer = (createCharScreen:GetEngineState() == 1 or createCharScreen:GetEngineState() == 7) and multiplayerScreen:GetEngineState() ~= 1
end
`
menu
{
	name 'CHARGEN_DIFFICULTY'
	align center center
	ignoreesc
	onopen 
	"
		currentDifficulty = 3
		WhoYouGonnaCall()
	"
	label
	{
		area 0 0 1444 818
		mosaic 'RGCDIF'
	}
	label
	{
		area 370 74 700 60
		text "DIFFICULTY_TITLE"
		text style "title"
	}
	label
	{
		area 94 148 1248 562
		rectangle 3
	}
	list
	{
		column 
		{ 
			width 10
			label
			{
				area 20 5 60 60
				bam "GUIDIFFS"
				frame lua "rowNumber-1"
				align center center
			}
		}
		column 
		{ 
			width 20
			label
			{
				area 0 0 -1 -1
				text lua "t( difficulties[rowNumber].name )"
				text style "label"
				text align center center
				text color	B
			}
		}
		column 
		{ 
			width 70
			label
			{
				area 10 0 -1 -1
				text lua "t( difficulties[rowNumber].description )"
				text style "label"
				text point	12
				text align left center
				text color	B
			}
		}
		area 116 170 1204 522
		rowheight	72
		table		"difficulties"
		var			"currentDifficulty"
		scrollbar	'GUISCRC'
		action
		"
		"
	}
	button
	{
		on escape
		area 352 732 230 44
		bam GUIBUTMT
		text 15416
		text style "button"
		action 
		"
			Infinity_PopMenu()
			if(createCharScreen:GetEngineState() == 7) then
				--If we're in import character mode, go back to the import screen.
				e:SelectEngine(startEngine)
				Infinity_PopMenu()
				startEngine:OnImportCharacterButtonClick()
			end
		"
	}
	button
	{
		area 866 732 230 44
		bam GUIBUTMT
		text lua "t('VENTURE_FORTH')"
		text style "button"
		enabled "fromSinglePlayer"
		action 
		"
			Infinity_PopMenu()
			createCharScreen:AcceptCharacter(currentDifficulty)
		"
	}
	button
	{
		area 586 732 230 44
		bam GUIBUTMT
		text 11973
		text style "button"
		enabled "fromMultiPlayer"
		action 
		"
			Infinity_PopMenu()
			Infinity_PopMenu()
			Infinity_PopMenu()
			Infinity_PopMenu()

			if connectionLocalNetworkGame == 1 then
				connectionIsHosting = true
				chooseNetworkProtocol(2)
			end

			fromMultiPlayer = false
			mulitplayerPreexistingDifficulty = currentDifficulty
			connectionScreen:OnNewGameButtonClick()
		"
	}
}
`
currentHLASelection = nil
function chargenHLADescription()
	if currentHLASelection == nil then
		return 63817
	else
		return chargen.HLAs[currentHLASelection].description
	end
end
function chargenHLAPlusMinusFrame(cell, rownumber)
	if cell == 3 then
		if chargen.HLAs[rownumber].canAdd then
			return currentCellCheck(cell)
		else
			return 3
		end
	elseif cell == 4 then
		if chargen.HLAs[rownumber].canSubtract then
			return currentCellCheck(cell)
		else
			return 3
		end
	end
end
`
menu
{
	name 'CHARGEN_HIGH_LEVEL_ABILITIES'
	align center center
	ignoreesc
	modal
	onOpen 
	"
		currentHLASelection = nil
	"
	label
	{
		area 0 0 864 710
		mosaic RGGHLA
	}
	label
	{
		area 74 10 716 52
		text "HIGH_LEVEL_ABILITIES_TITLE"
		text style "title"
	}
	label
	{
		area 54 122 760 44
		text lua "chargen.numHLAs"
		text style "normal"
		align center center
	}
	text
	{
		area 534 190 290 422
		text lua "Infinity_FetchString(chargenHLADescription())"
		text style "normal"
		scrollbar	'GUISCRC'
	}
	
	list
	{
		column
		{
			width 15

			label
			{
				bam GUIBTBUT
				area 0 0 52 52 
				align center center
				icon lua "chargen.HLAs[rowNumber].icon"
				glow lua "chargen.HLAs[rowNumber].count > 0"
				count lua "chargen.HLAs[rowNumber].count"
			}
		}
		column
		{
			width 61
			label
			{
				area 4 0 -1 -1
				text lua "Infinity_FetchString(chargen.HLAs[rowNumber].name)"
				text style "normal"
				align left center
				
			}
		}
		column
		{
			width 12
			label
			{
				area 0 4 45 42
				bam GUIOSW
				frame lua "chargenHLAPlusMinusFrame(3, rowNumber)"
				sequence 0
			}
		}
		column
		{
			width 12
			label
			{
				area 0 4 45 42
				bam GUIOSW
				frame lua "chargenHLAPlusMinusFrame(4, rowNumber)"
				sequence 1

			}
		}


		scrollbar	'GUISCRC'
		rowheight 52
		area 58 194 414 404
		table "chargen.HLAs"
		var currentHLASelection
		action 
		"
			if cellNumber == 3 and chargenHLAPlusMinusFrame(3, currentHLASelection) ~= 3 then
				createCharScreen:OnHLAButtonClick(currentHLASelection, 1)
			elseif cellNumber == 4 and chargenHLAPlusMinusFrame(4, currentHLASelection) ~= 3 then
				createCharScreen:OnHLAButtonClick(currentHLASelection, -1)
			end
			cellNumber = nil
		"
	}
	button
	{
		area 322 642 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "createCharScreen:IsDoneButtonClickable()"
		action 
		"
			createCharScreen:OnDoneButtonClick()
		"
	}
}
`
TEXT_popup_big = 0
`
menu
{
	name 'POPUP_BIG'
	align center center
	modal
	label
	{
		area 0 0 864 710
		mosaic GUIPOPF
	}
	text
	{
		area 40 98 788 496
		text lua "Infinity_FetchString(TEXT_popup_big)"
		text style	"label"
		text align left top
		scrollbar 'GUISCRC'
	}
	button
	{
		area 317 634 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style	"button"
		action 
		"
			Infinity_PopMenu()
		"
	}
}
menu
{
	name 'RG_PP_POPUP'
	align center center
	modal
	label
	{
		area 0 0 864 710
		mosaic GUIPOPF
	}
	text
	{
		area 40 98 788 496
		text lua "t('RG_PP_TOOLTIP1') .. '\n\n' .. t('RG_PP_TOOLTIP2') .. '\n\n' .. t('RG_PP_TOOLTIP3') .. '\n\n' .. t('RG_PP_TOOLTIP4')"
		text style	"label"
		text align left top
		scrollbar 'GUISCRC'
	}
	button
	{
		area 317 634 230 44
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style	"button"
		action 
		"
			Infinity_PopMenu()
		"
	}
}
`
list_GUIMOVIE_0_0_idx = 0
`
menu
{
	name 'MOVIES'
	align center center
	modal

	button
	{
		on escape
		action
		"
			--Return to world screen on escape 
			e:SelectEngine(optionsScreen)
		"
	}
	label
	{
		area 0 0 1444 818
		mosaic "RGOPTIO2"
	}
	label
	{
		area 504 88 422 622
		rectangle 3
	}
	label
	{
		area 246 32 948 44
		text "MOVIES_TITLE"
		text style "title"
	}
	list
	{
		column 
		{ 
			width 100
			label
			{
				area 0 0 384 18
				text lua "list_GUIMOVIE_0_0[rowNumber].description"
				text style	"list"
				pad 8 2 0 0
				text align left center
			}
		}
		area 528 114 376 574
		rowheight	28
		table		"list_GUIMOVIE_0_0"
		var		"list_GUIMOVIE_0_0_idx"
		scrollbar	'GUISCRC'
		action
		"
			moviesScreen:OnMovieItemSelect(list_GUIMOVIE_0_0[list_GUIMOVIE_0_0_idx].movieCode)
		"
	} 
	button
	{
		area 566 724 300 44
		bam GUIBUTWT
		text "PLAY_MOVIE_BUTTON"
		text style "button"
		action "moviesScreen:OnPlayButtonClick()"
	}
	button
	{
		area 160 724 300 44
		bam GUIBUTWT
		text "CREDITS_MOVIE_BUTTON"
		text style "button"
		action "moviesScreen:OnCreditsButtonClick()"
	}
	button
	{
		area 984 724 300 44
		bam GUIBUTWT
		text "DONE_BUTTON"
		text style "button"
		action "moviesScreen:OnDoneButtonClick()"
	}


}
`
--Multiplayer start.
mp_shownSessions = {}
selectedMp = 0
detailsStr = ""
passwordReq = 0
passwordMp = ""
connectionPlayerNameEdit = ""
connectionFilterNoPasswords = 0
connectionFilterNoFullGames = 0
selectedIndex = 0
connectionIsHosting = false

function connectionBuildGameList()
	local index = 1
	local count = 0
	local entryOK = true
	local foundSelected = false

	for index = 1, #(mp_sessions), 1 do
		entryOK = true
		Infinity_GetPasswordRequired(index)
		if mp_sessions[index] == nil then
			entryOK = false
		elseif mp_sessions[index]["flags"] == nil then
			entryOK = false
		elseif connectionFilterNoPasswords == 1 and passwordReq ~= 0 then
			entryOK = false
		elseif connectionFilterNoFullGames == 1 and mp_sessions[index]["players"] == 6 then 
			entryOK = false
		end

		if entryOK == true then
			count = count + 1
			mp_shownSessions[count] = {}
			mp_shownSessions[count]["actualIndex"] = index
			mp_shownSessions[count]["updated_at"] = mp_sessions[index]["updated_at"]

			if mp_sessions[index]['sessionIDString'] == selectedIndex then
				selectedMp = count
				foundSelected = true
			end
		end
	end

	local tableCount = #(mp_shownSessions) 
	while tableCount > count do
		mp_shownSessions[tableCount] = nil
		tableCount = tableCount - 1
	end

	if foundSelected == false then
		selectedMp = 0
	end
end
function chooseNetworkProtocol(num)
	connectionScreen:SelectServiceProvider(num)
end
function joinGameEnabled()
	if selectedMp <= 0 then
		return 0
	else
		return 1
	end
end
function gameHasPassword(slot)
	if(mp_sessions[mp_shownSessions[slot]["actualIndex"]] == nil) then
		--if the session isn't loaded don't show anything.
		return ""
	end
	Infinity_GetPasswordRequired(mp_shownSessions[slot]["actualIndex"])
	if passwordReq ~= 0 then 
		ret = t("YES")
	else
		ret = t("NO")
	end
	return ret
end
function connectionGetGameName(slot)
	ret = ""

	ret = mp_sessions[mp_shownSessions[slot]["actualIndex"]]['name']

	return ret
end
function connectionGetNumPlayers(slot)
	ret = 0

	ret = mp_sessions[mp_shownSessions[slot]["actualIndex"]]['players']

	return ret
end
function connectionGetGameType(slot)
	ret = ""

	if mp_sessions[mp_shownSessions[slot]["actualIndex"]] ~= nil then
		if mp_sessions[mp_shownSessions[slot]["actualIndex"]]["version"] == "bgee-main" then
			ret = t("MAIN_GAME_LABEL")
		elseif mp_sessions[mp_shownSessions[slot]["actualIndex"]]["version"] == "bgee-bp" then
			ret = t("ARENA_MODE_LABEL")
		elseif mp_sessions[mp_shownSessions[slot]["actualIndex"]]["version"] == "bgee-sod" then
			ret = t("EXPANSION_LABEL")
		end
	end

	return ret
end

function matchMultiplayerGameType(gameVersion)
	if gameVersion == "bgee-main" then
		startEngine:OnSoAButtonClick(false)
		e:CheckGUISong()
	elseif gameVersion == "bgee-bp" then
		startEngine:OnTBPButtonClick(false)
		e:CheckGUISong()
	elseif gameVersion == "bgee-sod" then
		startEngine:OnCampaignButtonClick('SOD',false)
		e:CheckGUISong()
	end
end
`
menu
{
	name 'CONNECTION'
	align center center
	onOpen
	"
		connectionFilterNoPasswords = 0
		connectionFilterNoFullGames = 0
		connectionIsHosting = false
		connectionBuildGameList()

		if connectionPlayerNameEdit == '' then
			connectionSetDefaultGameSettings()
		end
	"
	label -- Background
	{
		area 0 0 1444 818
		mosaic RGMPCON 
	}
	label -- Title
	{
		area 250 34 946 40
		text  "JOIN_GAME_TITLE"
		text style title
	}
	label
	{
		area 204 200 498 36
		text lua "t('GAME_NAME_LABEL')"
		text style "label_parchment"
		align center center
	}
	label
	{
		area 766 200 84 36
		text lua "t('PASSWORD_LABEL')"
		text style "label_parchment"
		align center center
	}
	label
	{
		area 864 200 70 36
		text lua "t('PLAYERS_LABEL')"
		text style "label_parchment"
		align center center
	}
	label
	{
		area 956 200 186 36
		text lua "t('GAME_TYPE_LABEL')"
		text style "label_parchment"
		align center center
	}
	list -- Multiplayer sessions
	{
		column 
		{ 
			width 60 
			label
			{
				area 20 0 500 40
				text lua "connectionGetGameName(rowNumber)"
				text style	"list_parchment"
				align left center 
			}

		}
		column 
		{ 
			width 10 
			label
			{
				area 20 0 210 40
				text lua "gameHasPassword(rowNumber)"
				text style	"list_parchment"
				align left center 
			}

		}
		column 
		{ 
			width 10 
			label
			{
				area 20 0 210 40
				text lua "connectionGetNumPlayers(rowNumber)"
				text style	"list_parchment"
				align left center 
			}

		}
		column 
		{ 
			width 20 
			label
			{
				area 20 0 210 40
				text lua "connectionGetGameType(rowNumber)"
				text style	"list_parchment"
				align left center 
			}

		}

		area 204 254 972 412
		
		rowheight	44
		table		"mp_shownSessions"
		var			selectedMp
		scrollbar	'GUISCRC'
		action
		"
			selectedIndex = mp_sessions[mp_shownSessions[selectedMp]['actualIndex']]['sessionIDString']
		"
	}

	label -- player name
	{
		area 616 80 210 40
		text  "PLAYER_NAME_LABEL"
		text style "label"
	}
	label
	{
		area 612 118 218 44
		fill 112 111 111 64
	}
	edit
	{
		name		"ConnectionPlayerNameEditArea"
		area		616 124 210 38
		var			connectionPlayerNameEdit
		text 		style "edit"
		maxlines	1
		maxchars 	32
	}

	label -- filter options
	{
		area		961 84 215 40
		text		style 'label'
		text		"CONNECTION_NOT_PASSWORD_PROTECTED_LABEL"
		align 		left center
		tooltip lua "t('CONNECTION_NO_PASSWORDS_TOOLTIP')"
	}
	button
	{
		area		911 84 45 40
		bam 		ROUNDBUT
		glow lua	"connectionFilterNoPasswords"
		align 		center center
		tooltip lua "t('CONNECTION_NO_PASSWORDS_TOOLTIP')"
		action
		"
			connectionFilterNoPasswords = 1 - connectionFilterNoPasswords
			connectionBuildGameList()
		"
	}
	label
	{
		area		961 130 215 42
		text		style 'label'
		text		"CONNECTION_NOT_FULL_LABEL"
		align 		left center
		tooltip lua "t('CONNECTION_NO_FULL_GAMES_TOOLTIP')"
	}
	button
	{
		area		911 130 45 42
		bam 		ROUNDBUT
		glow lua	"connectionFilterNoFullGames"
		align 		center center
		tooltip lua "t('CONNECTION_NO_FULL_GAMES_TOOLTIP')"
		action
		"
			connectionFilterNoFullGames = 1 - connectionFilterNoFullGames
			connectionBuildGameList()
		"
	}

	button -- Create game
	{
		area		168 110 230 44
		bam			GUIBUTMT
		sequence	6
		text  		"CONNECTION_CREATE_NEW_GAME_BUTTON"
		text style	"button"
		action
		"
			Infinity_PushMenu('CONNECTION_CREATE')
		"	
	}
	button -- Direct Connect
	{
		area		406 718 230 44
		bam			GUIBUTMT
		sequence	6
		text  		"CONNECTION_DIRECT_CONNECTION_BUTTON"
		text style	"button"
		tooltip lua "t('CONNECTION_DIRECT_CONNECT_TOOLTIP')"
		action
		"
			connectionIsHosting = false
			chooseNetworkProtocol(2)
		"	
	}
	button -- refresh
	{
		area		1202 96 70 66
		bam 		'GUMPBUTX'
		sequence 	2
		align 		center center
		tooltip lua "t('CONNECTION_REFRESH_TOOLTIP')"
		action
		"
			connectionScreen:ClearSessions()
		"
	}

	button -- Join game
	{
		area		1042 718 230 44
		bam			GUIBUTMT
		sequence	6
		text  "JOIN_BUTTON"
		text style	"button"
		clickable lua	"joinGameEnabled()"
		action
		"
			Infinity_GetPasswordRequired(mp_shownSessions[selectedMp]['actualIndex'])
			if passwordReq == 0 then
				Infinity_PopMenu(); 
				Infinity_PopMenu(); 
				mp_sessions[mp_shownSessions[selectedMp]['actualIndex']]['password'] = passwordMp
				Infinity_JoinMultiplayerGame(mp_shownSessions[selectedMp]['actualIndex'])
			else
				Infinity_PushMenu('CONNECTION_PASSWORD')
			end
		"	
	}
	button -- Back/ Log out
	{
		area		168 718 230 44
		bam			GUIBUTMT
		sequence	0
		text  "BACK_BUTTON"
		text style	"button"
		on 			escape
		action
		"
			Infinity_PopMenu();
			connectionScreen:OnMainCancelButtonClick()
		"	
	}
}
`
connectionTCPIPEdit = ""
`
menu
{
	name 'CONNECTION_IP'
	modal
	align center center

	onopen "Infinity_FocusTextEdit('ConnectionTCPIPEditArea')"
	label
	{
		area 0 0 657 234
		mosaic GUIERR6 
	}
	label --Title
	{
		area 42 20 572 64
		text  20681
		text style	"label"
	}
	button
	{
		area		370 170 230 44
		bam		GUIBUTMT
		sequence	0
		text  "DONE_BUTTON"
		text style	"button"
		on		return
		action
		"
			Infinity_PopMenu();
			connectionScreen:JoinGameIPAddress(connectionTCPIPEdit)
		"	
	}
	button
	{
		area		88 170 230 44
		bam		GUIBUTMT
		sequence	1
		text  "CANCEL_BUTTON"
		text style	"button"
		on 		escape
		action
		"
			Infinity_PopMenu();
			chooseNetworkProtocol(1)
		"	
	}
	
	label
	{
		area 56 84 544 44
		fill 112 111 111 64
	}
	
	edit
	{
		name		"ConnectionTCPIPEditArea"
		area		64 90 528 28
		var		connectionTCPIPEdit
		text style	"edit"
		maxlines	1

	}
}
`
connection = {}
connectionSessionNameEdit = ""
connectionSessionPasswordEdit = ""
connectionPasswordProtected = 0
connectionLocalNetworkGame = 0

function connectionCreateGameClickable()
	local ret = connectionPlayerNameEdit ~= '' and connectionSessionNameEdit ~= ''

	if connectionPasswordProtected == 1 then
		ret = ret and connectionSessionPasswordEdit ~= ""
	end

	return ret
end
function connectionSetDefaultGameSettings() 
	local player = t("MULTIPLAYER_DEFAULT_PLAYER")
	local game = t("MULTIPLAYER_ENTER_GAME_NAME")
	local pass = t("MULTIPLAYER_ENTER_GAME_PASSWORD")

	if connectionPlayerNameEdit == "" then
		connectionPlayerNameEdit = Infinity_GetINIString('Multiplayer', 'Player Name', player)
		Infinity_SetINIValue('Multiplayer', 'Player Name', connectionPlayerNameEdit)
	end

	if connectionSessionPasswordEdit == "" then
		connectionSessionPasswordEdit = Infinity_GetINIString('Multiplayer', 'Session Password', pass)
		Infinity_SetINIValue('Multiplayer', 'Session Password', connectionSessionPasswordEdit)
	end

	if connectionSessionNameEdit == "" then
		connectionSessionNameEdit = Infinity_GetINIString('Multiplayer', 'Session Name', game)
		Infinity_SetINIValue('Multiplayer', 'Session Name', connectionSessionNameEdit)
	end

	if connectionSessionPasswordEdit ~= "" then
		connectionPasswordProtected = 1
	else
		connectionPasswordProtected = 0
	end
	connectionLocalNetworkGame = 0
end
`
menu
{
	name 'CONNECTION_CREATE'
	align center center
	ignoreEsc
	modal

	onOpen
	"
		connectionSetDefaultGameSettings()
	"

	label
	{
		area 0 0 664 666
		mosaic "RECENTEV"
	}
	label
	{
		area		104 70 462 45
		text		style 'title'
		text		"CREATEGAME_TITLE"
	}
	
	label -- player
	{
		area		100 122 462 45
		text		style 'label'
		text		"PLAYER_NAME_LABEL"
	}
	label
	{
		area		164 167 344 45
		fill            112 111 111 64
	}
	edit
	{
		name		"connectionPlayerNameEditArea"
		area		170 174 334 32
		var			connectionPlayerNameEdit
		text style	"edit"
		maxlines	1
		maxchars 	32

	}

	label -- session
	{
		area		100 221 462 45
		text		style 'label'
		text		"SESSION_NAME_LABEL"
	}
	label
	{
		area		164 266 344 44
		fill        112 111 111 64
	}
	edit
	{
		name		"connectionSessionNameEditArea"
		area		170 272 334 32
		var			connectionSessionNameEdit
		text 		style	"edit"
		maxlines	1
	}


	text -- password option
	{
		area		280 321 241 40
		text		style 'label'
		text		"CONNECTION_PASSWORD_PROTECTED"
		tooltip lua "t('CONNECTION_PASSWORD_PROTECTED_TOOLTIP')"
		align 		left center
	}
	button
	{
		area		230 321 45 45
		bam 		ROUNDBUT
		glow lua	"connectionPasswordProtected"
		align 		center center
		tooltip lua "t('CONNECTION_PASSWORD_PROTECTED_TOOLTIP')"
		action
		"
			connectionPasswordProtected = 1 - connectionPasswordProtected
			if connectionPasswordProtected == 1 then
				Infinity_FocusTextEdit('connectionSessionPasswordEditArea')
			end
		"
	}

	text -- local option
	{
		area		280 366 241 40
		text		style 'label'
		text		"CONNECTION_LOCAL_NETWORK_GAME"
		tooltip lua "t('CONNECTION_LOCAL_NETWORK_GAME_TOOLTIP')"
		align 		left center
	}
	button
	{
		area		230 366 45 45
		bam 		ROUNDBUT
		glow lua	"connectionLocalNetworkGame"
		align 		center center
		tooltip lua "t('CONNECTION_LOCAL_NETWORK_GAME_TOOLTIP')"
		action
		"
			connectionLocalNetworkGame = 1 - connectionLocalNetworkGame
		"
	}

	label -- password
	{
		area		100 416 462 45
		text		style 'label'
		text		"CHOOSE_PASSWORD_LABEL"
		enabled 	connectionPasswordProtected
	}
	label
	{
		area		164 461 344 43
		fill        112 111 111 64
		enabled 	connectionPasswordProtected
	}
	edit
	{
		name		"connectionSessionPasswordEditArea"
		area		170 466 334 32
		var			connectionSessionPasswordEdit
		text 		style "edit"
		maxlines	1
		enabled 	connectionPasswordProtected
	}
	button
	{
		clickable lua 	"connectionCreateGameClickable()"
		area 			236 572 200 44
		bam				'GUIBUTNT'	
		text style		"button"
		text			"CREATEGAME_BUTTON"
		action		
		"
			if connectionPasswordProtected == 0 then
				connectionSessionPasswordEdit = ''
			end

			Infinity_PushMenu('CONNECTION_NEWORSAVED')
		"
	}
	button
	{
		area 		236 528 200 44
		bam			'GUIBUTNT'	
		text style	"button"
		text		"BACK_BUTTON"
		action		
		"
			Infinity_PopMenu()
		"
	}
}
menu
{
	name 'CONNECTION_NEWORSAVED'
	align center center
	modal

	label
	{
		area 0 0 664 668
		mosaic "RECENTEV"
	}
	label
	{
		area		104 70 460 48
		text		style 'title'
		text		"CONNECTION_NEW_OR_SAVED_GAME_TITLE"
	}
	label
	{
		area		130 140 392 45
		text		style 'label'
		text		"CONNECTION_SELECT_GAME_TYPE_LABEL"
	}

	button
	{
		bam 		GUIOSW
		on esc
		area 		614 7 44 44
		sequence 	2
		action 
		"	
			Infinity_PopMenu()
		"
	}

	button
	{
		area		210 250 237 66
		bam			'GUIBUTST'	
		text style	"button"
		text		"NEW_GAME_BUTTON"
		tooltip lua "t('CONNECTION_NEW_GAME_TOOLTIP')"
		action		
		"
			fromMultiPlayer = true
			Infinity_PushMenu('CHARGEN_DIFFICULTY')
		"
	}
	button
	{
		area		210 332 237 66
		bam			'GUIBUTST'	
		text style	"button"
		text		"LOAD_BUTTON"
		tooltip lua "t('CONNECTION_LOAD_GAME_TOOLTIP')"
		action		
		"
			Infinity_PopMenu()
			Infinity_PopMenu()
			Infinity_PopMenu()

			if connectionLocalNetworkGame == 1 then
				connectionIsHosting = true
				chooseNetworkProtocol(2)
			end

			connectionScreen:OnLoadGameButtonClick()
		"
	}

	button
	{
		area 			236 572 200 44
		bam			'GUIBUTNT'	
		text style	"button"
		text		"BACK_BUTTON"
		action		
		"
			Infinity_PopMenu()
		"
	}
}
`
connectionPasswordPasswordEdit = ""
`
menu
{
	name 'CONNECTION_PASSWORD'
	align center center
	modal
	onOpen
	"
		if mp_sessions[selectedMp]['name'] == Infinity_GetINIString('Multiplayer', 'Session Name', '') then
			connectionPasswordPasswordEdit = Infinity_GetINIString('Multiplayer', 'Session Password', '')
		else
			connectionPasswordPasswordEdit = ''
		end
		Infinity_FocusTextEdit('connectionPasswordPasswordEditArea')
	"

	label
	{
		area 0 0 658 240
		mosaic "GUIERR6"
	}
	label
	{
		area		22 14 606 45
		text		style 'title'
		text		"PASSWORD_REQUIRED_LABEL"
	}
	label
	{
		area		22 59 606 33
		text		style 'label'
		text		"ENTER_PASSWORD_LABEL"
	}

	button
	{
		bam 		GUIOSW
		on esc
		area 		614 0 44 44
		sequence 	2
		action 
		"	
			Infinity_PopMenu()
		"
	}

	edit
	{
		name		"connectionPasswordPasswordEditArea"
		area		22 92 606 50
		var			connectionPasswordPasswordEdit
		text style	"edit"
		text align 	center center
		maxlines	1
		fill        112 111 111 64
		action
		"
			--On return pressed
			if (key_pressed == 13) then
				mp_sessions[selectedMp]['password'] = connectionPasswordPasswordEdit
				Infinity_JoinMultiplayerGame(mp_shownSessions[selectedMp]['actualIndex'])
			end
			return 1
		"
	}

	button
	{
		area 		343 170 230 44
		bam			'GUIBUTMT'	
		text style	"button"
		text		"DONE_BUTTON"
		clickable lua "connectionPasswordPasswordEdit ~=''"
		action		
		"
			Infinity_PopMenu(); 
			mp_sessions[selectedMp]['password'] = connectionPasswordPasswordEdit
			Infinity_JoinMultiplayerGame(mp_shownSessions[selectedMp]['actualIndex'])
		"
	}

	button
	{
		area 79 170 230 44
		bam			'GUIBUTMT'	
		text style	"button"
		text		"BACK_BUTTON"
		action		
		"
			Infinity_PopMenu()
		"
	}
}
menu
{
	name 'CONNECTION_PLAYERNAME'
	align center center
	ignoreEsc
	modal

	onOpen
	"
		connectionPlayerNameEdit = Infinity_GetINIString('Multiplayer', 'Player Name', 'Player Name')
		Infinity_FocusTextEdit('connectionPlayerNameEditArea')
	"
	label
	{
		area 0 0 512 651
		mosaic "GUICONNB"
	}
	label
	{
		area 83 59 338 32
		text style "label"
		text "CURRENT_PLAYERS_LABEL"
	}
	label
	{
		area 83 446 338 32
		text style "label"
		text "PLAYER_NAME_LABEL"
	}

	list
	{
		column
		{
			width 100
			label
			{
				area 0 0 -1 -1
				text lua "connection.currentPlayers[rowNumber].name"
				text style "edit"
				align center center
			}
		}

		action 
		"
		"

		rowheight 50
		area 83 99 350 338
		table "connection.currentPlayers"
		var connectionSelectedPlayer
	}

	edit
	{
		name		"connectionPlayerNameEditArea"
		area		83 479 338 32
		var			connectionPlayerNameEdit
		text style	"edit"
		text align  center center
		maxlines	1
		maxchars 	32
		fill            112 111 111 64
	}
	button
	{
		clickable 	lua "connectionPlayerNameEdit ~= ''"
		area		150 535 230 44
		bam			GUIBUTMT
		sequence	0
		text  		"DONE_BUTTON"
		text style	"button"
		on			return
		action
		"
			Infinity_PopMenu();
			Infinity_PopMenu();
			connectionScreen:SetPlayerName(connectionPlayerNameEdit)
		"	
	}
}
menu
{
	name 'CONNECTION_JOINING'
	modal
	align center center

	label
	{
		area 0 0 657 234
		mosaic GUIERR6 
	}
	label --Title
	{
		area 30 20 594 124
		text  20274
		text style	"label"
	}
	button
	{
		area		222 170 230 44
		bam		GUIBUTMT
		sequence	0
		text  		"CANCEL_BUTTON"
		text style	"button"
		on		escape
		action
		"
			Infinity_PopMenu();
		"	
	}
}
menu
{
	name 'CONNECTION_ERROR'
	modal
	align center center

	label
	{
		area 0 0 657 234
		mosaic GUIERR6 
	}
	label --Title
	{
		area 30 20 600 64
		text lua "Infinity_FetchString(CONNECTION_ERROR_MESSAGE)"
		text style	"label"
	}
	button
	{
		area		222 170 230 44
		bam		GUIBUTMT
		sequence	0
		text  		"CANCEL_BUTTON"
		text style	"button"
		on		escape
		action
		"
			Infinity_PopMenu();
		"	
	}
}
menu
{
	name 'CONNECTION_WAITING_FOR_PROVIDER'
	modal
	align center center

	label
	{
		area 0 0 657 234
		mosaic GUIERR6 
	}
	label --Title
	{
		area 30 20 600 64
		text "CONNECTION_FINDING_DEVICES"
		text style	"label"
	}
}
menu
{
	name 'CONNECTION_WAITING_FOR_SERVER'
	modal
	align center center

	label
	{
		area 0 0 657 234
		mosaic GUIERR6 
	}
	label --Title
	{
		area 30 20 600 122
		text "CONNECTION_WAITING_FOR_SERVER"
		text style	"label"
	}
	button
	{
		area		216 166 202 44
		bam			GUIBUTNT
		sequence	0
		text  		"CANCEL_BUTTON"
		text style	"button"
		on		escape
		action
		"
			Infinity_PopMenu('CONNECTION_WAITING_FOR_SERVER')
			connectionScreen:CancelJoinGame();
		"	
	}
}
`
function getCampaignBackground()
	local campaign = startEngine:GetCampaign()
	return startCampaignData[campaign].background
end
function getBackgroundSize()
	local screenWidth, screenHeight = Infinity_GetScreenSize()
	Infinity_SetArea('RGDBACK1', nil, nil, screenWidth, screenHeight)
	Infinity_SetArea('RGDBACK2', nil, nil, screenWidth, screenHeight)
	Infinity_SetArea('RGDBACK3', nil, nil, screenWidth, screenHeight)
end
`
menu
{
	name 'BACKGROUND'
	align top left
	onOpen "
	Infinity_PlayMovie('RGDBACK1','RGDBACK1')
	Infinity_PlayMovie('RGDBACK2','RGDBACK2')
	Infinity_PlayMovie('RGDBACK3','RGDBACK3')
	getBackgroundSize()
	"
	movie
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 0"
		name "RGDBACK1"
		area 0 0 1366 768
                mosaic 'bg2back'
	}
	movie
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 1"
		name "RGDBACK2"
		area 0 0 1366 768
                mosaic 'tobback'
	}
	movie
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BP"
		name "RGDBACK3"
		area 0 0 1366 768
	}
	label
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 0"
		area 0 0 10000 8000
		mosaic "RGBACK1"
	}
	label
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BG and isTob == 1"
		area 0 0 10000 8000
		mosaic "RGBACK2"
	}
	label
	{
		enabled "startEngine:GetCampaign() == const.START_CAMPAIGN_BP"
		area 0 0 10000 8000
		mosaic "RGBACK3"
	}
}
`
multiplayer = {}
mpChatEdit = ""
mpHelpTextString = ""
mpModifyingCharacter = -1
mpErrorText = -1
mpErrorState = -1
text_GUIMP_0_25 = ""
text_GUIMP_0_25_lines = 0
multiplayerInPermission = false
multiplayerInPermissionForPlayer = 0

multiplayerSessionName = ""
multiplayerSaveName = ""
multiplayerLocationName = ""
multiplayerTimePlayed = ""
multiplayerDifficultyLabel = ""
multiplayerDifficultyImage = 0
mulitplayerPreexistingDifficulty = 0;

multiplayerLocalPlayerID = 1

multiplayerFromInGame = false

mpaCharacters = 
{
	{ready = false, name = "", class = "", player = 1, portrait = "NOPORTLS", inprogress = false, color = "0xffffff"},
	{ready = false, name = "", class = "", player = 1, portrait = "NOPORTLS", inprogress = false, color = "0xffffff"},
	{ready = false, name = "", class = "", player = 1, portrait = "NOPORTLS", inprogress = false, color = "0xffffff"},
	{ready = false, name = "", class = "", player = 1, portrait = "NOPORTLS", inprogress = false, color = "0xffffff"},
	{ready = false, name = "", class = "", player = 1, portrait = "NOPORTLS", inprogress = false, color = "0xffffff"},
	{ready = false, name = "", class = "", player = 1, portrait = "NOPORTLS", inprogress = false, color = "0xffffff"}
}

mpaPlayers =
{
	{name = "", id = 0, color = "0xfff600"},
	{name = "", id = 0, color = "0xff0000"},
	{name = "", id = 0, color = "0x000cff"},
	{name = "", id = 0, color = "0x1eff00"},
	{name = "", id = 0, color = "0x00fcff"},
	{name = "", id = 0, color = "0xff00f6"}
}

function updateMultiplayerPlayerSlot(slot,setting,value)
	if multiplayerLocalPlayerID == 1 and setting == "name" and mpaPlayers[slot][setting] == "" and value ~= "" then
		mpaPlayers[slot][setting] = value
		broadcastPlayerAdded(slot)
	elseif multiplayerLocalPlayerID == 1 and setting == "name" and mpaPlayers[slot][setting] ~= "" and value == "" then
		broadcastPlayerRemoved(slot)
		mpaPlayers[slot][setting] = value
	else
		mpaPlayers[slot][setting] = value
	end
end
function updateMultiplayerCharacterSlot(slot,setting,value)
	if multiplayerLocalPlayerID == 1 and setting == "color" and mpaCharacters[slot][setting] == "0xffffff" and value ~= "0xffffff" then
		mpaCharacters[slot][setting] = value
		broadcastCharacterAdded(slot)
	elseif multiplayerLocalPlayerID == 1 and setting == "ready" and mpaCharacters[slot][setting] == false and value == true then
		broadcastCharacterReady(slot)
		mpaCharacters[slot][setting] = value
	elseif multiplayerLocalPlayerID == 1 and setting == "ready" and mpaCharacters[slot][setting] == true and value == false then
		broadcastCharacterNotReady(slot)
		mpaCharacters[slot][setting] = value
	else
		mpaCharacters[slot][setting] = value
	end
end

function clearCharacterSlot(slot, announce)
	if announce == true and mpaCharacters[slot]['name'] ~= "" then
		broadcastCharacterRemoved(slot)
	end
	mpaCharacters[slot]['ready'] = false
	mpaCharacters[slot]['name'] = ""
	mpaCharacters[slot]['class'] = ""
	mpaCharacters[slot]['portrait'] = "NOPORTLS"
	mpaCharacters[slot]['inprogress'] = false
	mpaCharacters[slot]['color'] = "0xffffff"
end

function clearPlayerSlot(slot, announce)
	if announce == true and mpaPlayers[slot]["name"] ~= "" then
		broadcastPlayerRemoved(slot)
	end
	mpaPlayers[slot]["name"] = ""
	mpaPlayers[slot]["id"] = 0
end

function getMultiplayerCharacterName(slot, newLine, getClass)
	local ret = ""
	local separator = ", "

	if newLine == true then
		separator = "\n"
	end

	if mpaCharacters[slot]["name"] == "" and multiplayerLocalPlayerID == mpaCharacters[slot]["player"] then
		ret = t("MULTIPLAYER_CREATE_CHARACTER_MESSAGE")
	elseif mpaCharacters[slot]["name"] == "" and multiplayerLocalPlayerID ~= mpaCharacters[slot]["player"] and mpaCharacters[slot]["inprogress"] == false then
		ret = t("MULTIPLAYER_EMPTY_CHARACTER_MESSAGE")
	elseif mpaCharacters[slot]["inprogress"] == true and mpaCharacters[slot]["class"] == "" then
		setStringTokenLua("<PLAYER_NAME_1>",getMultiplayerPlayerName(mpaCharacters[slot]["player"], false, true))
		setStringTokenLua("<SEPERATOR>",separator)
		ret = t("MULTIPLAYER_CREATING_CHARACTER_MESSAGE")
		removeStringTokenLua("<SEPERATOR>")
		removeStringTokenLua("<PLAYER_NAME_1>")
	elseif mpaCharacters[slot]["name"] ~= "" and mpaCharacters[slot]["class"] ~= "" then
		ret = "^0xff"..mpaCharacters[slot]["color"]..mpaCharacters[slot]["name"].."^-"
		if getClass == true then
			ret = ret..separator..mpaCharacters[slot]["class"]
		end
	end

	return ret
end
function getMultiplayerCharacterButtonText(slot)
	local ret = ""

	if mpaCharacters[slot]["name"] == "" and multiplayerLocalPlayerID == mpaCharacters[slot]["player"] then
		ret = t("CREATE_CHAR_BUTTON")
	elseif mpaCharacters[slot]["name"] == "" and multiplayerLocalPlayerID ~= mpaCharacters[slot]["player"] then
		ret = ""
	elseif mpaCharacters[slot]["name"] ~= "" and mpaCharacters[slot]["class"] == "" then
		ret = ""
	elseif mpaCharacters[slot]["name"] ~= "" and mpaCharacters[slot]["class"] ~= "" and mpaCharacters[slot]["player"] ~= multiplayerLocalPlayerID then
		ret = t("MULTIPLAYER_VIEW_DETAILS_BUTTON")
	elseif mpaCharacters[slot]["name"] ~= "" and mpaCharacters[slot]["class"] ~= "" and mpaCharacters[slot]["player"] == multiplayerLocalPlayerID and multiplayer.allowreformparty == false and multiplayerDifficultyLabel ~= "" then
		ret = t("MULTIPLAYER_VIEW_DETAILS_BUTTON")
	elseif mpaCharacters[slot]["name"] ~= "" and mpaCharacters[slot]["class"] ~= "" and mpaCharacters[slot]["player"] == multiplayerLocalPlayerID then
		ret = t("MULTIPLAYER_EDIT_CHAR_BUTTON")
	end

	return ret
end
function getMultiplayerCharacterReadyText(slot)
	local ret = ""

	if mpaCharacters[slot]["name"] == "" and mpaCharacters[slot]["inprogress"] == false then
		ret = ""
	elseif mpaCharacters[slot]["ready"] == false then
		ret = t("MULTIPLAYER_NOT_READY_MESSAGE")
	elseif mpaCharacters[slot]["ready"] == true then
		ret = t("MULTIPLAYER_READY_MESSAGE")
	end

	return ret
end
function getMultiplayerPlayerName(slot,newLine,hostyou)
	local ret = mpaPlayers[slot]["name"]
	if ret ~= "" then
		ret = "^0x"..mpaPlayers[slot]["color"]..mpaPlayers[slot]["name"].."^-"
	end

	local separator = " "
	if newLine == true then
		separator = "\n"
	end

	if hostyou == true then
		if slot == multiplayerLocalPlayerID then
			ret = ret..separator.."^0xFFFFFFFF"..t("MULTIPLAYER_PLAYER_YOU").."^-"
		elseif slot == 1 then
			ret = ret..separator.."^0xFFFFFFFF"..t("MULTIPLAYER_PLAYER_HOST").."^-"
		elseif ret == "" then
			ret = "^0xFF9B9B9B"..t("MULTIPLAYER_EMPTY_PLAYER").."^-"
		end
	end

	return ret
end
function getMultiplayerPlayerControlledCharacter(player,slot)
	local count = 0
	local ret = "NOCTRL" -- need blank square or something

	local index = 1
	for index = 1, 6, 1 do
		if mpaCharacters[index]["player"] == player then
			count = count + 1
		end

		if currentMultiplayerSelectPlayer == player and mpDraggedCharacter == index then
			slot = slot + 1
		end

		if count == slot then
			ret = mpaCharacters[index]["portrait"]
			break
		end
	end

	return ret
end
function getMultiplayerPlayerControlledCharacterSlot(player,slot)
	local count = 0
	local ret = -1

	local index = 1
	for index = 1, 6, 1 do
		if mpaCharacters[index]["player"] == player then
			count = count + 1
		end

		if count == slot then
			ret = index
			break
		end
	end

	return ret
end

function getPlayerKickWidth(slot)
	if multiplayerLocalPlayerID ~= 1 or slot == 1 then
		return 0
	else
		return 10
	end
end

function getPlayerNameWidth(slot)
	if multiplayerLocalPlayerID ~= 1 or slot == 1 then
		return 45
	else
		return 35
	end
end

function getStartGameButtonTooltip()
	if multiplayer.donebuttonclickable then
		return ""
	else
		return t("MULTIPLAYER_CANNOT_START")
	end
end

function updateMultiplayerSessionData(sessionName, saveName, areaName, timePlayed, difficulty)
	local gold = "^0xffc7f8fb"
	multiplayerSessionName = gold..sessionName.."^-"

	if areaName ~= "" then
		multiplayerSaveName = gold..t("MULTIPLAYER_SAVED_GAME_LABEL").."^- ^0xffffffff"..saveName.."^-"
		multiplayerLocationName = gold..t("MULTIPLAYER_LOCATION_LABEL").."^- ^0xffffffff"..areaName.."^-"
		multiplayerTimePlayed = gold..t("MULTIPLAYER_TIME_PLAYED_LABEL").."^- ^0xffffffff"..timePlayed.."^-"
		if difficulty > 0 then
			mulitplayerPreexistingDifficulty = difficulty
			multiplayerDifficultyLabel = gold..t("MULTIPLAYER_DIFFICULTY_LABEL").."^-^0xffffffff"..t(difficulties[difficulty].name).."^-"
			multiplayerDifficultyImage = difficulty - 1
		end
	else
		multiplayerSaveName = gold..t("MULTIPLAYER_NEW_GAME_LABEL").."^- ^0xffffffff"..saveName.."^-"
		multiplayerLocationName = gold..t("MULTIPLAYER_LOCATION_NEW_GAME").."^-"
		multiplayerTimePlayed = gold..t("MULTIPLAYER_TIME_PLAYED_NEW_GAME").."^-"
		if difficulty > 0 then
			multiplayerDifficultyLabel = gold..t("MULTIPLAYER_DIFFICULTY_LABEL").."^-^0xffffffff"..t(difficulties[difficulty].name).."^-"
			multiplayerDifficultyImage = difficulty - 1
		end
	end
end

function broadcastCharacterControlChange(slot, newPlayer)
	print("newPlayer "..newPlayer.." current "..currentMultiplayerSelectPlayer.." playernumber "..mpaCharacters[slot]["player"])
	if mpaCharacters[slot]["player"] ~= newPlayer then
		local host = getMultiplayerPlayerName(1,false,false)
		local player = getMultiplayerPlayerName(newPlayer,false,false)
		setStringTokenLua("<PLAYER_NAME_1>",host)
		setStringTokenLua("<PLAYER_NAME_2>",player)
		local message = t("MULTIPLAYER_SLOT_"..slot.."_ASSIGNED_TO")
		removeStringTokenLua("<PLAYER_NAME_1>")
		removeStringTokenLua("<PLAYER_NAME_2>")
		print(message)
		Infinity_SendChatMessage(message, true) 
	end
end

function broadcastCharacterAdded(slot)
	local player = getMultiplayerPlayerName(mpaCharacters[slot]["player"],false,false)
	local character = getMultiplayerCharacterName(slot, false, true)
	setStringTokenLua("<PLAYER_NAME_1>",player)
	setStringTokenLua("<CHARACTER_NAME_1>",character)
	local message = t("MULTIPLAYER_HAS_ADDED")
	removeStringTokenLua("<PLAYER_NAME_1>")
	removeStringTokenLua("<CHARACTER_NAME_1>")
	print(message)
	Infinity_SendChatMessage(message, true) 
end

function broadcastCharacterRemoved(slot)
	local player = getMultiplayerPlayerName(mpaCharacters[slot]["player"],false,false)
	local character = getMultiplayerCharacterName(slot, false, true)
	setStringTokenLua("<PLAYER_NAME_1>",player)
	setStringTokenLua("<CHARACTER_NAME_1>",character)
	local message = t("MULTIPLAYER_HAS_REMOVED")
	removeStringTokenLua("<PLAYER_NAME_1>")
	removeStringTokenLua("<CHARACTER_NAME_1>")
	print(message)
	Infinity_SendChatMessage(message, true) 
end

function broadcastCharacterReady(slot)
	local character = getMultiplayerCharacterName(slot, false, false)
	setStringTokenLua("<CHARACTER_NAME_1>",character)
	local message = t("MULTIPLAYER_IS_READY_TO_START")
	removeStringTokenLua("<CHARACTER_NAME_1>")
	print(message)
	Infinity_SendChatMessage(message, true) 
end

function broadcastCharacterNotReady(slot)
	local character = getMultiplayerCharacterName(slot, false, false)
	setStringTokenLua("<CHARACTER_NAME_1>",character)
	local message = t("MULTIPLAYER_IS_NO_LONGER_READY")
	removeStringTokenLua("<CHARACTER_NAME_1>")
	print(message)
	Infinity_SendChatMessage(message, true) 
end

function broadcastPlayerAdded(slot)
	local player = getMultiplayerPlayerName(slot,false,false)
	setStringTokenLua("<PLAYER_NAME_1>",player)
	local message = t("MULTIPLAYER_HAS_JOINED_THE_GAME")
	removeStringTokenLua("<PLAYER_NAME_1>")
	print(message)
	Infinity_SendChatMessage(message, true) 
end

function broadcastPlayerRemoved(slot)
	local player = getMultiplayerPlayerName(slot,false,false)
	setStringTokenLua("<PLAYER_NAME_1>",player)
	local message = t("MULTIPLAYER_HAS_LEFT_THE_GAME")
	removeStringTokenLua("<PLAYER_NAME_1>")
	print(message)
	Infinity_SendChatMessage(message, true) 
end

mpDraggedCharacter = nil
mpDraggedPortrait = 'NOCTRL'

function multiplayerStartSwapPortraits(player, character)
	if multiplayerLocalPlayerID == 1 and player > 0 and player < 7 and mpaPlayers[player]["name"] ~= "" then
		print("Starting the drag of player "..player.." character slot "..character)
		mpDraggedCharacter = character
		multiplayerScreen:SetModifiedCharacterSlot(character - 1)
		currentMultiplayerSelectPlayer = player
		mpDraggedPortrait = mpaCharacters[character]["portrait"]
	end
end

function multiplayerStopSwapPortraits(player)
	if multiplayerLocalPlayerID == 1 then
		if player > 0 and player < 7 and mpaPlayers[player]["name"] ~= "" and currentMultiplayerSelectPlayer ~= nil then
			broadcastCharacterControlChange(mpDraggedCharacter, player)
			multiplayerScreen:OnPlayerSelection(player-1)
		end
		mpDraggedCharacter = nil
		currentMultiplayerSelectPlayer = nil
		mpDraggedPortrait = 'NOCTRL'
	end
end

function getMultiplayerReadyTooltip(character)
	local ret = ""

	if mpaCharacters[character]["ready"] == true then
		ret = t("MULTIPLAYER_READY_BUTTON_ON_TOOLTIP")
	else
		ret = t("MULTIPLAYER_READY_BUTTON_OFF_TOOLTIP")
	end

	return ret
end

function multiplayerUpdateDraggedPortrait()
	if mpDraggedPortrait ~= 'NOCTRL' and multiplayerLocalPlayerID == 1 then
		local x,y,w,h = Infinity_GetArea('multiplayerDraggingPortraitImage')
		x,y = Infinity_GetMousePosition();
		x = x - 20
		y = y - 30
		Infinity_SetArea('multiplayerDraggingPortraitImage',x,y,w,h)
		return true
	else
		local x,y,w,h = Infinity_GetArea('multiplayerDraggingPortraitImage')
		Infinity_SetArea('multiplayerDraggingPortraitImage',-20,-20,w,h)
		return false
	end
end

function get4CheckFrame(slot)
	local ret = 1

	if mpaCharacters[slot]['ready'] == true and mpaCharacters[slot]['player'] == multiplayerLocalPlayerID then
		ret = 0
	elseif mpaCharacters[slot]['ready'] == true then
		ret = 2
	end

	return ret
end

`
menu
{
	name 'MULTIPLAYER'
	align center center
	ignoreesc
	onOpen
	"
		existingDifficulty = Infinity_GetOption(12, 8) + 1;
		multiplayerFromInGame = multiplayerScreen:GetEngineState() == 2
	"
	label 
	{
		mosaic 'GUISMBM'
		area 0 0 1024 768
	}
	label
	{
		area 162 16 700 44
		text "ARBITRATION_TITLE"
		text style "title"
	}

	label
	{
		area 514 70 492 618
		fill 0 0 0 255
	}
	label
	{
		area 504 60 512 638
		rectangle 3
	}

	label
	{
		area 524 112 471 93
		fill 100 25 25 180
	}
	label
	{
		area 524 207 471 93
		fill 50 50 50 180
	}
	label
	{
		area 524 302 471 93
		fill 100 25 25 180
	}
	label
	{
		area 524 397 471 93
		fill 50 50 50 180
	}
	label
	{
		area 524 492 471 93
		fill 100 25 25 180
	}
	label
	{
		area 524 587 471 93
		fill 50 50 50 180
	}

	label
	{
		area 524 80 136 22
		text lua "t('PLAYER_LABEL')"
		text style "label"
		align center center
	}
	label
	{
		area 660 80 228 22
		text lua "t('CHARACTER_LABEL')"
		text style "label"
		align center center
	}
	label
	{
		area 888 80 107 22
		text lua "t('READY_TO_PLAY_LABEL')"
		text style "label"
		align center center
	}
	list -- character list
	{
		column --player
		{ 
			width 32 
			label
			{
				area 		6 5 140 44
				text lua	"getMultiplayerPlayerName(mpaCharacters[rowNumber]['player'],true,true)"
				text style 	"label"
				enabled 	"multiplayerLocalPlayerID == 1 and rowNumber ~= 1"
			}
			label
			{
				area 		6 0 140 95
				text lua	"getMultiplayerPlayerName(mpaCharacters[rowNumber]['player'],true,true)"
				text style 	"label"
				enabled 	"multiplayerLocalPlayerID ~= 1 or rowNumber == 1"
			}
			label
			{
				area		6 55 140 31
				bam 		'GUIBUTNS'
				sequence 	1
				frame lua 	"currentCellCheck(1)"
				align 		center center
				enabled 	"multiplayerLocalPlayerID == 1 and rowNumber ~= 1"
				text lua	"t('MULTIPLAYER_CHANGE_PLAYER_BUTTON')"
				text style 	"button"
			}

		}
		column --portrait
		{
			width 15
			label
			{
				area		0 0 -1 -1
				bam 		'GUIRSP10'
				sequence 	1
				align 		center center
			}
			label
			{
				area		6 5 56 85
				bitmap lua	'mpaCharacters[rowNumber]["portrait"]'
				sequence 	1
				align 		center center
			}
		}
		column --character
		{ 
			width 45
			label
			{
				area 		2 0 195 44
				text lua 	"getMultiplayerCharacterName(rowNumber, true, true)"
				text style 	"label"
				enabled 	"getMultiplayerCharacterButtonText(rowNumber) ~= ''"
			}
			label
			{
				area 		2 0 195 95
				text lua 	"getMultiplayerCharacterName(rowNumber, true, true)"
				text style 	"label"
				enabled 	"getMultiplayerCharacterButtonText(rowNumber) == ''"
			}
			label
			{
				area		2 50 195 44
				bam 		'GUIBUTNT'
				sequence 	1
				frame lua 	"currentCellCheck(3)"
				align 		center center
				enabled 	"getMultiplayerCharacterButtonText(rowNumber) ~= ''"
			}
			label
			{
				area		2 50 195 44
				text lua 	"getMultiplayerCharacterButtonText(rowNumber)"
				text style 	"button"
			}

		}
		column --ready
		{ 
			width 13
			label
			{
				area 		0 50 50 44
				text lua	"getMultiplayerCharacterReadyText(rowNumber)"
				text style 	"label"
			}

		}

		area 				520 112 475 570
		
		rowheight			95
		table				"mpaCharacters"
		var					selectedCharacter
		scrollbar			'GUISCRC'
		hidehighlight
		action
		"
			if cellNumber == 1 then
				cellNumber = nil
				if multiplayerLocalPlayerID == 1 and selectedCharacter ~= 1 then
					if multiplayerFromInGame == false then
						multiplayerScreen:SetModifiedCharacterSlot(selectedCharacter - 1)
						currentMultiplayerSelectPlayer = mpaCharacters[selectedCharacter]['player']
						Infinity_PushMenu('MP_PICKPLAYER')
					elseif multiplayerLocalPlayerID == 1 or multiplayer.player[multiplayerLocalPlayerID].permissions[1] == true then
						multiplayerScreen:OnModifyButtonClick()
					end
				end
			elseif cellNumber == 2 then
				cellNumber = nil
			elseif cellNumber == 3 then
				cellNumber = nil
				print(getMultiplayerCharacterButtonText(selectedCharacter))
				if getMultiplayerCharacterButtonText(selectedCharacter) == t('MULTIPLAYER_VIEW_DETAILS_BUTTON') then
					print('1')
					multiplayerScreen:OnPortraitButtonClick(selectedCharacter-1)
				elseif getMultiplayerCharacterButtonText(selectedCharacter) == t('CREATE_CHAR_BUTTON') then
					print('2')
					if multiplayerFromInGame == false then
					print('2a')
						multiplayerScreen:SetModifiedCharacterSlot(selectedCharacter-1)
						multiplayerScreen:UpdateModifyCharacterPanel()
					elseif multiplayerLocalPlayerID == 1 or multiplayer.player[multiplayerLocalPlayerID].permissions[1] == true then
					print('2b')
						multiplayerScreen:OnModifyButtonClick()
					end
				elseif getMultiplayerCharacterButtonText(selectedCharacter) == t('MULTIPLAYER_EDIT_CHAR_BUTTON') then
					print('3')
					if multiplayerFromInGame == false then
						mpModifyingCharacter = selectedCharacter - 1
						Infinity_PushMenu('MP_MODIFYCHARACTER')
					elseif multiplayerLocalPlayerID == 1 or multiplayer.player[multiplayerLocalPlayerID].permissions[1] == true then
						multiplayerScreen:OnModifyButtonClick()
					end
				end
			elseif cellNumber == 4 then
				cellNumber = nil
			end
		"
	}

	--ready buttons
	button
	{
		area 942 112 50 50
		bam 		'4CHECK'
		sequence lua "get4CheckFrame(1)"
		align 		center center
		tooltip lua "getMultiplayerReadyTooltip(1)"
		action
		"
			if multiplayerFromInGame == false then
				if multiplayerLocalPlayerID == mpaCharacters[1]['player'] then
					multiplayerScreen:OnReadyButtonClick(1-1)
				end
			end
		"
	}
	button
	{
		area 942 207 50 50
		bam 		'4CHECK'
		sequence lua "get4CheckFrame(2)"
		align 		center center
		action
		"
			if multiplayerFromInGame == false then
				if multiplayerLocalPlayerID == mpaCharacters[2]['player'] then
					multiplayerScreen:OnReadyButtonClick(2-1)
				end
			end
		"
	}
	button
	{
		area 942 304 50 50
		bam 		'4CHECK'
		sequence lua "get4CheckFrame(3)"
		align 		center center
		action
		"
			if multiplayerFromInGame == false then
				if multiplayerLocalPlayerID == mpaCharacters[3]['player'] then
					multiplayerScreen:OnReadyButtonClick(3-1)
				end
			end
		"
	}
	button
	{
		area 942 397 50 50
		bam 		'4CHECK'
		sequence lua "get4CheckFrame(4)"
		align 		center center
		action
		"
			if multiplayerFromInGame == false then
				if multiplayerLocalPlayerID == mpaCharacters[4]['player'] then
					multiplayerScreen:OnReadyButtonClick(4-1)
				end
			end
		"
	}
	button
	{
		area 942 492 50 50
		bam 		'4CHECK'
		sequence lua "get4CheckFrame(5)"
		align 		center center
		action
		"
			if multiplayerFromInGame == false then
				if multiplayerLocalPlayerID == mpaCharacters[5]['player'] then
					multiplayerScreen:OnReadyButtonClick(5-1)
				end
			end
		"
	}
	button
	{
		area 942 587 50 50
		bam 		'4CHECK'
		sequence lua "get4CheckFrame(6)"
		align 		center center
		action
		"
			if multiplayerFromInGame == false then
				if multiplayerLocalPlayerID == mpaCharacters[6]['player'] then
					multiplayerScreen:OnReadyButtonClick(6-1)
				end
			end
		"
	}

	label
	{
		area 40 308 454 25
		fill 125 125 125 180
	}
	label
	{
		area 40 343 454 47
		fill 50 50 50 180
	}
	label
	{
		area 40 394 454 47
		fill 50 50 50 180
	}
	label
	{
		area 40 445 454 47
		fill 50 50 50 180
	}
	label
	{
		area 40 496 454 47
		fill 50 50 50 180
	}
	label
	{
		area 40 547 454 47
		fill 50 50 50 180
	}
	label
	{
		area 40 598 454 47
		fill 50 50 50 180
	}
	label
	{
		area 40 308 207 25
		text lua "t('PLAYERS_LABEL')"
		text style "label"
		align center center
	}
	label
	{
		area 247 308 187 25
		text lua "t('PARTY_SLOTS_LABEL')"
		text style "label"
		align center center
	}
	label
	{
		area 434 308 60 25
		text lua "t('RULES_LABEL')"
		text style "label"
		align center center
	}
	list -- player list
	{
		column -- kick
		{
			width lua "getPlayerKickWidth(rowNumber)"
			label
			{
				area		6 5 45 45
			}
		}
		column --player
		{ 
			width lua "getPlayerNameWidth(rowNumber)"
			label
			{
				area 		0 0 195 55
				text lua	"getMultiplayerPlayerName(rowNumber, false, true)"
				text style 	"label"
				align 		left center
				enabled 	"getPlayerKickWidth(rowNumber) == 0"
			}
			label
			{
				area 		0 0 150 55
				text lua	"getMultiplayerPlayerName(rowNumber, false, true)"
				text style 	"label"
				align 		left center
				enabled 	"getPlayerKickWidth(rowNumber) ~= 0"
			}

		}
		column --portraits
		{ 
			width 45 
			label
			{
				area		6 5 25 38
			}
		}
		column -- permissions
		{
			width 10
			label
			{
				area		6 5 45 45
			}
		}

		area 				52 339 442 306
		
		rowheight			51
		table				"mpaPlayers"
		var					selectedPlayer
		scrollbar			'GUISCRC'
		hidehighlight
		action
		"
			if cellNumber == 1 and selectedPlayer > 1 then
				cellNumber = 0
			elseif cellNumber == 2 then
				cellNumber = 0
			elseif cellNumber == 3 then
				cellNumber = 0
			elseif cellNumber == 4 and selectedPlayer > 1  then
				cellNumber = 0
			end
		"
	}

	--kick
	button
	{
		area		40 395 46 45
		bam 			GUMPBUTX
		sequence 		4
		clickable lua	"mpaPlayers[2]['name'] ~= ''"
		align 		center center
		enabled 	"multiplayerLocalPlayerID == 1"
		tooltip lua	"t('MULTIPALYER_KICK_TOOLTIP')"
		action
		"
			if mpaPlayers[2]['name'] ~= '' then
				multiplayerScreen:OnKickPlayerButtonClick(2-1)
			end
		"
	}
	button
	{
		area		40 446 46 45
		bam 			GUMPBUTX
		sequence 		4
		clickable lua	"mpaPlayers[3]['name'] ~= ''"
		align 		center center
		enabled 	"multiplayerLocalPlayerID == 1"
		tooltip lua	"t('MULTIPALYER_KICK_TOOLTIP')"
		action
		"
			if mpaPlayers[3]['name'] ~= '' then
				multiplayerScreen:OnKickPlayerButtonClick(3-1)
			end
		"
	}
	button
	{
		area		40 497 46 45
		bam 			GUMPBUTX
		sequence 		4
		clickable lua	"mpaPlayers[4]['name'] ~= ''"
		align 		center center
		enabled 	"multiplayerLocalPlayerID == 1"
		tooltip lua	"t('MULTIPALYER_KICK_TOOLTIP')"
		action
		"
			if mpaPlayers[4]['name'] ~= '' then
				multiplayerScreen:OnKickPlayerButtonClick(4-1)
			end
		"
	}
	button
	{
		area		40 548 46 45
		bam 			GUMPBUTX
		sequence 		4
		clickable lua	"mpaPlayers[5]['name'] ~= ''"
		align 		center center
		enabled 	"multiplayerLocalPlayerID == 1"
		tooltip lua	"t('MULTIPALYER_KICK_TOOLTIP')"
		action
		"
			if mpaPlayers[5]['name'] ~= '' then
				multiplayerScreen:OnKickPlayerButtonClick(5-1)
			end
		"
	}
	button
	{
		area		40 599 46 45
		bam 			GUMPBUTX
		sequence 		4
		clickable lua	"mpaPlayers[6]['name'] ~= ''"
		align 		center center
		enabled 	"multiplayerLocalPlayerID == 1"
		tooltip lua	"t('MULTIPALYER_KICK_TOOLTIP')"
		action
		"
			if mpaPlayers[6]['name'] ~= '' then
				multiplayerScreen:OnKickPlayerButtonClick(6-1)
			end
		"
	}

	--permissions
	button
	{
		area		446 395 46 45
		bam 			GUMPBUTX
		sequence 		3
		clickable lua	"mpaPlayers[2]['name'] ~= ''"
		align 		center center
		tooltip lua	"t('MULTIPALYER_PERMISSION_TOOLTIP')"
		action
		"
			if mpaPlayers[2]['name'] ~= '' then
				multiplayerInPermission = true
				multiplayerInPermissionForPlayer = 2
				Infinity_PushMenu('MP_PERMISSIONS')
			end
		"
	}
	button
	{
		area		446 446 46 45
		bam 			GUMPBUTX
		sequence 		3
		clickable lua	"mpaPlayers[3]['name'] ~= ''"
		align 		center center
		tooltip lua	"t('MULTIPALYER_PERMISSION_TOOLTIP')"
		action
		"
			if mpaPlayers[3]['name'] ~= '' then
				multiplayerInPermission = true
				multiplayerInPermissionForPlayer = 3
				Infinity_PushMenu('MP_PERMISSIONS')
			end
		"
	}
	button
	{
		area		446 497 46 45
		bam 			GUMPBUTX
		sequence 		3
		clickable lua	"mpaPlayers[4]['name'] ~= ''"
		align 		center center
		tooltip lua	"t('MULTIPALYER_PERMISSION_TOOLTIP')"
		action
		"
			if mpaPlayers[4]['name'] ~= '' then
				multiplayerInPermission = true
				multiplayerInPermissionForPlayer = 4
				Infinity_PushMenu('MP_PERMISSIONS')
			end
		"
	}
	button
	{
		area		446 548 46 45
		bam 			GUMPBUTX
		sequence 		3
		clickable lua	"mpaPlayers[5]['name'] ~= ''"
		align 		center center
		tooltip lua	"t('MULTIPALYER_PERMISSION_TOOLTIP')"
		action
		"
			if mpaPlayers[5]['name'] ~= '' then
				multiplayerInPermission = true
				multiplayerInPermissionForPlayer = 5
				Infinity_PushMenu('MP_PERMISSIONS')
			end
		"
	}
	button
	{
		area		446 599 46 45
		bam 			GUMPBUTX
		sequence 		3
		clickable lua	"mpaPlayers[6]['name'] ~= ''"
		align 		center center
		tooltip lua	"t('MULTIPALYER_PERMISSION_TOOLTIP')"
		action
		"
			if mpaPlayers[6]['name'] ~= '' then
				multiplayerInPermission = true
				multiplayerInPermissionForPlayer = 6
				Infinity_PushMenu('MP_PERMISSIONS')
			end
		"
	}

	--character drag/drop
	--player 1
	button
	{
		area 247 348 180 38
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(1)
		"
	}
	button
	{
		area 				247 348 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(1,1)'
		sequence 			1
		align 				center center
		--No changing control of character 1
	}
	button
	{
		area 				278 348 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(1,2)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(1,2)
			multiplayerStartSwapPortraits(1,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(1)
		"
	}
	button
	{
		area 				309 348 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(1,3)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(1,3)
			multiplayerStartSwapPortraits(1,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(1)
		"
	}
	button
	{
		area 				340 348 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(1,4)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(1,4)
			multiplayerStartSwapPortraits(1,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(1)
		"
	}
	button
	{
		area 				371 348 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(1,5)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(1,5)
			multiplayerStartSwapPortraits(1,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(1)
		"
	}
	button
	{
		area 				402 348 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(1,6)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(1,6)
			multiplayerStartSwapPortraits(1,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(1)
		"
	}
	--player 2
	button
	{
		area 247 399 180 38
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(2)
		"
	}
	button
	{
		area 				247 399 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(2,1)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(2,1)
			multiplayerStartSwapPortraits(2,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(2)
		"
	}
	button
	{
		area 				278 399 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(2,2)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(2,2)
			multiplayerStartSwapPortraits(2,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(2)
		"
	}
	button
	{
		area 				309 399 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(2,3)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(2,3)
			multiplayerStartSwapPortraits(2,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(2)
		"
	}
	button
	{
		area 				340 399 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(2,4)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(2,4)
			multiplayerStartSwapPortraits(2,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(2)
		"
	}
	button
	{
		area 				371 399 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(2,5)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(2,5)
			multiplayerStartSwapPortraits(2,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(2)
		"
	}
	button
	{
		area 				402 399 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(2,6)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(2,6)
			multiplayerStartSwapPortraits(2,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(2)
		"
	}
	--player 3
	button
	{
		area 247 449 180 38
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(3)
		"
	}
	button
	{
		area 				247 449 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(3,1)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(3,1)
			multiplayerStartSwapPortraits(3,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(3)
		"
	}
	button
	{
		area 				278 449 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(3,2)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(3,2)
			multiplayerStartSwapPortraits(3,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(3)
		"
	}
	button
	{
		area 				309 449 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(3,3)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(3,3)
			multiplayerStartSwapPortraits(3,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(3)
		"
	}
	button
	{
		area 				340 449 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(3,4)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(3,4)
			multiplayerStartSwapPortraits(3,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(3)
		"
	}
	button
	{
		area 				371 449 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(3,5)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(3,5)
			multiplayerStartSwapPortraits(3,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(3)
		"
	}
	button
	{
		area 				402 449 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(3,6)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(3,6)
			multiplayerStartSwapPortraits(3,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(3)
		"
	}
	--player 4
	button
	{
		area 247 500 180 38
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(4)
		"
	}
	button
	{
		area 				247 500 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(4,1)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(4,1)
			multiplayerStartSwapPortraits(4,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(4)
		"
	}
	button
	{
		area 				278 500 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(4,2)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(4,2)
			multiplayerStartSwapPortraits(4,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(4)
		"
	}
	button
	{
		area 				309 500 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(4,3)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(4,3)
			multiplayerStartSwapPortraits(4,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(4)
		"
	}
	button
	{
		area 				340 500 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(4,4)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(4,4)
			multiplayerStartSwapPortraits(4,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(4)
		"
	}
	button
	{
		area 				371 500 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(4,5)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(4,5)
			multiplayerStartSwapPortraits(4,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(4)
		"
	}
	button
	{
		area 				402 500 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(4,6)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(4,6)
			multiplayerStartSwapPortraits(4,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(4)
		"
	}
	--player 5
	button
	{
		area 247 551 180 38
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(5)
		"
	}
	button
	{
		area 				247 551 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(5,1)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(5,1)
			multiplayerStartSwapPortraits(5,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(5)
		"
	}
	button
	{
		area 				278 551 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(5,2)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(5,2)
			multiplayerStartSwapPortraits(5,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(5)
		"
	}
	button
	{
		area 				309 551 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(5,3)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(5,3)
			multiplayerStartSwapPortraits(5,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(5)
		"
	}
	button
	{
		area 				340 551 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(5,4)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(5,4)
			multiplayerStartSwapPortraits(5,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(5)
		"
	}
	button
	{
		area 				371 551 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(5,5)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(5,5)
			multiplayerStartSwapPortraits(5,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(5)
		"
	}
	button
	{
		area 				402 551 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(5,6)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(5,6)
			multiplayerStartSwapPortraits(5,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(5)
		"
	}
	--player 6
	button
	{
		area 247 602 180 38
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(6)
		"
	}
	button
	{
		area 				247 602 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(6,1)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(6,1)
			multiplayerStartSwapPortraits(6,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(6)
		"
	}
	button
	{
		area 				278 602 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(6,2)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(6,2)
			multiplayerStartSwapPortraits(6,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(6)
		"
	}
	button
	{
		area 				309 602 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(6,3)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(6,3)
			multiplayerStartSwapPortraits(6,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(6)
		"
	}
	button
	{
		area 				340 602 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(6,4)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(6,4)
			multiplayerStartSwapPortraits(6,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(6)
		"
	}
	button
	{
		area 				371 602 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(6,5)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(6,5)
			multiplayerStartSwapPortraits(6,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(6)
		"
	}
	button
	{
		area 				402 602 25 38
		bitmap lua			'getMultiplayerPlayerControlledCharacter(6,6)'
		sequence 			1
		align 				center center
		actionSimpleDrag	
		"
			local slot = getMultiplayerPlayerControlledCharacterSlot(6,6)
			multiplayerStartSwapPortraits(6,slot)
		"
		actionSimpleDrop	
		"
			multiplayerStopSwapPortraits(6)
		"
	}

	label -- game name
	{
		area 		40 84 454 56
		text lua	"multiplayerSessionName"
		text style 	'label'
	}
	label -- new game type/save name
	{
		area 		206 140 288 44
		text lua	"multiplayerSaveName"
		text style 	'label'
		align 		left center
	}
	label -- location
	{
		area 		206 180 288 44
		text lua	"multiplayerLocationName"
		text style 	'label'
		align 		left center
	}
	label -- time played
	{
		area 		206 220 288 44
		text lua	"multiplayerTimePlayed"
		text style 	'label'
		align 		left center
	}
	label -- difficulty
	{
		area 		206 260 288 44
		text lua	"multiplayerDifficultyLabel"
		text style 	'label'
		align 		left center
	}
	label -- other difficulty
	{
		area 		40 140 166 164
		bam 		"GUIDIFF"
		frame lua	"multiplayerDifficultyImage"
		sequence 	0
		align 		center center
	}

	button
	{
		area 740 706 200 44
		bam 'GUIBUTNT'
		sequence 1
		text "START_GAME_BUTTON" -- Done
		text style 'button'
		clickable lua "multiplayer.donebuttonclickable"
		enabled "not multiplayerFromInGame"
		tooltip lua "getStartGameButtonTooltip()"
		action 
		"
			multiplayerScreen:OnMainDoneButtonClick(mulitplayerPreexistingDifficulty)
		"
	}
	button
	{
		on escape
		area 740 706 200 44
		bam 'GUIBUTNT'
		sequence 1
		text "DONE_BUTTON" -- Done
		text style 'button'
		clickable lua "multiplayer.donebuttonclickable"
		enabled "multiplayerFromInGame"
		tooltip lua "getStartGameButtonTooltip()"
		action 
		"
			multiplayerScreen:OnMainDoneButtonClick(mulitplayerPreexistingDifficulty)
		"
	}
	button
	{
		area 82 706 200 44
		bam 'GUIBUTNT'
		sequence 0
		text "LOGOUT_BUTTON" -- Logout
		text style 'button'
		action 
		"
			multiplayerScreen:OnLogoutButtonClick()
		"
	}
	button
	{
		area 298 652 200 42
		bam 'GUIBUTNT'
		sequence 0
		text "MULTIPLAYER_GAME_OPTIONS_BUTTON"
		text style 'button'
		enabled "multiplayerLocalPlayerID == 1"
		action 
		"
			helpTextString = Infinity_FetchString(11323)
			Infinity_PushMenu('MP_OPTIONS')
		"
	}

	--dragged portrait
	label
	{
		name 				"multiplayerDraggingPortraitImage"
		area 				-20 -20 37 57
		bitmap lua			'mpDraggedPortrait'
		sequence 			1
		align 				center center
		enabled 			"multiplayerUpdateDraggedPortrait()"
	}
}
`
multiplayerPermissions = 
{
	{'MULTIPLAYER_PERMISSIONS_MODIFY',	'MULTIPLAYER_PERMISSIONS_MODIFY_TOOLTIP',	false, false},
	{'MULTIPLAYER_PERMISSIONS_GOLD',	'MULTIPLAYER_PERMISSIONS_GOLD_TOOLTIP',		false, false},
	{'MULTIPLAYER_PERMISSIONS_TRAVEL',	'MULTIPLAYER_PERMISSIONS_TRAVEL_TOOLTIP',	false, false},
	{'MULTIPLAYER_PERMISSIONS_VIEW',	'MULTIPLAYER_PERMISSIONS_VIEW_TOOLTIP',		false, false},
	{'MULTIPLAYER_PERMISSIONS_DIALOGUE','MULTIPLAYER_PERMISSIONS_DIALOGUE_TOOLTIP',	false, false},
	{'MULTIPLAYER_PERMISSIONS_PAUSE',	'MULTIPLAYER_PERMISSIONS_PAUSE_TOOLTIP',	false, false}
}

function broadcastPermissionChange(player,permission,setting)
	local player = getMultiplayerPlayerName(player,false,true)
	local todo = t(multiplayerPermissions[permission][1])
	setStringTokenLua("<PLAYER_NAME_1>",player)
	setStringTokenLua("<PERMISSION>",todo)
	if setting == true then
		message = t("MULTIPLAYER_IS_NOW_PERMITTED")
	else
		message = t("MULTIPLAYER_IS_NOT_PERMITTED")
	end
	removeStringTokenLua("<PLAYER_NAME_1>")
	removeStringTokenLua("<PERMISSION>")
	print(message)
	Infinity_SendChatMessage(message, true) 
end

function getMultiplayerPlayerPermissionDescription()
	local player = getMultiplayerPlayerName(multiplayerInPermissionForPlayer,false,false)
	setStringTokenLua("<PLAYER_NAME_1>",player)
 	local canPerform = t("MULTIPLAYER_CAN_PERFORM")
	removeStringTokenLua("<PLAYER_NAME_1>")

	return canPerform
end
`
menu
{
	name 'MP_PERMISSIONS'
	align center center
	modal
	onOpen
	"
		local index = 1
		for index = 1, #(multiplayerPermissions), 1 do
			multiplayerPermissions[index][3] = multiplayer.player[multiplayerInPermissionForPlayer].permissions[index]
			multiplayerPermissions[index][4] = multiplayerPermissions[index][3]
		end
	"

	label 
	{
		mosaic 'RECENTEV'
		area 2 -2 664 668
	}
	label
	{
		area 106 70 458 44
		text "PERMISSIONS_TITLE"
		text style "title"
	}

	label
	{
		area 106 114 458 44
		text lua "getMultiplayerPlayerPermissionDescription()"
		text style "title"
	}

	button
	{
		bam GUIOSW
		on esc
		area 616 6 44 44
		sequence 2
		action 
		"	
			multiplayerScreen:OnCancelButtonClick()
			Infinity_PopMenu()
		"
	}

	--bottom buttons
	button
	{
		area 236 528 200 44
		bam 'GUIBUTNT'
		sequence 0
		text "CANCEL_BUTTON" -- Back
		text style 'button'
		action 
		"
			multiplayerScreen:OnCancelButtonClick()
			Infinity_PopMenu()
		"
	}
	button
	{
		on return
		area 236 572 200 44
		bam 'GUIBUTNT'
		sequence 1
		text "DONE_BUTTON" -- Done
		text style 'button'
		enabled "multiplayerLocalPlayerID == 1"
		action 
		"
			local index = 1
			for index = 1, #(multiplayerPermissions), 1 do
				if multiplayerPermissions[index][3] ~= multiplayerPermissions[index][4] then
					broadcastPermissionChange(multiplayerInPermissionForPlayer,index,multiplayerPermissions[index][3])
					multiplayerScreen:OnPermissionButtonClick(multiplayerInPermissionForPlayer - 1, index)
				end
			end

			multiplayerInPermission = false
			multiplayerScreen:OnDoneButtonClick()
			Infinity_PopMenu()
		"
	}

	--permissions
	button
	{
		area 261 170 45 42
		bam ROUNDBUT
		sequence 0
		glow lua "multiplayerPermissions[1][3] == true"
		tooltip lua "t(multiplayerPermissions[1][2])"
		align center center
		action 
		"
			if multiplayerLocalPlayerID == 1 then
				multiplayerPermissions[1][3] = not multiplayerPermissions[1][3]
			end
		"
	}
	text
	{
		area 306 166 212 56
		text lua "t(multiplayerPermissions[1][1])"
		tooltip lua "t(multiplayerPermissions[1][2])"
		text style "normal"
		align left center
	}
	button
	{
		area 261 226 45 42
		bam ROUNDBUT
		sequence 0
		glow lua "multiplayerPermissions[2][3] == true"
		tooltip lua "t(multiplayerPermissions[2][2])"
		align center center
		action 
		"
			if multiplayerLocalPlayerID == 1 then
				multiplayerPermissions[2][3] = not multiplayerPermissions[2][3]
			end
		"
	}
	text
	{
		area 306 222 212 56
		text lua "t(multiplayerPermissions[2][1])"
		tooltip lua "t(multiplayerPermissions[2][2])"
		text style "normal"
		align left center
	}
	button
	{
		area 261 282 45 42
		bam ROUNDBUT
		sequence 0
		glow lua "multiplayerPermissions[3][3] == true"
		tooltip lua "t(multiplayerPermissions[3][2])"
		align center center
		action 
		"
			if multiplayerLocalPlayerID == 1 then
				multiplayerPermissions[3][3] = not multiplayerPermissions[3][3]
			end
		"
	}
	text
	{
		area 306 278 212 56
		text lua "t(multiplayerPermissions[3][1])"
		tooltip lua "t(multiplayerPermissions[3][2])"
		text style "normal"
		align left center
	}
	button
	{
		area 261 340 45 42
		bam ROUNDBUT
		sequence 0
		glow lua "multiplayerPermissions[4][3] == true"
		tooltip lua "t(multiplayerPermissions[4][2])"
		align center center
		action 
		"
			if multiplayerLocalPlayerID == 1 then
				multiplayerPermissions[4][3] = not multiplayerPermissions[4][3]
			end
		"
	}
	text
	{
		area 306 334 212 56
		text lua "t(multiplayerPermissions[4][1])"
		tooltip lua "t(multiplayerPermissions[4][2])"
		text style "normal"
		align left center
	}
	button
	{
		area 261 394 45 42
		bam ROUNDBUT
		sequence 0
		glow lua "multiplayerPermissions[5][3] == true"
		tooltip lua "t(multiplayerPermissions[5][2])"
		align center center
		action 
		"
			if multiplayerLocalPlayerID == 1 then
				multiplayerPermissions[5][3] = not multiplayerPermissions[5][3]
			end
		"
	}
	text
	{
		area 306 390 212 56
		text lua "t(multiplayerPermissions[5][1])"
		tooltip lua "t(multiplayerPermissions[5][2])"
		text style "normal"
		align left center
	}
	button
	{
		area 261 452 45 42
		bam ROUNDBUT
		sequence 0
		glow lua "multiplayerPermissions[6][3] == true"
		tooltip lua "t(multiplayerPermissions[6][2])"
		align center center
		action 
		"
			if multiplayerLocalPlayerID == 1 then
				multiplayerPermissions[6][3] = not multiplayerPermissions[6][3]
			end
		"
	}
	text
	{
		area 306 446 212 56
		text lua "t(multiplayerPermissions[6][1])"
		tooltip lua "t(multiplayerPermissions[6][2])"
		text style "normal"
		align left center
	}
}
`
multiplayerGameOptions =
{
	{"LISTEN_JOIN_LABEL",	"LISTEN_JOIN_TOOLTIP",	false, false},
	{"ALLOW_REFORM_LABEL",	"ALLOW_REFORM_TOOLTIP",	false, false}
}
multiplayerImportOptions =
{
	{"MULTIPLAYER_IMPORT_CHARACTER_RULES_SEI"},
	{"MULTIPLAYER_IMPORT_CHARACTER_RULES_SE"},
	{"MULTIPLAYER_IMPORT_CHARACTER_RULES_S"}
}
multiplayerImportOption = 0

function broadcastOptionChange(slot, onOff)
	if multiplayerLocalPlayerID == 1 then
		local message = ""
		if slot < 3 then
			local setting = t(multiplayerGameOptions[slot][1])
			setStringTokenLua("<SESSION_RULES>",setting)
			if onOff == true then
				message = t("MULTIPLAYER_GAME_WILL_NOW")
			else
				message = t("MULTIPLAYER_GAME_WILL_NO_LONGER")
			end
			removeStringTokenLua("<SESSION_RULES>")
		else
			local setting = t(multiplayerImportOptions[slot-2][1])
			setStringTokenLua("<IMPORT_RULES>",setting)
			message = t("MULTIPLAYER_IMPORT_SETTINGS_CHANGE")
			removeStringTokenLua("<IMPORT_RULES>")
		end
		print(message)
		Infinity_SendChatMessage(message, true) 
	end
end
`
menu
{
	name 'MP_OPTIONS'
	align center center
	modal 
	onOpen
	"
		multiplayerGameOptions[1][3] = multiplayer.listentojoin
		multiplayerGameOptions[1][4] = multiplayerGameOptions[1][3]
		multiplayerGameOptions[2][3] = multiplayer.allowreformparty
		multiplayerGameOptions[2][4] = multiplayerGameOptions[2][3]
		multiplayerImportOption = multiplayer.importsetting + 1
	"

	label 
	{
		mosaic 'RECENTEV'
		area 2 -2 664 668
	}
	label
	{
		area 106 68 460 44
		text "OPTIONS_TITLE"
		text style "title"
	}
	label
	{
		area 74 262 516 56
		text "MULTIPLAYER_IMPORT_CHARACTER_RULES_LABEL"
		text style "title"
		align center center
	}

	button
	{
		area 202 142 45 42
		bam ROUNDBUT
		sequence 0
		glow lua "multiplayerGameOptions[1][3] == true"
		tooltip lua "t(multiplayerGameOptions[1][2])"
		align center center
		action 
		"
			multiplayerGameOptions[1][3] = not multiplayerGameOptions[1][3]
		"
	}
	text
	{
		area 252 142 303 42
		text lua "t(multiplayerGameOptions[1][1])"
		text style "normal"
		tooltip lua "t(multiplayerGameOptions[1][2])"
		align left center
	}
	button
	{
		area 202 196 45 42
		bam ROUNDBUT
		sequence 0
		glow lua "multiplayerGameOptions[2][3] == true"
		tooltip lua "t(multiplayerGameOptions[2][2])"
		align center center
		action 
		"
			multiplayerGameOptions[2][3] = not multiplayerGameOptions[2][3]
		"
	}
	text
	{
		area 252 196 303 42
		text lua "t(multiplayerGameOptions[2][1])"
		text style "normal"
		tooltip lua "t(multiplayerGameOptions[2][2])"
		align left center
	}

	button
	{
		area 202 326 45 42
		bam ROUNDBUT
		frame lua "currentCellCheck(3)"
		sequence 0
		glow lua "multiplayerImportOption == 1"
		tooltip lua "t('IMPORT_RULES_TOOLTIP')"
		align center center
		action 
		"
			multiplayerImportOption = 1
		"
	}
	text
	{
		area 252 326 303 42
		text lua "t('MULTIPLAYER_IMPORT_CHARACTER_RULES_SEI')"
		tooltip lua "t('IMPORT_RULES_TOOLTIP')"
		text style "normal"
		align left center
	}
	button
	{
		area 202 374 45 42
		bam ROUNDBUT
		frame lua "currentCellCheck(3)"
		sequence 0
		glow lua "multiplayerImportOption == 2"
		tooltip lua "t('IMPORT_RULES_TOOLTIP')"
		align center center
		action 
		"
			multiplayerImportOption = 2
		"
	}
	text
	{
		area 252 374 303 42
		text lua "t('MULTIPLAYER_IMPORT_CHARACTER_RULES_SE')"
		tooltip lua "t('IMPORT_RULES_TOOLTIP')"
		text style "normal"
		align left center
	}
	button
	{
		area 202 422 45 42
		bam ROUNDBUT
		frame lua "currentCellCheck(3)"
		sequence 0
		glow lua "multiplayerImportOption == 3"
		tooltip lua "t('IMPORT_RULES_TOOLTIP')"
		align center center
		action 
		"
			multiplayerImportOption = 3
		"
	}
	text
	{
		area 252 422 212 42
		text lua "t('MULTIPLAYER_IMPORT_CHARACTER_RULES_S')"
		tooltip lua "t('IMPORT_RULES_TOOLTIP')"
		text style "normal"
		align left center
	}

	button
	{
		bam GUIOSW
		on esc
		area 616 4 44 44
		sequence 2
		action 
		"	
			multiplayerScreen:OnCancelButtonClick()
			Infinity_PopMenu()
		"
	}

	--bottom buttons
	button
	{
		on return
		area 236 572 200 44
		bam 'GUIBUTNT'
		sequence 0
		text "DONE_BUTTON" -- Done
		text style 'button'
		action 
		"
			if multiplayerImportOption ~= multiplayer.importsetting + 1 then
				multiplayerScreen:SetImportSetting(multiplayerImportOption - 1)
				broadcastOptionChange(multiplayerImportOption+2)
			end

			if multiplayerGameOptions[1][3] ~= multiplayerGameOptions[1][4] then
				broadcastOptionChange(1, multiplayerGameOptions[1][3])
				multiplayerScreen:ToggleListenToJoin()
			end

			if multiplayerGameOptions[2][3] ~= multiplayerGameOptions[2][4] then
				broadcastOptionChange(2, multiplayerGameOptions[2][3])
				multiplayerScreen:ToggleAllowReformParty()
			end

			Infinity_PopMenu()
		"
	}
	button
	{
		on escape
		area 236 528 200 44
		bam 'GUIBUTNT'
		sequence 1
		text "CANCEL_BUTTON" -- Cancel
		text style 'button'
		action 
		"
			multiplayerScreen:OnCancelButtonClick()
			Infinity_PopMenu()
		"
	}
}
menu
{
	name 'MP_PICKPLAYER'
	align center center
	modal 
	label 
	{
		mosaic 'RECENTEV'
		area 0 0 664 662
	}
	label 
	{
		area 104 70 456 44
		text "SELECT_PLAYER_TITLE"
		text style "title"
	}
	label 
	{
		area 98 162 470 46
		text "SELECT_PLAYER_DESCRIPTION"
		text style "title"
	}

	-- list
	list
	{
		column
		{
			width 100
			label
			{
				area 0 0 340 32
				text lua "getMultiplayerPlayerName(rowNumber, false, true)"
				text style "normal"
				align left center
			}
		}

		action 
		"
		"

		rowheight 32
		area 202 218 258 280
		table "multiplayer.player"
		var currentMultiplayerSelectPlayer
	}
	
	button
	{
		bam GUIOSW
		on esc
		area 616 6 44 44
		sequence 2
		action 
		"	
			Infinity_PopMenu()
		"
	}

	button
	{
		on escape
		area 236 512 198 42
		text "CANCEL_BUTTON"
		text style "button"
		align center center
		bam 'GUIBUTNT'
		sequence 0
		action
		"	
			Infinity_PopMenu()
		"
	}
	button
	{
		on escape
		area 236 564 198 42
		text "DONE_BUTTON"
		text style "button"
		align center center
		bam 'GUIBUTNT'
		sequence 0
		action
		"	
			broadcastCharacterControlChange(selectedCharacter, currentMultiplayerSelectPlayer)
			multiplayerScreen:OnPlayerSelection(currentMultiplayerSelectPlayer-1)
			Infinity_PopMenu()
		"
	}
}
`
	function multiplayerIsDelete ()
		if (multiplayer.character[mpModifyingCharacter+1].portrait ~= '') then
			return t("DELETE_BUTTON")
		else
			return t("CREATE_BUTTON")
		end
	end
	function getModifyConfirmationLabel()
		print(mpModifyingCharacter+1)
		return t('MULTIPLAYER_EDIT_CONFIRM').. ' ' .. getMultiplayerCharacterName(mpModifyingCharacter+1)
	end
`
menu
{
	name 'MP_MODIFYCHARACTER'
	align center center
	modal 
	label 
	{
		mosaic 'GUIERR6'
		area 0 0 682 238
	}
	label
	{
		area 26 18 598 120
		text lua "getModifyConfirmationLabel()"
		text style "title"
		align center center
	}
	button
	{
		on escape
		area 44 170 230 44
		text "CANCEL_BUTTON" -- cancel
		text style "button"
		bam GUIBUTMT
		action
		"	
			Infinity_PopMenu()
		"
	}
	button
	{
		on return
		area 404 170 230 44
		text lua "multiplayerIsDelete()"
		text style "button"
		bam GUIBUTMT
		action
		"	
			Infinity_PopMenu()
			multiplayerScreen:SetModifiedCharacterSlot(mpModifyingCharacter)
			if (multiplayer.character[mpModifyingCharacter+1].portrait ~= '') then
				multiplayerScreen:OnModifyCharacterDelete()
			else
				multiplayerScreen:UpdateModifyCharacterPanel()
			end
		"
	}
}
menu
{
	name 'MP_ERRORONE'
	align center center
	modal 
	label 
	{
		mosaic 'GUIERR6'
		area 0 0 657 253
	}
	label
	{
		area 29 21 600 126
		text lua "Infinity_FetchString( mpErrorText )"
		text style "normal"
		align center center
	}
	button
	{
		on return
		area 213 170 230 44
		text "DONE_BUTTON" -- done
		text style "button"
		align center center
		bam GUIBUTMT
		action
		"	
			Infinity_PopMenu()
		"
	}
}
menu
{
	name 'MP_ERRORTWO'
	align center center
	modal 
	label 
	{
		mosaic 'GUIERR6'
		area 0 0 657 253
	}
	label
	{
		area 29 21 600 126
		text lua "Infinity_FetchString( mpErrorText )"
		text style "normal"
		align center center
	}
	button
	{
		on return
		enabled "mpErrorState == 2"
		area 343 170 230 44
		text "MODIFY_BUTTON" -- modify
		text style "button"
		align center center
		bam GUIBUTMT
		action
		"	
			Infinity_PopMenu()
			multiplayerScreen:ModifyCharacters()
		"
	}
	button
	{
		on return
		enabled "mpErrorState == 3"
		area 343 170 230 44
		text "KICK_BUTTON" -- kick player
		text style "button"
		align center center
		bam GUIBUTMT
		action
		"	
			Infinity_PopMenu()
			multiplayerScreen:KickPlayer()
		"
	}
	button
	{
		on return
		enabled "mpErrorState == 4"
		area 343 170 230 44
		text "LOGOUT_BUTTON" -- log out
		text style "button"
		align center center
		bam GUIBUTMT
		action
		"	
			local index = 1
			Infinity_PopMenu()
			multiplayerScreen:Logout()
		"
	}
	button
	{
		on escape
		area 79 170 230 44
		text "CANCEL_BUTTON" -- cancel
		text style "button"
		align center center
		bam GUIBUTMT
		action
		"	
			Infinity_PopMenu()
		"
	}
}
`
	function dragMPChat(newY)
		--do a quick bounds check.
		local area = {Infinity_GetArea("mpChatDisplayBackground")}
		if(area[4] + newY <= 150) then newY = 150 - area[4] end
		
		area = {Infinity_GetArea("mpChatHandle")}
		local screenWidth, screenHeight = Infinity_GetScreenSize()
		if(area[2] + area[4] + newY > screenHeight) then newY = screenHeight - area[2] - area[4] end
		
		adjustItemGroup({"mpChatDisplayBackground","mpChatDisplay"}, 0, 0, 0, newY)
		adjustItemGroup({"mpChatEditBackground","mpChatEdit","mpChatHandle"}, 0, newY, 0 , 0)
	end
	mpChatTable = {}
	showMpChat = 0
	function updateChatViewed()
		if(showMpChat == 0) then chatViewed = 0 end
	end
	function updateMPChatPreview(message)
		if(showMpChat == 0) then table.insert(mpChatTable,{text = message}) end
	end
	function getMPMessageOpacity()
		local current = mpChatTable[#mpChatTable]
		if(current == nil) then
			return 0
		end
		if(current.displayTime == nil) then
			current.displayTime = 500
			
			--set the box size
			Infinity_ScaleToText("mpChatPreview")
			
			--give some extra room for the padding
			adjustItemGroup({"mpChatPreview"},0,0,0,16)
		end
		if(current.displayTime > 0) then
			current.displayTime = current.displayTime - 4
		end
		if(current.displayTime > 255) then
			return 255
		else
			return current.displayTime
		end
	end
	function getMPMessage()
		if(#mpChatTable > 0 and mpChatTable[#mpChatTable].displayTime ~= nil) then 
			return mpChatTable[#mpChatTable].text 
		end
		return nil
	end
	function getChatIconOpacity()
		if(chatViewed == 1) then return 255 end
		local sinWave = math.sin(Infinity_GetFrameCounter() / 15)
		local sinWaveAdjusted = (sinWave / 2) + 0.5
		return sinWaveAdjusted * 255
	end
	function getChatBarTooltip()
		if(showMpChat == 0) then
			return t("MULTIPLAYER_CHAT_BAR_COLLAPSED")
		else
			return t("MULTIPLAYER_CHAT_BAR_EXPANDED")
		end
	end
	function resizeMpEditBox()
		Infinity_ScaleToText('mpChatEdit')
		local x,y,w,h = Infinity_GetArea('mpChatEdit')
		local offset = 20
		if(h + offset < 42) then h = (42 - offset) end
		
		
		Infinity_SetArea('mpChatEdit',x,y,w,h)
		Infinity_SetArea('mpChatEditBackground',nil,nil,nil,h + offset)
		Infinity_SetArea('mpChatHandle',nil,y+h+(offset/2),nil,nil)
	end
	mpChatEditOverlay = ""
`
menu
{
	name "MP_CHAT_OVERLAY"
	enabled "e:IsMultiplayer()"
	align right top
	ignoreEsc
	offset -120 0
	onOpen
	"
		chatViewed = 1
	"
	label
	{
		name "mpChatDisplayBackground"
		enabled "showMpChat"
		area 0 0 300 281
		rectangle 4
		rectangle opacity 200
	}
	label
	{
		area 0 0 300 42
		rectangle 0

	}
	label
	{
		area 10 8 28 28
		bam "CHTICN"
		frame 1
		opacity lua "getChatIconOpacity()"
		
	}
	label
	{
		area 10 8 28 28
		bam "CHTICN"
		frame 0
		opacity lua "255 - getChatIconOpacity()"
	}
	label
	{
		area 42 0 252 42
		text "MULTIPLAYER_CHAT_LABEL"
		text style "label"
	}
	button
	{
		area 0 0 300 42
		toggle "showMpChat"
		tooltip lua "getChatBarTooltip()"
		action
		"
			chatViewed = 1
		"
	}
	
	label
	{
		name "mpChatPreview"
		enabled "showMpChat == 0"
		opacity lua "getMPMessageOpacity()"
		area 0 42 300 56
		text style "normal"
		text lua "getMPMessage()"
		pad 8 8 8 8
		fill 0 0 0 200
	}
	text
	{
		name "mpChatDisplay"
		enabled "showMpChat"
		area 20 46 258 180
		text lua "mpChatText"
		scrollbar 'GUISCRC'
		scrollbar func "mpChatboxScroll"
		text style	normal
	}
	label
	{
		name "mpChatEditBackground"
		enabled "showMpChat"
		area 0 233 300 48
		rectangle 0
	}
	edit
	{
		name		"mpChatEdit"
		enabled 	"showMpChat"
		area		10 243 290 28
		var			mpChatEditOverlay
		scrollbar	'GUISCRC'
		text style	"edit"
		maxchars 255
		fill            112 111 111 64
		action
		"
			--On return pressed
			if (key_pressed == 13) then
				if (mpChatEditOverlay ~= '') then
					Infinity_SendChatMessage(mpChatEditOverlay, false) 
					Infinity_PlaySound('WAL_19B')
					mpChatEditOverlay=''
					resizeMpEditBox()
					return -1
				end
			end
			return 1
		"
		actionalt
		"
			resizeMpEditBox()
		"
	}
	handle
	{
		name "mpChatHandle"
		area 104 281 95 36
		bam "MPCHATAB"
		enabled "showMpChat"
		tooltip lua "t('MULTIPLAYER_CHAT_RESIZE_TOOLTIP')"
		actionDrag
		"
			dragMPChat(motionY)
		"
	}
}
`
function initQuests()
	--instead of always searching the quests, just map entry ids to their quests
	entryToQuest = {}
	for questIdx, quest in pairs(quests) do
		quests[questIdx].stateType = const.ENTRY_TYPE_NONE
		for objIdx,objective in pairs(quest.objectives) do
			quests[questIdx].objectives[objIdx].stateType = const.ENTRY_TYPE_NONE
			for entryIdx,entry in pairs(objective.entries) do
				quests[questIdx].objectives[objIdx].entries[entryIdx].stateType = const.ENTRY_TYPE_NONE
				entryToQuest[entry.id] = questIdx
			end
		end
	end
end

function compareByRecvTime(o1,o2)
	if(not o1.recvTime and not o2.recvTime) then return false end
	if(not o1.recvTime) then return false end
	if(not o2.recvTime) then return true end
	return o1.recvTime > o2.recvTime
end

function buildEntry(text, recvTime, stateType, chapter, timeStamp)
	local entry = 
		{
			text = text,
			recvTime = recvTime,
			stateType = stateType,
			timeStamp = timeStamp,
			chapters = {}
		}
	entry.chapters[chapter] = 1
	return entry	
end

--Update a journal entry by the strref/journalId
function updateJournalEntry(journalId, recvTime, stateType, chapter, timeStamp)
	if(stateType == const.ENTRY_TYPE_USER) then
		local entry = buildEntry(journalId, recvTime, stateType, chapter, timeStamp)
		table.insert(userNotes,entry)
		
		--update display data
		buildQuestDisplay()
		return
	end
	--find the quest that is parent to this entry.

	--NOTE this can be placed in a loop if there needs to be more than quest to an entry
	--this would just mean entryToQuest returns a table that we iterate over
	local questId = entryToQuest[journalId]
	if questId == nil then
		--add loose entries into the looseEntries table so they still get displayed.
		local entry = buildEntry(journalId, recvTime, stateType, chapter, timeStamp)
		table.insert(looseEntries,entry)
		
		--update display data
		buildQuestDisplay()
		return
	end

	local quest = quests[questId]
	if quest == nil then
		print("JOURNAL ERROR - no quest entry associated with questId "..questId)
		return
	end
	local previous = nil
	--traverse quest to find objective and entry
	for objIdx,objective in pairs(quest.objectives) do
		for entryIdx,entry in pairs(objective.entries) do
			if(entry.id == journalId) then
				--now we know where our quest, objective, and entry are
				--update quest, objective and entry appropriately
				entry.recvTime = recvTime
				entry.stateType = stateType
				if(not entry.chapters) then entry.chapters = {} end
				entry.chapters[chapter] = 1
				entry.timeStamp = timeStamp
				objective.entries[entryIdx] = entry
				
				objective.recvTime = recvTime
				if(not objective.chapters) then objective.chapters = {} end
				objective.chapters[chapter] = 1
				if(objective.stateType ~= const.ENTRY_TYPE_COMPLETE) then
					objective.stateType = stateType
				end
				quest.objectives[objIdx] = objective
				
				quest.recvTime = recvTime
				if(not quest.chapters) then quest.chapters = {} end
				quest.chapters[chapter] = 1
				if(quest.stateType ~= const.ENTRY_TYPE_COMPLETE) then
					quest.stateType = stateType
				end
				
				--mark any previous objective as complete
				if(entry.previous ~= nil) then
					for objIdx2,objective2 in pairs(quest.objectives) do
						for k, prevObj in pairs(entry.previous) do
							if(prevObj == objective2.text) then
								quest.objectives[objIdx2].stateType = const.ENTRY_TYPE_COMPLETE
							end
						end
					end
				end
				
				quests[questId] = quest
				
				--remove all in subgroup (except myself!)
				if(stateType == const.JOURNAL_STATE_COMPLETE and entry.subGroup) then
					for k,v in pairs(subGroups[entry.subGroup]) do
						if(v.id ~= entry.id) then
							removeJournalEntry(v.id)
						end
					end
				end
				
			end
		end
	end
	--sort the objectives.
	table.sort(quest.objectives,compareByRecvTime)
	
	--update display data
	buildQuestDisplay()
end
function checkEntryComplete(journalId, stateType)
	--Check if a journal entry is part of a quest that's already complete
	
	--If anything other than an unfinished entry return false.
	if(stateType ~= const.ENTRY_TYPE_INPROGRESS) then return false end
	
	--Check if my quest is marked complete.
	local questIndex = entryToQuest[journalId]
	if (quests[questIndex].stateType == const.ENTRY_TYPE_COMPLETE) then
		return 1
	else
		return 0
	end
end
--this should maybe be done recursively, but i kinda want direct control over each level
function buildQuestDisplay()
	--this is basically just a flatten
	questDisplay = {}
	journalDisplay = {}
	
	local journalEntries = {} --temp holding table for sorting the entries
	
	for k,quest in pairs(quests) do
		--skip inactive quests
		if(quest.stateType ~= nil and quest.stateType ~= const.ENTRY_TYPE_NONE) then
			quest.quest = 1 -- tell the renderer what type of entry this is
			table.insert(questDisplay, quest)
			local curQuestIdx = #questDisplay --we'll need to modify current quest with it's children, store a reference.
			local questChildren = {}
			for k2,objective in pairs(quest.objectives) do
				if(objective.stateType ~= const.ENTRY_TYPE_NONE) then
					objective.objective = 1
					objective.parent = curQuestIdx
					
					if(objective.stateType ~= const.ENTRY_TYPE_INFO) then
						--info entries should not go into quests
						table.insert(questDisplay, objective)
						table.insert(questChildren, #questDisplay)
					end
					
					local curObjectiveIdx = #questDisplay
					local objectiveChildren = {}
					for k3,entry in pairs(objective.entries) do
						entry.entry = 1
						
						entry.parent = curObjectiveIdx
						table.insert(questDisplay, entry)
						table.insert(objectiveChildren, #questDisplay)
					end
					questDisplay[curObjectiveIdx].children = objectiveChildren
				end
			end
			questDisplay[curQuestIdx].children = questChildren
		end
	end
	
	-- add the user entries to the journal display
	for k,entry in pairs(userNotes) do
		entry.entry = 1
		table.insert(journalEntries,entry)
	end
	
	--add the loose entries (entries without quests) to the journal display
	for k,entry in pairs(looseEntries) do
		entry.entry = 1
		table.insert(journalEntries,entry)
	end
	
		
	table.sort(journalEntries, compareByRecvTime)
	
	for k,entry in pairs(journalEntries) do
		local title  = {}
		title.title = 1
		title.text = entry.timeStamp
		title.chapters = entry.chapters
		table.insert(journalDisplay,title)
		table.insert(journalDisplay, entry)
	end
end
function questContainsSearchString(row)
	if(journalSearchString == nil or journalSearchString == "") then return 1 end --no search string, do nothing
	local text = Infinity_FetchString(questDisplay[row].text)
	if(string.find(string.lower(text),string.lower(journalSearchString))) then return 1 end -- string contains search string.
	if(questDisplay[row].children == nil) then return nil end --no children, does not contain search string.
	for k,v in pairs(questDisplay[row].children) do
		--Infinity_Log(v)
		if(containsSearchString(v)) then return 1 end -- one of children contains search string
	end
	return nil --does not contain search string
end
function containsChapter(tab, chapter)
	if(not tab) then return nil end
	return tab[chapter]
end
function entryEnabled(row)
	local rowTab =  questDisplay[row]
	if(rowTab == nil or rowTab.entry == nil or not containsChapter(rowTab.chapters,chapter)) then return nil end

	if objectiveEnabled(rowTab.parent) then return 1 else return nil end
end
function getEntryText(row)
	return questDisplay[row].timeStamp .. "\n" .. questDisplay[row].text
end

function objectiveEnabled(row)
	local rowTab =  questDisplay[row]
	if(rowTab == nil or rowTab.objective == nil or not containsChapter(rowTab.chapters,chapter)) then return nil end

	if(questEnabled(rowTab.parent) and questDisplay[rowTab.parent].expanded) then return 1 else return nil end
end
function getObjectiveText(row)
	local rowTab =  questDisplay[row]
	if (rowTab == nil) then return nil end
	local text = rowTab.text
	if(text == "" or text == nil) then
		text = t("NO_OBJECTIVE_NORMAL")
	end
	--objectives shouldn't really display a completed state since they don't actually follow a progression.
	--if(getFinished(row)) then
	--	text = "^0xFF666666" .. text .. " (Finished)^-"
	--end

	return text
end

function questEnabled(row)
	return (questDisplay[row] and questDisplay[row].quest and containsChapter(questDisplay[row].chapters,chapter) and (#questDisplay[row].children > 0))
end

function CloseAll(side)
	for i=1,#questDisplay,1 do
		if side == 1 then
			if questDisplay[i].expanded == 1 and questDisplay[i].stateType ~= const.ENTRY_TYPE_COMPLETE then
				questDisplay[i].expanded = nil
			end
		elseif side == 2 then
			if questDisplay[i].expanded == 1 and questDisplay[i].stateType == const.ENTRY_TYPE_COMPLETE then
				questDisplay[i].expanded = nil
			end
		end
	end
end


function hideFinished(row)
	return (questDisplay[row].stateType ~= const.ENTRY_TYPE_COMPLETE)
end
function hideUnfinished(row)
	return (questDisplay[row].stateType == const.ENTRY_TYPE_COMPLETE)
end
function getQuestText(row)
	local rowTab =  questDisplay[row]
	if (rowTab == nil) then return nil end
	local text = Infinity_FetchString(rowTab.text)
	
	if(getFinished(row)) then
		text = "^0xFF000000" .. text-- .. " (" .. t("OBJECTIVE_FINISHED_NORMAL") .. ")^-"
	end

	return text
end
function getArrowFrame(row)
	if(questDisplay[row] == nil or (questDisplay[row].objective == nil and questDisplay[row].quest == nil)) then return "" end

	
	if(questDisplay[row].expanded) then
		return 0
	else
		return 1
	end
end
function getArrowEnabled(row)
	if(questDisplay[row].quest == nil and questDisplay[row].objective == nil) then return nil end
	if(questDisplay[row].objective and not objectiveEnabled(row)) then return nil end
	if(questDisplay[row].quest and not questEnabled(row)) then return nil end
	if(questDisplay[row].objective) then return nil end
	return 1
end

function getFinished(row)
	if(questDisplay[row].stateType == const.ENTRY_TYPE_COMPLETE) then return 1 else return nil end
end
function showObjectiveSeperator(row)
	local tab = questDisplay[row]
	if(objectiveEnabled(row) or entryEnabled(row)) then
		--seperator is enabled for objective or entry as long as the next thing is an objective.
		--search until we find something enabled or end of table.
		local idx = row + 1
		while(questDisplay[idx]) do
			if(objectiveEnabled(idx)) then
				return 1
			else 
				if(questEnabled(idx) or entryEnabled(idx)) then
					return nil
				end
			end
			idx = idx + 1
		end
	end
end


function getJournalTitleEnabled(row)
	return journalDisplay[row].title and containsChapter(journalDisplay[row].chapters,chapter) and journalContainsSearchString(row)
end
function getJournalTitleText(row)
	return journalDisplay[row].text
end
function getJournalEntryEnabled(row)
	return journalDisplay[row].entry and containsChapter(journalDisplay[row].chapters,chapter) and journalContainsSearchString(row)
end
function getJournalEntryText(row)
	local text = Infinity_FetchString(journalDisplay[row].text)
	if(text == nil or text == "") then
		text = journalDisplay[row].text
	end
	
	if(journalSearchString and journalSearchString ~= "") then
		--do the search string highlight
		text = highlightString(text, journalSearchString, "^0xFF0000FF")
	end
	
	return text
end
function getJournalDarken(row)
	local entry = journalDisplay[row]
	if(entry.title) then
		return (row == selectedJournal or row + 1 == selectedJournal)
	end
	if(entry.entry) then
		return (row == selectedJournal or row - 1 == selectedJournal)
	end
end
function journalContainsSearchString(row)
	if(journalSearchString == nil or journalSearchString == "") then return 1 end --no search string, do nothing
	local text = Infinity_FetchString(journalDisplay[row].text)
	if(text == "") then text = journalDisplay[row].text end --no stringref, use the text.
	if(string.find(string.lower(text),string.lower(journalSearchString))) then return 1 end -- string contains search string.
	
	--check if the corresponding row to this one contains the string.
	local pairText = nil
	if(journalDisplay[row].title) then
		--check the corresponding entry
		pairText = Infinity_FetchString(journalDisplay[row+1].text) or journalDisplay[row+1].text
		if(pairText == "") then pairText = journalDisplay[row+1].text end 
	else 
		if (journalDisplay[row].entry) then
			pairText = Infinity_FetchString(journalDisplay[row-1].text) or journalDisplay[row-1].text
			if(pairText == "") then pairText = journalDisplay[row-1].text end 
		end
	end
	if(string.find(string.lower(pairText),string.lower(journalSearchString))) then return 1 end -- pair string contains search string.
	
	return nil --does not contain search string
end
-- function dragJournal()
	-- local offsetX,offsetY,menuWidth,menuHeight = Infinity_GetMenuArea('JOURNAL')
	-- offsetX = offsetX + motionX
	-- offsetY = offsetY + motionY
	
	-- clamping
	-- if(offsetX < 80) then
		-- offsetX = 80
	-- end
	-- if(offsetY < 0) then
		-- offsetY = 0
	-- end
	
	-- local screenWidth, screenHeight = Infinity_GetScreenSize()
	-- if(offsetX > screenWidth - 80 - menuWidth) then
		-- offsetX = screenWidth - 80 - menuWidth
	-- end
	-- if(offsetY > screenHeight - menuHeight) then
		-- offsetY = screenHeight - menuHeight
	-- end
	
	-- Infinity_SetOffset('JOURNAL', offsetX, offsetY)
-- end
function journalEntryClickable(selectedJournal)
	local entry = journalDisplay[selectedJournal]
	if(entry) then return true end
end
function getJournalEntryRef(selectedJournal)
	local entry = journalDisplay[selectedJournal]
	if(not entry) then return end
	if(entry.title) then
		return journalDisplay[selectedJournal + 1].text
	else
		return entry.text
	end
end
function getJournalBackgroundFrame()
	if(journalMode == const.JOURNAL_MODE_QUESTS) then
		return 0
	else
		return 1
	end
end
function PauseJournal()
	if worldScreen:CheckIfPaused() then
		return
	else
		worldScreen:TogglePauseGame(true)
	end
end
function getSidebarButtons_Large()
	local screenWidth, screenHeight = Infinity_GetScreenSize()
	Infinity_SetArea('journalLeftBack1', -((screenWidth-1364)/2), ((screenHeight-756)/2)+640, nil, nil)
	Infinity_SetArea('journalLeftBack2', -((screenWidth-1364)/2), ((screenHeight-756)/2)+703, nil, nil)
	Infinity_SetArea('journalRightBack1', ((screenWidth-1364)/2)+1245, ((screenHeight-756)/2)+640, nil, nil)
	Infinity_SetArea('journalRightBack2', ((screenWidth-1364)/2)+964, ((screenHeight-756)/2)+703, nil, nil)
	Infinity_SetArea('journalLeftButton1a', -((screenWidth-1364)/2), ((screenHeight-756)/2)+691, nil, nil)
	Infinity_SetArea('journalLeftButton1b', -((screenWidth-1364)/2)+1, ((screenHeight-756)/2)+692, nil, nil)
	Infinity_SetArea('journalLeftButton1c', -((screenWidth-1364)/2)+1, ((screenHeight-756)/2)+691, nil, nil)
	Infinity_SetArea('journalLeftButton2', -((screenWidth-1364)/2)+69, ((screenHeight-756)/2)+708, nil, nil)
	Infinity_SetArea('journalLeftButton3', -((screenWidth-1364)/2)+119, ((screenHeight-756)/2)+709, nil, nil)
	Infinity_SetArea('journalLeftButton4', -((screenWidth-1364)/2)+169, ((screenHeight-756)/2)+708, nil, nil)
	Infinity_SetArea('journalLeftButton5', -((screenWidth-1364)/2)+216, ((screenHeight-756)/2)+709, nil, nil)
	Infinity_SetArea('journalLeftButton6', -((screenWidth-1364)/2)+261, ((screenHeight-756)/2)+709, nil, nil)
	Infinity_SetArea('journalLeftButton7', -((screenWidth-1364)/2)+309, ((screenHeight-756)/2)+709, nil, nil)
	Infinity_SetArea('journalLeftButton8', -((screenWidth-1364)/2), ((screenHeight-756)/2)+688, nil, nil)
	Infinity_SetArea('journalLeftButton9', -((screenWidth-1364)/2), ((screenHeight-756)/2)+688, nil, nil)
	Infinity_SetArea('journalLeftButton10', -((screenWidth-1364)/2), ((screenHeight-756)/2)+650, nil, nil)
	Infinity_SetArea('journalRightButton1', ((screenWidth-1364)/2)+1295, -((screenHeight-756)/2)+14, nil, nil)
	Infinity_SetArea('journalRightButton2', ((screenWidth-1364)/2)+1295, -((screenHeight-756)/2)+112, nil, nil)
	Infinity_SetArea('journalRightButton3', ((screenWidth-1364)/2)+1295, -((screenHeight-756)/2)+210, nil, nil)
	Infinity_SetArea('journalRightButton4', ((screenWidth-1364)/2)+1295, -((screenHeight-756)/2)+308, nil, nil)
	Infinity_SetArea('journalRightButton5', ((screenWidth-1364)/2)+1295, -((screenHeight-756)/2)+406, nil, nil)
	Infinity_SetArea('journalRightButton6', ((screenWidth-1364)/2)+1295, -((screenHeight-756)/2)+504, nil, nil)
	Infinity_SetArea('journalRightButton1a', ((screenWidth-1364)/2)+1292, -((screenHeight-756)/2)+10, nil, nil)
	Infinity_SetArea('journalRightButton2a', ((screenWidth-1364)/2)+1292, -((screenHeight-756)/2)+108, nil, nil)
	Infinity_SetArea('journalRightButton3a', ((screenWidth-1364)/2)+1292, -((screenHeight-756)/2)+206, nil, nil)
	Infinity_SetArea('journalRightButton4a', ((screenWidth-1364)/2)+1292, -((screenHeight-756)/2)+304, nil, nil)
	Infinity_SetArea('journalRightButton5a', ((screenWidth-1364)/2)+1292, -((screenHeight-756)/2)+402, nil, nil)
	Infinity_SetArea('journalRightButton6a', ((screenWidth-1364)/2)+1292, -((screenHeight-756)/2)+500, nil, nil)
	Infinity_SetArea('journalRightButton7', ((screenWidth-1364)/2)+1311, ((screenHeight-756)/2)+701, nil, nil)
	Infinity_SetArea('journalRightButton8', ((screenWidth-1364)/2)+1004, ((screenHeight-756)/2)+709, nil, nil)
	Infinity_SetArea('journalRightButton9', ((screenWidth-1364)/2)+1050, ((screenHeight-756)/2)+709, nil, nil)
	Infinity_SetArea('journalRightButton10', ((screenWidth-1364)/2)+1098, ((screenHeight-756)/2)+709, nil, nil)
	Infinity_SetArea('journalRightButton11', ((screenWidth-1364)/2)+1149, ((screenHeight-756)/2)+709, nil, nil)
	Infinity_SetArea('journalRightButton12', ((screenWidth-1364)/2)+1197, ((screenHeight-756)/2)+709, nil, nil)
	Infinity_SetArea('journalRightButton13', ((screenWidth-1364)/2)+1242, ((screenHeight-756)/2)+708, nil, nil)
	Infinity_SetArea('journalRightButton14', ((screenWidth-1364)/2)+1343, ((screenHeight-756)/2)+650, nil, nil)
end
FirstUse = 0
function positionSmallJournal()
	HideLargeJournal()
	if FirstUse == 0 then
		FirstUse = 1
		-- Set the background to 0,0 (top-left)
		local screenWidth, screenHeight = Infinity_GetScreenSize()
		local area = {Infinity_GetArea('JournalSmall_Background')}
		area[1] = (1364 / 2) - (screenWidth / 2)
		area[2] = (756 / 2) - (screenHeight / 2)

		Infinity_SetArea('JournalSmall_Background', area[1], area[2], 501, 773)
		Infinity_SetArea('JournalSmall_1', area[1], area[2], 485, 747)
		Infinity_SetArea('JournalSmall_2', area[1], area[2], 472, 80)
		Infinity_SetArea('JournalSmall_3', area[1]+218, area[2]+18, 134, 42)
		Infinity_SetArea('JournalSmall_4', area[1]+34, area[2]+18, 136, 42) 
		Infinity_SetArea('JournalSmall_6', area[1]+84, area[2]+140, 118, 35)
		Infinity_SetArea('JournalSmall_7', area[1]+202, area[2]+140, 118, 35)
		Infinity_SetArea('JournalSmall_8', area[1]+320, area[2]+140, 118, 35)
		Infinity_SetArea('JournalSmall_9', area[1]+419, area[2]+13, 66, 67)
		Infinity_SetArea('JournalSmall_10', area[1]+170, area[2]+80, 146, 60)
		Infinity_SetArea('JournalSmall_11', area[1]+134, area[2]+80, 41, 60)
		Infinity_SetArea('JournalSmall_12', area[1]+306, area[2]+80, 41, 60)
		Infinity_SetArea('JournalSmall_13', area[1]+44, area[2]+175, 382, 29)
		Infinity_SetArea('JournalSmall_14', area[1]+62, area[2]+180, 357, 20)
		Infinity_SetArea('JournalSmall_15', area[1]+44, area[2]+174, 396, 490)
		Infinity_SetArea('JournalSmall_16', area[1]+44, area[2]+208, 396, 490)
		Infinity_SetArea('JournalSmall_17', area[1]+44, area[2]+140, 132, 35)
		Infinity_SetArea('JournalSmall_18', area[1]+176, area[2]+140, 132, 35)
		Infinity_SetArea('JournalSmall_19', area[1]+308, area[2]+140, 132, 35)
		Infinity_SetArea('JournalSmall_20', area[1]+44, area[2]+154, 382, 26)
		Infinity_SetArea('JournalSmall_21', area[1]+44, area[2]+200, 382, 4)
		Infinity_SetArea('JournalSmall_22', area[1]+44, area[2]+204, 382, 26)
		Infinity_SetArea('JournalSmall_23', area[1]+44, area[2]+230, 382, 411)
		Infinity_SetArea('JournalSmall_24', area[1]+44, area[2]+641, 162, 47)
		Infinity_SetArea('JournalSmall_25', area[1]+260, area[2]+641, 162, 47)
		Infinity_SetArea('JournalSmall_26', area[1]+400, area[2]+204, 30, 26)
	end
end
function HideLargeJournal()
	local screenWidth, screenHeight = Infinity_GetScreenSize()
	for i = 1, 26, 1 do
		Infinity_SetArea(('journalLarge_' .. i), -(screenWidth * 2), -(screenHeight * 2), -1, -1)
	end
end
function unHideLargeJournal()
	Infinity_SetArea(('journalLarge_1'), 0,0,1364,756)
	Infinity_SetArea(('journalLarge_2'), 205,31,954,44)
	Infinity_SetArea(('journalLarge_3'), 879,82,52,44)
	Infinity_SetArea(('journalLarge_4'), 437,82,52,44)
	Infinity_SetArea(('journalLarge_5'), 122,90,230,44)
	Infinity_SetArea(('journalLarge_6'), 1012,90,234,44)
	Infinity_SetArea(('journalLarge_7'), 122,90,230,44)
	Infinity_SetArea(('journalLarge_8'), 582,83,200,40)
	Infinity_SetArea(('journalLarge_9'), 538,73,39,65)
	Infinity_SetArea(('journalLarge_10'), 788,73,42,65)
	Infinity_SetArea(('journalLarge_11'), 122,140,200,32)
	Infinity_SetArea(('journalLarge_12'), 124,144,192,29)
	Infinity_SetArea(('journalLarge_13'), 122,141,534,534)
	Infinity_SetArea(('journalLarge_14'), 712,141,534,540)
	Infinity_SetArea(('journalLarge_15'), 122,173,538,502)
	Infinity_SetArea(('journalLarge_16'), 712,173,534,502)
	Infinity_SetArea(('journalLarge_17'), 327,128,162,47)
	Infinity_SetArea(('journalLarge_18'), 489,128,162,47)
	Infinity_SetArea(('journalLarge_19'), 122,148,534,36)
	Infinity_SetArea(('journalLarge_20'), 122,185,534,4)
	Infinity_SetArea(('journalLarge_21'), 122,189,534,42)
	Infinity_SetArea(('journalLarge_22'), 122,231,534,379)
	Infinity_SetArea(('journalLarge_23'), 426,610,162,47)
	Infinity_SetArea(('journalLarge_24'), 190,610,162,47)
	Infinity_SetArea(('journalLarge_25'), 626,196,30,26)
	Infinity_SetArea(('journalLarge_26'), 1012,90,234,44)
end
journalMode = const.JOURNAL_MODE_QUESTS
journalSearchString = ""

function myNotes(row)
	local text = Infinity_FetchString(journalDisplay[row].text)
	if(text == "") then text = journalDisplay[row].text end
	
	--check if the corresponding row to this one contains the string.
	local pairText = nil
	if(journalDisplay[row].title) then
		--check the corresponding entry
		pairText = Infinity_FetchString(journalDisplay[row+1].text) or journalDisplay[row+1].text
		if(pairText == "") then pairText = journalDisplay[row+1].text end 
	else 
		if (journalDisplay[row].entry) then
			pairText = Infinity_FetchString(journalDisplay[row-1].text) or journalDisplay[row-1].text
			if(pairText == "") then pairText = journalDisplay[row-1].text end 
		end
	end
	if(string.find(string.lower(pairText),string.lower(JFStrings.JF_Notes))) then return 1 end -- pair string contains My Notes
	
	if(string.find(string.lower(text),string.lower(JFStrings.JF_Notes))) then return 1 end -- string contains My Notes
	return nil --does not contain My Notes
end
function NotMyNotes(row)
	local text = Infinity_FetchString(journalDisplay[row].text)
	if(text == "") then text = journalDisplay[row].text end
	
	--check if the corresponding row to this one contains the string.
	local pairText = nil
	if(journalDisplay[row].title) then
		--check the corresponding entry
		pairText = Infinity_FetchString(journalDisplay[row+1].text) or journalDisplay[row+1].text
		if(pairText == "") then pairText = journalDisplay[row+1].text end 
	else 
		if (journalDisplay[row].entry) then
			pairText = Infinity_FetchString(journalDisplay[row-1].text) or journalDisplay[row-1].text
			if(pairText == "") then pairText = journalDisplay[row-1].text end 
		end
	end
	if(string.find(string.lower(pairText),string.lower(JFStrings.JF_Notes))) then return nil end -- pair string contains My Notes
	
	if(string.find(string.lower(text),string.lower(JFStrings.JF_Notes))) then return nil end -- string contains My Notes
	return 1 --does contain My Notes
end

`
menu
{
	name 'JOURNAL'
	align center center
	modal lua "JournalSize == UIStrings.UI_Large" 
	onopen
	"
		buildQuestDisplay()
		chapter = math.max(0,Infinity_GetMaxChapterPage())
		questOpened = 0
		journalOpen = 1
		if JournalSize == UIStrings.UI_Large then
			unHideLargeJournal()
			getSidebarButtons_Large()
			PauseJournal()
			Infinity_PopMenu('WORLD_QUICKLOOT');
			Infinity_PopMenu('WORLD_MESSAGES');
			Infinity_PopMenu('WORLD_ACTIONBAR');
		elseif JournalSize == UIStrings.UI_Small then
			positionSmallJournal()
			QFilter = 0
		end
	"
	onclose
	"
		unHideLargeJournal()
		if JournalSize == UIStrings.UI_Large then
			worldScreen:TogglePauseGame(true)
			Infinity_PushMenu('WORLD_MESSAGES')
			Infinity_PushMenu('WORLD_ACTIONBAR')
		end
		journalOpen = 0
	"
	label
	{
		name "journalLarge_1"
		-- enabled "JournalSize == UIStrings.UI_Large"
		area 0 0 1364 756
		mosaic "RGJRNL"
	}
	label
	{
		name "journalLeftBack1"
		enabled "JournalSize == UIStrings.UI_Large"
		area 0 0 119 116
		mosaic RGGAM01
	}
	label
	{
		name "journalLeftBack2"
		enabled "JournalSize == UIStrings.UI_Large"
		area 0 0 400 53
		mosaic RGGAM02
	}
	label
	{
		name "journalRightBack1"
		enabled "JournalSize == UIStrings.UI_Large"
		area 0 0 119 116
		mosaic RGGAM11
	}
	label
	{
		name "journalRightBack2"
		enabled "JournalSize == UIStrings.UI_Large"
		area 0 0 400 53
		mosaic RGGAM12
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large"
		name "journalLeftButton2"
		on 'm'
		area 0 0 48 47
		bam RGGBUT
		sequence 0
		frame lua "rggbuttHighlight2()"
		tooltip lua "getTooltipWithHotkey(4,15418)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(mapScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			e:GetActiveEngine():OnLeftPanelButtonClick(1)
		"
		actionhold
		"
			worldMapScreen:StartWorldMap(0)
			e:SelectEngine(worldMapScreen)
		"
		actionEnter
		"
			rgHighlightMap = 1
		"
		actionExit
		"
			rgHighlightMap = 0
		"
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large"
		name "journalLeftButton3"
		on 'J'
		area 0 0 48 47
		bam RGGBUT
		sequence 2
		frame lua "rggbuttHighlight3()"
		tooltip lua "getTooltipWithHotkey(3,24359)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "showJournal == 1"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
		"
		actionEnter
		"
			rgHighlightJou = 1
		"
		actionExit
		"
			rgHighlightJou = 0
		"
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large"
		name "journalLeftButton4"
		on 'i'
		area 0 0 48 47
		bam RGGBUT
		sequence 1
		frame lua "rggbuttHighlight4()"
		tooltip lua "getTooltipWithHotkey(0,24358)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(inventoryScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			e:GetActiveEngine():OnLeftPanelButtonClick(3)
		"
		actionEnter
		"
			rgHighlightInv = 1
		"
		actionExit
		"
			rgHighlightInv = 0
		"
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large"
		name "journalLeftButton5"
		on 'r'
		area 0 0 48 47
		bam RGGBUT
		sequence 3
		frame lua "rggbuttHighlight5()"
		tooltip lua "getTooltipWithHotkey(1,24356)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(characterScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			e:GetActiveEngine():OnLeftPanelButtonClick(4)
		"
		actionEnter
		"
			rgHighlightRec = 1
		"
		actionExit
		"
			rgHighlightRec = 0
		"
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large"
		name "journalLeftButton6"
		on 'w'
		area 0 0 48 47
		bam RGGBUT
		sequence 4
		frame lua "rggbuttHighlight6()"
		tooltip lua "getTooltipWithHotkey(5,24360)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(mageScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			e:GetActiveEngine():OnLeftPanelButtonClick(5)
		"
		actionEnter
		"
			rgHighlightMag = 1
		"
		actionExit
		"
			rgHighlightMag = 0
		"
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large"
		name "journalLeftButton7"
		on 'p'
		area 0 0 48 47
		bam RGGBUT
		sequence 5
		frame lua "rggbuttHighlight7()"
		tooltip lua "getTooltipWithHotkey(6,24357)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(priestScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			e:GetActiveEngine():OnLeftPanelButtonClick(6)
		"
		actionEnter
		"
			rgHighlightPri = 1
		"
		actionExit
		"
			rgHighlightPri = 0
		"
	}
	label
	{
		name "journalLeftButton8"
		enabled "JournalSize == UIStrings.UI_Large"
		area 0 48 64 68
		bam "CGEAR"
		frame lua "timer:GetCurrentTime()"
	}
	label
	{
		name "journalLeftButton9"
		enabled "JournalSize == UIStrings.UI_Large"
		area 0 48 64 68
		mosaic RGCLOCK
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large and startEngine:GetCampaign() == const.START_CAMPAIGN_BG"
		name "journalLeftButton1a"
		on escape
		area 0 51 58 59
		bam RGGLOGO
		sequence 0
		frame lua "rggbuttHighlight1()"
		tooltip lua "getTooltipWithHotkey(2,24364)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
--		glow lua "highlightSidebarButton(worldScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
		"
		actionEnter
		"
			rgHighlightLog = 1
		"
		actionExit
		"
			rgHighlightLog = 0
		"
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large and startEngine:GetCampaign() == const.START_CAMPAIGN_SOD"
		name "journalLeftButton1b"
		on escape
		area 1 52 58 59
		bam RGGLOGO
		sequence 1
		frame lua "rggbuttHighlight1()"
		tooltip lua "getTooltipWithHotkey(2,24364)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
--		glow lua "highlightSidebarButton(worldScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
		"
		actionEnter
		"
			rgHighlightLog = 1
		"
		actionExit
		"
			rgHighlightLog = 0
		"
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large and startEngine:GetCampaign() == const.START_CAMPAIGN_BP"
		name "journalLeftButton1c"
		on escape
		area 1 51 58 59
		bam RGGLOGO
		sequence 2
		frame lua "rggbuttHighlight1()"
		tooltip lua "getTooltipWithHotkey(2,24364)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
--		glow lua "highlightSidebarButton(worldScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
		"
		actionEnter
		"
			rgHighlightLog = 1
		"
		actionExit
		"
			rgHighlightLog = 0
		"
	}
	button
	{
		name "journalLeftButton10"
		enabled "JournalSize == UIStrings.UI_Large"
		area 379 10 21 52
		bam RGGHID
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large"
		name "journalRightButton7"
		on 'o'
		area 0 0 48 47
		bam RGGOPT
		tooltip lua "getTooltipWithHotkey(7,24362)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		glow lua "highlightSidebarButton(optionsScreen)"
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			e:GetActiveEngine():OnLeftPanelButtonClick(7)
		"
	}
	button
	{
		enabled "JournalSize == UIStrings.UI_Large"
		name "journalRightButton10"
		area 0 0 48 47
		bam RGGBUT
		sequence 7
		frame lua "rggbuttHighlight10()"
		tooltip lua "getTooltipWithHotkey(9,11942)"
		tooltip force lua "sidebarForceTooltips == 1"
		tooltip force top
		clickable lua "sidebarsGreyed ~= 1"
		action
		"
			e:GetActiveEngine():OnRestButtonClick()
		"
		actionEnter
		"
			rgHighlightRes = 1
		"
		actionExit
		"
			rgHighlightRes = 0
		"
	}
	button
	{
		name "journalRightButton8"
		area 40 69 48 47
		enabled "JournalSize == UIStrings.UI_Large"
		bam RGGBUT
		sequence 17
	}
	button
	{
		name "journalRightButton9"
		area 86 69 48 47
		enabled "JournalSize == UIStrings.UI_Large"
		bam RGGBUT
		sequence 15
	}
	button
	{
		name "journalRightButton11"
		area 185 69 48 47
		enabled "JournalSize == UIStrings.UI_Large"
		bam RGGBUT
		sequence 14
	}
	button
	{
		name "journalRightButton12"
		area 233 69 48 47
		enabled "JournalSize == UIStrings.UI_Large"
		bam RGGBUT
		sequence 16
	}
	button
	{
		name "journalRightButton13"
		area 278 68 48 47
		enabled "JournalSize == UIStrings.UI_Large"
		bam RGGBUT
		sequence 18
	}
	button
	{
		name "journalRightButton14"
		enabled "JournalSize == UIStrings.UI_Large"
		area 379 10 21 52
		bam RGGHID
		sequence 1
	}
	--button
	--{
	--	name "journalRightButton1"
	--	area 8 14 64 90
	--	portrait 0
	--	mosaic RGGFRM2
	--	enabled "Infinity_GetNumCharacters() > 0 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 0"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton1a"
	--	area 5 10 69 97
	--	bam RGGFRM
	--	enabled "Infinity_GetNumCharacters() > 0 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 0"
	--	action "Infinity_OnPortraitLClick(0)"
	--	actionAlt "e:GetActiveEngine():OnLeftPanelButtonClick(2)"
	--	actionDbl "Infinity_OnPortraitDblClick(0)"
	--	actiondrag "Infinity_SwapWithPortrait(0)"
	--	actionEnter "mouseOverPortrait = 0"
	--	actionExit "mouseOverPortrait = -1"
	--	actionSimpleDrag "draggedPortrait = 0"
	--	actionSimpleDrop "swapPortraits(0)"
	--	tooltip lua "Infinity_GetPortraitTooltip(0)"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton2"
	--	area 8 112 64 90
	--	portrait 1
	--	mosaic RGGFRM2
	--	enabled "Infinity_GetNumCharacters() > 1 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 1"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton2a"
	--	area 5 108 69 97
	--	bam RGGFRM
	--	enabled "Infinity_GetNumCharacters() > 1 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 1"
	--	action "Infinity_OnPortraitLClick(1)"
	--	actionAlt "e:GetActiveEngine():OnLeftPanelButtonClick(2)"
	--	actionDbl "Infinity_OnPortraitDblClick(1)"
	--	actiondrag "Infinity_SwapWithPortrait(1)"
	--	actionEnter "mouseOverPortrait = 1"
	--	actionExit "mouseOverPortrait = -1"
	--	actionSimpleDrag "draggedPortrait = 1"
	--	actionSimpleDrop "swapPortraits(1)"
	--	tooltip lua "Infinity_GetPortraitTooltip(1)"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton3"
	--	area 8 210 64 90
	--	portrait 2
	--	mosaic RGGFRM2
	--	enabled "Infinity_GetNumCharacters() > 2 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 2"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton3a"
	--	area 5 206 69 97
	--	bam RGGFRM
	--	enabled "Infinity_GetNumCharacters() > 2 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 2"
	--	action "Infinity_OnPortraitLClick(2)"
	--	actionAlt "e:GetActiveEngine():OnLeftPanelButtonClick(2)"
	--	actionDbl "Infinity_OnPortraitDblClick(2)"
	--	actiondrag "Infinity_SwapWithPortrait(2)"
	--	actionEnter "mouseOverPortrait = 2"
	--	actionExit "mouseOverPortrait = -1"
	--	actionSimpleDrag "draggedPortrait = 2"
	--	actionSimpleDrop "swapPortraits(2)"
	--	tooltip lua "Infinity_GetPortraitTooltip(2)"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton4"
	--	area 8 308 64 90
	--	portrait 3
	--	mosaic RGGFRM2
	--	enabled "Infinity_GetNumCharacters() > 3 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 3"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton4a"
	--	area 5 304 69 97
	--	bam RGGFRM
	--	enabled "Infinity_GetNumCharacters() > 3 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 3"
	--	action "Infinity_OnPortraitLClick(3)"
	--	actionAlt "e:GetActiveEngine():OnLeftPanelButtonClick(2)"
	--	actionDbl "Infinity_OnPortraitDblClick(3)"
	--	actiondrag "Infinity_SwapWithPortrait(3)"
	--	actionEnter "mouseOverPortrait = 3"
	--	actionExit "mouseOverPortrait = -1"
	--	actionSimpleDrag "draggedPortrait = 3"
	--	actionSimpleDrop "swapPortraits(3)"
	--	tooltip lua "Infinity_GetPortraitTooltip(3)"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton5"
	--	area 8 406 64 90
	--	portrait 4
	--	mosaic RGGFRM2
	--	enabled "Infinity_GetNumCharacters() > 4 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 4"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton5a"
	--	area 5 402 69 97
	--	bam RGGFRM
	--	enabled "Infinity_GetNumCharacters() > 4 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 4"
	--	action "Infinity_OnPortraitLClick(4)"
	--	actionAlt "e:GetActiveEngine():OnLeftPanelButtonClick(2)"
	--	actionDbl "Infinity_OnPortraitDblClick(4)"
	--	actiondrag "Infinity_SwapWithPortrait(4)"
	--	actionEnter "mouseOverPortrait = 4"
	--	actionExit "mouseOverPortrait = -1"
	--	actionSimpleDrag "draggedPortrait = 4"
	--	actionSimpleDrop "swapPortraits(4)"
	--	tooltip lua "Infinity_GetPortraitTooltip(4)"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton6"
	--	area 8 504 64 90
	--	portrait 5
	--	mosaic RGGFRM2
	--	enabled "Infinity_GetNumCharacters() > 5 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 5"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	--button
	--{
	--	name "journalRightButton6a"
	--	area 5 500 69 97
	--	bam RGGFRM
	--	enabled "Infinity_GetNumCharacters() > 5 and rgEscPortrait ~= 1 and JournalSize == UIStrings.UI_Large"
	--	glow lua "draggedPortrait and draggedPortrait ~= 5"
	--	action "Infinity_OnPortraitLClick(5)"
	--	actionAlt "e:GetActiveEngine():OnLeftPanelButtonClick(2)"
	--	actionDbl "Infinity_OnPortraitDblClick(5)"
	--	actiondrag "Infinity_SwapWithPortrait(5)"
	--	actionEnter "mouseOverPortrait = 5"
	--	actionExit "mouseOverPortrait = -1"
	--	actionSimpleDrag "draggedPortrait = 5"
	--	actionSimpleDrop "swapPortraits(5)"
	--	tooltip lua "Infinity_GetPortraitTooltip(5)"
	--	clickable lua "sidebarsGreyed ~= 1"
	--}
	label
	{
		name "journalLarge_2"
		-- enabled "JournalSize == UIStrings.UI_Large"
		area 205 31 954 44
		text "JOURNAL_LABEL"
		text style "title"
	}
	button
	{
		name "journalLarge_3"
		-- enabled "JournalSize == UIStrings.UI_Large"
		area 879 82 52 44
--		text "JOURNAL_LABEL"
--		text style "label_parchment"
--		text point 16
		bam "RGQBUT1"
		sequence 1
		glow lua "journalMode == const.JOURNAL_MODE_JOURNAL"
		action "journalMode = const.JOURNAL_MODE_JOURNAL"
	}
	button
	{
		name "journalLarge_4"
		-- enabled "JournalSize == UIStrings.UI_Large"
		area 437 82 52 44
--		text "QUESTS_LABEL"
--		text style "label_parchment"
--		text point 16
		bam "RGQBUT1"
		sequence 0
		glow lua "journalMode == const.JOURNAL_MODE_QUESTS"
		action "journalMode = const.JOURNAL_MODE_QUESTS"
	}
	button
	{
		name "journalLarge_5"
		area 122 90 230 44
		enabled "journalMode == const.JOURNAL_MODE_QUESTS"
		text 'RG_CURRENT_QUESTS'
		text style "label_parchment"
		text point 16
		action
		"
			CloseAll(1)
		"
	}
	button
	{
		name "journalLarge_6"
		area 1012 90 234 44
		enabled "journalMode == const.JOURNAL_MODE_QUESTS"
		text 'RG_FINISHED_QUESTS'
		text style "label_parchment"
		text point 16
		action
		"
			CloseAll(2)
		"
	}
	label
	{
		area 122 90 230 44
		name "journalLarge_7"
		enabled "journalMode == const.JOURNAL_MODE_JOURNAL"
		text "JOURNAL_LABEL"
		text style "label_parchment"
		text point 16
	}
	label
	{
		area 1012 90 230 44
		name "journalLarge_26"
		enabled "journalMode == const.JOURNAL_MODE_JOURNAL"
		text lua "string.sub(JFStrings.JF_Notes, 1, string.len(JFStrings.JF_Notes) - 1)"
		text style "label_parchment"
		text point 16
	}
	button -- Chapter
	{
		name "journalLarge_8"
		-- enabled "JournalSize == UIStrings.UI_Large"
		area 582 83 200 40
		text lua "chapterText()"
		text style "label"
		bam "GUIBUTNT"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			if JournalSize == UIStrings.UI_Large then
				JournalSize = UIStrings.UI_Small
			else
				JournalSize = UIStrings.UI_Large
			end
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
		"
	}
	button --prev chapter
	{
		name "journalLarge_9"
		-- enabled "JournalSize == UIStrings.UI_Large"
		area		538 73 39 65
		bam "GUIPRC"
		sequence 3
		
		action
		"
			incrChapter(-1);
		"	
	}
	button
	{
		name "journalLarge_10"
		-- enabled "JournalSize == UIStrings.UI_Large"
		area		788 73 42 65
		bam "GUIPRC"
		sequence 2
		
		action
		"
			incrChapter(1);
		"	
	}
	--[Bug #20368] Recent events button cut for now.
	--
	--button
	--{
	--	enabled "journalMode == const.JOURNAL_MODE_QUESTS"
	--	area 278 616 162 47
	--	bam "PAPERBUT"
	--	sequence 1
	--	text "RECENT_EVENTS_LABEL"
	--	text style "button_parchment"
	--	action 
	--	"
	--		Infinity_PushMenu('JOURNAL_RECENT_EVENTS')
	--	"
	--}
	label
	{
		name "journalLarge_11"
		enabled "journalMode == const.JOURNAL_MODE_JOURNAL"
		area 122 140 200 32
		fill 50 50 50 150
	}
	edit
	{
		name "journalLarge_12"
		enabled "journalMode == const.JOURNAL_MODE_JOURNAL"
		area 124 144 192 29
		var journalSearchString
		placeholder "ENTER_SEARCH_TERM_NORMAL"
		text style "edit"
		maxlines 1
	}
	list
	{
		column
		{
			width 5
			label
			{
				area 0 0 31 31
				enabled "getArrowEnabled(rowNumber) and hideFinished(rowNumber)"
				bam "PCHEV"
				frame lua "getArrowFrame(rowNumber)"
				text style "label_parchment"
				align top center
			}
		}
		column { 
			width 95 
			label
			{
				enabled "questEnabled(rowNumber) and hideFinished(rowNumber)"
				area 0 0 400 38
				mosaic RGQBACK
			}
			label
			{	
				enabled "questEnabled(rowNumber) and hideFinished(rowNumber)"
				area 16 0 400 38
				text lua "getQuestText(rowNumber)"
				text style "normal_parchment"
				--text color '5'
				align left center
			}
			label
			{
				enabled "objectiveEnabled(rowNumber) and hideFinished(rowNumber)"
				area 16 0 -1 -1
				pad 0 10 0 10
				text lua "getObjectiveText(rowNumber)"
				text style "normal_parchment"
			}
			label
			{
				enabled "entryEnabled(rowNumber) and hideFinished(rowNumber)"
				area 16 0 -1 -1
--				pad 0 10 0 10
				text lua "getEntryText(rowNumber)"
				text style "normal_parchment"
				text color M
			}
		}
		name "journalLarge_13"
		enabled "journalMode == const.JOURNAL_MODE_QUESTS"
		rowheight	dynamic
		hidehighlight
		seperator "showObjectiveSeperator(rowNumber)"
		table		"questDisplay"
		var			selectedQuest
		scrollbar	'GUISCRP'
		area		122 141 534 534
		action
		"
			if(questDisplay[selectedQuest].expanded) then 
				questDisplay[selectedQuest].expanded = nil
			else
				questDisplay[selectedQuest].expanded = 1
			end
		"
				
	}
	list
	{
		column
		{
			width 5
			label
			{
				area 0 0 31 31
				enabled "getArrowEnabled(rowNumber) and hideUnfinished(rowNumber)"
				bam "PCHEV"
				frame lua "getArrowFrame(rowNumber)"
				text style "label_parchment"
				align top center
			}
		}
		column { 
			width 95 
			label
			{
				enabled "questEnabled(rowNumber) and hideUnfinished(rowNumber)"
				area 0 0 400 38
				mosaic RGQBACK
			}
			label
			{	
				enabled "questEnabled(rowNumber) and hideUnfinished(rowNumber)"
				area 16 0 400 38
				text lua "getQuestText(rowNumber)"
				text style "normal_parchment"
				align left center
			}
			label
			{
				enabled "objectiveEnabled(rowNumber) and hideUnfinished(rowNumber)"
				area 16 0 -1 -1
				pad 0 10 0 10
				text lua "getObjectiveText(rowNumber)"
				text style "normal_parchment"
			}
			label
			{
				enabled "entryEnabled(rowNumber) and hideUnfinished(rowNumber)"
				area 16 0 -1 -1
--				pad 0 10 0 10
				text lua "getEntryText(rowNumber)"
				text style "normal_parchment"
				text color M
			}
		}
		name "journalLarge_14"
		enabled "journalMode == const.JOURNAL_MODE_QUESTS"
		rowheight	dynamic
		hidehighlight
		seperator "showObjectiveSeperator(rowNumber)"
		table		"questDisplay"
		var			selectedQuest
		scrollbar	'GUISCRP'
		area		712 141 534 540
		action
		"
			if(questDisplay[selectedQuest].expanded) then 
				questDisplay[selectedQuest].expanded = nil
			else
				questDisplay[selectedQuest].expanded = 1
			end
		"
				
	}
	
	list --journal
	{
		column
		{
			width 100
			--light
			label
			{
				enabled "getJournalTitleEnabled(rowNumber) and not getJournalDarken(rowNumber) and NotMyNotes(rowNumber)"
				area 0 0 -1 -1
				pad 0 16 0 0
				text lua "getJournalTitleText(rowNumber)"
				text style "label_parchment"
				text color 0 120 0 255
			}
			label
			{
				enabled "getJournalEntryEnabled(rowNumber) and NotMyNotes(rowNumber) and not getJournalDarken(rowNumber)"
				area 0 0 -1 -1
				pad 8 16 0 16
				text lua "getJournalEditedColours(getJournalEntryText(rowNumber))"
				text style "normal_parchment"
			}
			
			--dark
			label
			{
				enabled "NotMyNotes(rowNumber) and getJournalDarken(rowNumber) and (getJournalTitleEnabled(rowNumber) or getJournalEntryEnabled(rowNumber))"
				area 0 0 -1 -1
				fill 0 0 0 150
			}
			label
			{
				enabled "getJournalTitleEnabled(rowNumber) and getJournalDarken(rowNumber) and NotMyNotes(rowNumber)"
				area 0 0 -1 -1
				pad 0 16 0 0
				text lua "getJournalTitleText(rowNumber)"
				text style "label_parchment"
				text color 255 100 100 255
			}
			label
			{
				enabled "getJournalEntryEnabled(rowNumber) and getJournalDarken(rowNumber) and NotMyNotes(rowNumber)"
				area 0 0 -1 -1
				pad 8 16 0 16
				text lua "getJournalEditedColours(getJournalEntryText(rowNumber))"
				text style "normal_parchment"
				text color 'B'
			}
			
			
		}
		name "journalLarge_15"
		enabled "journalMode == const.JOURNAL_MODE_JOURNAL"
		seperator "getJournalEntryEnabled(rowNumber)"
		rowheight	dynamic
		hidehighlight
		table		"journalDisplay"
		var			selectedJournal
		scrollbar	'GUISCRP'
		area		122 173 538 502
		actionDbl
		"
			LargeEditAction()
		"
	}
	list --journal
	{
		column
		{
			width 100
			--light
			label
			{
				enabled "getJournalTitleEnabled(rowNumber) and not getJournalDarken(rowNumber) and myNotes(rowNumber)"
				area 0 0 -1 -1
				pad 0 16 0 0
				text lua "getJournalTitleText(rowNumber)"
				text style "label_parchment"
				text color 0 120 0 255
			}
			label
			{
				enabled "getJournalEntryEnabled(rowNumber) and not getJournalDarken(rowNumber) and myNotes(rowNumber)"
				area 0 0 -1 -1
				pad 8 16 0 16
				text lua "string.sub(getJournalEntryText(rowNumber),string.len(JFStrings.JF_Notes)+2)"
				text style "normal_parchment"
			}
			
			--dark
			label
			{
				enabled "myNotes(rowNumber) and getJournalDarken(rowNumber) and (getJournalTitleEnabled(rowNumber) or getJournalEntryEnabled(rowNumber))"
				area 0 0 -1 -1
				fill 0 0 0 150
			}
			label
			{
				enabled "getJournalTitleEnabled(rowNumber) and getJournalDarken(rowNumber) and myNotes(rowNumber)"
				area 0 0 -1 -1
				pad 0 16 0 0
				text lua "getJournalTitleText(rowNumber)"
				text style "label_parchment"
				text color 255 100 100 255
			}
			label
			{
				enabled "getJournalEntryEnabled(rowNumber) and getJournalDarken(rowNumber) and myNotes(rowNumber)"
				area 0 0 -1 -1
				pad 8 16 0 16
				text lua "string.sub(getJournalEntryText(rowNumber),string.len(JFStrings.JF_Notes)+2)"
				text style "normal_parchment"
				text color 'B'
			}
			
			
		}
		name "journalLarge_16"
		enabled "journalMode == const.JOURNAL_MODE_JOURNAL"
		seperator "getJournalEntryEnabled(rowNumber)"
		rowheight	dynamic
		hidehighlight
		table		"journalDisplay"
		var			selectedJournal
		scrollbar	'GUISCRP'
		area		712 173 534 502
		actionDbl
		"
			LargeEditAction()
		"
	}
	button
	{
		name "journalLarge_17"
		enabled "journalMode == const.JOURNAL_MODE_JOURNAL"
		area 327 128 162 47
		bam "PAPERBUT"
		sequence 1
		text "ADD_ENTRY_LABEL"
		text style "button_parchment"
		action 
		"
			journalMode = const.JOURNAL_MODE_EDIT
			journalNoteEdit = ''
			journalNoteEditRef = nil
		"
	}
	button
	{
		name "journalLarge_18"
		enabled "journalMode == const.JOURNAL_MODE_JOURNAL"
		clickable lua "journalEntryClickable(selectedJournal)"
		area 489 128 162 47
		bam "PAPERBUT"
		sequence 1
		text "EDIT_ENTRY_LABEL"
		text style "button_parchment"
		action
		"
			LargeEditAction()
		"
	}
	
	
	label
	{
		name "journalLarge_19"
		enabled "journalMode == const.JOURNAL_MODE_EDIT"
		area 122 148 534 36
		text style "normal_parchment"
		text "WRITE_ENTRY_TEXT"
		
	}
	label
	{
		name "journalLarge_20"
		enabled "journalMode == const.JOURNAL_MODE_EDIT"
		area 122 185 534 4
		fill 10 71 1 255
	}
	label
	{
		name "journalLarge_21"
		enabled "journalMode == const.JOURNAL_MODE_EDIT"
		area 122 189 534 42
		text style "label"
		text color 0 120 0 255
		text lua "Infinity_GetTimeString()"
	}
	edit
	{
		name "journalLarge_22"
		enabled "journalMode == const.JOURNAL_MODE_EDIT"
		area		122 231 534 379
		text style	"edit_parchment"
		var			journalNoteEdit
		scrollbar	'GUISCRP'
	}
	
	button
	{
		name "journalLarge_23"
		enabled "journalMode == const.JOURNAL_MODE_EDIT"
		area 426 610 162 47
		bam "PAPERBUT"
		sequence 1
		text "CANCEL_BUTTON"
		text style "button_parchment"
		action 
		"
			journalMode = const.JOURNAL_MODE_JOURNAL
		"
	}
	button
	{
		name "journalLarge_24"
		enabled "journalMode == const.JOURNAL_MODE_EDIT and journalNoteEdit ~= ''"
		area 190 610 162 47
		bam "PAPERBUT"
		sequence 1
		text "DONE_BUTTON"
		text style "button_parchment"
		action 
		"
			if (journalNoteEditRef == nil) then
				journalNoteEdit = JFStrings.JF_Notes .. '\n\n' .. journalNoteEdit .. '\n - ' .. Infinity_GetTimeString() 
				Infinity_OnAddUserEntry(journalNoteEdit)
			else
				if string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Notes)) then
					journalNoteEdit = JFStrings.JF_Notes .. '\n\n' .. journalNoteEdit .. '\n - ' .. Infinity_GetTimeString() 
				else
					journalNoteEdit = JFStrings.JF_Edited .. '\n\n' .. journalNoteEdit .. '\n -' .. Infinity_GetTimeString()
				end
				Infinity_OnEditUserEntry(journalNoteEditRef, journalNoteEdit)
			end
			journalMode = const.JOURNAL_MODE_JOURNAL
		"
	}
	button
	{
		name 		"journalLarge_25"
		enabled 	"journalMode == const.JOURNAL_MODE_EDIT and string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Notes))"
		area 		626 196 30 26
		text 		"X"
		text style 	"button_parchment"
		text align 	center center
		text color	R
		action 
		"
			journalNoteEditRef = getJournalEntryRef_Small(selectedJournal)
			journalNoteOld = Infinity_FetchString(journalNoteEditRef)
			
			if string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Notes)) then
				journalNoteEditRef = getJournalEntryRef_Small(selectedJournal)
				journalNoteEdit = ''
			end
			Infinity_OnEditUserEntry(journalNoteEditRef, journalNoteEdit)
			journalMode = const.JOURNAL_MODE_JOURNAL
		"
	}
	
-- JOURNALSIZE is SMALL
	
	label --background background
	{
		name 		"JournalSmall_Background"
		enabled 	"JournalSize == UIStrings.UI_Small"
		area 		0 0 501 756
		mosaic 		"QUESTBAK"
	}
	label --Background
	{
		name 		"JournalSmall_1"
		enabled 	"JournalSize == UIStrings.UI_Small"
		area  		0 0 485 747
		bam 		"QUESTBG"
		sequence 	0
		frame lua 	"getJournalBackgroundFrame_Small()"
	}
	handle
	{
		name 		"JournalSmall_2"
		enabled 	"JournalSize == UIStrings.UI_Small"
		area 		0 0 472 80
		actionDrag
		"
			dragJournal(motionX,motionY)
		"
	}
	button
	{
		name 		"JournalSmall_3"
		enabled 	"JournalSize == UIStrings.UI_Small"
		area		218 18 136 42
		text 		"JOURNAL_LABEL"
		text style 	"label_parchment"
		text point 	16
		action
		"
		CloseAll_Small()
		CheckForOpenedQuests_Small()
		journalMode = const.JOURNAL_MODE_JOURNAL
		"
	}
	button
	{
		name 		"JournalSmall_4"
		enabled 	"JournalSize == UIStrings.UI_Small"
		area 		34 18 136 42
		text 		"QUESTS_LABEL"
		text style 	"label_parchment"
		text point 	16
		action
		"
		CloseAll_Small()
		CheckForOpenedQuests_Small()
		journalMode = const.JOURNAL_MODE_QUESTS
		"
	}
	button
	{
		name 		"JournalSmall_6"
		area 		84 140 118 35
		enabled 	"journalMode == const.JOURNAL_MODE_QUESTS and JournalSize == UIStrings.UI_Small"
		text lua 	"highlightFilter_Small(t(JFStrings.JF_All))"
		text style 	"label_parchment"
		text point 	12
		action
		"
			CloseAll_Small()
			CheckForOpenedQuests_Small()
			QFilter = 0
		"
	}
	button
	{
		name 		"JournalSmall_7"
		area 		202 140 118 35
		enabled 	"journalMode == const.JOURNAL_MODE_QUESTS and JournalSize == UIStrings.UI_Small"
		text lua 	"highlightFilter_Small(t(JFStrings.JF_Active))"
		text style 	"label_parchment"
		text point 	12
		action
		"
			CloseAll_Small()
			CheckForOpenedQuests_Small()
			QFilter = 1
		"
	}
	button
	{
		name 		"JournalSmall_8"
		area 		320 140 120 35
		enabled 	"journalMode == const.JOURNAL_MODE_QUESTS and JournalSize == UIStrings.UI_Small"
		text lua 	"highlightFilter_Small(t(JFStrings.JF_Completed))"
		text style 	"label_parchment"
		text point 	12
		action
		"
			CloseAll_Small()
			CheckForOpenedQuests_Small()
			QFilter = 2
		"
	}
	button
	{
		name 		"JournalSmall_9"
		enabled 	"JournalSize == UIStrings.UI_Small"
		area 		419 13 66 67
		on esc
		bam 		"XBUTT"
		action 
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
		"
	}
	button -- Chapter
	{
		name 		"JournalSmall_10"
		enabled 	"JournalSize == UIStrings.UI_Small"
		area 		170 80 146 60
		text lua 	"chapterText()"		-- Not small specific
		text style 	"label_parchment"
		mosaic 		"PCHAPTER"
		action
		"
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			if JournalSize == UIStrings.UI_Large then
				JournalSize = UIStrings.UI_Small
			else
				JournalSize = UIStrings.UI_Large
			end
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
		"
	}
	button --prev chapter
	{
		name 		"JournalSmall_11"
		enabled 	"JournalSize == UIStrings.UI_Small"
		area		134 80 41 60
		bam 		"PARROW"
		sequence 	0
		action
		"
			incrChapter(-1)
		"	
	}
	button
	{
		name 		"JournalSmall_12"
		enabled 	"JournalSize == UIStrings.UI_Small"
		area		306 80 41 60
		bam 		"PARROW"
		sequence 	1
		action
		"
			incrChapter(1)
		"	
	}
	--[Bug #20368] Recent events button cut for now.
	--
	--button
	--{
	--	enabled "journalMode == const.JOURNAL_MODE_QUESTS and JournalSize == UIStrings.UI_Small"
	--	area 278 616 162 47
	--	bam "PAPERBUT"
	--	sequence 1
	--	text "RECENT_EVENTS_LABEL"
	--	text style "button_parchment"
	--	action 
	--	"
	--		Infinity_PushMenu('JOURNAL_RECENT_EVENTS_Small')
	--	"
	--}
	label
	{
		name 		"JournalSmall_13"
		enabled 	"journalMode == const.JOURNAL_MODE_JOURNAL and JournalSize == UIStrings.UI_Small"
		area 		44 175 382 29
		fill 		50 50 50 150
	}
	edit
	{
		name 		"JournalSmall_14"
		enabled 	"journalMode == const.JOURNAL_MODE_JOURNAL and JournalSize == UIStrings.UI_Small"
		area 		62 180 357 20
		var 		journalSearchString
		placeholder "ENTER_SEARCH_TERM_NORMAL"
		text style 	"edit"
		maxlines 	1
	}
	list
	{
		column
		{
			width 10
			label
			{
				area 		0 0 31 31
				enabled 	"getArrowEnabled_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				bam 		"PCHEV"
				frame lua 	"getArrowFrame_Small(rowNumber)"
				text style 	"label_parchment"
				align 		top center
			}
		}
		column { 
			width 90 
			label
			{
				enabled 	"questEnabled_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				area 		0 0 -1 -1
				mosaic 		rgjback
			}
			label
			{	
				enabled 	"questEnabled_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				area 		8 0 -1 -1
				text lua 	"getQuestText_Small(rowNumber)"
				text style 	"label"
				align 		left center
			}
			label
			{
				enabled 	"objectiveEnabled_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				area 		16 0 -1 -1
				pad 		0 10 0 10
				text lua 	"getObjectiveText_Small(rowNumber)"
				text style 	"normal_parchment"
			}
			label
			{
				enabled 	"entryEnabled_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				area 		16 0 -1 -1
				pad 		0 10 0 10
				text lua 	"getEntryText_Small(rowNumber)"
				text style 	"normal_parchment"
				text color 	M
			}
		}
		name 		"JournalSmall_15"
		enabled 	"journalMode == const.JOURNAL_MODE_QUESTS and JournalSize == UIStrings.UI_Small"
		rowheight	dynamic
		hidehighlight
		seperator 	"showObjectiveSeperator_Small(rowNumber)"
		table		"questDisplay"
		var			selectedQuest
		scrollbar	'GUISCRP'
		area		44 174 396 490
		action
		"
			if(questDisplay[selectedQuest].expanded) then 
				questDisplay[selectedQuest].expanded = nil
			else
				questDisplay[selectedQuest].expanded = 1
			end
			CheckForOpenedQuests_Small()
		"
		
	}
	
	list --journal
	{
		column
		{
			width 100
			--light
			label
			{
				enabled 	"getJournalTitleEnabled_Small(rowNumber) and not getJournalDarken_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				area 		0 0 -1 -1
				pad 		0 16 0 0
				text lua 	"getJournalTitleText_Small(rowNumber)"
				text style 	"label_parchment"
				text color 	0 60 0 255
			}
			label
			{
				enabled 	"getJournalEntryEnabled_Small(rowNumber) and not getJournalDarken_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				area 		0 0 -1 -1
				pad 		8 16 0 16
				text lua 	"getJournalEditedColours(getJournalEntryText_Small(rowNumber))"
				text style 	"normal_parchment"
			}
			
			--dark
			label
			{
				enabled 	"(getJournalTitleEnabled_Small(rowNumber) or getJournalEntryEnabled_Small(rowNumber)) and getJournalDarken_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				area 		0 0 -1 -1
				fill 		0 0 0 150
			}
			label
			{
				enabled 	"getJournalTitleEnabled_Small(rowNumber) and getJournalDarken_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				area 		0 0 -1 -1
				pad 		0 16 0 0
				text lua 	"getJournalTitleText_Small(rowNumber)"
				text style 	"label_parchment"
				text color 	255 100 100 255
			}
			label
			{
				enabled 	"getJournalEntryEnabled_Small(rowNumber) and getJournalDarken_Small(rowNumber) and JournalSize == UIStrings.UI_Small"
				area 		0 0 -1 -1
				pad 		8 16 0 16
				text lua 	"getJournalEditedColours(getJournalEntryText_Small(rowNumber))"
				text style 	"normal_parchment"
				text color 	'B'
			}
			
			
		}
		name 		"JournalSmall_16"
		enabled 	"journalMode == const.JOURNAL_MODE_JOURNAL and JournalSize == UIStrings.UI_Small"
		seperator 	"getJournalEntryEnabled_Small(rowNumber)"
		rowheight	dynamic
		hidehighlight
		table		"journalDisplay"
		var			selectedJournal
		scrollbar	'GUISCRP'
		area		44 208 396 488
		actionDbl
		"
			SmallEditAction()
		"
	}
	button
	{
		name 		"JournalSmall_17"
		enabled 	"journalMode == const.JOURNAL_MODE_JOURNAL and JournalSize == UIStrings.UI_Small"
		area 		44 140 132 35
		text 		"ADD_ENTRY_LABEL"
		text style "button_parchment"
		action 
		"
			journalMode = const.JOURNAL_MODE_EDIT
			journalNoteEdit = ''
			journalNoteEditRef = nil
		"
	}
	button
	{
		name 		"JournalSmall_18"
		enabled 	"journalMode == const.JOURNAL_MODE_JOURNAL and JournalSize == UIStrings.UI_Small"
		clickable 	lua "journalEntryClickable_Small(selectedJournal)"
		area 		176 140 132 35
		text 		"EDIT_ENTRY_LABEL"
		text style 	"button_parchment"
		action
		"
			SmallEditAction()
		"
	}
	button
	{
		name 		"JournalSmall_19"
		enabled 	"journalMode == const.JOURNAL_MODE_JOURNAL and JournalSize == UIStrings.UI_Small"
		area 		308 140 132 35
		sequence 	1
		text lua	"JFStrings.JF_Notes"
		text style "button_parchment"
		action 
		"
			if journalSearchString == JFStrings.JF_Notes then
				journalSearchString = ''
			else
				journalSearchString = JFStrings.JF_Notes
			end
		"
	}
	label
	{
		name 		"JournalSmall_20"
		enabled 	"journalMode == const.JOURNAL_MODE_EDIT and JournalSize == UIStrings.UI_Small"
		area 		58 154 382 26
		text style 	"normal_parchment"
		text 		"WRITE_ENTRY_TEXT"
		
	}
	label
	{
		name 		"JournalSmall_21"
		enabled 	"journalMode == const.JOURNAL_MODE_EDIT and JournalSize == UIStrings.UI_Small"
		area 		58 200 382 4
		fill 		10 71 1 255
	}
	label
	{
		name 		"JournalSmall_22"
		enabled 	"journalMode == const.JOURNAL_MODE_EDIT and JournalSize == UIStrings.UI_Small"
		area 		58 204 382 26
		text style 	"label"
		text color 	0 120 0 255
		text lua 	"Infinity_GetTimeString()"
	}
	edit
	{
		name 		"JournalSmall_23"
		enabled 	"journalMode == const.JOURNAL_MODE_EDIT and JournalSize == UIStrings.UI_Small"
		area		58 230 382 411
		text style	"edit_parchment"
		var			journalNoteEdit
		scrollbar	'GUISCRP'
		
	}
	
	button
	{
		name 		"JournalSmall_24"
		enabled 	"journalMode == const.JOURNAL_MODE_EDIT and JournalSize == UIStrings.UI_Small"
		area 		58 641 162 47
		bam 		"PAPERBUT"
		sequence	1
		text 		"CANCEL_BUTTON"
		text style 	"button_parchment"
		action 
		"
			journalMode = const.JOURNAL_MODE_JOURNAL
		"
	}
	button
	{
		name "JournalSmall_25"
		enabled "journalMode == const.JOURNAL_MODE_EDIT and JournalSize == UIStrings.UI_Small and journalNoteEdit ~= ''"
		area 260 641 162 47
		bam "PAPERBUT"
		sequence 1
		text "DONE_BUTTON"
		text style "button_parchment"
		action 
		"
			if (journalNoteEditRef == nil) then
				journalNoteEdit = JFStrings.JF_Notes .. '\n\n' .. journalNoteEdit .. '\n - ' .. Infinity_GetTimeString() 
				Infinity_OnAddUserEntry(journalNoteEdit)
			else
				if string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Notes)) then
					journalNoteEdit = JFStrings.JF_Notes .. '\n\n' .. journalNoteEdit .. '\n - ' .. Infinity_GetTimeString() 
				else
					journalNoteEdit = JFStrings.JF_Edited .. '\n\n' .. journalNoteEdit .. '\n -' .. Infinity_GetTimeString()
				end
				Infinity_OnEditUserEntry(journalNoteEditRef, journalNoteEdit)
			end
			journalMode = const.JOURNAL_MODE_JOURNAL
		"
	}
	button
	{
		name 		"JournalSmall_26"
		enabled 	"journalMode == const.JOURNAL_MODE_EDIT and JournalSize == UIStrings.UI_Small and string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Notes))"
		area 		400 204 30 26
		text 		"X"
		text style 	"button_parchment"
		text align 	center center
		text color	R
		action 
		"
			journalNoteEditRef = getJournalEntryRef_Small(selectedJournal)
			journalNoteOld = Infinity_FetchString(journalNoteEditRef)
			
			if string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Notes)) then
				journalNoteEditRef = getJournalEntryRef_Small(selectedJournal)
				journalNoteEdit = ''
			end
			Infinity_OnEditUserEntry(journalNoteEditRef, journalNoteEdit)
			journalMode = const.JOURNAL_MODE_JOURNAL
		"
	}
}
`
function SmallEditAction()
	journalNoteEditRef = getJournalEntryRef_Small(selectedJournal)
	journalNoteOld = Infinity_FetchString(journalNoteEditRef)
	if string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Notes)) then
		journalNoteEdit = string.sub(journalNoteOld,string.len(JFStrings.JF_Notes)+2) .. '\n\n'
	elseif string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Edited)) then
		journalNoteEdit = string.sub(journalNoteOld,string.len(JFStrings.JF_Edited)+2) .. '\n\n'
	else
		journalNoteEdit = journalNoteOld .. '\n\n'
	end
	journalMode = const.JOURNAL_MODE_EDIT
end
function LargeEditAction()
	journalNoteEditRef = getJournalEntryRef(selectedJournal)
	journalNoteOld = Infinity_FetchString(journalNoteEditRef)
	if string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Notes)) then
		journalNoteEdit = string.sub(journalNoteOld,string.len(JFStrings.JF_Notes)+2) .. '\n\n'
	elseif string.find(string.lower(journalNoteOld),string.lower(JFStrings.JF_Edited)) then
		journalNoteEdit = string.sub(journalNoteOld,string.len(JFStrings.JF_Edited)+2) .. '\n\n'
	else
		journalNoteEdit = journalNoteOld .. '\n\n'
	end
	journalMode = const.JOURNAL_MODE_EDIT
end

function processQuestsWithStyle()
	out = ""
	for k,v in pairs(quests_old) do
		local questStrref = v[3]
		out = out .. "createQuest    ( " .. questStrref .. " )\n"
		
		for k2,v2 in pairs(journals_quests_old) do
			if(v2[2] == k) then
				local subgroup = v2[const.ENTRIES_IDX_SUBGROUP]
				if(subgroup == 0) then subgroup = "nil" end
				out = out .. "createEntry    ( " .. questStrref .. ", -1, " .. v2[1] .. ", {}, " .. subgroup .." )\n"
			end
		end
	end
	Infinity_Log(out)
end
`
-- menu
-- {
	-- name 'JOURNAL_RECENT_EVENTS'
	-- align center center
	-- modal
	-- label
	-- {
		-- enabled "JournalSize == UIStrings.UI_Large"
		-- area 0 0 672 672
		-- mosaic "RECENTEV"
		
	-- }
	-- label
	-- {
		-- enabled "JournalSize == UIStrings.UI_Large"
		-- area 158 52 354 46
		-- text "RECENT_EVENTS_TITLE"
		-- text style "title"
	-- }
	-- button
	-- {
		-- enabled "JournalSize == UIStrings.UI_Large"
		-- area 594 10 33 35
		-- bam "XBUTT"
		-- action 
		-- "
			-- Infinity_PopMenu('JOURNAL_RECENT_EVENTS')
		-- "
	-- }
	-- text
	-- {
		-- enabled "JournalSize == UIStrings.UI_Large"
		-- area 126 106 422 458
		-- text "Recent events text will go here."
		-- text style "normal"
	-- }
	-- button
	-- { 
		-- enabled "JournalSize == UIStrings.UI_Large"
		-- area		320 572 200 44
		-- text		"DONE_BUTTON"
		-- text style	'button'
		-- bam			GUIBUTNT
		-- sequence	2
		-- action
		-- "
			-- Infinity_PopMenu('JOURNAL_RECENT_EVENTS')
		-- "
	-- }

-- JOURNALSIZE is SMALL

	-- label
	-- {
		-- enabled "JournalSize == UIStrings.UI_Small"
		-- area 0 0 672 672
		-- mosaic "RECENTEV"
		
	-- }
	-- label
	-- {
		-- enabled "JournalSize == UIStrings.UI_Small"
		-- area 158 52 354 46
		-- text "RECENT_EVENTS_TITLE"
		-- text style "title"
	-- }
	-- button
	-- {
		-- enabled "JournalSize == UIStrings.UI_Small"
		-- area 594 10 33 35
		-- bam "XBUTT"
		-- action 
		-- "
			-- Infinity_PopMenu('JOURNAL_RECENT_EVENTS_Small')
		-- "
	-- }
	-- text
	-- {
		-- enabled "JournalSize == UIStrings.UI_Small"
		-- area 126 106 422 458
		-- text "Recent events text will go here."
		-- text style "normal"
	-- }
	-- button
	-- { 
		-- enabled "JournalSize == UIStrings.UI_Small"
		-- area		320 572 200 44
		-- text		"DONE_BUTTON"
		-- text style	'button'
		-- bam			GUIBUTNT
		-- sequence	2
		-- action
		-- "
			-- Infinity_PopMenu('JOURNAL_RECENT_EVENTS_Small')
		-- "
	-- }
-- }

menu
{
	name 'MESSAGE_SCREEN'
	align center center
	label
	{
		area 0 0 657 234
		mosaic GUIERR6
	}
	label
	{
		area 29 21 580 126
		text lua "Infinity_FetchString(messageScreenText)"
		text style	"label"
	}
}
`
megacredits = ''
epilogueImage = "GUIOSTUR"
`
menu
{
	name 'EPILOGUE'
	align center center
	ignoreEsc
	onOpen 
	"
		generateMegaCredits()
	"
	label
	{
		area 0 0 1024 768
		mosaic "NPCCHAP"
	}
	text
	{
		area 100 50 828 36
		text style "title"
		text "MAIN_GAME_LABEL"
	}
	text
	{
		area 100 86 828 34
		text style "title"
		text "EXPANSION_LABEL"
	}
	label
	{
		area 110 176 274 430
		mosaic lua "epilogueImage"
	}
	text
	{
		name "text_CHAPTERSCROLL_item"
		area 440 148 492 482
		text lua "megacredits"
		text style normal
		text align center top
		scrollbar 'GUISCRC'
		scrollbar func 'UpdateChapterScroll'
		scrollbar hide lua 'text_CHAPTERSCROLL_auto == 1'
		action
		"
			text_CHAPTERSCROLL_auto = 0
		"
	}
	button
	{
		area 526 662 230 40
		bam GUIBUTMT
		text "DONE_BUTTON"
		text style "button"
		clickable lua "chapterScreen:IsDoneButtonClickable()"
		action
		"
			megacredits = ''
			chapterScreen:OnDoneButtonClick()
		"
	}
	button
	{
		area 284 662 230 40
		bam GUIBUTMT
		text "REPLAY_BUTTON"
		text style "button"
		clickable lua "chapterScreen:IsReplayButtonClickable()"
		action
		"
			chapterScreen:OnReplayButtonClick()
		"
	}
}
`
	worldNPCDialogText = ""
	worldPlayerDialogChoices = {}
	glowTest = nil
	startingDialogHeight = 0
	previousTop = nil
	scrolled = false
	scrollToBottom = false
	
	function dialogScroll(top, height, contentHeight)
		if scrolled then
			if scrollToBottom and contentHeight > height then
				scrollToBottom = false
				return height - contentHeight
			end
			return nil
		end
		if previousTop ~= nil and top ~= previousTop then
			scrolled = true
			scrollToBottom = true
			return -1
		end
		previousTop = -1
		return -1
	end
	
	function mergeDialog(t)
		local dialog = {}
		for key, value in pairs(t) do
			dialog[key] = value
		end
		table.insert(dialog, 1, '')
		table.insert(dialog, 1, '')
		return dialog
	end

-- Drag Message History on Y-axis
	function dragMessagesBoxHistoryY(newY)
		setMessageBoxHistoryY(newY)
		worldMessageBoxClickedOnce = 1
	end
	
	function clampMessageBoxHistoryHeight(hNew, hOld)
			if(hNew <= 200) then
				--lower bound on height, sliced rects can't get too small and we don't want to make the message box invisible.
				return hOld - 200
			end
			if(hNew >= 500) then
				--also don't go too high because it looks bad.
				return hOld - 500
			end
			return hOld - hNew
	end
	
	function setMessageBoxHistoryY(newY)
			local x,y,w,hOld = Infinity_GetArea('worldMessageBoxHistoryBackground')
			h = hOld - newY
			newY = clampMessageBoxHistoryHeight(h,hOld)
			
			adjustItemGroup({"worldMessageBoxHistoryHandle"},0,newY,0,0)
			adjustItemGroup({"worldMessageBoxHistoryBackground","worldMessageBoxHistory"},0,newY,0,-newY)
			
			chatboxScrollToBottom = 1
	end
	 
-- Drag Dialog on X axis
	function dragDialogX(newX)
		--do a quick bounds check.
		local screenWidth, screenHeight = Infinity_GetScreenSize()
		local area = {Infinity_GetArea("worldDialogBackground")}
		if(area[1] + newX) < 125 and worldNPCDialogPortrait ~= 'NONE' then
			Infinity_SetArea('worldDialogPortraitArea', area[1]+496, nil, nil, nil)
			PortPosition = 'Left'
		elseif (area[1] + newX) > screenWidth - 694 and worldNPCDialogPortrait ~= 'NONE' then
			Infinity_SetArea('worldDialogPortraitArea', area[1]-100, nil, nil, nil)
			PortPosition = 'Right'
		end
		
		if(area[1] + newX) < 0 then
			newX = 0 - area[1]
		elseif (area[1] + newX) > screenWidth - 569 then
			newX = screenWidth - 569 - area[1]
		end
		adjustItemGroup({"worldDialogBackground","worldDialogHandle","worldDialogHandleDrag","worldDialogPortraitArea","worldNPCDialog","worldPlayerDialogChoicesList","worldDialogConfirm","worldDialogPortraitBackgroundL","worldDialogPortraitBackgroundR","worldDialogButton1","worldDialogButton2","worldDialogButton3"}, newX, 0, 0, 0)
	end

-- NOT SURE but I left this just in case
	function dialogEntryGreyed()
		return not worldScreen:GetInControlOfDialog()
	end

-- Toggle MessageHistory
	function toggleDialogShowMessages()
		if(showWorldMessages == 1) then showWorldMessages = 0 else showWorldMessages = 1 end
	end

-- Sets the the desired dialog background area
	function getDesiredDialogHeight()
	
		--get npc area
		local npcX,npcY,npcW,npcH = Infinity_GetArea('worldNPCDialog')
		
		--get dialog choices height
		local choicesHeight = Infinity_GetListHeight('worldPlayerDialogChoicesList')

		-- set the area to npcDialog + choicesHeight + 100 (60,npcDialog,10,choices,30)
		if (choicesHeight + npcH + 100) < 300 then 
			return 300
		else
			return (choicesHeight + npcH + 100)
		end
	end

-- Retrieves the current dialog background area
	
	function resizeDialog()
	if ( ClassicDialog == 1) then
	previousTop = nil
	scrolled = false
	else
		--fit the npc text area to the text height.
		Infinity_ScaleToText("worldNPCDialog")
		
		--Get available height to work in
		local desiredHeight = getDesiredDialogHeight()
		desiredHeight = desiredHeight + 30
		--get areas
		local npcX,npcY,npcW,npcH = Infinity_GetArea('worldNPCDialog')
		local choicesHeight = Infinity_GetListHeight('worldPlayerDialogChoicesList')
		choicesHeight = choicesHeight + 40
		local x,y,w,h = Infinity_GetArea('worldDialogBackground')
		local WDHx,WDHy,WDHw,WDHh = Infinity_GetArea('worldDialogHandleDrag')
		local xL,yL,wL,hL = Infinity_GetArea('worldDialogPortraitBackgroundL')
		local xR,yR,wR,hR = Infinity_GetArea('worldDialogPortraitBackgroundR')
		local x2,y2,w2,h2 = Infinity_GetArea('worldDialogPortraitArea')
		local WDB1x,WDB1y,WDB1w,WDB1h = Infinity_GetArea('worldDialogButton1')
		local WDB2x,WDB2y,WDB2w,WDB2h = Infinity_GetArea('worldDialogButton2')
		local WDB3x,WDB3y,WDB3w,WDB3h = Infinity_GetArea('worldDialogButton3')
		local screenWidth,screenHeight = Infinity_GetScreenSize()
				
		if (choicesHeight + npcH + 100) > (screenHeight * (8/10)) then 
			choicesHeight = (screenHeight * (8/10)) - 100 - npcH
			desiredHeight = choicesHeight + 100 + npcH
		end
		
		if x > screenWidth - w - 69 then
			newX = screenWidth - w - 69
			WDHx = newX + 153
			npcX = newX + 30
			if newX < 0 then
				xR = newX + 496
				x2 = newX + 488
				PortPosition = 'Right'
			elseif newX > screenWidth - 197 - w then
				xL = newX - 112
				x2 = newX - 100
				PortPosition = 'Left'
			end
		end
		
		-- reposition all elements
		Infinity_SetArea('worldDialogBackground', newX, y, w, desiredHeight)
		Infinity_SetArea(('worldNPCDialog'), npcX,npcY,npcW,npcH)
		Infinity_SetArea(('worldDialogButton1'), newX, nil, nil, nil)
		Infinity_SetArea(('worldDialogButton2'), newX, nil, nil, nil)
		Infinity_SetArea(('worldDialogButton3'), newX, nil, nil, nil)
		Infinity_SetArea(('worldPlayerDialogChoicesList'), npcX,npcY+npcH+10,npcW,choicesHeight)
		
		Infinity_SetArea(('worldDialogConfirm'), WDHx+103, desiredHeight+2, nil, nil)
		Infinity_SetArea(('worldDialogHandle'), WDHx, desiredHeight-33, nil, nil)
		Infinity_SetArea(('worldDialogHandleDrag'), WDHx, 0, nil, nil)	
		
		Infinity_SetArea(('worldDialogPortraitArea'), x2, nil, nil, nil)
		Infinity_SetArea(('worldDialogPortraitBackgroundR'), xR, nil, nil, nil)
		Infinity_SetArea(('worldDialogPortraitBackgroundL'), xL, nil, nil, nil)
	end
	end
	

	function getDialogButtonEnabled()
		if(gameOptions.m_bConfirmDialog == true) then
			return true
		else
			return (#worldPlayerDialogChoices == 0)
		end
	end

	function getDialogButtonClickable()
		if(gameOptions.m_bConfirmDialog == true) then
			return (#worldPlayerDialogChoices == 0) or (worldPlayerDialogSelection and worldPlayerDialogSelection > 0) --no choices, or we've selected a choice.
		else
			return true
		end
	end
	
	function getDialogEntryText(row)
		if (ClassicDialog == 1) then
			row = row - 2
		end
	local text = worldPlayerDialogChoices[row].text
		if (ClassicDialog == 1) then
			row = row + 2
		end
		if (row == worldPlayerDialogSelection) then
			--Color the text white when selected
			text = string.gsub(text, "%^0xff212eff", "^0xFFFFFFFF")
		end
		return text
	end

-- World Messages Box Drag
	 worldMessageBoxText = ""
	 worldMessageBoxLines = 0
	 worldMessageBoxClickedOnce = 0
	 function dragMessagesY(newY)
		setMessagesY(newY)
		worldMessageBoxClickedOnce = 1
	 end
	function clampMessageBoxHeight(hNew, hOld)
			if(hNew <= 64) then
				--lower bound on height, sliced rects can't get too small and we don't want to make the message box invisible.
				return hOld - 64
			end
			if(hNew >= 500) then
				--also don't go too high because it looks bad.
				return hOld - 500
			end
			return hOld - hNew
	end
	function setMessagesY(newY)
		local x,y,w,hOld = Infinity_GetArea('messagesRect')
		h = hOld - newY
		newY = clampMessageBoxHeight(h,hOld)
		
		adjustItemGroup({"messagesHandleY"},0,newY,0,0)
		adjustItemGroup({"messagesRect","worldMessageBox"},0,newY,0,-newY)
		
		chatboxScrollToBottom = 1
		worldMessageBoxTop = y + newY
	end

	PortPosition = "Left"
	
	function AddNewNote(text)
		if alreadyAdded == 0 then
			RevertJournal = 0
			if JournalSize == UIStrings.UI_Large then
				RevertJournal = 1
				JournalSize = UIStrings.UI_Small
			end
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			journalMode = const.JOURNAL_MODE_EDIT
			text = string.gsub(text, "%^0x........", "")
			text = string.gsub(text, '%\n', '\n"') .. '"'
			journalNoteEdit =  text
			journalNoteEditRef = nil
			journalNoteEdit = JFStrings.JF_Notes .. '\n' .. journalNoteEdit .. '\n - ' .. Infinity_GetTimeString()
			Infinity_OnAddUserEntry(journalNoteEdit)
			journalMode = const.JOURNAL_MODE_JOURNAL
			e:GetActiveEngine():OnLeftPanelButtonClick(2)
			if RevertJournal == 1 then
				RevertJournal = 0
				JournalSize = UIStrings.UI_Large
			end
			alreadyAdded = 1
		end
	end
	function SetPosition()
		local x,y,w,h = Infinity_GetArea('worldDialogBackground')
		local screenWidth, screenHeight = Infinity_GetScreenSize()
		if x < (screenWidth/2 - w/2) then
			x = screenWidth/2 - w/2
			PortPosition = 'Right'
			Infinity_SetArea(('worldDialogPortraitArea'), x-100, nil, nil, nil)
		elseif x < screenWidth - w - 69 then
			x = screenWidth - w - 69
			PortPosition = 'Right'
			Infinity_SetArea(('worldDialogPortraitArea'), x-100, nil, nil, nil)
		elseif x == screenWidth - w - 69 then
			x = 0
			PortPosition = 'Left'
			Infinity_SetArea(('worldDialogPortraitArea'), x+496, nil, nil, nil)
		end

		Infinity_SetArea('worldDialogBackground',x,nil,nil,nil)
		Infinity_SetArea(('worldNPCDialog'), x+30,nil,nil,nil)
		Infinity_SetArea(('worldDialogButton1'), x+340,nil,nil,nil)
		Infinity_SetArea(('worldDialogButton2'), x+380,nil,nil,nil)
		Infinity_SetArea(('worldDialogButton3'), x+420,nil,nil,nil)
		Infinity_SetArea(('worldPlayerDialogChoicesList'), x+30,nil,nil,nil)
		
		Infinity_SetArea(('worldDialogConfirm'), x+103,nil,nil,nil)
		Infinity_SetArea(('worldDialogHandle'), x,nil,nil,nil)
		Infinity_SetArea(('worldDialogHandleDrag'), x,nil,nil,nil)
		
		Infinity_SetArea(('worldDialogPortraitBackgroundR'), x+488, nil, nil, nil)
		Infinity_SetArea(('worldDialogPortraitBackgroundL'), x-112, nil, nil, nil)
	end
	function SetBottomPosition()
		local x,y,w,h = Infinity_GetArea()
		local screenWidth, screenHeight = Infinity_GetScreenSize()

		Infinity_SetArea(('worldDialogBackgroundBottom'),(screenWidth/2)-432,screenHeight-353,nil,nil)
		Infinity_SetArea(('worldDialogBackgroundBottom1'),(screenWidth/2)-432,screenHeight-83,nil,nil)
		Infinity_SetArea(('worldDialogPortraitAreaBottom'), (screenWidth/2)-533,screenHeight-283,nil,nil)
		Infinity_SetArea(('worldDialogPortraitBackgroundBottom'), (screenWidth/2)-544,screenHeight-303,nil,nil)
		Infinity_SetArea(('worldPlayerDialogChoicesListBottom'), (screenWidth/2)-394,screenHeight-324,nil,nil)
	end

	WorldDialog = {
		areas = {
			'worldDialogBackground',
			'worldDialogButton1',
			'worldDialogButton2',
			'worldDialogButton3',
			'worldDialogConfirm',
			'worldDialogHandle',
			'worldDialogHandleDrag',
			'worldDialogPortraitArea',
			'worldDialogPortraitBackgroundL',
			'worldDialogPortraitBackgroundR',
			'worldNPCDialog',
			'worldPlayerDialogChoicesList',
		},
		restored = false
	}

	function WorldDialog:save()
		if ClassicDialog == 1 then
			return
		end

		Infinity_SetINIValue('WorldDialog', 'PortPosition', PortPosition)

		for _, key in ipairs(self.areas) do
			local x, y, w, h = Infinity_GetArea(key)
			Infinity_SetINIValue('WorldDialog', key, table.concat({x, y, w, h}, ':'))
		end
	end

	function WorldDialog:restore()
		-- only try to restore the first time and for enhanced dialog
		if ClassicDialog == 1 or self.restored then
			return
		end
		self.restored = true

		-- various globals
		local portPosition = Infinity_GetINIString('WorldDialog', 'PortPosition', '')
		if portPosition == '' then
			return
		end

		-- restore areas
		local areas = {}

		for _, key in ipairs(self.areas) do
			local area = Infinity_GetINIString('WorldDialog', key, '')
			if area == '' then
				return
			end

			local rect = {}
			area:gsub('%-?%d+', function(n) table.insert(rect, tonumber(n)) end)
			if #rect ~= 4 then
				return
			end

			areas[key] = rect
		end

		-- everything is okay, finally set the variables
		PortPosition = portPosition

		for key, r in pairs(areas) do
			Infinity_SetArea(key, r[1], r[2], r[3], r[4])
		end
	end

`
menu
{
	name 'WORLD_DIALOG'
	align left top
	ignoreEsc
	onOpen
	"
		ClassicDialog = Infinity_GetINIValue('Game Options','ClassicDialog',0)
		disableDialogOnSpace = Infinity_GetINIValue('Game Options', 'Disable Space Key In Conversations', 1)
		WorldDialog:restore()

		SetBottomPosition()
		resizeDialog()
		greySidebars()
		Infinity_PushMenu('WORLD_MESSAGEBOXHISTORY')
		Infinity_PopMenu('JOURNAL')
		SMH = Infinity_GetINIString('Game Options','ShowMessageHistory',1)
		if SMH ~= 'On' then
			SMH = 'Off'
			showWorldMessages = 0
			Infinity_SetINIValue('Game Options','ShowMessageHistory','Off')
		else
			SMH = 'On'
			showWorldMessages = 1
			Infinity_SetINIValue('Game Options','ShowMessageHistory','On')
		end
		alreadyAdded = 0
		Infinity_PushMenu('WORLD_DIALOG_CONFIRM')
		greySidebars()
		previousTop = nil
		scrolled = false
		scrollToBottom = false
	"
	onClose
	"
		ungreySidebars()
		dialogButtonText = ''
		Infinity_PopMenu('WORLD_MESSAGEBOXHISTORY')
		worldNPCDialogPortrait='NONE'
		if groundItemsButtonToggle == 1 then
			Infinity_PushMenu('WORLD_QUICKLOOT')
		end
		Infinity_PopMenu('WORLD_DIALOG_CONFIRM')

		WorldDialog:save()
	"

	-- Optionally disable continuing dialog on space bar
	label
	{
		on space
		name "worldDialogOnSpaceLabel"
		enabled "disableDialogOnSpace == 1"
	}

	--classic dialog
	label
	{
		enabled "ClassicDialog == 1"
		name "worldDialogBackgroundBottom"
		area 251 415 863 303
		mosaic RGDBBOX1
	}
	label
	{
		enabled "ClassicDialog == 1"
		name "worldDialogBackgroundBottom1"
		area 251 685 863 83
		mosaic RGDBBOX2
	}
	label
	{
		enabled "worldNPCDialogPortrait~='NONE' and worldNPCDialogPortrait~='' and ClassicDialog == 1"
		name "worldDialogPortraitAreaBottom"
		area 150 485 108 170
		bitmap lua "worldNPCDialogPortrait"
	}
	label
	{
		enabled "worldNPCDialogPortrait~='NONE' and worldNPCDialogPortrait~='' and ClassicDialog == 1"
		name "worldDialogPortraitBackgroundBottom"
		area 139 465 125 209
		mosaic "rgboxp1"
	}
	--label
	--{
	--	enabled "ClassicDialog == 1"
	--	name "worldDialogBackgroundBottom"
	--	area 0 0 863 253
	--	rectangle 4
	--}
	--label
	--{
	--	enabled "ClassicDialog == 1"
	--	name "worldDialogPortraitAreaBottom"
	--	area 24 24 54 84
	--	bitmap lua "worldNPCDialogPortrait"
	--}
	list
	{
		column
		{
			width 100
			label
			{
				area 0 0 -1 1
				enabled "rowNumber == 1 and not scrolled"
			}
			text
			{
				area 0 0 -1 -1
				pad 0 0 0 12
				enabled "rowNumber == 2 and scrolled"
				text lua "worldMessageBoxText"
				text style "gamelog"
			}
			text
			{
				area 0 0 -1 -1
				pad 0 0 0 12
				enabled "rowNumber == 2 and not scrolled"
				text lua "worldNPCDialogText:gsub('\n', ': ', 1)"
				text style "gamelog"
			}
			label
			{
				area 0 0 -1 -1
				pad 12 0 0 0
				enabled "rowNumber > 2 and dialogEntryGreyed()"
				rectangle 1
				rectangle opacity 100
			}
			text
			{
				area 0 0 -1 -1
				pad 12 0 0 0
				enabled "rowNumber > 2"
				text lua "getDialogEntryText(rowNumber)"
				text style "gamelog"
			}
		}
		enabled "ClassicDialog == 1"
		name "worldPlayerDialogChoicesListBottom"
		area 289 444 806 265
		rowheight dynamic
		hideHighlight
		table "mergeDialog(worldPlayerDialogChoices)"
		var "worldPlayerDialogSelection"
		scrollbar 'RGSCRBR'
		scrollbar func "dialogScroll"
		actionEnter
		"
			worldPlayerDialogSelection = mouseoverRow
		"
		actionExit
		"
			worldPlayerDialogSelection = 0
		"
		action
		"
			if (worldPlayerDialogChoices[worldPlayerDialogSelection - 2] == nil) then return end
			worldScreen:OnDialogReplyClick(worldPlayerDialogChoices[worldPlayerDialogSelection - 2].marker)
			worldPlayerDialogSelection = 0
		"
	}
	--enhanced dialog
	button
	{
		enabled "ClassicDialog ~= 1"
		area 0 0 500 330
		name "worldDialogBackground"
		mosaic RGDBOX1
	}
	label
	{
		enabled "worldNPCDialogPortrait~='NONE' and worldNPCDialogPortrait~='' and ClassicDialog ~= 1"
		name "worldDialogPortraitArea"
		area 496 70 108 170
		bitmap lua "worldNPCDialogPortrait"
	}
	label
	{
		enabled "worldNPCDialogPortrait~='NONE' and worldNPCDialogPortrait~='' and PortPosition == 'Right' and ClassicDialog ~= 1"
		name "worldDialogPortraitBackgroundL"
		area -112 50 125 209
		mosaic "rgboxp1"
	}
	label
	{
		enabled "worldNPCDialogPortrait~='NONE' and worldNPCDialogPortrait~='' and PortPosition == 'Left' and ClassicDialog ~= 1"
		name "worldDialogPortraitBackgroundR"
		area 488 50 125 209
		mosaic "rgboxp2"
	}
	text
	{
		enabled "ClassicDialog ~= 1"
		name "worldNPCDialog"
		area 30 50 440 133
		text lua "worldNPCDialogText"
		text style "gamelog"
		scrollbar	'GUISCRC'
	}
	list
	{
		column
		{
			width 100
			label
			{
				area 0 0 -1 -1
				enabled "dialogEntryGreyed()"
				fill 0 0 0 100
			}
			text
			{
				area 0 0 -1 -1
				text lua "getDialogEntryText(rowNumber)"
				text style "gamelog"
			}
		}
		enabled "ClassicDialog ~= 1"
		name "worldPlayerDialogChoicesList"
		area 30 193 440 40
		rowheight dynamic
		hideHighlight
		table "worldPlayerDialogChoices"
		var "worldPlayerDialogSelection"
		scrollbar	'GUISCRC'
		actionEnter
		"
			if(gameOptions.m_bConfirmDialog == true) then return end
			glowTest = mouseoverRow
			worldPlayerDialogSelection = mouseoverRow
		"
		actionExit
		"
			if(gameOptions.m_bConfirmDialog == true) then return end
			glowTest = nil
			worldPlayerDialogSelection = 0
		"
		action
		"
			--In confirm mode, just highlight the choice.
			if(gameOptions.m_bConfirmDialog == true) then return end
			worldScreen:OnDialogReplyClick(worldPlayerDialogChoices[worldPlayerDialogSelection].marker)
			worldPlayerDialogSelection = 0
			alreadyAdded = 0
		"
	}
	button
	{
		enabled "ClassicDialog ~= 1"
		name "worldDialogHandle"
		area 0 285 500 83
		mosaic "RGDBOX2"
	}
	handle
	{
		enabled "ClassicDialog ~= 1"
		name "worldDialogHandleDrag"
		area 0 0 500 30
		actionDrag
		"
			dragDialogX(motionX)
		"
	}
	button
	{
		enabled "ClassicDialog ~= 1"
		name "worldDialogButton1"
		area 340 13 36 22
		bam "RGDBUTT"
		sequence 1
		action
		"
			if SMH == 'Off' then
				SMH = 'On'
				Infinity_SetINIValue('Game Options','ShowMessageHistory','On')
			else
				SMH = 'Off'
				Infinity_SetINIValue('Game Options','ShowMessageHistory','Off')
			end
			toggleDialogShowMessages()
		"
	}
	button
	{
		enabled "ClassicDialog ~= 1"
		name "worldDialogButton2"
		area 380 13 36 22
		bam "RGDBUTT"
		sequence 0
		action
		"
			SetPosition()
		"
	}
	button
	{
		enabled "ClassicDialog ~= 1"
		name "worldDialogButton3"
		area 420 13 36 22
		bam "RGDBUTT"
		sequence 2
		action
		"
			AddNewNote(worldNPCDialogText)
		"
	}
	button
	{
		area 103 320 294 38
		name "worldDialogConfirm"
		bam "RGBOXD"
		text lua "dialogButtonText"
		enabled "getDialogButtonEnabled() and ClassicDialog ~= 1"
		clickable lua "getDialogButtonClickable()"		
		text style "button"
		action 
		"
			if(gameOptions.m_bConfirmDialog == true and (#worldPlayerDialogChoices > 0)) then
				-- if confirm dialog and choices available.
				worldScreen:OnDialogReplyClick(worldPlayerDialogChoices[worldPlayerDialogSelection].marker)
				worldPlayerDialogSelection = 0
			else
				-- no choices, just step.
				worldScreen:StepDialog()
			end
			alreadyAdded = 0
		"
	}
}

`
function getDialogButtonEnabled()
	return (#worldPlayerDialogChoices == 0)
end
dialogTable = {}
	dialogOverflowTable = {}
	hasDialogResponse = nil
	
	chatboxScrollToBottom = nil
	chatboxScrollTimeLast = 0
	chatboxContentHeight = 0
	chatboxOverflowed = nil
	chatboxJumpToBottom = nil
	
	-- The following two values determine how many item entries can exist.  We trim 
	-- the number of entries to numDialogTrimEntries once it has overflowed that value
	-- by numDialogOverflowLimit.
	numDialogTrimEntries = 512
	numDialogOverflowEntries = numDialogTrimEntries + 128
	
	lastTrimmedContentHeight = 0
	
	function getNumDialogTableEntries()
		local count = 0
		for _ in pairs(dialogTable) do count = count + 1 end
		return count
	end
	
	function trimDialogTableSize()
		local  numTableEntries = getNumDialogTableEntries()
		if (numTableEntries > numDialogOverflowEntries) then
			local numEntriesToRemove = numTableEntries - numDialogTrimEntries
			while (numEntriesToRemove > 0) do
				-- Get our table entry and calculate its size
				local tableEntry = dialogTable[1]
				local delta = Infinity_GetContentHeight(styles.normal.font, w, tableEntry.text, styles.normal.point, 1, styles.normal.useFontZoom) --1 for indent.
				chatboxContentHeight = chatboxContentHeight - delta
				lastTrimmedContentHeight = lastTrimmedContentHeight + delta
					
				table.remove(dialogTable, 1)
				numEntriesToRemove = numEntriesToRemove - 1
			end
		end
	end
	
	function buildResponsesList()

		hasDialogResponse = nil
		dialogResponses = {}
		for k,v in pairs(worldPlayerDialogChoices) do
			if v.marker then
				table.insert(dialogResponses, v)
				hasDialogResponse = 1
			end
		end
	end
	function canShowDialogButton(num)
		-- Show the buttons if we have a response, and the dialog button is not enabled
		return dialogResponses and dialogResponses[num] ~= nil and showDialogButtonChoices()
	end
	
	function addDialogMessage(text,marker,makeTop)
		local tab = {}
		tab.text = text
		tab.marker = marker
		if(marker) then 
			dialogViewMode = nil
			if(text == "") then
				--empty markers are a signal, we shouldn't actually display them.
				if(makeTop == true) then
					--we'll ensure the next line is included in the visible content.
					chatboxContentHeight = 0
				end
				return
			else
				hasDialogResponse = 1
			end
		end
		
		--Calculate running total of dialog content height
		local x,y,w,h = Infinity_GetArea("worldPlayerDialogChoicesList")
		w = w - 18 --account for scrollbar influence on width
		local delta = Infinity_GetContentHeight(styles.normal.font, w, text, styles.normal.point, 1, styles.normal.useFontZoom) --1 for indent.
		chatboxContentHeight = chatboxContentHeight + delta
		
		if(marker and chatboxContentHeight > h) then
			--More to display than we have room for, put the responses in overflow and hide them behind button
			table.insert(dialogOverflowTable,tab)
		else
			table.insert(dialogTable,tab)
		end
		
		if(makeTop == true) then
			--we'll ensure the next line is included in the visible content.
			chatboxContentHeight = 0
		end
		
		trimDialogTableSize()
		
		triggerChatboxScroll()
		
		buildResponsesList()
	end
	function clearDialogResponses()
		for k,v in pairs(dialogTable) do
			if(v.marker) then
				table.remove(dialogTable,k)
				clearDialogResponses()
			end
		end
		hasDialogResponse = nil
		chatboxOverflowed = nil
		chatboxContentHeight = 0
		dialogOverflowTable = {}
	end
	function dialogEntrySelectable(row)
		return (dialogTable[row].marker ~= nil)
	end
	function showDialogButtonChoices()
		return not (not hasDialogResponse or dialogViewMode or #dialogOverflowTable > 0)
	end
	function getResponsePickable()
		return not hasDialogResponse or dialogViewMode or (gameOptions.m_bConfirmDialog == true)
	end
	function getDialogButtonText()
		if(dialogViewMode) then
			return t("DONE_BUTTON")
		end
		
		if(#dialogOverflowTable > 0) then
			return t("SHOW_MORE_RESPONSES_BUTTON")
		end
		
		if(gameOptions.m_bConfirmDialog == true) then
			return t("CHOOSE_RESPONSE_BUTTON")
		end
		
		return dialogButtonText
	end
	function triggerChatboxScroll()
		chatboxScrollToBottom = 1
		chatboxScrollTimeLast = Infinity_GetClockTicks()
	end
	function chatboxScroll(top, height, contentHeight)
		if(chatboxJumpToBottom and contentHeight > height) then
			chatboxJumpToBottom = nil
			return height-contentHeight
		end
		if(chatboxScrollToBottom == 0) then
			--defer to default scrolling
			return nil
		end
		if(contentHeight < height) then
			--no scrolling required, content fits
			chatboxScrollToBottom = nil
			return nil
		end
		local dT = Infinity_GetClockTicks() - chatboxScrollTimeLast
		chatboxScrollTimeLast = Infinity_GetClockTicks()
		top = top + lastTrimmedContentHeight
		lastTrimmedContentHeight = 0
		local newTop = (dT * -0.25) + top
		if (newTop + contentHeight > height + 200) then
			return (height - contentHeight + 200)
		end
		if(newTop + contentHeight < height) then
			chatboxScrollToBottom = 0
			return height - contentHeight
		end
		return newTop
	end
	function displayOverflowResponses()
		for k,v in pairs(dialogOverflowTable) do
			table.insert(dialogTable,v)
		end
		dialogOverflowTable = {}
		triggerChatboxScroll()
		buildResponsesList()
	end
	function GetFirstMarkedResponse()
		for k,v in pairs(dialogTable) do
			if v.marker ~= nil then
				return k
			end
		end
		return -1	
	end
	function onDialogButtonClick()
		if(dialogViewMode) then
			--In dialog view mode this button closes the menu.
			worldScreen:StopDialogHistory()
			return
		end
		
		if(#dialogOverflowTable > 0) then
			displayOverflowResponses()
			return
		end

		if(gameOptions.m_bConfirmDialog == true and hasDialogResponse) then
			-- if confirm dialog and choices available.
			worldScreen:OnDialogReplyClick(dialogTable[worldPlayerDialogSelection].marker)
			worldPlayerDialogSelection = 0
			return
		else
			-- no choices, just step.
			worldScreen:StepDialog()
		end
	end
	function getDialogRowClickable(row)
		return dialogTable[row].marker ~= nil
	end
	function isTouchActionbar()
		--Make this read from an option to make it easy to switch out.
		local default = 0
		if(e:IsTouchUI()) then default = 1 end
		local val = Infinity_GetINIValue('Program Options', 'Use Touch Actionbar', default)
		if (val ~= 0) then
			return 1
		else
			return nil
		end
	end
`
menu
{
	name 'WORLD_DIALOG_CONFIRM'
	offset 0 -5
	align center bottom
	ignoreEsc
	button
	{
		area 0 0 300 45
		--bam GUIBUTWT
		text lua "dialogButtonText"
		enabled "getDialogButtonEnabled() and ClassicDialog == 1"
		text style "button"
		action 
		"
			worldScreen:StepDialog()
		"
	}
}
menu
{
	name 'WORLD_MESSAGEBOXHISTORY'
	align center bottom
	ignoreEsc
	onopen "
		local x,y,w,h = Infinity_GetArea('messagesRect')
		Infinity_SetArea('worldMessageBoxHistoryBackground',x,y-110,w,h)
		Infinity_SetArea('worldMessageBoxHistoryHandle',nil,y-110,nil,nil)
		Infinity_SetArea('worldMessageBoxHistory',x+28,y-86,w-47,h-40)
	"
	label
	{
		name 'worldMessageBoxHistoryBackground'
		enabled "showWorldMessages"
		area 0 -63 792 206
		mosaic RGBOXZ
	}
	label
	{
		area 0 91 792 106
		enabled "showWorldMessages"
		mosaic RGBOXY
	}
	label
	{
		name "worldMessageBoxHistory"
		enabled "showWorldMessages"
		area 28 -39 745 166
		text lua "worldMessageBoxText"
		text style "gamelog"
		scrollbar	'RGSCRBR'
		scrollbar func "chatboxScroll"
	}
	handle
	{
		name "worldMessageBoxHistoryHandle"
		enabled "showWorldMessages"
		area 0 -63 792 30
--		mosaic "RGTAB3"
		actionDrag
		"
			dragMessagesBoxHistoryY(motionY)
		"
	}
}
menu
{
	name 'WORLD_MESSAGES'
	align center bottom
	ignoreEsc
	onOpen
	"
		Infinity_SetOffset('WORLD_MESSAGES', 0, -toolbarTop)
		local x,y,w,h = Infinity_GetArea('messagesRect')
		toolbarTop = toolbarTop + h
		setMessagesY(worldMessageBoxTop - y)	
	"
	onClose
	"
		local x,y,w,h = Infinity_GetArea('messagesRect')
		toolbarTop = toolbarTop - h
	"
	label
	{
		name 'messagesRect'
		area 0 47 792 206
		mosaic RGBOXZ
	}
	label
	{
		area 0 201 792 56
		mosaic RGBOXY
	}
	button
	{
		area 28 152 1 1
		on pageup
		action
		"
			dragMessagesY(-20)
		"
	}
	button
	{
	 	area 28 152 1 1
		on pagedown
		action
		"
			dragMessagesY(20)
		"
	}
	--text
	--{
	--	name "worldMessageBox"
	--	area 28 102 745 135
	--	text lua "worldMessageBoxText"
	--	text style "gamelog"
	--	scrollbar	'RGSCRBR'
	--	scrollbar func "chatboxScroll"
	--}
	list
	{
		column
		{
			width 100
			label
			{
				area 0 0 745 -1
					text lua "combatLog[rowNumber]"
					text style "gamelog"
			}
		}
		name "worldMessageBox"
		area 28 71 745 166
		rowheight dynamic
		table "combatLog"
		hideHighlight
		scrollbar	'RGSCRBR'
		scrollbar func "chatboxScroll"
		scrollbar skipReset
	}
	handle
	{
		name 'messagesHandleY'
		area 0 47 792 22
		pulse lua "worldMessageBoxClickedOnce == 0"
		actionDrag
		"
			dragMessagesY(motionY)
		"
	}
}
`
function initQuests_Small()
	--instead of always searching the quests, just map entry ids to their quests
	entryToQuest = {}
	for questIdx, quest in pairs(quests) do
		quests[questIdx].stateType = const.ENTRY_TYPE_NONE
		for objIdx,objective in pairs(quest.objectives) do
			quests[questIdx].objectives[objIdx].stateType = const.ENTRY_TYPE_NONE
			for entryIdx,entry in pairs(objective.entries) do
				quests[questIdx].objectives[objIdx].entries[entryIdx].stateType = const.ENTRY_TYPE_NONE
				entryToQuest[entry.id] = questIdx
			end
		end
	end
end

function compareByRecvTime_Small(o1,o2)
	if(not o1.recvTime and not o2.recvTime) then return false end
	if(not o1.recvTime) then return false end
	if(not o2.recvTime) then return true end
	return o1.recvTime > o2.recvTime
end

function buildEntry_Small(text, recvTime, stateType, chapter, timeStamp)
	local entry = 
		{
			text = text,
			recvTime = recvTime,
			stateType = stateType,
			timeStamp = timeStamp,
			chapters = {}
		}
	entry.chapters[chapter] = 1
	return entry	
end

--Update a journal entry by the strref/journalId
function updateJournalEntry_Small(journalId, recvTime, stateType, chapter, timeStamp)
	if(stateType == const.ENTRY_TYPE_USER) then
		local entry = buildEntry(journalId, recvTime, stateType, chapter, timeStamp)
		table.insert(userNotes,entry)
		
		--update display data
		buildQuestDisplay()
		return
	end
	--find the quest that is parent to this entry.

	--NOTE this can be placed in a loop if there needs to be more than quest to an entry
	--this would just mean entryToQuest returns a table that we iterate over
	local questId = entryToQuest[journalId]
	if questId == nil then
		--add loose entries into the looseEntries table so they still get displayed.
		local entry = buildEntry(journalId, recvTime, stateType, chapter, timeStamp)
		table.insert(looseEntries,entry)
		
		--update display data
		buildQuestDisplay()
		return
	end

	local quest = quests[questId]
	if quest == nil then
		print("JOURNAL ERROR - no quest entry associated with questId "..questId)
		return
	end
	local previous = nil
	--traverse quest to find objective and entry
	for objIdx,objective in pairs(quest.objectives) do
		for entryIdx,entry in pairs(objective.entries) do
			if(entry.id == journalId) then
				--now we know where our quest, objective, and entry are
				--update quest, objective and entry appropriately
				entry.recvTime = recvTime
				entry.stateType = stateType
				if(not entry.chapters) then entry.chapters = {} end
				entry.chapters[chapter] = 1
				entry.timeStamp = timeStamp
				objective.entries[entryIdx] = entry
				
				objective.recvTime = recvTime
				if(not objective.chapters) then objective.chapters = {} end
				objective.chapters[chapter] = 1
				if(objective.stateType ~= const.ENTRY_TYPE_COMPLETE) then
					objective.stateType = stateType
				end
				quest.objectives[objIdx] = objective
				
				quest.recvTime = recvTime
				if(not quest.chapters) then quest.chapters = {} end
				quest.chapters[chapter] = 1
				if(quest.stateType ~= const.ENTRY_TYPE_COMPLETE) then
					quest.stateType = stateType
				end
				
				--mark any previous objective as complete
				if(entry.previous ~= nil) then
					for objIdx2,objective2 in pairs(quest.objectives) do
						for k, prevObj in pairs(entry.previous) do
							if(prevObj == objective2.text) then
								quest.objectives[objIdx2].stateType = const.ENTRY_TYPE_COMPLETE
							end
						end
					end
				end
				
				quests[questId] = quest
				
				--remove all in subgroup (except myself!)
				if(stateType == const.JOURNAL_STATE_COMPLETE and entry.subGroup) then
					for k,v in pairs(subGroups[entry.subGroup]) do
						if(v.id ~= entry.id) then
							removeJournalEntry(v.id)
						end
					end
				end
				
			end
		end
	end
	--sort the objectives.
	table.sort(quest.objectives,compareByRecvTime)
	
	--update display data
	buildQuestDisplay()
end
function checkEntryComplete_Small(journalId, stateType)
	--Check if a journal entry is part of a quest that's already complete
	
	--If anything other than an unfinished entry return false.
	if(stateType ~= const.ENTRY_TYPE_INPROGRESS) then return false end
	
	--Check if my quest is marked complete.
	local questIndex = entryToQuest[journalId]
	if (quests[questIndex].stateType == const.ENTRY_TYPE_COMPLETE) then
		return 1
	else
		return 0
	end
end
--this should maybe be done recursively, but i kinda want direct control over each level
function buildQuestDisplay_Small()
	--this is basically just a flatten
	questDisplay = {}
	journalDisplay = {}
	
	local journalEntries = {} --temp holding table for sorting the entries
	
	for k,quest in pairs(quests) do
		--skip inactive quests
		if(quest.stateType ~= nil and quest.stateType ~= const.ENTRY_TYPE_NONE) then
			quest.quest = 1 -- tell the renderer what type of entry this is
			table.insert(questDisplay, quest)
			local curQuestIdx = #questDisplay --we'll need to modify current quest with it's children, store a reference.
			local questChildren = {}
			for k2,objective in pairs(quest.objectives) do
				if(objective.stateType ~= const.ENTRY_TYPE_NONE) then
					objective.objective = 1
					objective.parent = curQuestIdx
					
					if(objective.stateType ~= const.ENTRY_TYPE_INFO) then
						--info entries should not go into quests
						table.insert(questDisplay, objective)
						table.insert(questChildren, #questDisplay)
					end
					
					local curObjectiveIdx = #questDisplay
					local objectiveChildren = {}
					for k3,entry in pairs(objective.entries) do
						entry.entry = 1
						
						entry.parent = curObjectiveIdx
						table.insert(questDisplay, entry)
						table.insert(objectiveChildren, #questDisplay)
					end
					questDisplay[curObjectiveIdx].children = objectiveChildren
				end
			end
			questDisplay[curQuestIdx].children = questChildren
		end
	end
	
	-- add the user entries to the journal display
	for k,entry in pairs(userNotes) do
		entry.entry = 1
		table.insert(journalEntries,entry)
	end
	
	--add the loose entries (entries without quests) to the journal display
	for k,entry in pairs(looseEntries) do
		entry.entry = 1
		table.insert(journalEntries,entry)
	end
	
		
	table.sort(journalEntries, compareByState_Small)
	
	for k,entry in pairs(journalEntries) do
		local title  = {}
		title.title = 1
		title.text = entry.timeStamp
		title.chapters = entry.chapters
		table.insert(journalDisplay,title)
		table.insert(journalDisplay, entry)
	end
end
function questContainsSearchString_Small(row)
	if(journalSearchString == nil or journalSearchString == "") then return 1 end --no search string, do nothing
	local text = Infinity_FetchString(questDisplay[row].text)
	if(string.find(string.lower(text),string.lower(journalSearchString))) then return 1 end -- string contains search string.
	if(questDisplay[row].children == nil) then return nil end --no children, does not contain search string.
	for k,v in pairs(questDisplay[row].children) do
		--Infinity_Log(v)
		if(containsSearchString(v)) then return 1 end -- one of children contains search string
	end
	return nil --does not contain search string
end
function containsChapter_Small(tab, chapter)
	if(not tab) then return nil end
	return tab[chapter]
end
function entryEnabled_Small(row)
	local rowTab =  questDisplay[row]
	if(rowTab == nil or rowTab.entry == nil or not containsChapter(rowTab.chapters,chapter)) then return nil end

	if(objectiveEnabled(rowTab.parent) and questDisplay[rowTab.parent].expanded) then return 1 else return nil end
end
function getEntryText_Small(row)
	return questDisplay[row].timeStamp .. "\n" .. questDisplay[row].text
end

function objectiveEnabled_Small(row)
	local rowTab =  questDisplay[row]
	if(rowTab == nil or rowTab.objective == nil or not containsChapter(rowTab.chapters,chapter)) then return nil end

	if(questEnabled(rowTab.parent) and questDisplay[rowTab.parent].expanded) then return 1 else return nil end
end
function getObjectiveText_Small(row)
	local rowTab =  questDisplay[row]
	if (rowTab == nil) then return nil end
	local text = rowTab.text
	if(text == "" or text == nil) then
		text = t("NO_OBJECTIVE_NORMAL")
	end
	--objectives shouldn't really display a completed state since they don't actually follow a progression.
	--if(getFinished(row)) then
	--	text = "^M .. text .. " (Finished)^-"
	--end

	return text
end

QFilter = 0

function highlightFilter_Small(text)
	if QFilter == 0 and text == 'All' then
		return '^M' .. text .. '^-'
	elseif QFilter == 1 and text == 'Active' then
		return '^M' .. text .. '^-'
	elseif QFilter == 2 and text == 'Completed' then
		return '^M' .. text .. '^-'
	end
	return '^5' .. text .. '^-'
end

function CloseAll_Small()
	for i=1,#questDisplay,1 do
		if questDisplay[i].expanded == 1 then questDisplay[i].expanded = nil end
	end
end

function CheckForOpenedQuests_Small()
	QuestOpen = 0
	for i=1,#questDisplay,1 do
		if questDisplay[i].expanded == 1  then
			QuestOpen = 1
		end
	end
end

function findQuestPopUp()
	FindTitle = string.sub(FindTitle,1,15)
	for i=1,#questDisplay,1 do
		local rowTab =  questDisplay[i]
		local text = Infinity_FetchString(rowTab.text)
		if string.find(string.lower(text), string.lower(FindTitle)) then
			questDisplay[i].expanded = 1
			questDisplay[i+1].expanded = 1
			QFilter = 3
		end
	end
end

function questEnabled_Small(row)
	if (QFilter==0) then
		return (questDisplay[row] and questDisplay[row].quest and containsChapter(questDisplay[row].chapters,chapter) and (#questDisplay[row].children > 0))
	elseif (QFilter==1) then
		if getFinished(row) then
		-- Do Nothing
		else
			return (questDisplay[row] and questDisplay[row].quest and containsChapter(questDisplay[row].chapters,chapter) and (#questDisplay[row].children > 0))
		end
	elseif (QFilter==2) then
		if getFinished(row) then
			return (questDisplay[row] and questDisplay[row].quest and containsChapter(questDisplay[row].chapters,chapter) and (#questDisplay[row].children > 0))
		end
	elseif (QFilter==3) then
		if questDisplay[row].expanded == 1  then
			return (questDisplay[row] and questDisplay[row].quest and containsChapter(questDisplay[row].chapters,chapter) and (#questDisplay[row].children > 0))
		else
			-- Do Nothing
		end
	end
end

function getQuestText_Small(row)
	local rowTab =  questDisplay[row]
	if (rowTab == nil) then return nil end
	local text = Infinity_FetchString(rowTab.text)
	
	if(getFinished(row)) then
		text = "^5" .. text .. " (" .. t("OBJECTIVE_FINISHED_NORMAL") .. ")^-"
	end

	return text
end
function getArrowFrame_Small(row)
	if(questDisplay[row] == nil or (questDisplay[row].objective == nil and questDisplay[row].quest == nil)) then return "" end

	if(questDisplay[row].expanded) then
		return 0
	else
		return 1
	end
end
function getArrowEnabled_Small(row)
	if(questDisplay[row].quest == nil and questDisplay[row].objective == nil) then return nil end
	if(questDisplay[row].objective and not objectiveEnabled_Small(row)) then return nil end
	if(questDisplay[row].quest and not questEnabled_Small(row)) then return nil end
	return 1
end

function getFinished_Small(row)
	if(questDisplay[row].stateType == const.ENTRY_TYPE_COMPLETE) then return 1 else return nil end
end
function showObjectiveSeperator_Small(row)
	local tab = questDisplay[row]
	if(objectiveEnabled(row) or entryEnabled(row)) then
		--seperator is enabled for objective or entry as long as the next thing is an objective.
		--search until we find something enabled or end of table.
		local idx = row + 1
		while(questDisplay[idx]) do
			if(objectiveEnabled(idx)) then
				return 1
			else 
				if(questEnabled(idx) or entryEnabled(idx)) then
					return nil
				end
			end
			idx = idx + 1
		end
	end
end


function getJournalTitleEnabled_Small(row)
	return journalDisplay[row].title and containsChapter(journalDisplay[row].chapters,chapter) and journalContainsSearchString(row)
end
function getJournalTitleText_Small(row)
	return journalDisplay[row].text
end
function getJournalEntryEnabled_Small(row)
	return journalDisplay[row].entry and containsChapter(journalDisplay[row].chapters,chapter) and journalContainsSearchString(row)
end
function getJournalEntryText_Small(row)
	local text = Infinity_FetchString(journalDisplay[row].text)
	if(text == nil or text == "") then
		text = journalDisplay[row].text
	end
	
	if(journalSearchString and journalSearchString ~= "") then
		--do the search string highlight
		text = highlightString(text, journalSearchString, "^0xFF0000FF")
	end
	
	return text
end
function getJournalDarken_Small(row)
	local entry = journalDisplay[row]
	if(entry.title) then
		return (row == selectedJournal or row + 1 == selectedJournal)
	end
	if(entry.entry) then
		return (row == selectedJournal or row - 1 == selectedJournal)
	end
end
function journalContainsSearchString_Small(row)
	if(journalSearchString == nil or journalSearchString == "") then return 1 end --no search string, do nothing
	local text = Infinity_FetchString(journalDisplay[row].text)
	if(text == "") then text = journalDisplay[row].text end --no stringref, use the text.
	if(string.find(string.lower(text),string.lower(journalSearchString))) then return 1 end -- string contains search string.
	
	--check if the corresponding row to this one contains the string.
	local pairText = nil
	if(journalDisplay[row].title) then
		--check the corresponding entry
		pairText = Infinity_FetchString(journalDisplay[row+1].text) or journalDisplay[row+1].text
		if(pairText == "") then pairText = journalDisplay[row+1].text end 
	else 
		if (journalDisplay[row].entry) then
			pairText = Infinity_FetchString(journalDisplay[row-1].text) or journalDisplay[row-1].text
			if(pairText == "") then pairText = journalDisplay[row-1].text end 
		end
	end
	if(string.find(string.lower(pairText),string.lower(journalSearchString))) then return 1 end -- pair string contains search string.
	
	return nil --does not contain search string
end

function dragJournal(newX,newY)
	local area = {Infinity_GetArea("JournalSmall_Background")}
	local screenWidth, screenHeight = Infinity_GetScreenSize()

	--clamping
	if area[1] + newX < 1364/2 - screenWidth/2 then
		newX = ((1364 / 2) - (screenWidth / 2)) - area[1]
	end
	if area[2] + newY < 756/2 - screenHeight/2 then
		newY = 756/2 - screenHeight/2 - area[2]
	end
	
	if area[1] + area[3] + newX > 1364/2 + screenWidth/2 - 80 then
		newX = 1364/2 + screenWidth/2 - 80 - area[1] - area[3]
	end
	if area[2] + area[4] + newY > screenHeight/2 + 756/2 - 120 then
		newY = screenHeight/2 + 756/2 - area[2] - area[4] - 120
	end

	adjustItemGroup({"JournalSmall_Background","JournalSmall_1","JournalSmall_2","JournalSmall_3","JournalSmall_4","JournalSmall_6","JournalSmall_7","JournalSmall_8","JournalSmall_9","JournalSmall_10","JournalSmall_11","JournalSmall_12","JournalSmall_13","JournalSmall_14","JournalSmall_15","JournalSmall_16","JournalSmall_17","JournalSmall_18","JournalSmall_19","JournalSmall_20","JournalSmall_21","JournalSmall_22","JournalSmall_23","JournalSmall_24","JournalSmall_25","JournalSmall_26"}, newX, newY, 0, 0)
end
function journalEntryClickable_Small(selectedJournal)
	local entry = journalDisplay[selectedJournal]
	if(entry) then return true end
end
function getJournalEntryRef_Small(selectedJournal)
	local entry = journalDisplay[selectedJournal]
	if(not entry) then return end
	if(entry.title) then
		return journalDisplay[selectedJournal + 1].text
	else
		return entry.text
	end
end
function getJournalBackgroundFrame_Small()
	if(journalMode == const.JOURNAL_MODE_QUESTS) then
		return 0
	else
		return 1
	end
end
journalMode = const.JOURNAL_MODE_QUESTS
journalSearchString = ""
function processQuestsWithStyle_Small()
	out = ""
	for k,v in pairs(quests_old) do
		local questStrref = v[3]
		out = out .. "createQuest    ( " .. questStrref .. " )\n"
		
		for k2,v2 in pairs(journals_quests_old) do
			if(v2[2] == k) then
				local subgroup = v2[const.ENTRIES_IDX_SUBGROUP]
				if(subgroup == 0) then subgroup = "nil" end
				out = out .. "createEntry    ( " .. questStrref .. ", -1, " .. v2[1] .. ", {}, " .. subgroup .." )\n"
			end
		end
	end
	Infinity_Log(out)
end
function getJournalEditedColours(text)
	if string.sub(text, 1, string.len(JFStrings.JF_Notes)-1) == string.sub(JFStrings.JF_Notes, 1, string.len(JFStrings.JF_Notes) - 1) then
		text = string.sub(text, string.len(JFStrings.JF_Notes)+1)
		if getJournalDarken(rowNumber) then
			text = "^$" .. JFStrings.JF_Notes .. "^-" .. text
		else	
			text = "^M" .. JFStrings.JF_Notes .. "^-" .. text
		end
	elseif string.sub(text, 1, string.len(JFStrings.JF_Edited)-1) == string.sub(JFStrings.JF_Edited, 1, string.len(JFStrings.JF_Edited) - 1) then
		text = string.sub(text, string.len(JFStrings.JF_Edited)+1)
		if getJournalDarken(rowNumber) then
			text = "^$" .. JFStrings.JF_Edited .. "^-" .. text
		else	
			text = "^M" .. JFStrings.JF_Edited .. "^-" .. text
		end
	end
	return text
end
`
