Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- animations = {}
- animations.__index = animations
- local DGS = exports.mf_gui
- local font1 = dxCreateFont("files/Verdana.ttf", 17)
- local font2 = dxCreateFont("files/Verdana.ttf", 10)
- local xml = xmlLoadFile("animations.xml")
- local function ReverseTable(table)
- for i=1, math.floor(#table / 2) do
- table[i], table[#table - i + 1] = table[#table - i + 1], table[i]
- end
- end
- function animations:new(...)
- local object = setmetatable({}, {__index = self})
- if object.constructor then
- object:constructor(...)
- end
- return object
- end
- function animations:setAnimationGuiVisible(bool)
- DGS:dgsSetVisible(self.gui.animationName, bool)
- DGS:dgsSetVisible(self.gui.animationDesp, bool)
- DGS:dgsSetVisible(self.gui.favoriteButton, bool)
- DGS:dgsSetVisible(self.gui.useAnimation, bool)
- end
- function animations:addCategories()
- local group = xmlNodeGetChildren(xml)
- DGS:dgsGridListClear(self.gui.categoryList)
- DGS:dgsGridListAddColumn(self.gui.categoryList, "Kategorie", 0.76)
- ReverseTable(group)
- for i,v in ipairs(group) do
- local attributes = xmlNodeGetAttributes(group[i])
- DGS:dgsGridListAddRow(self.gui.categoryList, 0.75, attributes.name)
- end
- end
- function animations:addAnimations(category)
- local anims = xmlNodeGetChildren(xmlNodeGetChildren(xml, category))
- DGS:dgsGridListClear(self.gui.animationsList)
- DGS:dgsGridListAddColumn(self.gui.animationsList, "Animacje", 0.76)
- ReverseTable(anims)
- for i,v in ipairs(anims) do
- local attributes = xmlNodeGetAttributes(anims[i])
- DGS:dgsGridListAddRow(self.gui.animationsList, 0.75, attributes.name)
- end
- end
- function animations:addAnimationToFavortie(selectedGroup, selectedAnim)
- local favoriteGroup = xmlNodeGetChildren(xml, 0)
- local anim = xmlNodeGetChildren(xmlNodeGetChildren(xml, selectedGroup), selectedAnim)
- local selectedAttributes = xmlNodeGetAttributes(anim)
- local new = xmlCreateChild(favoriteGroup, "anim")
- xmlNodeSetAttribute(new, "name", selectedAttributes.name)
- xmlNodeSetAttribute(new, "desp", selectedAttributes.desp)
- xmlNodeSetAttribute(new, "block", selectedAttributes.block)
- xmlNodeSetAttribute(new, "anim", selectedAttributes.anim)
- end
- function animations:removeFavoriteAnimation(attributes)
- local parent = xmlFindChild(xml, "group", 0)
- local chilld = xmlNodeGetChildren(parent)
- for i,v in pairs(chilld) do
- if xmlNodeGetAttributes(chilld[i]).name == attributes.name then
- xmlDestroyNode(chilld[i])
- end
- end
- end
- function animations:moving()
- end
- function animations:onClick(button, state)
- if button == "left" and state == "down" then
- local selectedCategory = DGS:dgsGridListGetSelectedItem(self.gui.categoryList) - 1
- local selectedAnim = DGS:dgsGridListGetSelectedItem(self.gui.animationsList) - 1
- if source == self.gui.categoryList then
- animations:setAnimationGuiVisible(false)
- if selectedCategory < 0 then
- DGS:dgsGridListClear(self.gui.animationsList)
- DGS:dgsGridListAddColumn(self.gui.animationsList, "Animacje", 0.76)
- return
- end
- animations:addAnimations(selectedCategory)
- elseif source == self.gui.animationsList then
- if selectedAnim < 0 then return animations:setAnimationGuiVisible(false) end
- DGS:dgsSetText(self.gui.favoriteButton, "Dodaj do ulubionych")
- selectedGroup = xmlNodeGetChildren(xml, selectedCategory)
- selectedAnims = xmlNodeGetChildren(selectedGroup, selectedAnim)
- attributes = xmlNodeGetAttributes(selectedAnims)
- DGS:dgsSetText(self.gui.animationName, attributes.name)
- DGS:dgsSetText(self.gui.animationDesp, attributes.desp)
- animations:setAnimationGuiVisible(true)
- local favoriteChilld = xmlNodeGetChildren(xmlFindChild(xml, "group", 0))
- for i,v in pairs(favoriteChilld) do
- if xmlNodeGetAttributes(favoriteChilld[i]).name == attributes.name then
- DGS:dgsSetText(self.gui.favoriteButton, "Usuń z ulubionych")
- end
- end
- elseif source == self.gui.useAnimation then
- setPedAnimation(localPlayer, attributes.block, attributes.anim)
- elseif source == self.gui.favoriteButton then
- if DGS:dgsGetText(self.gui.favoriteButton) == "Dodaj do ulubionych" then
- animations:addAnimationToFavortie(selectedCategory, selectedAnim)
- DGS:dgsSetText(self.gui.favoriteButton, "Usuń z ulubionych")
- else
- animations:removeFavoriteAnimation(attributes)
- DGS:dgsSetText(self.gui.favoriteButton, "Dodaj do ulubionych")
- if selectedCategory == 0 then
- animations:setAnimationGuiVisible(false)
- animations:addAnimations(0)
- end
- end
- end
- end
- end
- function animations:visible()
- DGS:dgsSetVisible(self.gui.window, not DGS:dgsGetVisible(self.gui.window))
- showCursor(not isCursorShowing(), false)
- end
- function animations:constructor()
- self.gui = {}
- self.gui.window = DGS:dgsCreateWindow(0.35, 0.21, 0.30, 0.58, "Animacje", true, 0xFFFFFFFF, 25, nil, tocolor(20,20,20), nil, tocolor(15,15,15), 5, true)
- DGS:dgsWindowSetSizable(self.gui.window, false)
- DGS:dgsSetVisible(self.gui.window, false)
- self.gui.categoryList = DGS:dgsCreateGridList(0.02, 0.05, 0.23, 0.94, true, self.gui.window, 20, tocolor(20,20,20), 0xFF000000, tocolor(25,25,25), 0xFFC8C8C8, 0xFF969696, 0xFF00ACF2, nil, nil, nil, nil, nil)
- self.gui.animationsList = DGS:dgsCreateGridList(0.27, 0.05, 0.28, 0.93, true, self.gui.window, 20, tocolor(20,20,20), 0xFF000000, tocolor(25,25,25), 0xFFC8C8C8, 0xFF969696, 0xFF00ACF2, nil, nil, nil, nil, nil)
- self.gui.animationName = DGS:dgsCreateLabel(0.57, 0.06, 0.41, 0.08, "Anim Name", true, self.gui.window, 0xFFFFFFFF, 1, 1, nil, nil, nil, "center", "center")
- DGS:dgsSetFont(self.gui.animationName, font1)
- self.gui.animationDesp = DGS:dgsCreateLabel(0.57, 0.14, 0.41, 0.08, "Opisik będzie tutaj sobie", true, self.gui.window, 0xFFFFFFFF, 1, 1, nil, nil, nil, "center", "center")
- DGS:dgsSetFont(self.gui.animationDesp, font2)
- self.gui.useAnimation = DGS:dgsCreateButton(0.58, 0.26, 0.17, 0.07, "Użyj", true, self.gui.window, 0xFFFFFFFF, 1, 1, nil, nil, nil, tocolor(255, 191, 0), tocolor(255, 170, 0), tocolor(255, 150, 0))
- DGS:dgsSetFont(self.gui.useAnimation, font2)
- self.gui.favoriteButton = DGS:dgsCreateButton(0.77, 0.26, 0.22, 0.07, "Dodaj do ulubionych", true, self.gui.window, 0xFFFFFFFF, 1, 1, nil, nil, nil, tocolor(255, 191, 0), tocolor(255, 170, 0), tocolor(255, 150, 0))
- DGS:dgsSetFont(self.gui.favoriteButton, font2)
- self.gridListClick = function(button, state) self:onClick(button, state) end
- self.windowVisible = function() self:visible() end
- addEventHandler("onDgsMouseClick", root, self.gridListClick)
- bindKey("L", "down", self.windowVisible)
- end
- animations = animations:new()
- animations:addCategories()
- animations:setAnimationGuiVisible(false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement