cw.directory classclient
Defines the client-side cw.directory library, the HTML help pages shown in the directory menu.
Categories form a tree and hold pages of HTML added with cw.directory:AddCode or cw.directory:AddPage, each
category with optional formatting, sorting, text replacements, a tooltip and a friendly name. The file also sets up
the Commands, Plugins, Flags and Voice Commands categories.
Summary
Methods
Methods
cw.directory:AddCategory(category, parent)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:218Adds a directory category, or moves an existing one under a new parent.
The parent category is created if it does not exist. Does nothing once the client has finished booting.
Parameters
- category String Name of the category
- parent String optional, defaults to
nilName of the parent category;falseadds the category without changing the parent of an existing one
Returns
- String The category name
- String The parent name
cw.directory:AddCategoryMatch(category, sFind, sReplace)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:81Adds a text replacement applied to a category's HTML when it is shown.
cw.directory:AddCategoryMatch('Flags', '[icon]', 'materials/icon16/flag_blue.png')
Parameters
- category String Name of the category
- sFind String Text to look for, such as
'[icon]' - sReplace String Text to put in its place
See also
cw.directory:AddCategoryPage(category, parent, htmlCode, isWebsite)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:125Adds a category made of a single HTML page or website.
Combines cw.directory:AddCategory and cw.directory:AddPage.
Parameters
- category String Name of the category
- parent String Name of the parent category, or
nilfor a top level category - htmlCode String HTML of the page, or its URL when
isWebsiteis set - isWebsite Boolean optional, defaults to
nilWhetherhtmlCodeis a URL to open
cw.directory:AddCode(category, htmlCode, noLineBreak, sortData, Callback)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:262Adds a page of HTML to a category, creating the category if needed.
Rebuilds the directory panel if it is open. Does nothing once the client has finished booting.
cw.directory:AddCode('Flags', '<tr><td>[details]</td></tr>', nil, flag, function(htmlCode, sortData)
return string.Replace(htmlCode, '[details]', L(details))
end)
Parameters
- category String Name of the category
- htmlCode String HTML of the page
- noLineBreak Boolean optional, defaults to
nilWhether no<br>is put before this page - sortData Any optional, defaults to
nilValue used by the category's sorting function and passed toCallback - Callback Function optional, defaults to
nilCalled with the HTML andsortDatawhen the page is shown; returns the HTML to show
Returns
- Number ID of the page within the category, for
cw.directory:RemoveCode
cw.directory:AddPage(category, htmlCode, isWebsite)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:346Sets a category's content to a single HTML page or website, creating the category if needed.
Rebuilds the directory panel if it is open. Does nothing once the client has finished booting.
Parameters
- category String Name of the category
- htmlCode String HTML of the page, or its URL when
isWebsiteis set - isWebsite Boolean optional, defaults to
nilWhetherhtmlCodeis a URL to open
cw.directory:CategoryExists(category)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:202Returns whether a directory category exists.
Parameters
- category String Name of the category
Returns
- Boolean
trueif it exists,nilotherwise
cw.directory:GetCategory(category)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:63Returns a directory category.
Parameters
- category String Name of the category
Returns
- Map The category table (
category,pageData,parent...) - Number Its index in
cw.directory.stored; bothnilif the category does not exist
cw.directory:GetCategoryFormatting(category)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:180Returns the formatting of a category.
Parameters
- category String Name of the category
Returns
- Map The formatting (
htmlCode,noLineBreaks,noMasterFormatting), orcw.directory.formatDefaultif none is set
cw.directory:GetCategorySorting(category)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:195Returns the page comparator of a category.
Parameters
- category String Name of the category
Returns
- Function The comparator, or
nilif the pages are not sorted
cw.directory:GetCategoryTip(category)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:114Returns the tooltip of a category.
Parameters
- category String Name of the category
Returns
- String The tooltip, or
nilif none is set
cw.directory:GetFriendlyName(category)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:142Returns the name a category is displayed with.
Parameters
- category String Name of the category
Returns
- String The friendly name, or
categoryif none is set
cw.directory:GetMasterFormatting()
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:156Returns the HTML every directory page is wrapped in.
Returns
- String The master HTML
Returns the directory menu panel.
Returns
- Panel The panel, or
nilif it has not been created
cw.directory:RemoveCode(category, uniqueID, forceRemove)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:297Removes a page from a category, or the whole category.
Removing the last page also removes the category, unless it has child categories. Rebuilds the directory panel if it is open. Does nothing once the client has finished booting.
Parameters
- category String Name of the category
- uniqueID Number optional, defaults to
nilID returned bycw.directory:AddCode; whennilthe category is removed - forceRemove Boolean optional, defaults to
nilWhether to remove the category even when it has child categories
cw.directory:ReplaceMatches(category, htmlCode)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:94Applies a category's text replacements to some HTML.
Parameters
- category String Name of the category
- htmlCode String HTML to change
Returns
- String The HTML with every match replaced
See also
cw.directory:SetCategoryFormatting(category, htmlCode, noLineBreaks, noMasterFormatting)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:168Sets the HTML a category's content is wrapped in.
[information] in it is replaced with the joined pages, [category] with the
category name.
Parameters
- category String Name of the category
- htmlCode String The category HTML
- noLineBreaks Boolean optional, defaults to
falseWhether pages are joined without<br>between them - noMasterFormatting Boolean optional, defaults to
falseStored with the formatting asnoMasterFormatting
cw.directory:SetCategorySorting(category, Callback)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:188Sets how the pages of a category are sorted.
Parameters
- category String Name of the category
- Callback Function
table.sortcomparator called with two page data tables (htmlCode,sortData...)
cw.directory:SetCategoryTip(category, tip)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:107Sets the tooltip shown on a category in the directory tree.
Parameters
- category String Name of the category
- tip String Tooltip text
cw.directory:SetFriendlyName(category, name)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:135Sets the name a category is displayed with in the directory tree.
Category names are identifiers, so this is where language phrases go.
Parameters
- category String Name of the category
- name String Displayed name, or a language phrase
cw.directory:SetMasterFormatting(htmlCode)
client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:150Sets the HTML every directory page is wrapped in.
[information] in it is replaced with the page's content.
Parameters
- htmlCode String The master HTML, usually with the page's
<head>and styles