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

Wysłany: 2021-01-11, 14:40


NoNamik







Wiek: 30
Na forum: 224 dni
Posty: 180
Nick w MP: JestemNoNamem

Piwa: 95

Respekt: 50


Witam wiem ze da się zrobić guieditora oraz handling editora pod serial jak to zrobic?

Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-01-11, 14:52


MrVip615







Wiek: 16
Na forum: 2346 dni
Posty: 145
Nick w MP: ramzes

Piwa: 118

Respekt: 75,3


To znaczy? Chodzi Ci o to, zeby tylko osoba z okreslonym serialem mogla je wlaczyc? Jesli tak, to wystarczy, ze dodasz sprawdzanie po wpisaniu komendy/kliknieciu klawisza za pomoca
Więcej informacji znajdziesz w Wikipedii MTA:

getPlayerSerial


Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-01-11, 15:06


dioR







Wiek: 15
Na forum: 85 dni
Posty: 13
Nick w MP: dioR

Piwa: 48

Respekt: 50


A więc tak wystarczy że przejdziesz do hedita następnie folder client następnie gui i włączysz guicreator.lua i tam użyjesz to co napisał MrVip czyli getPlayerSerial u mnie wygląda to tak B)
https://imgur.com/a/pB6WErT
Jeśli pomogłem to liczę na piwko

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
NoNamik
Wysłany: 2021-01-11, 15:07


NoNamik







Wiek: 30
Na forum: 224 dni
Posty: 180
Nick w MP: JestemNoNamem

Piwa: 95

Respekt: 50


a guieditor?

function switch()
    if gEnabled then
        ContextBar.add("GUI Editor disabled")
        gEnabled false
        showCursor(false)
    else
        gEnabled true
        setup()
        ContextBar.add("GUI Editor enabled")    
        UndoRedo.updateGUI()
    end
end
addCommandHandler("guied", switch)




Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-01-11, 15:10


MrVip615







Wiek: 16
Na forum: 2346 dni
Posty: 145
Nick w MP: ramzes

Piwa: 118

Respekt: 75,3


"NoNamik" napisał/a:

a guieditor?

function switch()
    if gEnabled then
        ContextBar.add("GUI Editor disabled")
        gEnabled false
        showCursor(false)
    else
        gEnabled true
        setup()
        ContextBar.add("GUI Editor enabled")    
        UndoRedo.updateGUI()
    end
end
addCommandHandler("guied", switch)




function switch(plr)
    if not getPlayerSerial(plr)=="twoj serial" then return end
    if gEnabled then
        ContextBar.add("GUI Editor disabled")
        gEnabled false
        showCursor(false)
    else
        gEnabled true
        setup()
        ContextBar.add("GUI Editor enabled")    
        UndoRedo.updateGUI()
    end
end
addCommandHandler("guied", switch)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-01-11, 15:21


NoNamik







Wiek: 30
Na forum: 224 dni
Posty: 180
Nick w MP: JestemNoNamem

Piwa: 95

Respekt: 50


MrVip615, nie dziala

Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-01-11, 15:25


MrVip615







Wiek: 16
Na forum: 2346 dni
Posty: 145
Nick w MP: ramzes

Piwa: 118

Respekt: 75,3


"NoNamik" napisał/a:

MrVip615, nie dziala

pokaz jak to zrobiles

Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-01-11, 15:26


NoNamik







Wiek: 30
Na forum: 224 dni
Posty: 180
Nick w MP: JestemNoNamem

Piwa: 95

Respekt: 50


MrVip615,

function switch()
     if not getPlayerSerial(plr)=="123" then return end
    if gEnabled then
        ContextBar.add("GUI Editor disabled")
        gEnabled false
        showCursor(false)
    else
        gEnabled true
        setup()
        ContextBar.add("GUI Editor enabled")    
        UndoRedo.updateGUI()
    end
end
addCommandHandler("guied", switch)


Dalem serial jako 123 by sprawdzic czy inni gracze moga zrobic nie majac takowego serialu i moga

  
Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-01-11, 15:34


MrVip615







Wiek: 16
Na forum: 2346 dni
Posty: 145
Nick w MP: ramzes

Piwa: 118

Respekt: 75,3


"NoNamik" napisał/a:

MrVip615,

function switch()
     if not getPlayerSerial(plr)=="123" then return end
    if gEnabled then
        ContextBar.add("GUI Editor disabled")
        gEnabled false
        showCursor(false)
    else
        gEnabled true
        setup()
        ContextBar.add("GUI Editor enabled")    
        UndoRedo.updateGUI()
    end
end
addCommandHandler("guied", switch)


Dalem serial jako 123 by sprawdzic czy inni gracze moga zrobic nie majac takowego serialu i moga


To zrob tak:

function switch(plr)
    if gEnabled then
        ContextBar.add("GUI Editor disabled")
        gEnabled false
        showCursor(false)
    else
        if getPlayerSerial(plr)=="sadsa" then
            gEnabled true
            setup()
            ContextBar.add("GUI Editor enabled")    
            UndoRedo.updateGUI()
        end
    end
end
addCommandHandler("guied", switch)

Jak cos, to jeszcze jest pod przycisk bindowany guieditor w pliku server.lua

Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-01-11, 15:36


NoNamik







Wiek: 30
Na forum: 224 dni
Posty: 180
Nick w MP: JestemNoNamem

Piwa: 95

Respekt: 50


MrVip615, binda usunalem a to dalej nie dziala moze dam caly kod

--[[--------------------------------------------------
    GUI Editor
    client
    main.lua
    
    Released as isyou are free to do whatever you want with the code
    
    For any questions please try the following:
        MTA forum posthttp://forum.mtasa.com/viewtopic.php?f=108&t=22831
        MTA community posthttp://community.mtasa.com/index.php?p=resources&s=details&id=141
        PM me on the MTA forum (user 'Remp'): http://forum.mtasa.com/ucp.php?i=pm&mode=compose&u=25266
        Find me on GTANet irc (user 'Remp')
    

    Bugs/issues:
        - cannot get the original filepath of a gui image
        many other elements have properties that can be set and never got
        gridlists crash guiGetProperties
        guiGetFont does not return an element when a custom font is used
            
    Wishlist:
        - make multiple selection right click menu smarter when selecting many of the same element type
        better editbox support (highlighting from outside the boundsmultiline editing)
        - GUI Editor wiki page
        Output in OO format
        Document all new changes
        add undo/redo actions for gridlist options
        Fix the problems with relative DX loading/output
        
    Changes:

--]]--------------------------------------------------

gEnabled false

gFilepathPrefix ":"..tostring(getResourceName(resource)).."/"

gRadioButtonGroupID 1

gScreen = {}
gScreen.xgScreen.guiGetScreenSize()

gGUISides = {left 0right 1top 2bottom 3}
gGUIDimensions = {width 4height 5}
gEventPriorities = {
    elementSelectRender "high+101",
    elementBorderRender "high+100",
    DXElementRender "high+10",

    snappingRender "low-100",
    hackClick "low-99999"
}

gColours = {
    primary = {2556959255}, -- red
    secondary = {25511846255}, -- orange
    tertiary = {23242104255}, -- pink
    
    defaultLabel = {255255255},
    grey = {120120120},
    --primaryLight = {255153145255},
    primaryLight = {237126119255},
}
-- primarysecondarytertiaryquaternaryquinarysenaryseptenaryoctonarynonary, and denary

gAreaColours = {
    primary "777777",
    secondary "CCCCCC",
    
    dark "000000",
}
gAreaColours.primaryPacked = {gAreaColours.primarygAreaColours.primarygAreaColours.primarygAreaColours.primary}
gAreaColours.secondaryPacked = {gAreaColours.secondarygAreaColours.secondarygAreaColours.secondarygAreaColours.secondary}
gAreaColours.darkPacked = {gAreaColours.darkgAreaColours.darkgAreaColours.darkgAreaColours.dark}

gGUITypes = {
    "gui-window",
    "gui-button",
    "gui-label",
    "gui-checkbox",
    "gui-memo",
    "gui-edit",
    "gui-gridlist",
    "gui-progressbar",
    "gui-tabpanel",
    "gui-tab",
    "gui-radiobutton",
    "gui-staticimage",
    "gui-scrollpane",
    "gui-scrollbar",
    "gui-combobox"
}

gFonts = {
    "default-normal",
    "default-small",
    "default-bold-small",
    "clear-normal",
    "sa-header",
    "sa-gothic",
}

gDXFonts = {
    "default",
    "default-bold",
    "clear",
    "arial",
    "sans",
    "pricedown",
    "bankgothic",
    "diploma",
    "beckett",
}


