PolskiSebek12
Programista
Wiek: 28 Na forum: 4346 dni Posty: 343
Nick w MP: CrosRoad95
Piwa : 3883
Witam
Wyci?gn??em z guieditor'a ciekaw? funkcje kt?ra umo?liwia dodanie do oknie doda? przyciski. Wygl?da to tak:
Skrypt:
gWindowTitlebarButtons = {
defaultColour = { 160 , 160 , 160 },
defaultDivider = "|" ,
}
gGUISides = { left = 0 , right = 1 , top = 2 , bottom = 3 }
gColours = {
primary = { 255 , 69 , 59 , 255 }, -- red
secondary = { 255 , 118 , 46 , 255 }, -- orange
tertiary = { 232 , 42 , 104 , 255 }, -- pink
defaultLabel = { 255 , 255 , 255 },
grey = { 120 , 120 , 120 },
-- primaryLight = { 255 , 153 , 145 , 255 },
primaryLight = { 237 , 126 , 119 , 255 },
}
function setRolloverColour ( element , rollover , rolloff )
setElementData ( element , "guieditor:rollonColour" , rollover )
setElementData ( element , "guieditor:rolloffColour" , rolloff )
addEventHandler ( "onClientMouseEnter" , element , rollover_on , false )
addEventHandler ( "onClientMouseLeave" , element , rollover_off , false )
end
function rollover_on ()
guiSetColour ( source , unpack ( getElementData ( source , "guieditor:rollonColour" )))
end
function rollover_off ()
guiSetColour ( source , unpack ( getElementData ( source , "guieditor:rolloffColour" )))
end
function exists ( e )
return e and isElement ( e )
end
function stripGUIPrefix ( s )
if type ( s ) == "string" then
return s : sub ( 5 )
else
-- outputDebug ( "Invalid type " .. type ( s ).. " in stripGUIPrefix" , "GENERAL" )
return ""
end
end
function guiSetColour ( element , r , g , b , a )
if exists ( element ) then
local t = stripGUIPrefix ( getElementType ( element ))
if t == "label" then
guiLabelSetColor ( element , r , g , b )
elseif t == "window" then
guiSetProperty ( element , "CaptionColour" , rgbaToHex ( r , g , b , a ))
elseif t == "staticimage" then
local col = rgbaToHex ( r , g , b , a )
guiSetProperty ( element , "ImageColours" , string . format ( "tl:%s tr:%s bl:%s br:%s" , tostring ( col ), tostring ( col ), tostring ( col ), tostring ( col )))
elseif t == "combobox" then
guiSetProperty ( element , "NormalEditTextColour" , rgbaToHex ( r , g , b , a ))
else
guiSetProperty ( element , "NormalTextColour" , rgbaToHex ( r , g , b , a ))
end
end
end
function guiWindowTitlebarButtonAdd ( window , text , alignment , onClick , ...)
local offset = getElementData ( window , "guieditor:titlebarButton_" .. alignment ) or 5
local w = guiGetSize ( window , false )
-- don 't add a divider before the first item
if offset > 10 then
local width = dxGetTextWidth(gWindowTitlebarButtons.defaultDivider, 1, "default")
local label = guiCreateLabel(alignment == "left" and offset or w - offset - width, 2, width, 15, gWindowTitlebarButtons.defaultDivider, false, window)
guiLabelSetColor(label, unpack(gWindowTitlebarButtons.defaultColour))
guiLabelSetHorizontalAlign(label, "center", false)
guiSetProperty(label, "ClippedByParent", "False")
guiSetProperty(label, "AlwaysOnTop", "True")
if alignment == "right" then
setElementData(label, "guiSnapTo", {[gGUISides.right] = offset})
end
offset = offset + width + 5
end
local width = dxGetTextWidth(text, 1, "default")
local label = guiCreateLabel(alignment == "left" and offset or w - offset - width, 2, width, 15, text, false, window)
guiLabelSetColor(label, unpack(gWindowTitlebarButtons.defaultColour))
guiLabelSetHorizontalAlign(label, "center", false)
guiSetProperty(label, "ClippedByParent", "False")
guiSetProperty(label, "AlwaysOnTop", "True")
if alignment == "right" then
setElementData(label, "guiSnapTo", {[gGUISides.right] = offset})
end
offset = offset + width + 5
local args = {...}
for i,v in ipairs(args) do
if v == "__self" then
args[i] = label
end
end
addEventHandler("onClientGUIClick", label,
function(button, state)
if button == "left" and state == "up" then
if onClick then
onClick(unpack(args or {}))
end
end
end,
false)
setRolloverColour(label, gColours.primary, gWindowTitlebarButtons.defaultColour)
--addEventHandler("onClientMouseEnter", label, function() guiLabelSetColor(label, unpack(gColours.primary)) end, false)
--addEventHandler("onClientMouseLeave", label, function() guiLabelSetColor(label, unpack(gWindowTitlebarButtons.defaultColour)) end, false)
setElementData(window, "guieditor:titlebarButton_" .. alignment, offset)
end
Przyk??d u?ycia
gui = guiCreateWindow ( 100 , 100 , 400 , 300 , "Przyk?adowe gui" , false )
function funkcjaA ()
outputChatBox ( "klikn??e? na przycisk: Test1A" )
end
function funkcjaB ()
outputChatBox ( "klikn??e? na przycisk: Test1B" )
end
function funkcjaAa ()
outputChatBox ( "klikn??e? na przycisk: Test2A" )
end
function funkcjaBb ()
outputChatBox ( "klikn??e? na przycisk: Test2B" )
end
guiWindowTitlebarButtonAdd ( gui , "Test1A" , "right" , funkcjaA )
guiWindowTitlebarButtonAdd ( gui , "Test1B" , "right" , funkcjaB )
guiWindowTitlebarButtonAdd ( gui , "Test2A" , "left" , funkcjaAa )
guiWindowTitlebarButtonAdd ( gui , "Test2B" , "left" , funkcjaBb )