API:ColorPickerCreateWithColorTable
From RoR Wiki
UI Lua API · ColorPicker functions
Version: WAR 1.4.8
Fills a ColorPicker with the colours from a Lua table, replacing any colours it had.
ColorPickerCreateWithColorTable(colorPickerName, colorTable, columnsPerRow, spacingX, spacingY)
Arguments
- colorPickerName
string– Name of the ColorPicker.- colorTable
lua-object– A table of colour entries, read ascolorTable[1],colorTable[2], … (see Details).- columnsPerRow
number– Number of swatches per row. Values below 1 are treated as 1.- spacingX, spacingY
number– Gap between swatches in pixels, horizontally and vertically.
Returns
Nothing.
Details
- All existing colours are removed first, as with ColorPickerClear.
columnsPerRow,spacingXandspacingYreplace the values from the window's XML definition. They are converted to whole numbers.- Each entry is a table with these fields:
| Field | Type | Meaning |
|---|---|---|
r, g, b |
number |
Colour components, 0–255. Required. |
id |
number |
Identifier returned by the lookup functions. Required. |
x, y |
number |
Optional position in the picker. If both are numbers the swatch is placed there, as with ColorPickerAddColorAtPosition. Otherwise it takes the next grid position, as with ColorPickerAddColor. |
- If
r,g,boridis missing or not a number, the client reports an error for that key and skips the entry. The other entries are still added. - The client counts all entries of the table, including ones with non-number keys, and reads the integer keys from 1 up to that count. Entries that are not tables are skipped without an error. This makes it safe to pass a table that also has extra named fields, such as the dye list from
GetDyeMerchantData(), which has anumColorsfield.
Errors
Error in function call 'ColorPickerCreateWithColorTable': Window %s does not existError in function call 'ColorPickerCreateWithColorTable': Window %s is not a ColorPickerError in function call 'ColorPickerCreateWithColorTable': color table parameter is not a tableError in passed in table lookup: key %s's value is nil– for a missingr,g,borid.Error in passed in table lookup: key %s's value is not a number
Example
From default/ea_chatwindow/source/chatoptionswindow.lua:
ColorPickerCreateWithColorTable("ChatOptionsWindowColorPicker", ChatSettings.Colors, 4, 10, 10)
From default/ea_characterwindow/source/characterwindowdyes.lua, placing a marker on one of the colours afterwards:
ColorPickerCreateWithColorTable("DyeMerchantColorPicker", CharacterWindow.dyeColors, 5, 10, 10)
if( bleachId )
then
local _, _, _, _, bleachX, bleachY = ColorPickerGetColorById( "DyeMerchantColorPicker", bleachId )
local x, y = WindowGetOffsetFromParent( "DyeMerchantColorPicker" )
WindowSetOffsetFromParent("DyeMerchantBleachSwatch", bleachX + x - 3, bleachY + y - 3)
end
