Enemy Addon (Test Mode Fix)

Here you can post addons, or anything related to addons.

Moderators: Management, Web Developer

Forum rules
Before posting on this forum, be sure to read the Terms of Use
User avatar
xruptor
Posts: 111

Enemy Addon (Test Mode Fix)

Post#1 » Sat Sep 26, 2020 2:28 pm

So the buggy Test Mode was driving me insane for Enemy addon. Sometimes the groups would show sometimes they didn't. Sometimes they showed up on the upper left hand corner of the screen and sometimes they didn't. So it turns out it's a positioning issue that conflicts with the test data that is generated when "Test Mode" is activated. Yes the groups were randomly generated but the positioning and display was not working properly. Instead I removed the randomness of the group generation, forced all groups to show and forced them to populate. This way you have FULL control over how Enemy displays it's groups.

So I went ahead and forced ALL GROUPS and ALL PLAYERS to show during Test Mode. This will allow you to properly configure all aspects of the groups and their layouts during Test Mode.

Find UnitFrames.lua located Interface\AddOns\Enemy\Code\UnitFrames\UnitFrames.lua That's UnitFrames with an S at the end

Find the following:

Code: Select all

local function UpdateTestMode ()

	if (config_dlg._prev_unitFramesTestMode == config_dlg.unitFramesTestMode) then return end
	
	config_dlg._prev_unitFramesTestMode = config_dlg.unitFramesTestMode
	config_dlg.testData = {}
	
	for group_index = 1, Enemy.MaxGroups
	do
		local test_group = {}
		tinsert (config_dlg.testData, test_group)
		
		if (group_index ~= Enemy.groups.player.groupIndex and math.random (0, 5) == 3) then continue end
	
		for index = 1, 6
		do
			if ((group_index == Enemy.groups.player.groupIndex and index == Enemy.groups.player.index)
				or
				math.random (0, 5) == 3) then continue end
			
			test_group[index] = EnemyPlayer.GetRandomExample ()
			test_group[index].isInPlayerGroup = (group_index == Enemy.groups.player.groupIndex)
			test_group[index].isSelf = false
		end
	end
end
Replace it with this

Code: Select all

local function UpdateTestMode ()

	if (config_dlg._prev_unitFramesTestMode == config_dlg.unitFramesTestMode) then return end
	
	config_dlg._prev_unitFramesTestMode = config_dlg.unitFramesTestMode
	config_dlg.testData = {}
	
	for group_index = 1, Enemy.MaxGroups
	do
		local test_group = {}
		tinsert (config_dlg.testData, test_group)

		for index = 1, 6
		do
			test_group[index] = EnemyPlayer.GetRandomExample (group_index, index)
			test_group[index].isInPlayerGroup = (group_index == Enemy.groups.player.groupIndex)
			test_group[index].isSelf = false
		end
	end
end
Find the following:

Code: Select all

function Enemy._UnitFramesUI_ConfigDialog_TestSettings ()

	Enemy.ConfigurationWindowSaveData (config_dlg.cwnMain, config_dlg)
	Enemy.ConfigurationWindowSaveData (config_dlg.cwnAppearance, config_dlg)
	UpdateTestMode ()
			
	if (config_dlg.unitFramesEnabled)
	then
		for group_index = 1, Enemy.MaxGroups
		do
			for index = 1, 6
			do
				g.frames[group_index][index]:Reset (true)
			end
		end
	end

	Enemy.UnitFrames_OnSettingsChanged (config_dlg)
	
	if (config_dlg.unitFramesTestMode)
	then
		for group_index = 1, Enemy.MaxGroups
		do
			for index = 1, 6
			do
				local test_player = config_dlg.testData[group_index][index]
				if (not test_player) then continue end
			
				local frame = g.frames[group_index][index]
				
				frame:Enable ()
				frame:Update (test_player)
			end
		end
	end
	
	for group_index = 1, Enemy.MaxGroups
	do
		for index = 1, 6
		do
			g.frames[group_index][index]:BoundingBoxSetShowing (config_dlg.unitFramesShowBoundingBox)
		end
	end
			
	Enemy._UnitFramesRecalculatePosititionMatrix ()