gDefaults = {
    alpha = {
        ["gui-window"] = 80,
        ["gui-button"] = 100,
        ["gui-label"] = 100,
        ["gui-checkbox"] = 100,
        ["gui-memo"] = 100,
        ["gui-edit"] = 100,
        ["gui-gridlist"] = 100,
        ["gui-progressbar"] = 100,
        ["gui-tabpanel"] = 100,
        ["gui-tab"] = 100,
        ["gui-radiobutton"] = 100,
        ["gui-staticimage"] = 100,
        ["gui-scrollpane"] = 100,
        ["gui-scrollbar"] = 100,
        ["gui-combobox"] = 100,
    },
    
    colour = {
        ["gui-window"] = {255255255255},
        ["gui-button"] = {124124124255},
        ["gui-label"] = {255255255255},
        ["gui-checkbox"] = {255255255255},
        ["gui-memo"] = {000255},
        ["gui-edit"] = {000255},
        ["gui-gridlist"] = nil,
        ["gui-progressbar"] = nil,
        ["gui-tabpanel"] = nil,
        ["gui-tab"] = nil,
        ["gui-radiobutton"] = {255255255255},
        ["gui-staticimage"] = {255255255255},
        ["gui-scrollpane"] = nil,
        ["gui-scrollbar"] = nil,
        ["gui-combobox"] = {000255},
    },
    
    properties = {},
    
    font = {
        ["gui-window"] = "default-normal",
        ["gui-button"] = "default-normal",
        ["gui-label"] = "default-normal",
        ["gui-checkbox"] = "default-normal",
        ["gui-memo"] = "default-normal",
        ["gui-edit"] = "default-normal",
        ["gui-gridlist"] = "default-normal",
        ["gui-progressbar"] = "default-normal",
        ["gui-tabpanel"] = "default-normal",
        ["gui-tab"] = "default-normal",
        ["gui-radiobutton"] = "default-normal",
        ["gui-staticimage"] = "default-normal",
        ["gui-scrollpane"] = "default-normal",
        ["gui-scrollbar"] = "default-normal",
        ["gui-combobox"] = "default-normal",
    }
}


gCustomFonts = {}

gDataNames = {}
gDefaultInputMode "no_binds_when_editing"
guiSetInputMode(gDefaultInputMode)


gRightClickHack = {}
gDrawSelectionList = {}


addEventHandler("onClientResourceStart"resourceRoot,
    function()
        setup()
    end
)

--[[
addEventHandler("onClientKey"root,
    function(buttondownOrUp)
        if downOrUp == false then
            if button == "g" then
                if getKeyState("lctrl") or getKeyState("lshift"then
                    switch()
                end
            elseif button == "lctrl" then
                if getKeyState("g"then
                    switch()
                end        
            elseif button == "lshift" then
                if getKeyState("g"then
                    switch()
                end
            end
        end
    end
)
]]

--[[bindKey("g""down",
    function()
        if getKeyState("lshift"then
            switch()
        end
    end
)
bindKey("lshift""down",
    function()
        if getKeyState("g"then
            switch()
        end
    end
)--]]



function setup()
    if gEnabled then
        Settings.setup()
        
        if toBool(Settings.loaded.guieditor_update_check.valuethen
            checkForUpdates(true)
        end

        createMenus()
        
        showCursor(true)        
    end
end


function switch()
    if gEnabled then
        ContextBar.add("GUI Editor disabled")
        gEnabled false
        showCursor(false)
    else
        gEnabled true
        setup()
        ContextBar.add("GUI Editor enabled")    
        UndoRedo.updateGUI()
    end
end
addCommandHandler("guied", switch)


function checkForUpdates(automatic)
    if not gEnabled then
        return
    end
    
    triggerServerEvent("guieditor:server_checkUpdateStatus"localPlayerautomatic)
end


addEvent("guieditor:client_getUpdateStatus"true)
addEventHandler("guieditor:client_getUpdateStatus"root,
    function(automaticupdatenewVersionoldVersion)
        if update then
            local mbox MessageBox_Info:create("Update Available""There is a new version of GUI Editor available at community.mtasa.com\n\nCurrent Version: "..tostring(oldVersion).."\nNew Version: "..tostring(newVersion))
        else
            if not automatic then
                if update == nil then
                    local mbox MessageBox_Info:create("Error""Could not get update status.\nCheck ACL permissions and website availability.\n\nCurrent Version: "..tostring(oldVersion))
                else
                    local mbox MessageBox_Info:create("No Updates Available""You are running the latest version of the GUI Editor.\n\nCurrent Version: "..tostring(oldVersion))
                end
            end
        end
    end
)



addEventHandler("onClientClick"root,
    function(buttonstateabsoluteXabsoluteY)
        if not gEnabled then
            return
        end
        
        if button == "right" and state == "up" then
            for imenu in ipairs(Menu.instances) do
                if menu.visible then
                    menu:close()
                end
            end    

            local t Tutorial.active()
            if t then
                if t.id ~= "main" then
                    return
                end
            end
            
            if table.count(Multiple.inside) > 0 then
                gMenus.multiple:open(absoluteXabsoluteY)
                gMenus.multiple.guiSelection Multiple.inside
                return
            else
                gMenus.multiple.guiSelection nil
            end
            
            
            local dxindex dxGetHoverElement()
            
            -- dx above gui elements
            if dx and dx:postGUI() then
                if resolutionPreview.active then
                    resolutionPreview.prepareMenu() 
                    gMenus.main:open(absoluteXabsoluteYtrue)
                    return
                end

                if dx.dxType == gDXTypes.line then
                    gMenus.dxLine:open(absoluteXabsoluteYdx)
                elseif dx.dxType == gDXTypes.rectangle then
                    gMenus.dxRectangle:open(absoluteXabsoluteYdx)
                elseif dx.dxType == gDXTypes.image then
                    gMenus.dxImage:open(absoluteXabsoluteYdx)
                elseif dx.dxType == gDXTypes.text then
                    gMenus.dxText:open(absoluteXabsoluteYdx)
                end
                return
            end            
            
            local e guiGetHoverElement()
            
            -- dx below gui elements
            if (not e) and dx and (not dx:postGUI()) then
                if resolutionPreview.active then
                    resolutionPreview.prepareMenu() 
                    gMenus.main:open(absoluteXabsoluteYtrue)
                    return
                end

                if dx.dxType == gDXTypes.line then
                    gMenus.dxLine:open(absoluteXabsoluteYdxtrue)
                elseif dx.dxType == gDXTypes.rectangle then
                    gMenus.dxRectangle:open(absoluteXabsoluteYdxtrue)
                elseif dx.dxType == gDXTypes.image then
                    gMenus.dxImage:open(absoluteXabsoluteYdxtrue)
                elseif dx.dxType == gDXTypes.text then
                    gMenus.dxText:open(absoluteXabsoluteYdxtrue)
                end
                return            
            end
            
            if not e then
                if resolutionPreview.active then
                    resolutionPreview.prepareMenu() 
                else
                    for 1#gMenus.main.items - 1 do
                        gMenus.main:getItem(i):setEnabled(true)
                    end                    
                end
            
                gMenus.main:open(absoluteXabsoluteYtrue)
            else
                if resolutionPreview.active then
                    resolutionPreview.prepareMenu() 
                    gMenus.main:open(absoluteXabsoluteYtrue)
                    return
                end
                    
                --if getElementData(e"guieditor.internal:redirect"then
                --    getElementData(e"guieditor.internal:redirect")
                --end

                if managed(ethen
                    local elementType string.lower(getElementType(e))
                    elementType stripGUIPrefix(elementType)
                    
                    if gMenus[elementTypethen
                        gMenus[elementType]:open(absoluteXabsoluteYetrue)
                    else
                        gMenus.main:open(absoluteXabsoluteYtrue)
                    end
                else
                    if getElementData(e"guieditor.internal:noLoad"then
                        gMenus.noLoad:open(absoluteXabsoluteY)
                    else
                        gMenus.notLoaded:open(absoluteXabsoluteYtrue)
                    end
                end
            end        
        elseif button == "left" and state == "up" then
            
        end
        
        menuItemClick(buttonstateabsoluteXabsoluteY)
        
        menuClick(buttonstateabsoluteXabsoluteY)
        
        Creator.click(buttonstateabsoluteXabsoluteY)
        
        Sizer.click(buttonstateabsoluteXabsoluteY)
        Mover.click(buttonstateabsoluteXabsoluteY)
                
        resolutionPreview.click(buttonstateabsoluteXabsoluteY)
        
        Offset.click(buttonstateabsoluteXabsoluteY)
        Attacher.click(buttonstateabsoluteXabsoluteY)
        
        Multiple.click(buttonstateabsoluteXabsoluteY)
        
        HelpWindow.click(buttonstateabsoluteXabsoluteY)
    end
)


addEventHandler("onClientMouseEnter"root,
    function(absoluteXabsoluteY)
        if not gEnabled then
            return
        end

        Creator.enter(sourceabsoluteXabsoluteY)
        Attacher.enter(sourceabsoluteXabsoluteY)
    end
)


addEventHandler("onClientMouseLeave"root,
    function(absoluteXabsoluteY)
        if not gEnabled then
            return
        end
        
        Creator.leave(sourceabsoluteXabsoluteY)
        Attacher.leave(sourceabsoluteXabsoluteY)
    end
)


--[[--------------------------------------------------
    nasty hack to get elements that don't trigger mouse events to work
    
    each broken element is masked with a gui label completely covering it
    the label has MousePassThroughEnabled set to true so it doesn't capture any mouse events
    this means that left click will still interact with the original element (egopen the combo box dropdowndrag the scrollbar pointer)
    
    we bind right click and on down we set MousePassThroughEnabled to falseso the labels capture mouse events again
    then we force a mouse movement (that the user doesn't see), which forces all the mouse events to update and trigger for the labels
    once the onClientClick event has completed firing (and we have done everything we need to with the right click menus)
    we set MousePassThroughEnabled back to true so the original elements can be interacted with again
    
    known problems:
        - when editboxes or memos have input focus, right clicks on broken elements don't work until you click them (to give them focus)
        - borders don't get drawn (because the enter/exit events don't fire)
        - scrollpane scrollbars cannot be dragged
            this is a choice between either non-dragable scrollbars, or not having a border
            since having no border would make them completely uselesshaving non working scrollbars and being semi-useful is the best choice
            
    Update 19/07/2014
        The mouse events now trigger for all gui elements properlyHowevermouse events for children of those fixed elements are now wrong. 
        E.ga label that is a child of a scrollpane will trigger onClientMouseEnter when the mouse is nowhere near the label
        Keeping this hack in until this is fixed in mta
--]]--------------------------------------------------
addEventHandler("onClientClick"root,
    function(buttonstateabsoluteXabsoluteY)
        if not gEnabled then
            return
        end
        
        if button == "right" and state == "up" then
            for element in pairs(gRightClickHack) do
                if exists(elementthen
                    guiSetProperty(element"MousePassThroughEnabled""True")
                    guiSetProperty(getElementData(element"guieditor.internal:redirect"), "ZOrderChangeEnabled""True")
                    --guiSetProperty(element"RiseOnClick""True")
                end
            end
        end
    end,
truegEventPriorities.hackClick)


bindKey("mouse2""down",
    function()
        if not gEnabled then
            return
        end
        
        for _,guiType in ipairs(gGUITypes) do
            for element in pairs(gRightClickHack) do
                if exists(elementthen
                    guiSetProperty(element"MousePassThroughEnabled""False")
                    guiSetProperty(getElementData(element"guieditor.internal:redirect"), "ZOrderChangeEnabled""False")
                    --guiSetProperty(element"RiseOnClick""False")
                    guiBringToFront(element)
                    
                    for i,v in ipairs(guiGetSiblings(element)) do
                        if ~= element then
                            guiBringToFront(v)
                        end
                    end
                end
            end
        end

        jiggleMouse()
    end
)



--[[--------------------------------------------------
    moved mouse over a GUI element
--]]--------------------------------------------------
addEventHandler("onClientMouseMove"root,
    function(absoluteXabsoluteY)
        if not gEnabled then
            return
        end

        Creator.move(sourceabsoluteXabsoluteY)
    end
)

--[[--------------------------------------------------
    moved mouse
--]]--------------------------------------------------
addEventHandler("onClientCursorMove"root,
    function(xyabsoluteXabsoluteY)
        if not gEnabled then
            return
        end
        
        Sizer.move(absoluteXabsoluteY)
        Mover.move(absoluteXabsoluteY)
        
        resolutionPreview.move(absoluteXabsoluteY)
        
        Multiple.move(absoluteXabsoluteY)
        
        Snapping.snap()
    end
)



--[[--------------------------------------------------
    force trigger any gui cursor move/on/off events
--]]--------------------------------------------------
function jiggleMouse()
    if not gEnabled then
        return
    end
        
    local xgetCursorPosition(true)
    
    if x then
        setCursorPosition(x1)
        setCursorPosition(xy)
    end
end



--[[--------------------------------------------------
    border drawing
--]]--------------------------------------------------
local drawBorderList = {}

addEventHandler("onClientRender"root,
    function()
        if not gEnabled then
            return
        end

        local dxindex dxGetHoverElement()
        
        if dx then
            -- draw border
            if dx.dxType == gDXTypes.line then
                
            elseif dx.dxType == gDXTypes.rectangle then
            
            elseif dx.dxType == gDXTypes.text or dx.dxType == gDXTypes.image then
                drawBorderRaw(dx.xdx.ydx.widthdx.height)
            end    
        end            
        
        if guiGetHoverElement() and not Menu.anyOpen() then
            local element guiGetHoverElement()
            
            if getElementData(element"guieditor:border"then
                drawBorder(element)
            end
        end
        
        for _,e in ipairs(drawBorderList) do
            if exists(ethen
                drawBorder(e)
            end
        end
    end
,truegEventPriorities.elementBorderRender)


function drawBorder(element)
    if not gEnabled then
        return
    end
    
    if not removed(elementthen
        local xguiGetAbsolutePosition(element)
        local wguiGetSize(elementfalse)
        
        drawBorderRaw(xywh)
    end
end

function drawBorderRaw(xywh)
    if not gEnabled then
        return
    end
    
    if and and and h then
        dxDrawLine(xywytocolor(unpack(gColours.tertiary)), 1true)
        dxDrawLine(xyxhtocolor(unpack(gColours.tertiary)), 1true)
        dxDrawLine(wywhtocolor(unpack(gColours.tertiary)), 1true)
        dxDrawLine(xhwhtocolor(unpack(gColours.tertiary)), 1true)
    end
end


addEventHandler("onClientElementDataChange"root,
    function(dataoldValue)
        if not gEnabled then
            return
        end
        
        -- track all the element datas we use. This gives us an always accurate list at any point in time of which element datas any given element could have
        -- easier than defining them manually and forgetting to update the list when you add new ones
        if string.find(data"guieditor:"1truethen
            gDataNames[data] = true
        end
        
        if data == "guieditor:drawBorder" then
            if getElementData(source"guieditor:drawBorder"then
                table.insert(drawBorderListsource)
            else
                for i,e in ipairs(drawBorderList) do
                    if == source then
                        table.remove(drawBorderListi)
                        break
                    end
                end
            end
        elseif data == "guiSnapTo" and getElementData(source"guiSnapTo"then
            local p guiGetParent(source)
            
            if and exists(pthen
                setElementData(p"childSnaps"true)
            end
        end
    end
)


addEventHandler("onClientElementDestroy"root,
    function()
        if not gEnabled then
            return
        end
        
        for i,e in ipairs(drawBorderList) do
            if == source then
                table.remove(drawBorderListi)
                break
            end
        end
    end
)

function guiNeedsBorder(element)
    if exists(elementthen
        if getElementData(element"guieditor.internal:dxElement"then
            local dx DX_Element.getDXFromElement(element)
            
            if dx then
                if dx.dxType == gDXTypes.text or dx.dxType == gDXTypes.image then
                    return true
                end
            end
            
            return
        end
        
        local t stripGUIPrefix(getElementType(element))
    
        return == "label" or == "checkbox" or == "radiobutton" or == "staticimage" or == "scrollpane" or == "combobox"
    end
    
    return false
end


--[[--------------------------------------------------
    selection drawing
--]]--------------------------------------------------
addEventHandler("onClientRender"root,
    function()
        if not gEnabled then
            return
        end
        
        for element,pos in pairs(gDrawSelectionList) do
            dxDrawImage(pos.- (pos./  2), pos.- (pos.2), pos.spos.s"images/dx_elements/radio_button.png"000tocolor(unpack(gColours.tertiary)), true)
        end
    end
,truegEventPriorities.elementSelectRender)


function addToSelectionList(elementsize)
    local xguiGetAbsolutePosition(element)
    local wguiGetSize(elementfalse)
    size tonumber(size) or 8

    if not gDrawSelectionList[elementthen
        gDrawSelectionList[element] = {+ (2), + (2), size}
    end
end

function removeFromSelectionList(element)
    gDrawSelectionList[element] = nil
end


addEventHandler("onClientGUIFocus"guiRoot,
    function()
        if getElementType(source) == "gui-edit" or getElementType(source) == "gui-memo" and not DX_Editbox.inUse() then
            guiSetInputMode(gDefaultInputMode)
        end
    end
)


--[[--------------------------------------------------
    set element as deleted
--]]--------------------------------------------------

function guiRemove(elementcreateAction)
    guiSetVisible(elementfalse)
    setElementData(element"guieditor:drawBorder"nil)
    
    doOnChildren(elementsetElementData"guieditor:removed"true)
    
    if createAction then
        UndoRedo.generateActionUndo(UndoRedo.presets.deleteelement)
    end
end


function guiRestore(element)
    doOnChildren(elementsetElementData"guieditor:removed"nil)
    
    guiSetVisible(elementtrue)
end


function guiDelete(element)
    destroyElement(element)
end



function setElementOutputType(elementoutputType)
    local t outputType
    
    -- radio button menu item
    if type(outputType) == "table" then
        local i outputType:getSelected()
        
        if i then
            t == 2
        end
    end

    if isBool(tthen    
        setElementData(element"guieditor:relative"t)
    end
end


function setElementText(element)
    local multiline false
    local t getElementType(element)
    
    if == "gui-button" or == "gui-label" or == "gui-memo" then
        multiline true
    end
    
    local action = {}
    local currentText guiGetText(element)
    
    if getElementData(element"guieditor.internal:dxElement"then
        local dx DX_Element.ids[getElementData(element"guieditor.internal:dxElement")]
        
        if dx.dxType then
            action[#action + 1] = {}
            action[#action].ufunc = DX_Text.text
            action[#action].uvalues = {dx, dx.text_}
            
            currentText dx:text()
        end
    else
        action[#action + 1] = {}
        action[#action].ufunc = guiSetText
        action[#action].uvalues = {element, guiGetText(element)}
    end
    
    setElementData(element"guieditor.internal:actionUndoText"action)
    
    local mbox MessageBox_Input:create(multiline)
    mbox.element element
    mbox:setText(currentText)
    mbox.onPostAccept =
        function()
            local action getElementData(element"guieditor.internal:actionUndoText")
            
            if getElementData(element"guieditor.internal:dxElement"then
                local dx DX_Element.ids[getElementData(element"guieditor.internal:dxElement")]
                
                if dx.dxType then
                    action[#action + 1] = {}
                    action[#action].rfunc = DX_Text.text
                    action[#action].rvalues = {dx, guiGetText(element)}
                end
                
                action.description "Set ".. DX_Element.getTypeFriendly(dx.dxType) .." text"

                dx:text(guiGetText(element))
                guiSetText(element"")
            else
                action[#action + 1] = {}
                action[#action].rfunc = guiSetText
                action[#action].rvalues = {element, guiGetText(element)}
                
                action.description "Set " ..stripGUIPrefix(getElementType(element)).. " text"
            end
            
            UndoRedo.add(action)
            
            setElementData(element"guieditor.internal:actionUndoText"nil)
        end
end


function divider(parentxywidthcolour)
    imgDividerLeft guiCreateStaticImage(xywidth 21"images/dot_white.png"falseparent)
    imgDividerRight guiCreateStaticImage(+ (width 2), ywidth 21"images/dot_white.png"falseparent)
                
    if not colour then
        colour gAreaColours.secondary
    end
                
    guiSetProperty(imgDividerLeft"ImageColours"string.format("tl:00%s tr:FF%s bl:00%s br:FF%s"colourcolourcolourcolour))
    guiSetProperty(imgDividerRight"ImageColours"string.format("tl:FF%s tr:00%s bl:FF%s br:00%s"colourcolourcolourcolour))
    
    return imgDividerLeftimgDividerRight
end



-- fix for guiGetFont not actually returning an element when custom fonts are used
-- this only becomes a problem for us when loading gui code
-- so when we create a custom font from codesave the filepath against the font
-- then when we set the font on an elementtransfer the path data to the element
guiSetFont_ guiSetFont
function guiSetFont(elementfont)    
    guiSetFont_(elementfont)

    if exists(font) and getElementData(font"guieditor:font"then
        setElementData(element"guieditor:font"getElementData(font"guieditor:font"))
    end
end



function dxGetHoverElement()
    if #DX_Element.instances > 0 then
        local absoluteXabsoluteY getCursorPosition(true)
        local e guiGetHoverElement()
        
        -- go backwards so we get the one that is on top
        for #DX_Element.instances, 1, -1 do
            if (not e) or (DX_Element.instances[i].postGUIthen
                local dx DX_Element.instances[i]
                
                if dx then
                    if dx.dxType == gDXTypes.line then
                        -- get distance to line
                        if distToLineSquared({absoluteXabsoluteY}, {dx.startXdx.startY}, {dx.endXdx.endY}) <= math.max(square(dx.width or 0), square(5)) then
                            return dxi
                        end
                    elseif dx.dxType == gDXTypes.rectangle or dx.dxType == gDXTypes.image or dx.dxType == gDXTypes.text then
                        if (absoluteX dx.and absoluteX < (dx.dx.width)) and
                            (absoluteY dx.and absoluteY < (dx.dx.height)) then
                            return dxi
                        end        
                    end
                else
                    -- something has gone wrong
                    table.remove(DX_Element.instancesi)
                end
            end
        end    
    end
end




function square(x) 
    return x
end

function dist2(se)
    return square(s.e.x) + square(s.e.yend

function distToLineSquared(pse)
    local length dist2(se)
    
    if (length == 0then
        return dist2(ps)
    end
    
    local t = ((p.s.x) * (e.s.x) + (p.s.y) * (e.s.y)) / length
    
    if (0then
        return dist2(ps)
    end
    
    if (1then
        return dist2(pe)
    end
    
    return dist2(p, {s.* (e.s.x), s.* (e.s.y)})
end

function distToLine(pse)
    return math.sqrt(distToLineSquared(pse))
end






local cancelNextSizeTrigger = {}
local delayedPositioning = {}
local delayedSizing = {}

addEventHandler("onClientGUISize"getResourceGUIElement(),
    function()
        if not gEnabled then
            return
        end
        
        if cancelNextSizeTrigger[sourcethen
            cancelNextSizeTrigger[source] = nil
            return true
        end
    
        local parentWidthparentHeight guiGetSize(sourcefalse)
        
        if getElementData(source"childSnaps"then
            for _,child in ipairs(getElementChildren(source)) do            
                if getElementData(child"guiSnapTo"then    
                    local lefttoprightbottomwh
                    
                    for sidevalue in pairs(getElementData(child"guiSnapTo")) do
                        if side and value then                        
                            if side == gGUISides.left then
                                left = (value <= and parentWidth value or value)
                            elseif side == gGUISides.right then
                                right = (value <= and parentWidth value or value)    
                            elseif side == gGUISides.top then
                                top = (value <= and parentHeight value or value)                    
                            elseif side == gGUISides.bottom then
                                bottom = (value <= and parentHeight value or value)    
                            elseif side == gGUIDimensions.width then
                                w value
                            elseif side == gGUIDimensions.height then
                                h value
                            end
                        end
                    end    
                    
                    local xguiGetPosition(childfalse)
                    local widthheight guiGetSize(childfalse)    
                    
                    if delayedPositioning[childthen
                        xdelayedPositioning[child][1], delayedPositioning[child][2]
                    end
                    
                    if delayedSizing[childthen
                        widthheight delayedSizing[child][1], delayedSizing[child][2]
                    end
                    
                    if left and right then
                        --guiSetPosition(childleftyfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childparentWidth left rightheightfalse)
                        delayedPositioning[child] = {leftyfalse}
                        delayedSizing[child] = {parentWidth left rightheightfalse}
                    elseif left then
                        --guiSetPosition(childleftyfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthheightfalse)
                        delayedPositioning[child] = {leftyfalse}
                        delayedSizing[child] = {widthheightfalse}
                    elseif right then
                        --guiSetPosition(childparentWidth width rightyfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthheightfalse)
                        delayedPositioning[child] = {parentWidth width rightyfalse}
                        delayedSizing[child] = {widthheightfalse}
                    end
                    
                    width guiGetSize(childfalse)
                    guiGetPosition(childfalse)
                    
                    if delayedPositioning[childthen
                        x delayedPositioning[child][1]
                    end
                    
                    if delayedSizing[childthen
                        width delayedSizing[child][1]
                    end                    
                    
                    if top and bottom then
                        --guiSetPosition(childxtopfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthparentHeight top bottomfalse)
                        delayedPositioning[child] = {xtopfalse}
                        delayedSizing[child] = {widthparentHeight top bottomfalse}
                    elseif top then
                        --guiSetPosition(childxtopfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthheightfalse)
                        delayedPositioning[child] = {xtopfalse}
                        delayedSizing[child] = {widthheightfalse}
                    elseif bottom then
                        --guiSetPosition(childxparentHeight height bottomfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthheightfalse)
                        delayedPositioning[child] = {xparentHeight height bottomfalse}
                        delayedSizing[child] = {widthheightfalse}
                    end
                    
                    if and h then
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwhfalse)
                        delayedSizing[child] = {whfalse}
                    elseif h then
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthhfalse)
                        delayedSizing[child] = {widthhfalse}
                    elseif w then
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwheightfalse)
                        delayedSizing[child] = {wheightfalse}
                    end
                end
                
                
                if getElementData(child"guieditor:positionCode"then
                    local w,guiGetPosition(childfalsetrueparentWidthparentHeight)
                    guiSetPosition(childwhfalse)
                end
            end
        end
        
        if getElementData(source"guiSizeMinimum"then
            local size getElementData(source"guiSizeMinimum")
            local widthheight guiGetSize(sourcefalse)
            local cxcy getCursorPosition(true)
            local xguiGetAbsolutePosition(source)
            
            if width size.and height size.h then
                cancelNextSizeTrigger[source] = true
                guiSetSize(sourcesize.wsize.hfalse)
                setCursorPosition(size.wsize.h)
            elseif width size.w then    
                cancelNextSizeTrigger[source] = true
                guiSetSize(sourcesize.wheightfalse)
                setCursorPosition(size.wcy)
            elseif height size.h then
                cancelNextSizeTrigger[source] = true
                guiSetSize(sourcewidthsize.hfalse)
                setCursorPosition(cxsize.h)
            end
        end
    end
)

-- do this weirdness to help prevent some of the crazy recursion you get when calling guiSetSize inside onClientGUISize
-- doesn't help that much and is pretty nasty, but probably worth keeping anyway
addEventHandler("onClientPreRender", root,
    function()
        if not gEnabled then
            return
        end
    
        for e,s in pairs(delayedPositioning) do
            if exists(e) then
                guiSetPosition(e, s[1], s[2], s[3])
            end
        end    
        delayedPositioning = {}        
    
        for e,s in pairs(delayedSizing) do
            if exists(e) then
                guiSetSize(e, s[1], s[2], s[3])
            end
        end    
        delayedSizing = {}    
    end
)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2021-01-11, 15:38


MrVip615







Wiek: 16
Na forum: 2346 dni
Posty: 145
Nick w MP: ramzes

Piwa: 118

Respekt: 75,3


"NoNamik" napisał/a:

MrVip615, binda usunalem a to dalej nie dziala moze dam caly kod

--[[--------------------------------------------------
    GUI Editor
    client
    main.lua
    
    Released as isyou are free to do whatever you want with the code
    
    For any questions please try the following:
        MTA forum posthttp://forum.mtasa.com/viewtopic.php?f=108&t=22831
        MTA community posthttp://community.mtasa.com/index.php?p=resources&s=details&id=141
        PM me on the MTA forum (user 'Remp'): http://forum.mtasa.com/ucp.php?i=pm&mode=compose&u=25266
        Find me on GTANet irc (user 'Remp')
    

    Bugs/issues:
        - cannot get the original filepath of a gui image
        many other elements have properties that can be set and never got
        gridlists crash guiGetProperties
        guiGetFont does not return an element when a custom font is used
            
    Wishlist:
        - make multiple selection right click menu smarter when selecting many of the same element type
        better editbox support (highlighting from outside the boundsmultiline editing)
        - GUI Editor wiki page
        Output in OO format
        Document all new changes
        add undo/redo actions for gridlist options
        Fix the problems with relative DX loading/output
        
    Changes:

--]]--------------------------------------------------

gEnabled false

gFilepathPrefix ":"..tostring(getResourceName(resource)).."/"

gRadioButtonGroupID 1

gScreen = {}
gScreen.xgScreen.guiGetScreenSize()

gGUISides = {left 0right 1top 2bottom 3}
gGUIDimensions = {width 4height 5}
gEventPriorities = {
    elementSelectRender "high+101",
    elementBorderRender "high+100",
    DXElementRender "high+10",

    snappingRender "low-100",
    hackClick "low-99999"
}

gColours = {
    primary = {2556959255}, -- red
    secondary = {25511846255}, -- orange
    tertiary = {23242104255}, -- pink
    
    defaultLabel = {255255255},
    grey = {120120120},
    --primaryLight = {255153145255},
    primaryLight = {237126119255},
}
-- primarysecondarytertiaryquaternaryquinarysenaryseptenaryoctonarynonary, and denary

gAreaColours = {
    primary "777777",
    secondary "CCCCCC",
    
    dark "000000",
}
gAreaColours.primaryPacked = {gAreaColours.primarygAreaColours.primarygAreaColours.primarygAreaColours.primary}
gAreaColours.secondaryPacked = {gAreaColours.secondarygAreaColours.secondarygAreaColours.secondarygAreaColours.secondary}
gAreaColours.darkPacked = {gAreaColours.darkgAreaColours.darkgAreaColours.darkgAreaColours.dark}

gGUITypes = {
    "gui-window",
    "gui-button",
    "gui-label",
    "gui-checkbox",
    "gui-memo",
    "gui-edit",
    "gui-gridlist",
    "gui-progressbar",
    "gui-tabpanel",
    "gui-tab",
    "gui-radiobutton",
    "gui-staticimage",
    "gui-scrollpane",
    "gui-scrollbar",
    "gui-combobox"
}

gFonts = {
    "default-normal",
    "default-small",
    "default-bold-small",
    "clear-normal",
    "sa-header",
    "sa-gothic",
}

gDXFonts = {
    "default",
    "default-bold",
    "clear",
    "arial",
    "sans",
    "pricedown",
    "bankgothic",
    "diploma",
    "beckett",
}


gDefaults = {
    alpha = {
        ["gui-window"] = 80,
        ["gui-button"] = 100,
        ["gui-label"] = 100,
        ["gui-checkbox"] = 100,
        ["gui-memo"] = 100,
        ["gui-edit"] = 100,
        ["gui-gridlist"] = 100,
        ["gui-progressbar"] = 100,
        ["gui-tabpanel"] = 100,
        ["gui-tab"] = 100,
        ["gui-radiobutton"] = 100,
        ["gui-staticimage"] = 100,
        ["gui-scrollpane"] = 100,
        ["gui-scrollbar"] = 100,
        ["gui-combobox"] = 100,
    },
    
    colour = {
        ["gui-window"] = {255255255255},
        ["gui-button"] = {124124124255},
        ["gui-label"] = {255255255255},
        ["gui-checkbox"] = {255255255255},
        ["gui-memo"] = {000255},
        ["gui-edit"] = {000255},
        ["gui-gridlist"] = nil,
        ["gui-progressbar"] = nil,
        ["gui-tabpanel"] = nil,
        ["gui-tab"] = nil,
        ["gui-radiobutton"] = {255255255255},
        ["gui-staticimage"] = {255255255255},
        ["gui-scrollpane"] = nil,
        ["gui-scrollbar"] = nil,
        ["gui-combobox"] = {000255},
    },
    
    properties = {},
    
    font = {
        ["gui-window"] = "default-normal",
        ["gui-button"] = "default-normal",
        ["gui-label"] = "default-normal",
        ["gui-checkbox"] = "default-normal",
        ["gui-memo"] = "default-normal",
        ["gui-edit"] = "default-normal",
        ["gui-gridlist"] = "default-normal",
        ["gui-progressbar"] = "default-normal",
        ["gui-tabpanel"] = "default-normal",
        ["gui-tab"] = "default-normal",
        ["gui-radiobutton"] = "default-normal",
        ["gui-staticimage"] = "default-normal",
        ["gui-scrollpane"] = "default-normal",
        ["gui-scrollbar"] = "default-normal",
        ["gui-combobox"] = "default-normal",
    }
}


gCustomFonts = {}

gDataNames = {}
gDefaultInputMode "no_binds_when_editing"
guiSetInputMode(gDefaultInputMode)


gRightClickHack = {}
gDrawSelectionList = {}


addEventHandler("onClientResourceStart"resourceRoot,
    function()
        setup()
    end
)

--[[
addEventHandler("onClientKey"root,
    function(buttondownOrUp)
        if downOrUp == false then
            if button == "g" then
                if getKeyState("lctrl") or getKeyState("lshift"then
                    switch()
                end
            elseif button == "lctrl" then
                if getKeyState("g"then
                    switch()
                end        
            elseif button == "lshift" then
                if getKeyState("g"then
                    switch()
                end
            end
        end
    end
)
]]

--[[bindKey("g""down",
    function()
        if getKeyState("lshift"then
            switch()
        end
    end
)
bindKey("lshift""down",
    function()
        if getKeyState("g"then
            switch()
        end
    end
)--]]



function setup()
    if gEnabled then
        Settings.setup()
        
        if toBool(Settings.loaded.guieditor_update_check.valuethen
            checkForUpdates(true)
        end

        createMenus()
        
        showCursor(true)        
    end
end


function switch()
    if gEnabled then
        ContextBar.add("GUI Editor disabled")
        gEnabled false
        showCursor(false)
    else
        gEnabled true
        setup()
        ContextBar.add("GUI Editor enabled")    
        UndoRedo.updateGUI()
    end
end
addCommandHandler("guied", switch)


function checkForUpdates(automatic)
    if not gEnabled then
        return
    end
    
    triggerServerEvent("guieditor:server_checkUpdateStatus"localPlayerautomatic)
end


addEvent("guieditor:client_getUpdateStatus"true)
addEventHandler("guieditor:client_getUpdateStatus"root,
    function(automaticupdatenewVersionoldVersion)
        if update then
            local mbox MessageBox_Info:create("Update Available""There is a new version of GUI Editor available at community.mtasa.com\n\nCurrent Version: "..tostring(oldVersion).."\nNew Version: "..tostring(newVersion))
        else
            if not automatic then
                if update == nil then
                    local mbox MessageBox_Info:create("Error""Could not get update status.\nCheck ACL permissions and website availability.\n\nCurrent Version: "..tostring(oldVersion))
                else
                    local mbox MessageBox_Info:create("No Updates Available""You are running the latest version of the GUI Editor.\n\nCurrent Version: "..tostring(oldVersion))
                end
            end
        end
    end
)



addEventHandler("onClientClick"root,
    function(buttonstateabsoluteXabsoluteY)
        if not gEnabled then
            return
        end
        
        if button == "right" and state == "up" then
            for imenu in ipairs(Menu.instances) do
                if menu.visible then
                    menu:close()
                end
            end    

            local t Tutorial.active()
            if t then
                if t.id ~= "main" then
                    return
                end
            end
            
            if table.count(Multiple.inside) > 0 then
                gMenus.multiple:open(absoluteXabsoluteY)
                gMenus.multiple.guiSelection Multiple.inside
                return
            else
                gMenus.multiple.guiSelection nil
            end
            
            
            local dxindex dxGetHoverElement()
            
            -- dx above gui elements
            if dx and dx:postGUI() then
                if resolutionPreview.active then
                    resolutionPreview.prepareMenu() 
                    gMenus.main:open(absoluteXabsoluteYtrue)
                    return
                end

                if dx.dxType == gDXTypes.line then
                    gMenus.dxLine:open(absoluteXabsoluteYdx)
                elseif dx.dxType == gDXTypes.rectangle then
                    gMenus.dxRectangle:open(absoluteXabsoluteYdx)
                elseif dx.dxType == gDXTypes.image then
                    gMenus.dxImage:open(absoluteXabsoluteYdx)
                elseif dx.dxType == gDXTypes.text then
                    gMenus.dxText:open(absoluteXabsoluteYdx)
                end
                return
            end            
            
            local e guiGetHoverElement()
            
            -- dx below gui elements
            if (not e) and dx and (not dx:postGUI()) then
                if resolutionPreview.active then
                    resolutionPreview.prepareMenu() 
                    gMenus.main:open(absoluteXabsoluteYtrue)
                    return
                end

                if dx.dxType == gDXTypes.line then
                    gMenus.dxLine:open(absoluteXabsoluteYdxtrue)
                elseif dx.dxType == gDXTypes.rectangle then
                    gMenus.dxRectangle:open(absoluteXabsoluteYdxtrue)
                elseif dx.dxType == gDXTypes.image then
                    gMenus.dxImage:open(absoluteXabsoluteYdxtrue)
                elseif dx.dxType == gDXTypes.text then
                    gMenus.dxText:open(absoluteXabsoluteYdxtrue)
                end
                return            
            end
            
            if not e then
                if resolutionPreview.active then
                    resolutionPreview.prepareMenu() 
                else
                    for 1#gMenus.main.items - 1 do
                        gMenus.main:getItem(i):setEnabled(true)
                    end                    
                end
            
                gMenus.main:open(absoluteXabsoluteYtrue)
            else
                if resolutionPreview.active then
                    resolutionPreview.prepareMenu() 
                    gMenus.main:open(absoluteXabsoluteYtrue)
                    return
                end
                    
                --if getElementData(e"guieditor.internal:redirect"then
                --    getElementData(e"guieditor.internal:redirect")
                --end

                if managed(ethen
                    local elementType string.lower(getElementType(e))
                    elementType stripGUIPrefix(elementType)
                    
                    if gMenus[elementTypethen
                        gMenus[elementType]:open(absoluteXabsoluteYetrue)
                    else
                        gMenus.main:open(absoluteXabsoluteYtrue)
                    end
                else
                    if getElementData(e"guieditor.internal:noLoad"then
                        gMenus.noLoad:open(absoluteXabsoluteY)
                    else
                        gMenus.notLoaded:open(absoluteXabsoluteYtrue)
                    end
                end
            end        
        elseif button == "left" and state == "up" then
            
        end
        
        menuItemClick(buttonstateabsoluteXabsoluteY)
        
        menuClick(buttonstateabsoluteXabsoluteY)
        
        Creator.click(buttonstateabsoluteXabsoluteY)
        
        Sizer.click(buttonstateabsoluteXabsoluteY)
        Mover.click(buttonstateabsoluteXabsoluteY)
                
        resolutionPreview.click(buttonstateabsoluteXabsoluteY)
        
        Offset.click(buttonstateabsoluteXabsoluteY)
        Attacher.click(buttonstateabsoluteXabsoluteY)
        
        Multiple.click(buttonstateabsoluteXabsoluteY)
        
        HelpWindow.click(buttonstateabsoluteXabsoluteY)
    end
)


addEventHandler("onClientMouseEnter"root,
    function(absoluteXabsoluteY)
        if not gEnabled then
            return
        end

        Creator.enter(sourceabsoluteXabsoluteY)
        Attacher.enter(sourceabsoluteXabsoluteY)
    end
)


addEventHandler("onClientMouseLeave"root,
    function(absoluteXabsoluteY)
        if not gEnabled then
            return
        end
        
        Creator.leave(sourceabsoluteXabsoluteY)
        Attacher.leave(sourceabsoluteXabsoluteY)
    end
)


--[[--------------------------------------------------
    nasty hack to get elements that don't trigger mouse events to work
    
    each broken element is masked with a gui label completely covering it
    the label has MousePassThroughEnabled set to true so it doesn't capture any mouse events
    this means that left click will still interact with the original element (egopen the combo box dropdowndrag the scrollbar pointer)
    
    we bind right click and on down we set MousePassThroughEnabled to falseso the labels capture mouse events again
    then we force a mouse movement (that the user doesn't see), which forces all the mouse events to update and trigger for the labels
    once the onClientClick event has completed firing (and we have done everything we need to with the right click menus)
    we set MousePassThroughEnabled back to true so the original elements can be interacted with again
    
    known problems:
        - when editboxes or memos have input focus, right clicks on broken elements don't work until you click them (to give them focus)
        - borders don't get drawn (because the enter/exit events don't fire)
        - scrollpane scrollbars cannot be dragged
            this is a choice between either non-dragable scrollbars, or not having a border
            since having no border would make them completely uselesshaving non working scrollbars and being semi-useful is the best choice
            
    Update 19/07/2014
        The mouse events now trigger for all gui elements properlyHowevermouse events for children of those fixed elements are now wrong. 
        E.ga label that is a child of a scrollpane will trigger onClientMouseEnter when the mouse is nowhere near the label
        Keeping this hack in until this is fixed in mta
--]]--------------------------------------------------
addEventHandler("onClientClick"root,
    function(buttonstateabsoluteXabsoluteY)
        if not gEnabled then
            return
        end
        
        if button == "right" and state == "up" then
            for element in pairs(gRightClickHack) do
                if exists(elementthen
                    guiSetProperty(element"MousePassThroughEnabled""True")
                    guiSetProperty(getElementData(element"guieditor.internal:redirect"), "ZOrderChangeEnabled""True")
                    --guiSetProperty(element"RiseOnClick""True")
                end
            end
        end
    end,
truegEventPriorities.hackClick)


bindKey("mouse2""down",
    function()
        if not gEnabled then
            return
        end
        
        for _,guiType in ipairs(gGUITypes) do
            for element in pairs(gRightClickHack) do
                if exists(elementthen
                    guiSetProperty(element"MousePassThroughEnabled""False")
                    guiSetProperty(getElementData(element"guieditor.internal:redirect"), "ZOrderChangeEnabled""False")
                    --guiSetProperty(element"RiseOnClick""False")
                    guiBringToFront(element)
                    
                    for i,v in ipairs(guiGetSiblings(element)) do
                        if ~= element then
                            guiBringToFront(v)
                        end
                    end
                end
            end
        end

        jiggleMouse()
    end
)



--[[--------------------------------------------------
    moved mouse over a GUI element
--]]--------------------------------------------------
addEventHandler("onClientMouseMove"root,
    function(absoluteXabsoluteY)
        if not gEnabled then
            return
        end

        Creator.move(sourceabsoluteXabsoluteY)
    end
)

--[[--------------------------------------------------
    moved mouse
--]]--------------------------------------------------
addEventHandler("onClientCursorMove"root,
    function(xyabsoluteXabsoluteY)
        if not gEnabled then
            return
        end
        
        Sizer.move(absoluteXabsoluteY)
        Mover.move(absoluteXabsoluteY)
        
        resolutionPreview.move(absoluteXabsoluteY)
        
        Multiple.move(absoluteXabsoluteY)
        
        Snapping.snap()
    end
)



--[[--------------------------------------------------
    force trigger any gui cursor move/on/off events
--]]--------------------------------------------------
function jiggleMouse()
    if not gEnabled then
        return
    end
        
    local xgetCursorPosition(true)
    
    if x then
        setCursorPosition(x1)
        setCursorPosition(xy)
    end
end



--[[--------------------------------------------------
    border drawing
--]]--------------------------------------------------
local drawBorderList = {}

addEventHandler("onClientRender"root,
    function()
        if not gEnabled then
            return
        end

        local dxindex dxGetHoverElement()
        
        if dx then
            -- draw border
            if dx.dxType == gDXTypes.line then
                
            elseif dx.dxType == gDXTypes.rectangle then
            
            elseif dx.dxType == gDXTypes.text or dx.dxType == gDXTypes.image then
                drawBorderRaw(dx.xdx.ydx.widthdx.height)
            end    
        end            
        
        if guiGetHoverElement() and not Menu.anyOpen() then
            local element guiGetHoverElement()
            
            if getElementData(element"guieditor:border"then
                drawBorder(element)
            end
        end
        
        for _,e in ipairs(drawBorderList) do
            if exists(ethen
                drawBorder(e)
            end
        end
    end
,truegEventPriorities.elementBorderRender)


function drawBorder(element)
    if not gEnabled then
        return
    end
    
    if not removed(elementthen
        local xguiGetAbsolutePosition(element)
        local wguiGetSize(elementfalse)
        
        drawBorderRaw(xywh)
    end
end

function drawBorderRaw(xywh)
    if not gEnabled then
        return
    end
    
    if and and and h then
        dxDrawLine(xywytocolor(unpack(gColours.tertiary)), 1true)
        dxDrawLine(xyxhtocolor(unpack(gColours.tertiary)), 1true)
        dxDrawLine(wywhtocolor(unpack(gColours.tertiary)), 1true)
        dxDrawLine(xhwhtocolor(unpack(gColours.tertiary)), 1true)
    end
end


addEventHandler("onClientElementDataChange"root,
    function(dataoldValue)
        if not gEnabled then
            return
        end
        
        -- track all the element datas we use. This gives us an always accurate list at any point in time of which element datas any given element could have
        -- easier than defining them manually and forgetting to update the list when you add new ones
        if string.find(data"guieditor:"1truethen
            gDataNames[data] = true
        end
        
        if data == "guieditor:drawBorder" then
            if getElementData(source"guieditor:drawBorder"then
                table.insert(drawBorderListsource)
            else
                for i,e in ipairs(drawBorderList) do
                    if == source then
                        table.remove(drawBorderListi)
                        break
                    end
                end
            end
        elseif data == "guiSnapTo" and getElementData(source"guiSnapTo"then
            local p guiGetParent(source)
            
            if and exists(pthen
                setElementData(p"childSnaps"true)
            end
        end
    end
)


addEventHandler("onClientElementDestroy"root,
    function()
        if not gEnabled then
            return
        end
        
        for i,e in ipairs(drawBorderList) do
            if == source then
                table.remove(drawBorderListi)
                break
            end
        end
    end
)

function guiNeedsBorder(element)
    if exists(elementthen
        if getElementData(element"guieditor.internal:dxElement"then
            local dx DX_Element.getDXFromElement(element)
            
            if dx then
                if dx.dxType == gDXTypes.text or dx.dxType == gDXTypes.image then
                    return true
                end
            end
            
            return
        end
        
        local t stripGUIPrefix(getElementType(element))
    
        return == "label" or == "checkbox" or == "radiobutton" or == "staticimage" or == "scrollpane" or == "combobox"
    end
    
    return false
end


--[[--------------------------------------------------
    selection drawing
--]]--------------------------------------------------
addEventHandler("onClientRender"root,
    function()
        if not gEnabled then
            return
        end
        
        for element,pos in pairs(gDrawSelectionList) do
            dxDrawImage(pos.- (pos./  2), pos.- (pos.2), pos.spos.s"images/dx_elements/radio_button.png"000tocolor(unpack(gColours.tertiary)), true)
        end
    end
,truegEventPriorities.elementSelectRender)


function addToSelectionList(elementsize)
    local xguiGetAbsolutePosition(element)
    local wguiGetSize(elementfalse)
    size tonumber(size) or 8

    if not gDrawSelectionList[elementthen
        gDrawSelectionList[element] = {+ (2), + (2), size}
    end
end

function removeFromSelectionList(element)
    gDrawSelectionList[element] = nil
end


addEventHandler("onClientGUIFocus"guiRoot,
    function()
        if getElementType(source) == "gui-edit" or getElementType(source) == "gui-memo" and not DX_Editbox.inUse() then
            guiSetInputMode(gDefaultInputMode)
        end
    end
)


--[[--------------------------------------------------
    set element as deleted
--]]--------------------------------------------------

function guiRemove(elementcreateAction)
    guiSetVisible(elementfalse)
    setElementData(element"guieditor:drawBorder"nil)
    
    doOnChildren(elementsetElementData"guieditor:removed"true)
    
    if createAction then
        UndoRedo.generateActionUndo(UndoRedo.presets.deleteelement)
    end
end


function guiRestore(element)
    doOnChildren(elementsetElementData"guieditor:removed"nil)
    
    guiSetVisible(elementtrue)
end


function guiDelete(element)
    destroyElement(element)
end



function setElementOutputType(elementoutputType)
    local t outputType
    
    -- radio button menu item
    if type(outputType) == "table" then
        local i outputType:getSelected()
        
        if i then
            t == 2
        end
    end

    if isBool(tthen    
        setElementData(element"guieditor:relative"t)
    end
end


function setElementText(element)
    local multiline false
    local t getElementType(element)
    
    if == "gui-button" or == "gui-label" or == "gui-memo" then
        multiline true
    end
    
    local action = {}
    local currentText guiGetText(element)
    
    if getElementData(element"guieditor.internal:dxElement"then
        local dx DX_Element.ids[getElementData(element"guieditor.internal:dxElement")]
        
        if dx.dxType then
            action[#action + 1] = {}
            action[#action].ufunc = DX_Text.text
            action[#action].uvalues = {dx, dx.text_}
            
            currentText dx:text()
        end
    else
        action[#action + 1] = {}
        action[#action].ufunc = guiSetText
        action[#action].uvalues = {element, guiGetText(element)}
    end
    
    setElementData(element"guieditor.internal:actionUndoText"action)
    
    local mbox MessageBox_Input:create(multiline)
    mbox.element element
    mbox:setText(currentText)
    mbox.onPostAccept =
        function()
            local action getElementData(element"guieditor.internal:actionUndoText")
            
            if getElementData(element"guieditor.internal:dxElement"then
                local dx DX_Element.ids[getElementData(element"guieditor.internal:dxElement")]
                
                if dx.dxType then
                    action[#action + 1] = {}
                    action[#action].rfunc = DX_Text.text
                    action[#action].rvalues = {dx, guiGetText(element)}
                end
                
                action.description "Set ".. DX_Element.getTypeFriendly(dx.dxType) .." text"

                dx:text(guiGetText(element))
                guiSetText(element"")
            else
                action[#action + 1] = {}
                action[#action].rfunc = guiSetText
                action[#action].rvalues = {element, guiGetText(element)}
                
                action.description "Set " ..stripGUIPrefix(getElementType(element)).. " text"
            end
            
            UndoRedo.add(action)
            
            setElementData(element"guieditor.internal:actionUndoText"nil)
        end
end


function divider(parentxywidthcolour)
    imgDividerLeft guiCreateStaticImage(xywidth 21"images/dot_white.png"falseparent)
    imgDividerRight guiCreateStaticImage(+ (width 2), ywidth 21"images/dot_white.png"falseparent)
                
    if not colour then
        colour gAreaColours.secondary
    end
                
    guiSetProperty(imgDividerLeft"ImageColours"string.format("tl:00%s tr:FF%s bl:00%s br:FF%s"colourcolourcolourcolour))
    guiSetProperty(imgDividerRight"ImageColours"string.format("tl:FF%s tr:00%s bl:FF%s br:00%s"colourcolourcolourcolour))
    
    return imgDividerLeftimgDividerRight
end



-- fix for guiGetFont not actually returning an element when custom fonts are used
-- this only becomes a problem for us when loading gui code
-- so when we create a custom font from codesave the filepath against the font
-- then when we set the font on an elementtransfer the path data to the element
guiSetFont_ guiSetFont
function guiSetFont(elementfont)    
    guiSetFont_(elementfont)

    if exists(font) and getElementData(font"guieditor:font"then
        setElementData(element"guieditor:font"getElementData(font"guieditor:font"))
    end
end



function dxGetHoverElement()
    if #DX_Element.instances > 0 then
        local absoluteXabsoluteY getCursorPosition(true)
        local e guiGetHoverElement()
        
        -- go backwards so we get the one that is on top
        for #DX_Element.instances, 1, -1 do
            if (not e) or (DX_Element.instances[i].postGUIthen
                local dx DX_Element.instances[i]
                
                if dx then
                    if dx.dxType == gDXTypes.line then
                        -- get distance to line
                        if distToLineSquared({absoluteXabsoluteY}, {dx.startXdx.startY}, {dx.endXdx.endY}) <= math.max(square(dx.width or 0), square(5)) then
                            return dxi
                        end
                    elseif dx.dxType == gDXTypes.rectangle or dx.dxType == gDXTypes.image or dx.dxType == gDXTypes.text then
                        if (absoluteX dx.and absoluteX < (dx.dx.width)) and
                            (absoluteY dx.and absoluteY < (dx.dx.height)) then
                            return dxi
                        end        
                    end
                else
                    -- something has gone wrong
                    table.remove(DX_Element.instancesi)
                end
            end
        end    
    end
end




function square(x) 
    return x
end

function dist2(se)
    return square(s.e.x) + square(s.e.yend

function distToLineSquared(pse)
    local length dist2(se)
    
    if (length == 0then
        return dist2(ps)
    end
    
    local t = ((p.s.x) * (e.s.x) + (p.s.y) * (e.s.y)) / length
    
    if (0then
        return dist2(ps)
    end
    
    if (1then
        return dist2(pe)
    end
    
    return dist2(p, {s.* (e.s.x), s.* (e.s.y)})
end

function distToLine(pse)
    return math.sqrt(distToLineSquared(pse))
end






local cancelNextSizeTrigger = {}
local delayedPositioning = {}
local delayedSizing = {}

addEventHandler("onClientGUISize"getResourceGUIElement(),
    function()
        if not gEnabled then
            return
        end
        
        if cancelNextSizeTrigger[sourcethen
            cancelNextSizeTrigger[source] = nil
            return true
        end
    
        local parentWidthparentHeight guiGetSize(sourcefalse)
        
        if getElementData(source"childSnaps"then
            for _,child in ipairs(getElementChildren(source)) do            
                if getElementData(child"guiSnapTo"then    
                    local lefttoprightbottomwh
                    
                    for sidevalue in pairs(getElementData(child"guiSnapTo")) do
                        if side and value then                        
                            if side == gGUISides.left then
                                left = (value <= and parentWidth value or value)
                            elseif side == gGUISides.right then
                                right = (value <= and parentWidth value or value)    
                            elseif side == gGUISides.top then
                                top = (value <= and parentHeight value or value)                    
                            elseif side == gGUISides.bottom then
                                bottom = (value <= and parentHeight value or value)    
                            elseif side == gGUIDimensions.width then
                                w value
                            elseif side == gGUIDimensions.height then
                                h value
                            end
                        end
                    end    
                    
                    local xguiGetPosition(childfalse)
                    local widthheight guiGetSize(childfalse)    
                    
                    if delayedPositioning[childthen
                        xdelayedPositioning[child][1], delayedPositioning[child][2]
                    end
                    
                    if delayedSizing[childthen
                        widthheight delayedSizing[child][1], delayedSizing[child][2]
                    end
                    
                    if left and right then
                        --guiSetPosition(childleftyfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childparentWidth left rightheightfalse)
                        delayedPositioning[child] = {leftyfalse}
                        delayedSizing[child] = {parentWidth left rightheightfalse}
                    elseif left then
                        --guiSetPosition(childleftyfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthheightfalse)
                        delayedPositioning[child] = {leftyfalse}
                        delayedSizing[child] = {widthheightfalse}
                    elseif right then
                        --guiSetPosition(childparentWidth width rightyfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthheightfalse)
                        delayedPositioning[child] = {parentWidth width rightyfalse}
                        delayedSizing[child] = {widthheightfalse}
                    end
                    
                    width guiGetSize(childfalse)
                    guiGetPosition(childfalse)
                    
                    if delayedPositioning[childthen
                        x delayedPositioning[child][1]
                    end
                    
                    if delayedSizing[childthen
                        width delayedSizing[child][1]
                    end                    
                    
                    if top and bottom then
                        --guiSetPosition(childxtopfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthparentHeight top bottomfalse)
                        delayedPositioning[child] = {xtopfalse}
                        delayedSizing[child] = {widthparentHeight top bottomfalse}
                    elseif top then
                        --guiSetPosition(childxtopfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthheightfalse)
                        delayedPositioning[child] = {xtopfalse}
                        delayedSizing[child] = {widthheightfalse}
                    elseif bottom then
                        --guiSetPosition(childxparentHeight height bottomfalse)
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthheightfalse)
                        delayedPositioning[child] = {xparentHeight height bottomfalse}
                        delayedSizing[child] = {widthheightfalse}
                    end
                    
                    if and h then
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwhfalse)
                        delayedSizing[child] = {whfalse}
                    elseif h then
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwidthhfalse)
                        delayedSizing[child] = {widthhfalse}
                    elseif w then
                        --cancelNextSizeTrigger[child] = true
                        --guiSetSize(childwheightfalse)
                        delayedSizing[child] = {wheightfalse}
                    end
                end
                
                
                if getElementData(child"guieditor:positionCode"then
                    local w,guiGetPosition(childfalsetrueparentWidthparentHeight)
                    guiSetPosition(childwhfalse)
                end
            end
        end
        
        if getElementData(source"guiSizeMinimum"then
            local size getElementData(source"guiSizeMinimum")
            local widthheight guiGetSize(sourcefalse)
            local cxcy getCursorPosition(true)
            local xguiGetAbsolutePosition(source)
            
            if width size.and height size.h then
                cancelNextSizeTrigger[source] = true
                guiSetSize(sourcesize.wsize.hfalse)
                setCursorPosition(size.wsize.h)
            elseif width size.w then    
                cancelNextSizeTrigger[source] = true
                guiSetSize(sourcesize.wheightfalse)
                setCursorPosition(size.wcy)
            elseif height size.h then
                cancelNextSizeTrigger[source] = true
                guiSetSize(sourcewidthsize.hfalse)
                setCursorPosition(cxsize.h)
            end
        end
    end
)

-- do this weirdness to help prevent some of the crazy recursion you get when calling guiSetSize inside onClientGUISize
-- doesn't help that much and is pretty nasty, but probably worth keeping anyway
addEventHandler("onClientPreRender", root,
    function()
        if not gEnabled then
            return
        end
    
        for e,s in pairs(delayedPositioning) do
            if exists(e) then
                guiSetPosition(e, s[1], s[2], s[3])
            end
        end    
        delayedPositioning = {}        
    
        for e,s in pairs(delayedSizing) do
            if exists(e) then
                guiSetSize(e, s[1], s[2], s[3])
            end
        end    
        delayedSizing = {}    
    end
)


Przekopiuj po prostu moja wersje i wklej tam, sprawdzanie serialu jest w miejscu gdzie ma byc dopiero wlaczony guieditor

Postaw piwo autorowi tego posta
 

 
Tagi: guieditor :: hedit :: pod :: serial
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:








Wyświetl posty z ostatnich:   

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

Skocz do: