Advertisement
Guest User

Untitled

a guest
May 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.62 KB | None | 0 0
  1. animations = {}
  2. animations.__index = animations
  3.  
  4. local DGS = exports.mf_gui
  5. local font1 = dxCreateFont("files/Verdana.ttf", 17)
  6. local font2 = dxCreateFont("files/Verdana.ttf", 10)
  7. local xml = xmlLoadFile("animations.xml")
  8.  
  9. local function ReverseTable(table)
  10.   for i=1, math.floor(#table / 2) do
  11.     table[i], table[#table - i + 1] = table[#table - i + 1], table[i]
  12.   end
  13. end
  14. function animations:new(...)
  15.     local object = setmetatable({}, {__index = self})
  16.     if object.constructor then
  17.         object:constructor(...)
  18.     end
  19.     return object
  20. end
  21. function animations:setAnimationGuiVisible(bool)
  22.     DGS:dgsSetVisible(self.gui.animationName, bool)
  23.     DGS:dgsSetVisible(self.gui.animationDesp, bool)
  24.     DGS:dgsSetVisible(self.gui.favoriteButton, bool)
  25.     DGS:dgsSetVisible(self.gui.useAnimation, bool)
  26. end
  27. function animations:addCategories()
  28.     local group = xmlNodeGetChildren(xml)
  29.     DGS:dgsGridListClear(self.gui.categoryList)
  30.     DGS:dgsGridListAddColumn(self.gui.categoryList, "Kategorie", 0.76)
  31.     ReverseTable(group)
  32.     for i,v in ipairs(group) do
  33.         local attributes = xmlNodeGetAttributes(group[i])
  34.         DGS:dgsGridListAddRow(self.gui.categoryList, 0.75, attributes.name)
  35.     end
  36. end
  37. function animations:addAnimations(category)
  38.     local anims = xmlNodeGetChildren(xmlNodeGetChildren(xml, category))
  39.     DGS:dgsGridListClear(self.gui.animationsList)
  40.     DGS:dgsGridListAddColumn(self.gui.animationsList, "Animacje", 0.76)
  41.     ReverseTable(anims)
  42.     for i,v in ipairs(anims) do
  43.         local attributes = xmlNodeGetAttributes(anims[i])
  44.         DGS:dgsGridListAddRow(self.gui.animationsList, 0.75, attributes.name)
  45.     end
  46. end
  47. function animations:addAnimationToFavortie(selectedGroup, selectedAnim)
  48.     local favoriteGroup = xmlNodeGetChildren(xml, 0)
  49.     local anim = xmlNodeGetChildren(xmlNodeGetChildren(xml, selectedGroup), selectedAnim)
  50.     local selectedAttributes = xmlNodeGetAttributes(anim)
  51.  
  52.     local new = xmlCreateChild(favoriteGroup, "anim")
  53.     xmlNodeSetAttribute(new, "name", selectedAttributes.name)
  54.     xmlNodeSetAttribute(new, "desp", selectedAttributes.desp)
  55.     xmlNodeSetAttribute(new, "block", selectedAttributes.block)
  56.     xmlNodeSetAttribute(new, "anim", selectedAttributes.anim)
  57. end
  58. function animations:removeFavoriteAnimation(attributes)
  59.     local parent = xmlFindChild(xml, "group", 0)
  60.     local chilld = xmlNodeGetChildren(parent)
  61.     for i,v in pairs(chilld) do
  62.         if xmlNodeGetAttributes(chilld[i]).name ==  attributes.name then
  63.             xmlDestroyNode(chilld[i])
  64.         end
  65.     end
  66. end
  67. function animations:moving()
  68. end
  69. function animations:onClick(button, state)
  70.     if button == "left" and state == "down" then
  71.         local selectedCategory = DGS:dgsGridListGetSelectedItem(self.gui.categoryList) - 1
  72.         local selectedAnim = DGS:dgsGridListGetSelectedItem(self.gui.animationsList) - 1
  73.  
  74.         if source == self.gui.categoryList then
  75.             animations:setAnimationGuiVisible(false)
  76.             if selectedCategory < 0 then
  77.                 DGS:dgsGridListClear(self.gui.animationsList)
  78.                 DGS:dgsGridListAddColumn(self.gui.animationsList, "Animacje", 0.76)
  79.                 return
  80.             end
  81.             animations:addAnimations(selectedCategory)
  82.         elseif source == self.gui.animationsList then
  83.             if selectedAnim < 0 then return animations:setAnimationGuiVisible(false) end
  84.             DGS:dgsSetText(self.gui.favoriteButton, "Dodaj do ulubionych")
  85.             selectedGroup = xmlNodeGetChildren(xml, selectedCategory)
  86.             selectedAnims = xmlNodeGetChildren(selectedGroup, selectedAnim)
  87.             attributes = xmlNodeGetAttributes(selectedAnims)
  88.             DGS:dgsSetText(self.gui.animationName, attributes.name)
  89.             DGS:dgsSetText(self.gui.animationDesp, attributes.desp)
  90.             animations:setAnimationGuiVisible(true)
  91.             local favoriteChilld = xmlNodeGetChildren(xmlFindChild(xml, "group", 0))
  92.             for i,v in pairs(favoriteChilld) do
  93.                 if xmlNodeGetAttributes(favoriteChilld[i]).name == attributes.name then
  94.                     DGS:dgsSetText(self.gui.favoriteButton, "Usuń z ulubionych")
  95.                 end
  96.             end
  97.         elseif source == self.gui.useAnimation then
  98.             setPedAnimation(localPlayer, attributes.block, attributes.anim)
  99.         elseif source == self.gui.favoriteButton then
  100.             if DGS:dgsGetText(self.gui.favoriteButton) == "Dodaj do ulubionych" then
  101.                 animations:addAnimationToFavortie(selectedCategory, selectedAnim)
  102.                 DGS:dgsSetText(self.gui.favoriteButton, "Usuń z ulubionych")
  103.             else
  104.                 animations:removeFavoriteAnimation(attributes)
  105.                 DGS:dgsSetText(self.gui.favoriteButton, "Dodaj do ulubionych")
  106.                 if selectedCategory == 0 then
  107.                     animations:setAnimationGuiVisible(false)
  108.                     animations:addAnimations(0)
  109.                 end
  110.             end
  111.         end
  112.     end
  113. end
  114. function animations:visible()
  115.     DGS:dgsSetVisible(self.gui.window, not DGS:dgsGetVisible(self.gui.window))
  116.     showCursor(not isCursorShowing(), false)
  117. end
  118. function animations:constructor()
  119.     self.gui = {}
  120.  
  121.     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)
  122.         DGS:dgsWindowSetSizable(self.gui.window, false)
  123.         DGS:dgsSetVisible(self.gui.window, false)
  124.     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)
  125.     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)
  126.     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")
  127.         DGS:dgsSetFont(self.gui.animationName, font1)
  128.     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")
  129.         DGS:dgsSetFont(self.gui.animationDesp, font2)
  130.     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))
  131.         DGS:dgsSetFont(self.gui.useAnimation, font2)
  132.     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))
  133.         DGS:dgsSetFont(self.gui.favoriteButton, font2)
  134.  
  135.     self.gridListClick = function(button, state) self:onClick(button, state) end
  136.     self.windowVisible = function() self:visible() end
  137.     addEventHandler("onDgsMouseClick", root, self.gridListClick)
  138.     bindKey("L", "down", self.windowVisible)
  139. end
  140. animations = animations:new()  
  141. animations:addCategories()
  142. animations:setAnimationGuiVisible(false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement