Skip to content

Commit

Permalink
Initial WIP of icon browser tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Meorawr committed Nov 12, 2023
1 parent b439868 commit 11dde5b
Show file tree
Hide file tree
Showing 18 changed files with 841 additions and 286 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: nebularg/actions-luacheck@v1
with:
args: --no-color -q
files: $(git ls-files '*.lua' ':!:totalRP3/Libs/Ellyb/Libraries/*' ':!:totalRP3/Libs/MSA-DropDownMenu-1.0/*' ':!:totalRP3/Libs/TaintLess/*' ':!:totalRP3/Locales/????.lua')
files: $(git ls-files '*.lua' ':!:totalRP3/Libs/Ellyb/Libraries/*' ':!:totalRP3/Libs/MSA-DropDownMenu-1.0/*' ':!:totalRP3/Libs/TaintLess/*' ':!:totalRP3/Locales/????.lua', ':!:Types/*')
annotate: warning

- name: Run editorconfig-checker
Expand Down
5 changes: 4 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ max_line_length = false
exclude_files = {
"Scripts/mature_dictionary_template.lua",
"totalRP3/Libs",
"Types",
};

ignore = {
Expand Down Expand Up @@ -397,6 +398,7 @@ stds.wow = {
"CreateFromMixins",
"CreateIndexRangeDataProvider",
"CreateScrollBoxListGridView",
"CreateTextureMarkup",
"CreateVector2D",
"DisableAddOn",
"EventRegistry",
Expand Down Expand Up @@ -472,7 +474,6 @@ stds.wow = {
"IsVeteranTrialAccount",
"JoinChannelByName",
"Lerp",
"LIGHTBLUE_FONT_COLOR",
"Mixin",
"MouseIsOver",
"NeutralPlayerSelectFaction",
Expand Down Expand Up @@ -606,6 +607,7 @@ stds.wow = {
"FUEL",
"FURY",
"GENERIC_FRACTION_STRING",
"GREEN_FONT_COLOR",
"HEALTH",
"HIGHLIGHT_FONT_COLOR",
"HOLY_POWER",
Expand Down Expand Up @@ -644,6 +646,7 @@ stds.wow = {
"LE_PET_JOURNAL_FILTER_COLLECTED",
"LE_PET_JOURNAL_FILTER_NOT_COLLECTED",
"LE_SORT_BY_LEVEL",
"LIGHTBLUE_FONT_COLOR",
"LINK_FONT_COLOR",
"LIST_DELIMITER",
"LOCALE_enGB",
Expand Down
48 changes: 48 additions & 0 deletions Types/CallbackRegistry.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---@meta

--- An object that acts as the owning handle of a callback registration.
---@alias TRP3.CallbackOwner string|table|thread

--- Interface for objects that allow untyped callback event registrations,
--- mirroring the interface exposed by CallbackHandler-1.0.
---
---@class TRP3.CallbackRegistry
local CallbackRegistry = {};

---@generic T: string
---@param owner TRP3.CallbackOwner
---@param event T
---@param callback fun(event: T, ...)|string?
function CallbackRegistry.RegisterCallback(owner, event, callback) end

---@generic T: string, V
---@param owner TRP3.CallbackOwner
---@param event T
---@param callback fun(arg1: V, event: T, ...)|string?
---@param arg1 V
function CallbackRegistry.RegisterCallback(owner, event, callback, arg1) end

---@param owner TRP3.CallbackOwner
---@param event string
function CallbackRegistry.UnregisterCallback(owner, event) end

---@param owner TRP3.CallbackOwner
function CallbackRegistry.UnregisterAllCallbacks(owner) end

--- Interface for objects that allow dispatching of untyped callback events,
--- mirroring the interface exposed by CallbackHandler-1.0.
---@class TRP3.CallbackDispatcher
local CallbackDispatcher = {};

---@param event string
---@param ... any
function CallbackDispatcher:Fire(event, ...) end

---@param object table
---@return TRP3.CallbackDispatcher callbacks
function TRP3_API.InitCallbackRegistry(object) end

---@param object table
---@param events string[] | { [string]: string }
---@return TRP3.CallbackDispatcher callbacks
function TRP3_API.InitCallbackRegistryWithEvents(object, events) end
4 changes: 4 additions & 0 deletions Types/Core.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---@meta

---@class TRP3_API
TRP3_API = {};
5 changes: 5 additions & 0 deletions Types/Game.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---@meta

---@alias TRP3.ClassToken "DEATHKNIGHT" | "DEMONHUNTER" | "DRUID" | "EVOKER" | "HUNTER" | "MAGE" | "MONK" | "PALADIN" | "PRIEST" | "ROGUE" | "SHAMAN" | "WARLOCK" | "WARRIOR"
---@alias TRP3.FileID integer
---@alias TRP3.AtlasElementID integer
63 changes: 63 additions & 0 deletions Types/IconBrowser.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---@meta

---@class TRP3.IconBrowserModel
local IconBrowserModel = {};

---@param owner TRP3.CallbackOwner
---@param event "OnModelUpdated"
---@param callback fun(event: "OnModelUpdated")|string?
function IconBrowserModel.RegisterCallback(owner, event, callback) end

---@param owner TRP3.CallbackOwner
---@param event "OnModelUpdated"
function IconBrowserModel.UnregisterCallback(owner, event) end

---@param owner TRP3.CallbackOwner
function IconBrowserModel.UnregisterAllCallbacks(owner) end

---@class TRP3.IconBrowserFilterModel : TRP3.IconBrowserModel
local IconBrowserFilterModel = {};

---@param owner TRP3.CallbackOwner
---@param event "OnModelUpdated"
---@param callback fun(event: "OnModelUpdated")|string?
function IconBrowserFilterModel.RegisterCallback(owner, event, callback) end

---@param owner TRP3.CallbackOwner
---@param event "OnSearchProgressChanged"
---@param callback fun(event: "OnSearchProgressChanged", progress: TRP3.IconBrowserSearchProgress)|string?
function IconBrowserFilterModel.RegisterCallback(owner, event, callback) end

---@param owner TRP3.CallbackOwner
---@param event "OnSearchStateChanged"
---@param callback fun(event: "OnSearchStateChanged", state: "running" | "finished")|string?
function IconBrowserFilterModel.RegisterCallback(owner, event, callback) end

---@param owner TRP3.CallbackOwner
---@param event "OnSearchProgressChanged"
function IconBrowserFilterModel.UnregisterCallback(owner, event) end

---@class TRP3.IconBrowserFilterTask
local IconBrowserSearchTask = {};

---@param owner TRP3.CallbackOwner
---@param event "OnProgressChanged"
---@param callback fun(event: "OnProgressChanged", progress: TRP3.IconBrowserSearchProgress)|string?
function IconBrowserSearchTask.RegisterCallback(owner, event, callback) end

---@param owner TRP3.CallbackOwner
---@param event "OnResultsChanged"
---@param callback fun(event: "OnResultsChanged", results: integer[])|string?
function IconBrowserSearchTask.RegisterCallback(owner, event, callback) end

---@param owner TRP3.CallbackOwner
---@param event "OnStateChanged"
---@param callback fun(event: "OnStateChanged", state: "running" | "finished")|string?
function IconBrowserSearchTask.RegisterCallback(owner, event, callback) end

---@param owner TRP3.CallbackOwner
---@param event "OnStateChanged" | "OnProgressChanged" | "OnResultsChanged"
function IconBrowserSearchTask.UnregisterCallback(owner, event) end

---@param owner TRP3.CallbackOwner
function IconBrowserSearchTask.UnregisterAllCallbacks(owner) end
1 change: 1 addition & 0 deletions totalRP3/Core/Core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ https://raw.githubusercontent.com/Meorawr/wow-ui-schema/main/UI.xsd">
<Include file="Events.lua"/>
<Include file="Color.lua"/>
<Include file="ColorData.lua"/>
<Include file="FunctionUtil.lua"/>
<Include file="StringUtil.lua"/>
<Include file="BindingUtil.lua"/>

Expand Down
52 changes: 52 additions & 0 deletions totalRP3/Core/FunctionUtil.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- Copyright The Total RP 3 Authors
-- SPDX-License-Identifier: Apache-2.0

TRP3_FunctionUtil = {};

--- Returns a closure that when first invoked will start a timer of duration
--- `timeout`. When this timer has elapsed, the supplied callback will be
--- invoked.
---
--- Repeated calls to the closure will reset the timeout back to zero, in
--- effect delaying execution of the callback.
---
--- @param timeout number
--- @param callback function
function TRP3_FunctionUtil.Debounce(timeout, callback)
local calls = 0;

local function Decrement()
calls = calls - 1;

if calls == 0 then
callback();
end
end

return function()
C_Timer.After(timeout, Decrement);
calls = calls + 1;
end
end

--- Returns a closure that when first invoked will immediately execute the
--- supplied callback, and starts a timer of duration `timeout`. Until the
--- timer has elapsed, future invocations will do nothing.
---
--- @param timeout number
--- @param callback function
function TRP3_FunctionUtil.Throttle(timeout, callback)
local callable = true;

local function Reset()
callable = true;
end

return function()
if callable then
C_Timer.After(timeout, Reset);
callable = false;
callback();
end
end
end
40 changes: 19 additions & 21 deletions totalRP3/Core/Popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -394,35 +394,33 @@ end
-- Icon browser
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

local IconBrowserCallbackOwner = {}; -- Dummy owner for callback registrations.

local function OnIconBrowserSelection(onSelectCallback, _, iconInfo)
TRP3_IconBrowserUtil.UnregisterAllCallbacks(IconBrowserCallbackOwner);
hidePopups();
local function showIconBrowser(onSelectCallback, onCancelCallback, scale, selectedIcon)
local function OnAccept(iconInfo)
hidePopups();

if onSelectCallback then
onSelectCallback(iconInfo.name, iconInfo);
if onSelectCallback then
onSelectCallback(iconInfo.name, iconInfo);
end
end
end

local function OnIconBrowserClosed(onCancelCallback)
TRP3_IconBrowserUtil.UnregisterAllCallbacks(IconBrowserCallbackOwner);
hidePopups();
local function OnCancel()
hidePopups();

if onCancelCallback then
onCancelCallback();
if onCancelCallback then
onCancelCallback();
end
end
end

local function showIconBrowser(onSelectCallback, onCancelCallback, scale)
TRP3_IconBrowserUtil.RegisterCallback(IconBrowserCallbackOwner, "OnBrowserIconSelected", OnIconBrowserSelection, onSelectCallback);
TRP3_IconBrowserUtil.RegisterCallback(IconBrowserCallbackOwner, "OnBrowserClosed", OnIconBrowserClosed, onCancelCallback);
TRP3_IconBrowserUtil.OpenBrowser();
TRP3_IconBrowser:SetScale(scale or 1);
TRP3_IconBrowser.Open({
onAcceptCallback = OnAccept,
onCancelCallback = OnCancel,
scale = scale,
selectedIcon = selectedIcon,
});
end

function TRP3_API.popup.hideIconBrowser()
TRP3_IconBrowserUtil.CloseBrowser();
TRP3_IconBrowser.Close();
end

--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Expand Down Expand Up @@ -1145,7 +1143,7 @@ local POPUP_STRUCTURE = {
showMethod = showColorBrowser,
},
[TRP3_API.popup.ICONS] = {
frame = TRP3_IconBrowser,
frame = TRP3_IconBrowserFrame,
showMethod = showIconBrowser,
},
[TRP3_API.popup.MUSICS] = {
Expand Down
13 changes: 13 additions & 0 deletions totalRP3/Core/Prototype.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Copyright The Total RP 3 Authors
-- SPDX-License-Identifier: Apache-2.0

---@class TRP3_API
local TRP3_API = select(2, ...);

-- Prototype factory
Expand Down Expand Up @@ -53,21 +54,33 @@ function PrototypeMetatableFactory:GetOrCreate(prototype)
return metatable;
end

---@generic T : table
---@param prototype T
---@return T object
function TRP3_API.CreateFromPrototype(prototype)
local metatable = PrototypeMetatableFactory:GetOrCreate(prototype);
return setmetatable({}, metatable);
end

---@generic T : table & { __init: fun(object: table, ...: any)? }
---@param prototype T
---@param ... any
---@return T object
function TRP3_API.CreateAndInitFromPrototype(prototype, ...)
local object = TRP3_API.CreateFromPrototype(prototype);

---@cast prototype table
if prototype.__init then
prototype.__init(object, ...);
end

return object;
end

---@generic T : table
---@param object table
---@param prototype T
---@return T object
function TRP3_API.ApplyPrototypeToObject(object, prototype)
local metatable = PrototypeMetatableFactory:GetOrCreate(prototype);
return setmetatable(object, metatable);
Expand Down
2 changes: 2 additions & 0 deletions totalRP3/Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ This will works:|cff00ff00
UI_IMAGE_BROWSER = "Image browser",
UI_IMAGE_SELECT = "Select image",
UI_FILTER = "Filter",
UI_FILTER_NO_RESULTS_FOUND_TITLE = "No results found.",
UI_FILTER_NO_RESULTS_FOUND_TEXT = "Try adjusting your search criteria.",
UI_LINK_URL = "http://your.url.here",
UI_LINK_TEXT = "Your text here",
UI_LINK_SAFE = [[Here's the link URL.]],
Expand Down
12 changes: 6 additions & 6 deletions totalRP3/Modules/Register/Characters/RegisterAbout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ local CONFIG_REGISTER_ABOUT_H3_SIZE = "config_register_about_h3_size";
local defaultFontParameters;
local refreshTemplate2EditDisplay, saveInDraft, template2SaveToDraft; -- Function reference

local showIconBrowser = function(callback)
TRP3_API.popup.showPopup(TRP3_API.popup.ICONS, nil, {callback});
local showIconBrowser = function(callback, selectedIcon)
TRP3_API.popup.showPopup(TRP3_API.popup.ICONS, nil, {callback, nil, nil, selectedIcon});
end;

local function updateAboutTemplateFonts(frame)
Expand Down Expand Up @@ -337,7 +337,7 @@ function refreshTemplate2EditDisplay()
showIconBrowser(function(icon)
frame.frameData.IC = icon;
setupIconButton(_G[frame:GetName().."Icon"], icon);
end);
end, frameData.IC);
end);
-- Buttons
if frameIndex == 1 then
Expand Down Expand Up @@ -894,9 +894,9 @@ function TRP3_API.register.inits.aboutInit()
setupListBox(TRP3_RegisterAbout_Edit_Template3_PhysBkg, bkgTab, setTemplate3PhysBkg, nil, 150, true);
setupListBox(TRP3_RegisterAbout_Edit_Template3_PsyBkg, bkgTab, setTemplate3PsyBkg, nil, 150, true);
setupListBox(TRP3_RegisterAbout_Edit_Template3_HistBkg, bkgTab, setTemplate3HistBkg, nil, 150, true);
TRP3_RegisterAbout_Edit_Template3_PhysIcon:SetScript("OnClick", function() showIconBrowser(onPhisIconSelected) end );
TRP3_RegisterAbout_Edit_Template3_PsyIcon:SetScript("OnClick", function() showIconBrowser(onPsychoIconSelected) end );
TRP3_RegisterAbout_Edit_Template3_HistIcon:SetScript("OnClick", function() showIconBrowser(onHistoIconSelected) end );
TRP3_RegisterAbout_Edit_Template3_PhysIcon:SetScript("OnClick", function() showIconBrowser(onPhisIconSelected, draftData.T3.PH.IC) end );
TRP3_RegisterAbout_Edit_Template3_PsyIcon:SetScript("OnClick", function() showIconBrowser(onPsychoIconSelected, draftData.T3.PS.IC) end );
TRP3_RegisterAbout_Edit_Template3_HistIcon:SetScript("OnClick", function() showIconBrowser(onHistoIconSelected, draftData.T3.HI.IC) end );
TRP3_RegisterAbout_Edit_Music_Action:SetScript("OnClick", onMusicEditClicked);
TRP3_RegisterAbout_Edit_Template2_Add:SetScript("OnClick", template2AddFrame);
TRP3_RegisterAbout_AboutPanel_EditButton:SetScript("OnClick", onEdit);
Expand Down
Loading

0 comments on commit 11dde5b

Please sign in to comment.