LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

ColorPickButtonElement

Description
Clickable button element with one or two colors inside and a special selection design
Parent
ButtonElement
Functions

copyAttributes

Description
Definition
copyAttributes()
Code
53function ColorPickButtonElement:copyAttributes(src)
54 ColorPickButtonElement:superClass().copyAttributes(self, src)
55
56 self.selectionFrameThickness = table.copy(src.selectionFrameThickness)
57 self.selectionFrameColor = table.copy(src.selectionFrameColor)
58 self.metallicImageUVs = table.copy(src.metallicImageUVs)
59 self.nonMetallicImageUVs = table.copy(src.nonMetallicImageUVs)
60end

draw

Description
Definition
draw()
Code
64function ColorPickButtonElement:draw(clipX1, clipY1, clipX2, clipY2)
65 if self:getIsSelected() then
66 GuiOverlay.renderOverlay(self.overlay, self.absPosition[1] + self.absSize[1] * 0.15, self.absPosition[2] + self.absSize[2] * 0.15, self.absSize[1] * 0.7, self.absSize[2] * 0.7, self:getOverlayState(), clipX1, clipY1, clipX2, clipY2)
67
68
69 local r, g, b, a = unpack(self.selectionFrameColor)
70 drawFilledRect(self.absPosition[1], self.absPosition[2], self.absSize[1], self.selectionFrameThickness[2], r, g, b, a)
71 drawFilledRect(self.absPosition[1], self.absPosition[2] + self.absSize[2] - self.selectionFrameThickness[2], self.absSize[1], self.selectionFrameThickness[2], r, g, b, a)
72
73 drawFilledRect(self.absPosition[1], self.absPosition[2], self.selectionFrameThickness[1], self.absSize[2], r, g, b, a)
74 drawFilledRect(self.absPosition[1] + self.absSize[1] - self.selectionFrameThickness[1], self.absPosition[2], self.selectionFrameThickness[1], self.absSize[2], r, g, b, a)
75 else
76 GuiOverlay.renderOverlay(self.overlay, self.absPosition[1], self.absPosition[2], self.absSize[1], self.absSize[2], self:getOverlayState(), clipX1, clipY1, clipX2, clipY2)
77 end
78
79 if self.debugEnabled or g_uiDebugEnabled then
80 local xPixel = 1 / g_screenWidth
81 local yPixel = 1 / g_screenHeight
82
83 local posX1 = self.absPosition[1]
84 local posX2 = self.absPosition[1]+self.size[1]-xPixel
85
86 local posY1 = self.absPosition[2]
87 local posY2 = self.absPosition[2]+self.size[2]-yPixel
88
89 drawFilledRect(posX1, posY1, posX2-posX1, yPixel, 0, 1, 0, 0.7)
90 drawFilledRect(posX1, posY2, posX2-posX1, yPixel, 0, 1, 0, 0.7)
91 drawFilledRect(posX1, posY1, xPixel, posY2-posY1, 0, 1, 0, 0.7)
92 drawFilledRect(posX1+posX2-posX1, posY1, xPixel, posY2-posY1, 0, 1, 0, 0.7)
93 end
94end

loadFromXML

Description
Definition
loadFromXML()
Code
31function ColorPickButtonElement:loadFromXML(xmlFile, key)
32 ColorPickButtonElement:superClass().loadFromXML(self, xmlFile, key)
33
34 -- create second overlay for the second color.
35
36 self.selectionFrameThickness = GuiUtils.getNormalizedValues(getXMLString(xmlFile, key.."#selectionFrameThickness"), self.outputSize, self.selectionFrameThickness)
37 self.selectionFrameColor = GuiUtils.getColorArray(getXMLString(xmlFile, key.."#selectionFrameColor"), self.selectionFrameColor)
38end

loadProfile

Description
Definition
loadProfile()
Code
42function ColorPickButtonElement:loadProfile(profile, applyProfile)
43 ColorPickButtonElement:superClass().loadProfile(self, profile, applyProfile)
44
45 self.selectionFrameThickness = GuiUtils.getNormalizedValues(profile:getValue("selectionFrameThickness"), self.outputSize, self.selectionFrameThickness)
46 self.selectionFrameColor = GuiUtils.getColorArray(profile:getValue("selectionFrameColor"), self.selectionFrameColor)
47 self.metallicImageUVs = GuiUtils.getUVs(profile:getValue("metallicImageUVs"))
48 self.nonMetallicImageUVs = table.copy(self.overlay.uvs)
49end

new

Description
Definition
new()
Code
16function ColorPickButtonElement.new(target, custom_mt)
17 local self = ColorPickButtonElement:superClass().new(target, custom_mt or ColorPickButtonElement_mt)
18
19 self.colors = {
20 {1,1,1,1}
21 }
22
23 self.selectionFrameThickness = {0, 0}
24 self.selectionFrameColor = {1,1,1,1}
25
26 return self
27end