Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make icon searching asynchronous #800

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ stds.wow = {
ScrollUtil = {
fields = {
"AddManagedScrollBarVisibilityBehavior",
"InitScrollBoxListWithScrollBar",
"RegisterScrollBoxWithScrollBar",
},
},
Expand Down Expand Up @@ -393,6 +394,8 @@ stds.wow = {
"CreateFrame",
"CreateFramePool",
"CreateFromMixins",
"CreateIndexRangeDataProvider",
"CreateScrollBoxListGridView",
"CreateTextureMarkup",
"CreateVector2D",
"DisableAddOn",
Expand Down Expand Up @@ -436,15 +439,16 @@ stds.wow = {
"GetNormalizedRealmName",
"GetNumLanguages",
"GetPlayerInfoByGUID",
"GetUnitName",
"GetRealmName",
"GetSpellDescription",
"GetSpellInfo",
"GetSpellTexture",
"GetStablePetInfo",
"GetSubZoneText",
"GetTickTime",
"GetTime",
"GetTimePreciseSec",
"GetUnitName",
"GetZonePVPInfo",
"GetZoneText",
"HideUIPanel",
Expand Down
2 changes: 1 addition & 1 deletion totalRP3/Core/Core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ https://raw.githubusercontent.com/Meorawr/wow-ui-schema/main/UI.xsd">

<Include file="UIMain.lua"/>

<Include file="..\UI\Browsers\Icons.xml"/>
<Include file="..\UI\Browsers\IconBrowser.xml"/>
<Include file="..\UI\Browsers\Companions.xml"/>
<Include file="..\UI\Browsers\Musics.xml"/>
<Include file="..\UI\Browsers\Colors.xml"/>
Expand Down
82 changes: 16 additions & 66 deletions totalRP3/Core/Popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local initList = TRP3_API.ui.list.initList;
local tinsert, tremove, _G, pairs, wipe, math, assert = tinsert, tremove, _G, pairs, wipe, math, assert;
local handleMouseWheel = TRP3_API.ui.list.handleMouseWheel;
local setTooltipForFrame, setTooltipForSameFrame = TRP3_API.ui.tooltip.setTooltipForFrame, TRP3_API.ui.tooltip.setTooltipForSameFrame;
local getIconList, getIconListSize, getImageList, getImageListSize, getMusicList, getMusicListSize;
local getImageList, getImageListSize, getMusicList, getMusicListSize;
local displayDropDown = TRP3_API.ui.listbox.displayDropDown;
local max = math.max;
local TRP3_Enums = AddOn_TotalRP3.Enums;
Expand Down Expand Up @@ -394,83 +394,35 @@ end
-- Icon browser
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

local TRP3_IconBrowser = TRP3_IconBrowser;
local iconWidgetTab = {};
local filteredIconList;
local ui_IconBrowserContent = TRP3_IconBrowserContent;
local IconBrowserCallbackOwner = {}; -- Dummy owner for callback registrations.

local function decorateIcon(icon, index)
icon:SetNormalTexture("Interface\\ICONS\\"..filteredIconList[index]);
icon:SetPushedTexture("Interface\\ICONS\\"..filteredIconList[index]);
setTooltipForFrame(icon, TRP3_IconBrowser, "RIGHT", 0, -100, Utils.str.icon(filteredIconList[index], 75), filteredIconList[index]);
icon.index = index;
end

local function onIconClick(icon)
TRP3_API.popup.hideIconBrowser();
if ui_IconBrowserContent.onSelectCallback then
ui_IconBrowserContent.onSelectCallback(filteredIconList[icon.index], icon);
end
end
local function OnIconBrowserSelection(onSelectCallback, _, iconInfo)
TRP3_IconBrowserUtil.UnregisterAllCallbacks(IconBrowserCallbackOwner);
hidePopups();

local function onIconClose()
TRP3_API.popup.hideIconBrowser();
if ui_IconBrowserContent.onCancelCallback then
ui_IconBrowserContent.onCancelCallback();
if onSelectCallback then
onSelectCallback(iconInfo.name, iconInfo);
end
end

local function filteredIconBrowser()
local filter = TRP3_IconBrowserFilterBox:GetText();
if filteredIconList and filteredIconList ~= getIconList() then -- Remove previous filtering if is not full list
wipe(filteredIconList);
filteredIconList = nil;
end
filteredIconList = getIconList(filter);
TRP3_IconBrowserTotal:SetText(string.format(GENERIC_FRACTION_STRING, #filteredIconList, getIconListSize()));
initList(
{
widgetTab = iconWidgetTab,
decorate = decorateIcon
},
filteredIconList,
TRP3_IconBrowserContentSlider
);
end
local function OnIconBrowserClosed(onCancelCallback)
TRP3_IconBrowserUtil.UnregisterAllCallbacks(IconBrowserCallbackOwner);
hidePopups();

local function initIconBrowser()
handleMouseWheel(ui_IconBrowserContent, TRP3_IconBrowserContentSlider);
TRP3_IconBrowserContentSlider:SetValue(0);
-- Create icons
for row = 0, 5 do
for column = 0, 7 do
local button = CreateFrame("Button", "TRP3_IconBrowserButton_"..row.."_"..column, ui_IconBrowserContent, "TRP3_IconBrowserButton");
button:ClearAllPoints();
button:SetPoint("TOPLEFT", ui_IconBrowserContent, "TOPLEFT", 15 + (column * 45), -15 + (row * (-45)));
button:SetScript("OnClick", onIconClick);
tinsert(iconWidgetTab, button);
end
if onCancelCallback then
onCancelCallback();
end

TRP3_IconBrowserFilterBox:SetScript("OnTextChanged", filteredIconBrowser);
TRP3_IconBrowserClose:SetScript("OnClick", onIconClose);

TRP3_IconBrowserTitle:SetText(loc.UI_ICON_BROWSER);
TRP3_IconBrowserFilterBoxText:SetText(loc.UI_FILTER);
filteredIconBrowser();
end

local function showIconBrowser(onSelectCallback, onCancelCallback, scale)
ui_IconBrowserContent.onSelectCallback = onSelectCallback;
ui_IconBrowserContent.onCancelCallback = onCancelCallback;
TRP3_IconBrowserFilterBox:SetText("");
TRP3_IconBrowserFilterBox:SetFocus();
TRP3_IconBrowserUtil.RegisterCallback(IconBrowserCallbackOwner, "OnBrowserIconSelected", OnIconBrowserSelection, onSelectCallback);
TRP3_IconBrowserUtil.RegisterCallback(IconBrowserCallbackOwner, "OnBrowserClosed", OnIconBrowserClosed, onCancelCallback);
TRP3_IconBrowserUtil.OpenBrowser();
TRP3_IconBrowser:SetScale(scale or 1);
end

function TRP3_API.popup.hideIconBrowser()
hidePopups();
TRP3_IconBrowser:Hide();
TRP3_IconBrowserUtil.CloseBrowser();
end

--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Expand Down Expand Up @@ -1161,11 +1113,9 @@ end
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

function TRP3_API.popup.init()
getIconList, getIconListSize = TRP3_API.utils.resources.getIconList, TRP3_API.utils.resources.getIconListSize;
getImageList, getImageListSize = TRP3_API.utils.resources.getImageList, TRP3_API.utils.resources.getImageListSize;
getMusicList, getMusicListSize = TRP3_API.utils.resources.getMusicList, TRP3_API.utils.resources.getMusicListSize;

initIconBrowser();
initCompanionBrowser();
initMusicBrowser();
initColorBrowser();
Expand Down
1 change: 1 addition & 0 deletions totalRP3/Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ Use the |cffffff00Import profile|r option to paste data from a previous export i
This will works:|cff00ff00
- On any item in your bags
- On any icon in the spellbook|r]],
UI_ICON_BROWSER_SEARCHING = "Searching... (%d%%)",
UI_COMPANION_BROWSER_HELP = "Select a battle pet",
UI_COMPANION_BROWSER_HELP_TT = "|cffffff00Warning: |rOnly renamed battle pets can be linked to a profile.\n\n|cff00ff00This section lists these battle pets only.",
UI_ICON_SELECT = "Select icon",
Expand Down
20 changes: 0 additions & 20 deletions totalRP3/Resources/IconList.lua

This file was deleted.

1 change: 0 additions & 1 deletion totalRP3/Resources/Resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
-->
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
https://raw.githubusercontent.com/Meorawr/wow-ui-schema/main/UI.xsd">
<Include file="IconList.lua"/>
<Include file="MusicList.lua"/>
<Include file="ImageList.lua"/>
<Include file="ImageListClassic.lua"/>
Expand Down
Loading
Loading