end
Replace it with

Code: Select all

function Enemy._UnitFramesUI_ConfigDialog_TestSettings ()

	Enemy.ConfigurationWindowSaveData (config_dlg.cwnMain, config_dlg)
	Enemy.ConfigurationWindowSaveData (config_dlg.cwnAppearance, config_dlg)
	UpdateTestMode ()
			
	if (config_dlg.unitFramesEnabled)
	then
		for group_index = 1, Enemy.MaxGroups
		do
			for index = 1, 6
			do
				g.frames[group_index][index]:Reset (true)
			end
		end
	end

	Enemy.UnitFrames_OnSettingsChanged (config_dlg)
	
	if (config_dlg.unitFramesTestMode)
	then
		for group_index = 1, Enemy.MaxGroups
		do
			for index = 1, 6
			do
				local test_player = config_dlg.testData[group_index][index]
				if (not test_player) then continue end
			
				local frame = g.frames[group_index][index]
				
				frame:Enable ()
				frame:Update (test_player)
				if index == 1 then
					frame:_ShowAllEffectsIndicators ()
				end
			end
		end
	end
	
	for group_index = 1, Enemy.MaxGroups
	do
		for index = 1, 6
		do
			g.frames[group_index][index]:BoundingBoxSetShowing (config_dlg.unitFramesShowBoundingBox)
		end
	end
			
	Enemy._UnitFramesRecalculatePosititionMatrix (true)
end
Find the following:

Code: Select all

function Enemy._UnitFramesRecalculatePosititionMatrix ()

	local max_groups = Enemy.UnitFramesGetMaxGroups ()
	
	local archetype_sorting = {}
	if (g.settings.unitFramesSortingEnabled)
	then
		for k = 1, 3
		do
			archetype_sorting[g.settings.unitFramesSorting[k]] = k
		end
	end
	
	local global_scale = InterfaceCore.GetScale ()
	
	local group_pos_matrix, group_max_x, group_max_y = Enemy.CalculatePositioningMatrix (
		0, 0,
		g.settings.unitFramesSize[1] * g.settings.unitFramesScale,
		g.settings.unitFramesSize[2] * g.settings.unitFramesScale,
		g.settings.unitFramesDirection1, g.settings.unitFramesPadding1, g.settings.unitFramesCount1,
		g.settings.unitFramesDirection2, g.settings.unitFramesPadding2, mmax (1, mceil (6 / g.settings.unitFramesCount1))
	)
	
	local groups_pos_matrix, groups_max_x, groups_max_y = Enemy.CalculatePositioningMatrix (
		0, 0,
		group_max_x, group_max_y,
		g.settings.unitFramesGroupsDirection1, g.settings.unitFramesGroupsPadding1, g.settings.unitFramesGroupsCount1,
		g.settings.unitFramesGroupsDirection2, g.settings.unitFramesGroupsPadding2, mmax (1, mceil (max_groups / g.settings.unitFramesGroupsCount1))
	)
	
	g.positionMatrix = {}
	
	local base_x = 10
	local base_y = 10
		
	local groups_indexes = {}
	for _idx = 1, max_groups do tinsert (groups_indexes, _idx) end
	
	local me = Enemy.groups.player

	if (me and me:IsInGroup())
	then
		if (g.settings.unitFramesDetachMyGroup)
		then
			-- make our group last (prepare for detach)
			tremove (groups_indexes, me.groupIndex)
			tinsert (groups_indexes, max_groups, me.groupIndex)
		else
			if (g.settings.unitFramesMyGroupFirst and me.groupIndex ~= 1)
			then
				tremove (groups_indexes, me.groupIndex)
				tinsert (groups_indexes, 1, me.groupIndex)
			end
		end
	end
	
	local pos_matrix_group_index = 1
	
	for k = 1, max_groups
	do
		local group_index = groups_indexes[k]
		local frames_group = g.frames[group_index]
		local frames_group_pos = {}
		
		if (Enemy.groups.groupsPlayersCount[group_index] > 0 and g.groupFilter[group_index])
		then
			local group_base_pos = nil
			
			if (group_index == me.groupIndex and g.settings.unitFramesDetachMyGroup)
			then			
				group_base_pos =
				{
					x = 0,
					y = 0,
					anchorWindow = g.anchorWindows[2]
				}
			else
				group_base_pos = groups_pos_matrix[pos_matrix_group_index]
				pos_matrix_group_index = pos_matrix_group_index + 1
			end

			local frames_indexes = { 1, 2, 3, 4, 5, 6 }
				
			if (g.settings.unitFramesSortingEnabled)
			then
				tsort (frames_indexes, function (index1, index2)
				
					local frame1 = frames_group[index1]
					local frame2 = frames_group[index2]
					local frame1_ok = frame1 and frame1:IsEnabled ()
					local frame2_ok = frame2 and frame2:IsEnabled ()
					
					if (frame1_ok and frame2_ok)
					then
						local a = archetype_sorting[Enemy.careerArchetypes[frame1.playerCareer]]
						local b = archetype_sorting[Enemy.careerArchetypes[frame2.playerCareer]]
						
						if (a == b)
						then
							return frame1.playerName < frame2.playerName
						end
							
						return a < b
							
					elseif (not frame1_ok and not frame2_ok)
					then
						return index1 < index2
						
					elseif (frame1_ok)
					then
						return true
					end
					
					return false
				end)
			end
			
			for index = 1, 6
			do
				frames_group_pos[frames_indexes[index]] =
				{
					x = group_base_pos.x + base_x + group_pos_matrix[index].x,
					y = group_base_pos.y + base_y + group_pos_matrix[index].y,
					anchorWindow = group_base_pos.anchorWindow or g.anchorWindows[1]
				}
			end
		end
		
		g.positionMatrix[group_index] = frames_group_pos
	end
	
	for group_index = 1, max_groups
	do
		if (Enemy.groups.groupsPlayersCount[group_index] > 0)
		then
			for index = 1, 6
			do
				g.frames[group_index][index]:UpdatePosition ()
			end
		end
	end
end
Replace it with this:

Code: Select all

function Enemy._UnitFramesRecalculatePosititionMatrix (isTestMode)

	local max_groups = Enemy.UnitFramesGetMaxGroups ()
	local doGroups = isTestMode
	
	local archetype_sorting = {}
	if (g.settings.unitFramesSortingEnabled)
	then
		for k = 1, 3
		do
			archetype_sorting[g.settings.unitFramesSorting[k]] = k
		end
	end
	
	local global_scale = InterfaceCore.GetScale ()
	
	local group_pos_matrix, group_max_x, group_max_y = Enemy.CalculatePositioningMatrix (
		0, 0,
		g.settings.unitFramesSize[1] * g.settings.unitFramesScale,
		g.settings.unitFramesSize[2] * g.settings.unitFramesScale,
		g.settings.unitFramesDirection1, g.settings.unitFramesPadding1, g.settings.unitFramesCount1,
		g.settings.unitFramesDirection2, g.settings.unitFramesPadding2, mmax (1, mceil (6 / g.settings.unitFramesCount1))
	)
	
	local groups_pos_matrix, groups_max_x, groups_max_y = Enemy.CalculatePositioningMatrix (
		0, 0,
		group_max_x, group_max_y,
		g.settings.unitFramesGroupsDirection1, g.settings.unitFramesGroupsPadding1, g.settings.unitFramesGroupsCount1,
		g.settings.unitFramesGroupsDirection2, g.settings.unitFramesGroupsPadding2, mmax (1, mceil (max_groups / g.settings.unitFramesGroupsCount1))
	)
	
	g.positionMatrix = {}
	
	local base_x = 10
	local base_y = 10
		
	local groups_indexes = {}
	for _idx = 1, max_groups do tinsert (groups_indexes, _idx) end
	
	local me = Enemy.groups.player

	if (me and me:IsInGroup())
	then
		if (g.settings.unitFramesDetachMyGroup)
		then
			-- make our group last (prepare for detach)
			tremove (groups_indexes, me.groupIndex)
			tinsert (groups_indexes, max_groups, me.groupIndex)
		else
			if (g.settings.unitFramesMyGroupFirst and me.groupIndex ~= 1)
			then
				tremove (groups_indexes, me.groupIndex)
				tinsert (groups_indexes, 1, me.groupIndex)
			end
		end
	end
	
	local pos_matrix_group_index = 1
	
	for k = 1, max_groups
	do
		local group_index = groups_indexes[k]
		local frames_group = g.frames[group_index]
		local frames_group_pos = {}
		
		doGroups = isTestMode
		if not doGroups then
			doGroups = (Enemy.groups.groupsPlayersCount[group_index] > 0 and g.groupFilter[group_index])
		end

		if (doGroups)
		then
			local group_base_pos = nil
			
			if (group_index == me.groupIndex and g.settings.unitFramesDetachMyGroup)
			then			
				group_base_pos =
				{
					x = 0,
					y = 0,
					anchorWindow = g.anchorWindows[2]
				}
			else
				group_base_pos = groups_pos_matrix[pos_matrix_group_index]
				pos_matrix_group_index = pos_matrix_group_index + 1
			end

			local frames_indexes = { 1, 2, 3, 4, 5, 6 }
				
			if (g.settings.unitFramesSortingEnabled)
			then
				tsort (frames_indexes, function (index1, index2)
				
					local frame1 = frames_group[index1]
					local frame2 = frames_group[index2]
					local frame1_ok = frame1 and frame1:IsEnabled ()
					local frame2_ok = frame2 and frame2:IsEnabled ()
					
					if (frame1_ok and frame2_ok)
					then
						local a = archetype_sorting[Enemy.careerArchetypes[frame1.playerCareer]]
						local b = archetype_sorting[Enemy.careerArchetypes[frame2.playerCareer]]
						
						if (a == b)
						then
							return frame1.playerName < frame2.playerName
						end
							
						return a < b
							
					elseif (not frame1_ok and not frame2_ok)
					then
						return index1 < index2
						
					elseif (frame1_ok)
					then
						return true
					end
					
					return false
				end)
			end
			
			for index = 1, 6
			do
				frames_group_pos[frames_indexes[index]] =
				{
					x = group_base_pos.x + base_x + group_pos_matrix[index].x,
					y = group_base_pos.y + base_y + group_pos_matrix[index].y,
					anchorWindow = group_base_pos.anchorWindow or g.anchorWindows[1]
				}
			end
		end
		
		g.positionMatrix[group_index] = frames_group_pos
	end
	
	for group_index = 1, max_groups
	do
		doGroups = isTestMode
		if not doGroups then
			doGroups = (Enemy.groups.groupsPlayersCount[group_index] > 0)
		end
		
		if (doGroups)
		then
			for index = 1, 6
			do
				g.frames[group_index][index]:UpdatePosition ()
			end
		end
	end
end
Open EnemyPlayer.lua located \Interface\AddOns\Enemy\Code\Core\Groups\EnemyPlayer.lua

Find the following:

Code: Select all

function EnemyPlayer.GetRandomExample ()

	local obj = EnemyPlayer.New (towstring (Enemy.capitalize (Enemy.GetRandomString2 (math.random (4, 15)))))
	
	obj.career = math.random (24)
	obj.level = math.random (40)
	obj.hp = math.random (0, 100)
	obj.ap = math.random (0, 100)
	obj.morale = math.random (0, 4)
	obj.distance = math.random (DISTANT_DISTANCE + 50)
	
	obj.isOnline = math.random (0, 10) ~= 5
	obj.isDistant = obj.distance >= DISTANT_DISTANCE
	obj.isGroupLeader = math.random (0, 1) == 0
	obj.isInPlayerGroup = math.random (0, 1) == 0
	obj.isSelected = math.random (0, 3) == 2
	obj.isLOS = math.random (0, 10) == 5
	obj.isSelf = obj.isInPlayerGroup and (math.random (0, 1) == 0)
	
	return obj
end
Replace with the following:

Code: Select all

function EnemyPlayer.GetRandomExample (group_index, index)
	
	local prefix = ""
	if group_index then prefix = prefix.."G:"..group_index end
	if index then prefix = prefix.."P:"..index end

	local obj = EnemyPlayer.New (towstring (Enemy.capitalize (prefix..(Enemy.GetRandomString2 (math.random (4, 15)))  )  ))
	
	obj.career = math.random (24)
	obj.level = math.random (40)
	obj.hp = math.random (0, 100)
	obj.ap = math.random (0, 100)
	obj.morale = math.random (0, 4)
	obj.distance = math.random (DISTANT_DISTANCE + 50)
	
	obj.isOnline = math.random (0, 10) ~= 5
	obj.isDistant = obj.distance >= DISTANT_DISTANCE
	obj.isGroupLeader = math.random (0, 1) == 0
	obj.isInPlayerGroup = math.random (0, 1) == 0
	obj.isSelected = math.random (0, 3) == 2
	obj.isLOS = math.random (0, 10) == 5
	obj.isSelf = obj.isInPlayerGroup and (math.random (0, 1) == 0)
	
	return obj
end
Open UnitFrame.lua located Interface\AddOns\Enemy\Code\UnitFrames\UnitFrame.lua That's UnitFrame WITHOUT the S at the end.

Find the following:

Code: Select all

function EnemyUnitFrame:_HideAllEffectsIndicators ()

	for _, effects_indicator in ipairs (self.effectsIndicators)
	do
		effects_indicator:Hide ()
	end
end
ADD (not replace!) the following code under the above code.

Code: Select all

function EnemyUnitFrame:_ShowAllEffectsIndicators ()

	for _, effects_indicator in ipairs (self.effectsIndicators)
	do
		effects_indicator:Show ()
	end
end

If instead you want an already updated Enemy addon, here is the link. https://filebin.net/uv8wrnmqo65rc07s or https://easyupload.io/q1gi3y (these links do expire at some point)

BTW If you want to separate groups on the second anchor, you gotta play around with the "Groups Count 1" set it to how many columns of groups you want. Then set the "Groups Direction 1".

Example for set of 3 groups that extend to the right from Anchor 2.

Image

Ads
User avatar
xruptor
Posts: 111

Re: Enemy Addon (Test Mode Fix)

Post#2 » Sat Sep 26, 2020 7:46 pm

I've updated the code again. I went ahead and added the group number and player number for each unit frame. That way you can at least see what groups and player number is being displayed as you are sorting them out, rather than having random names. So G = Group # and P = Player#. Example: G:1P:2 = Group 1 Player 2

In addition I have it show all the indicators for the first party member of each group. This should help with aligning the cells properly and perfecting your layout.

Here is an example of the new changes.

Image


Also for some reason Enemy has hard coded a max of 10 party groups. If you want to reduce this down to lets say a max of 6 party groups, then do the following.

Open Constants.lua located Interface\AddOns\Enemy\Code\Core\Constants.lua

Find the following:

Code: Select all

Enemy.MaxGroups = 10
Replace with

Code: Select all

Enemy.MaxGroups = 6
You can change it to however many groups max you want displayed.

Dueil
Posts: 9

Re: Enemy Addon (Test Mode Fix)

Post#3 » Sun Sep 27, 2020 4:26 pm

This is excellent stuff, will make sure to make these changes when im back home. Made some huge changes to my Enemy setup recently and it was a pain testing it out since I had to join random wbs just to see if I got things right haha. Big thanks!
Dueil - 82 Shield DoK
Pesten - 74 2h BG
Illvilja - 58 Heal Shaman
Saga - 65 Shield WP
Saqa - 58 Heal AM

User avatar
xruptor
Posts: 111

Re: Enemy Addon (Test Mode Fix)

Post#4 » Mon Sep 28, 2020 1:29 am

Dueil wrote:
Sun Sep 27, 2020 4:26 pm
This is excellent stuff, will make sure to make these changes when im back home. Made some huge changes to my Enemy setup recently and it was a pain testing it out since I had to join random wbs just to see if I got things right haha. Big thanks!
Glad it will help someone out. Let me know if it works out for you or if you have issues.

Who is online

Users browsing this forum: No registered users and 3 guests