cw.theme classclient
Defines the client-side cw.theme library, which registers interface themes and switches between them.
A theme is built between cw.theme:New and cw.theme:Register and can replace or wrap methods of Derma panel
classes with cw.theme:HookReplace, cw.theme:HookBefore and cw.theme:HookAfter. vgui.Register is replaced so
the original panel methods are backed up and restored when a theme is unloaded, and cw.theme:GetMarkupObject
returns the builder used for tooltip text.
Summary
Methods
skin table into the Clockwork Derma skin and refreshes the skins.cwTHEME.cwTHEME.cwTHEME with cw.theme:Finish.Methods
cw.theme:Begin(isFixed, name, baseName)
client deprecated gamemodes/catwork/gamemode/core/libraries/cl_theme.lua:191Deprecated
Use cw.theme:New, which takes the arguments as (name, baseName, isFixed).
Starts building a new theme with the arguments in the old order.
Parameters
- isFixed Boolean optional, defaults to
nilWhether players cannot change the information color - name String optional, defaults to
'Schema'Name of the theme - baseName String optional, defaults to
nilName of the theme to derive from
Returns
- Map The new theme table
Calls a hook of the active theme.
Theme hooks such as PreMainMenuPaint live in the theme's hooks table. The
Pre hooks can return true to replace the default drawing or behaviour.
Parameters
- hookName String Name of the hook
- ... Any Arguments passed to the hook
Returns
- Any Whatever the hook returns, or
nilif the active theme does not define it
Copies the active theme's skin table into the Clockwork Derma skin and refreshes the skins.
Returns whether a theme is registered.
Parameters
- id String Name of the theme
Returns
- Boolean Whether the theme exists
Returns a registered theme by name.
Parameters
- id String Name of the theme
Returns
- Map The theme table, or
nilif it does not exist
cw.theme:Finish(themeTable, bNoSwitch)
client gamemodes/catwork/gamemode/core/libraries/cl_theme.lua:313Saves a theme to the theme library and clears cwTHEME.
Parameters
- themeTable Map The theme table
- bNoSwitch Boolean optional, defaults to
nilWhether to keep the current theme instead of switching to this one
See also
Returns the active theme.
Returns
- Map The active theme table, or
nilif none is loaded
Returns every registered theme.
Returns
- Map<Map> Theme tables keyed by name
Returns a new markup object for building tooltip and info text.
local markup = cw.theme:GetMarkupObject()
markup:Title(itemTable.name)
markup:Add(itemTable.description)
local toolTip = markup:GetText()
Returns
- Map The markup object, with
Add,TitleandGetTextmethods
cw.theme:HookAfter(vguiName, functionName, callback)
client gamemodes/catwork/gamemode/core/libraries/cl_theme.lua:143Adds a function that runs after a method of a Derma panel class, in the theme being built.
Must be called between cw.theme:New and cw.theme:Register; does nothing
otherwise or if the panel class or method does not exist.
Parameters
- vguiName String Name of the panel class
- functionName String Name of the method
- callback Function Called with the panel and the method's arguments after the method
See also
cw.theme:HookBefore(vguiName, functionName, callback)
client gamemodes/catwork/gamemode/core/libraries/cl_theme.lua:113Adds a function that runs before a method of a Derma panel class, in the theme being built.
Must be called between cw.theme:New and cw.theme:Register; does nothing
otherwise or if the panel class or method does not exist.
Parameters
- vguiName String Name of the panel class
- functionName String Name of the method
- callback Function Called with the panel and the method's arguments before the method
See also
cw.theme:HookReplace(vguiName, functionName, callback)
client gamemodes/catwork/gamemode/core/libraries/cl_theme.lua:90Replaces a method of a Derma panel class in the theme being built.
Must be called between cw.theme:New and cw.theme:Register; does nothing
otherwise or if the panel class does not exist.
cw.theme:HookReplace('cwStorage', 'Paint', function(panel, w, h)
draw.RoundedBox(0, 0, 0, w, h, Color(20, 20, 20))
end)
Parameters
- vguiName String Name of the panel class
- functionName String Name of the method to replace
- callback Function The new method, called with the panel and the method's arguments
See also
Internal
This function is internal. It is not part of the public API and may change without notice.
Called from GM:Initialize.
Loads the starting theme when Catwork initializes.
Uses the default_theme config, or the player's cwActiveTheme console
variable when the modify_themes config is on, falling back to Clockwork.
Returns whether the active theme stops players from changing the information color.
Returns
- Boolean Whether the color is fixed;
nilif no theme is active
cw.theme:LoadTheme(themeTable, isBase)
client internal gamemodes/catwork/gamemode/core/libraries/cl_theme.lua:359Internal
This function is internal. It is not part of the public API and may change without notice.
Called by cw.theme:SetActive.
Loads a theme and its base themes.
Calls the theme's CreateFonts, Initialize and PostInitialize methods,
registers its module as the Theme plugin module and merges its panel
changes into the VGUI factory. Does not unload the previous theme; use
cw.theme:SetActive.
Parameters
- themeTable Map The theme table
- isBase Boolean optional, defaults to
nilWhether the theme is loaded as the base of another, which skips the module and panel changes
cw.theme:New(themeName, baseName, isFixed)
client gamemodes/catwork/gamemode/core/libraries/cl_theme.lua:217Starts building a new theme and stores it in the global cwTHEME.
The theme starts as a copy of its base theme, or of the Clockwork theme when
no base is given. Fill in its hooks (theme hooks run by cw.theme:Call),
module (plugin hooks), skin and factory tables and its CreateFonts,
Initialize, PostInitialize and OnUnloaded methods, then call
cw.theme:Register.
local THEME = cw.theme:New('Combine', 'Clockwork')
function THEME.hooks:PostMainMenuPaint(panel)
draw.RoundedBox(0, 0, 0, panel:GetWide(), 4, Color(0, 120, 255))
end
cw.theme:Register()
Parameters
- themeName String optional, defaults to
'Schema'Name of the theme - baseName String optional, defaults to
nilName of the theme to derive from - isFixed Boolean optional, defaults to
nilWhether players cannot change the information color
Returns
- Map The new theme table
Saves the theme being built in cwTHEME with cw.theme:Finish.
Parameters
- bSwitchTo Boolean optional, defaults to
nilWhether to switch to the theme right away
Returns
- String Name of the theme, or
nilif no theme was being built
cw.theme:SetActive(theme, firstLoad)
client gamemodes/catwork/gamemode/core/libraries/cl_theme.lua:330Switches to a theme, unloading the active one first.
Loads the theme with its bases and copies its skin. Does nothing if a theme name is given and no such theme exists.
Parameters
- theme String Name of the theme, or the theme table itself
- firstLoad Boolean optional, defaults to
nilWhether this is the first theme loaded, which skips unloading; only set by Catwork when it initializes
cw.theme:UnloadTheme(theme, isBase)
client internal gamemodes/catwork/gamemode/core/libraries/cl_theme.lua:397Internal
This function is internal. It is not part of the public API and may change without notice.
Called by cw.theme:SetActive.
Unloads a theme and its base themes.
Calls the theme's OnUnloaded method, removes the Theme plugin module and
restores the panel methods it changed from the backup factory. Does not load
another theme; use cw.theme:SetActive.
Parameters
- theme Map optional, defaults to
nilThe theme table; the active theme whennil - isBase Boolean optional, defaults to
nilWhether the theme is unloaded as the base of another