68 - Adding Feature: Searching Teams by Name
Using Hack addon, I did a script to find teams using its name. I have thousands of teams, so it's really needed some kind of search method, instead to expend minutes searching for them while scrolling, scrolling...
How it works:
It adds a small, non intrusive EditBox in top of the label "Selected Team". Just move your mouse to it and you will see some fade effect. Click it, type your team name and hit ENTER. If there is any team matching its name with you typed, it will be selected. If you have more than one team matching, just hit ENTER again to select the next matched team.
I'm newbie while programming wow addons, so sorry for my mess in the code. Fell free to use or non use it in the official code, as you want.
The code:
local tm = LibStub("AceAddon-3.0"):GetAddon("PetBattleTeams"):GetModule("TeamManager");
FixPetTeams = FixPetTeams or tm;
function FixPetTeams:GetPetInfoBySpeciesIDLevel(reqSpecieID, reqLevel)
local numPets, _ = C_PetJournal.GetNumPets();
for idxPet=1, numPets do
local petID, speciesID, _, _, level, _, _, name = C_PetJournal.GetPetInfoByIndex(idxPet);
if (reqSpecieID == speciesID) and (level == reqLevel) then
return petID, name;
end
end
end
-- To use this function, just call: FixPetTeams:fixPetID();
function FixPetTeams:fixPetID()
local PETS_PER_TEAM = 3;
local numTeams = self:GetNumTeams()
for team=1,numTeams do
for petIndex = 1, PETS_PER_TEAM do
local petSlotInfo = self.teams[team][petIndex];
local speciesID = petSlotInfo.speciesID
if speciesID then
local petID, name = self:GetPetInfoBySpeciesIDLevel(speciesID, 25);
if petID then
petSlotInfo.petID = petID;
petSlotInfo.name = name;
print( name );
end
end
end
end
end
-- --------------------------------------------- --
-- Adds support to search teams by name.
--
local GUI = LibStub("AceAddon-3.0"):GetAddon("PetBattleTeams"):GetModule("GUI");
FixPetTeams.GUI = GUI;
local widget = PetBattleTeamFrame;
function FixPetTeams:findTeamByName(nameFilter)
if (not nameFilter) then return end
local numTeams = self:GetNumTeams();
nameFilter = strlower( tostring(nameFilter) );
if (strlen(nameFilter) < 1) then return end
local result = {};
for idxTeam=1,numTeams do
local teamInfo = self.teams[idxTeam];
local sName = teamInfo.name;
if (sName) then
sName = strlower(sName);
local posName = strfind(sName, nameFilter, 1, true);
if (posName) then
--print( teamInfo.name );
result[idxTeam] = teamInfo;
end
end
end
return result;
end
-- To use, just call:
-- FixPetTeams.GUI:addSearchSupport()
-- Just for convenience (or lazy people like me - mwb):
--
function GUI:addSearchSupport()
local findTeamEdit = widget.findTeamEdit or CreateFrame("EditBox", "FindTeamEdit", widget, "InputBoxTemplate");
widget.findTeamEdit = findTeamEdit;
_G.findTeamEdit = findTeamEdit;
findTeamEdit:SetPoint("TOP", widget, "BOTTOM");
findTeamEdit:SetAutoFocus(false);
--findTeamEdit:SetAllPoints();
findTeamEdit:Show();
return widget;
end
local function findTeamEdit_OnTextChanged(self)
local sNameFilter = self:GetText();
local resultFound = FixPetTeams:findTeamByName(sNameFilter);
if not resultFound then
print("-----------------------------");
return;
end
for idxTeam, teamInfo in ipairs(resultFound) do
print( sNameFilter );
end
end
local function findTeamEdit_OnEnterPressed(self)
local sNameFilter = self:GetText();
print("");
print("-----------------------------");
local resultFound = FixPetTeams:findTeamByName(sNameFilter);
if not resultFound then
return;
end
local idxCurTeam = FixPetTeams:GetSelected() or 0;
local idxNewTeam = 0;
local idxFirstTeam = 0;
for idxTeam, teamInfo in pairs(resultFound) do
print( "#" .. idxTeam .. " " .. teamInfo.name );
if (idxFirstTeam<1) then
idxFirstTeam = idxTeam;
end
--print( idxTeam );
if (idxTeam > idxCurTeam) then
if (idxNewTeam==0 or idxNewTeam>idxTeam) then
idxNewTeam = idxTeam;
end
end
end
if (idxNewTeam<1) then
idxNewTeam = idxFirstTeam;
end
--GUI:ResetScrollBar();
--PetBattleTeamsScrollFrame:Hide();
FixPetTeams:SetSelected(idxNewTeam);
--PetBattleTeamsScrollFrame:Show();
do
local self = PetBattleTeamsRosterFrame;
local teamFrames = self.scrollChild.teamFrames
local rowHeight = teamFrames[1]:GetHeight();
local totalHeight = self.scrollFrame:GetVerticalScrollRange()
local tot = totalHeight;
local pos = tot / (rowHeight+64) * (idxNewTeam-1);
if (pos<0) then
pos = 0;
elseif (pos>tot) then
pos = tot;
end
self.scrollFrame:SetVerticalScroll(pos)
end
print( "TIME: " .. idxNewTeam);
end
local FIND_EDIT_GAIN_FOCUS_ALPHA = 0.95;
local FIND_EDIT_LOST_FOCUS_ALPHA = 0.3;
GUI:addSearchSupport();
widget:Hide();
findTeamEdit:Hide();
findTeamEdit:SetFrameStrata("DIALOG");
findTeamEdit:SetAlpha(FIND_EDIT_LOST_FOCUS_ALPHA);
--findTeamEdit:ClearAllPoints();
findTeamEdit:SetAllPoints(widget.selectedTeamText
--findTeamEdit:SetSize(60, 25);
--findTeamEdit:SetPoint("TOP", widget.selectedTeamText "BOTTOM");
findTeamEdit:SetScript("OnTextChanged", findTeamEdit_OnTextChanged);
findTeamEdit:SetScript("OnEnterPressed", findTeamEdit_OnEnterPressed);
findTeamEdit:SetScript("OnEnter", function(self)
widget.selectedTeamText:SetAlpha(FIND_EDIT_LOST_FOCUS_ALPHA)
end);
findTeamEdit:SetScript("OnLeave", function(self)
if (strlen(self:GetText())==0) then
widget.selectedTeamText:SetAlpha(FIND_EDIT_GAIN_FOCUS_ALPHA)
end
end);
findTeamEdit:SetScript("OnEditFocusGained", function(self)
self:SetAlpha(FIND_EDIT_GAIN_FOCUS_ALPHA);
widget.selectedTeamText:SetAlpha(FIND_EDIT_LOST_FOCUS_ALPHA)
end);
findTeamEdit:SetScript("OnEditFocusLost", function(self)
self:SetAlpha(FIND_EDIT_LOST_FOCUS_ALPHA);
widget.selectedTeamText:SetAlpha(FIND_EDIT_GAIN_FOCUS_ALPHA)
end);
--findTeamEdit:SetScript("OnEscapePressed", function(self) self:SetText("" end);
findTeamEdit:Show();
widget:Show();
| Name | Description | Size | MD5 |
|---|---|---|---|
| fixPetBattleTeams.lua | The code to search teams by name | 6.0 KiB | 4b8f7132403d... |
| User | When | Change |
|---|---|---|
| marciowb | Dec 15, 2013 at 14:28 UTC | Changed description:end - + -- To use this function, just call: FixPetTeams:fixPetID(); function FixPetTeams:fixPetID() local PETS_PER_TEAM = 3; local numTeams = self:GetNumTeams() ---------------------------------------- end - -- --------------------------------------------- -- -- Adds support to search teams by name. -- ---------------------------------------- nameFilter = strlower( tostring(nameFilter) ); - if (strlen(nameFilter) < 1) then return end + if (strlen(nameFilter) < 1) then return end local result = {}; ---------------------------------------- for idxTeam, teamInfo in pairs(resultFound) do print( "#" .. idxTeam .. " " .. teamInfo.name ); - if (idxFirstTeam<1) then + if (idxFirstTeam<1) then idxFirstTeam = idxTeam; end --print( idxTeam ); - if (idxTeam > idxCurTeam) then + if (idxTeam > idxCurTeam) then - if (idxNewTeam==0 or idxNewTeam>idxTeam) then + if (idxNewTeam==0 or idxNewTeam>idxTeam) then idxNewTeam = idxTeam; end end end - if (idxNewTeam<1) then + if (idxNewTeam<1) then idxNewTeam = idxFirstTeam; end ---------------------------------------- local totalHeight = self.scrollFrame:GetVerticalScrollRange(); local tot = totalHeight; local pos = tot / (rowHeight+64) * (idxNewTeam-1); - if (pos<0) then + if (pos<0) then pos = 0; - elseif (pos>tot) then + elseif (pos>tot) then pos = tot; end self.scrollFrame:SetVerticalScroll(pos); |
| marciowb | Dec 15, 2013 at 14:27 UTC | Added attachment WoWScrnShot_121513_102858.jpg |
| marciowb | Dec 15, 2013 at 14:26 UTC | Added attachment fixPetBattleTeams.lua |
| marciowb | Dec 15, 2013 at 14:25 UTC | Create |
- 1 comment
- 1 comment
Facts
- Last updated
- Dec 15, 2013
- Reported
- Dec 15, 2013
- Status
- New - Issue has not had initial review yet.
- Type
- Enhancement - A change which is intended to better the project in some way
- Priority
- Medium - Normal priority.
- Votes
- 0
- Reply
- #1
marciowb Dec 15, 2013 at 14:28 UTC - 0 likesJust formatting the code.