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

Adds a directory category, or moves an existing one under a new parent.
Adds a text replacement applied to a category's HTML when it is shown.
Adds a category made of a single HTML page or website.
Adds a page of HTML to a category, creating the category if needed.
Sets a category's content to a single HTML page or website, creating the category if needed.
Returns whether a directory category exists.
Returns a directory category.
Returns the formatting of a category.
Returns the page comparator of a category.
Returns the tooltip of a category.
Returns the name a category is displayed with.
Returns the HTML every directory page is wrapped in.
Returns the directory menu panel.
Removes a page from a category, or the whole category.
Applies a category's text replacements to some HTML.
Sets the HTML a category's content is wrapped in.
Sets how the pages of a category are sorted.
Sets the tooltip shown on a category in the directory tree.
Sets the name a category is displayed with in the directory tree.
Sets the HTML every directory page is wrapped in.

Methods

cw.directory:AddCategory(category, parent)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:218

Adds 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 nil Name of the parent category; false adds 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:81

Adds 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:125

Adds 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 nil for a top level category
  • htmlCode String HTML of the page, or its URL when isWebsite is set
  • isWebsite Boolean optional, defaults to nil Whether htmlCode is a URL to open

cw.directory:AddCode(category, htmlCode, noLineBreak, sortData, Callback)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:262

Adds 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 nil Whether no <br> is put before this page
  • sortData Any optional, defaults to nil Value used by the category's sorting function and passed to Callback
  • Callback Function optional, defaults to nil Called with the HTML and sortData when the page is shown; returns the HTML to show

Returns

cw.directory:AddPage(category, htmlCode, isWebsite)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:346

Sets 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 isWebsite is set
  • isWebsite Boolean optional, defaults to nil Whether htmlCode is a URL to open

cw.directory:CategoryExists(category)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:202

Returns whether a directory category exists.

Parameters

  • category String Name of the category

Returns

  • Boolean true if it exists, nil otherwise

cw.directory:GetCategory(category)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:63

Returns 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; both nil if the category does not exist

cw.directory:GetCategoryFormatting(category)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:180

Returns the formatting of a category.

Parameters

  • category String Name of the category

Returns

  • Map The formatting (htmlCode, noLineBreaks, noMasterFormatting), or cw.directory.formatDefault if none is set

cw.directory:GetCategorySorting(category)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:195

Returns the page comparator of a category.

Parameters

  • category String Name of the category

Returns

  • Function The comparator, or nil if the pages are not sorted

cw.directory:GetCategoryTip(category)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:114

Returns the tooltip of a category.

Parameters

  • category String Name of the category

Returns

  • String The tooltip, or nil if none is set

cw.directory:GetFriendlyName(category)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:142

Returns the name a category is displayed with.

Parameters

  • category String Name of the category

Returns

  • String The friendly name, or category if none is set

cw.directory:GetMasterFormatting()

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:156

Returns the HTML every directory page is wrapped in.

Returns

  • String The master HTML

Returns the directory menu panel.

Returns

  • Panel The panel, or nil if it has not been created

cw.directory:RemoveCode(category, uniqueID, forceRemove)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:297

Removes 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 nil ID returned by cw.directory:AddCode; when nil the category is removed
  • forceRemove Boolean optional, defaults to nil Whether to remove the category even when it has child categories

cw.directory:ReplaceMatches(category, htmlCode)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:94

Applies 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:168

Sets 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 false Whether pages are joined without <br> between them
  • noMasterFormatting Boolean optional, defaults to false Stored with the formatting as noMasterFormatting

cw.directory:SetCategorySorting(category, Callback)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:188

Sets how the pages of a category are sorted.

Parameters

  • category String Name of the category
  • Callback Function table.sort comparator called with two page data tables (htmlCode, sortData...)

cw.directory:SetCategoryTip(category, tip)

client gamemodes/catwork/gamemode/core/libraries/cl_directory.lua:107

Sets 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:135

Sets 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:150

Sets 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

Defined in