Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2015-05-04, 17:41


PolskiSebek12

Programista






Wiek: 28
Na forum: 4347 dni
Posty: 343
Nick w MP: CrosRoad95

Piwa: 3883

Respekt: 288,8
Respekt: 288,8Respekt: 288,8Respekt: 288,8

Ostrzeżeń: 100%
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 = {160160160},
    defaultDivider "|",
}
gGUISides = {left 0right 1top 2bottom 3}
gColours = {
    primary = {2556959255}, -- red
    secondary = {25511846255}, -- orange
    tertiary = {23242104255}, -- pink
    
    defaultLabel = {255255255},
    grey = {120120120},
    --primaryLight = {255153145255},
    primaryLight = {237126119255},
}
function setRolloverColour(elementrolloverrolloff)
    setElementData(element"guieditor:rollonColour"rollover)
    setElementData(element"guieditor:rolloffColour"rolloff)

    addEventHandler("onClientMouseEnter"elementrollover_onfalse)
    addEventHandler("onClientMouseLeave"elementrollover_offfalse)
end
function rollover_on()
    guiSetColour(sourceunpack(getElementData(source"guieditor:rollonColour")))
end
function rollover_off()
    guiSetColour(sourceunpack(getElementData(source"guieditor:rolloffColour")))
end
function exists(e)
    return 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(elementrgba)
    if exists(elementthen
        local t stripGUIPrefix(getElementType(element))
        
        if == "label" then
            guiLabelSetColor(elementrgb)
        elseif == "window" then
            guiSetProperty(element"CaptionColour"rgbaToHex(rgba))
        elseif == "staticimage" then
            local col rgbaToHex(rgba)
            
            guiSetProperty(element"ImageColours"string.format("tl:%s tr:%s bl:%s br:%s"tostring(col), tostring(col), tostring(col), tostring(col)))
        elseif == "combobox" then
            guiSetProperty(element"NormalEditTextColour"rgbaToHex(rgba))
        else
            guiSetProperty(element"NormalTextColour"rgbaToHex(rgba))
        end
    end
end
function guiWindowTitlebarButtonAdd(windowtextalignmentonClick, ...)
    local offset getElementData(window"guieditor:titlebarButton_"..alignment) or 5
    local w guiGetSize(windowfalse)
    
    -- 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(100100400300"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)


Podpis
Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
Shama0921
Tagi: dodatek :: gui
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Zasoby do MTA » [SKRYPT] Dodatek do gui Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku