Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.91 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 group = xmlNodeGetChildren(xml, category)
  39.     local anims = xmlNodeGetChildren(group)
  40.     DGS:dgsGridListClear(self.gui.animationsList)
  41.     DGS:dgsGridListAddColumn(self.gui.animationsList, "Animacje", 0.76)
  42.     ReverseTable(anims)
  43.     for i,v in ipairs(anims) do
  44.         local attributes = xmlNodeGetAttributes(anims[i])
  45.         DGS:dgsGridListAddRow(self.gui.animationsList, 0.75, attributes.name)
  46.     end
  47. end
  48. function animations:onClick(button, state)
  49.     if button == "left" and state == "down" then
  50.         local selectedCategory = DGS:dgsGridListGetSelectedItem(self.gui.categoryList) - 1
  51.         local selectedAnim = DGS:dgsGridListGetSelectedItem(self.gui.animationsList) - 1
  52.  
  53.         if source == self.gui.categoryList then
  54.             if selectedCategory < 0 then
  55.                 DGS:dgsGridListClear(self.gui.animationsList)
  56.                 DGS:dgsGridListAddColumn(self.gui.animationsList, "Animacje", 0.76)
  57.                 return
  58.             end
  59.             animations:addAnimations(selectedCategory)
  60.             animations:setAnimationGuiVisible(false)
  61.         elseif source == self.gui.animationsList then
  62.             if selectedAnim < 0 then return animations:setAnimationGuiVisible(false) end
  63.             selectedGroup = xmlNodeGetChildren(xml, selectedCategory)
  64.             selectedAnims = xmlNodeGetChildren(selectedGroup, selectedAnim)
  65.             attributes = xmlNodeGetAttributes(selectedAnims)
  66.             DGS:dgsSetText(self.gui.animationName, attributes.name)
  67.             DGS:dgsSetText(self.gui.animationDesp, attributes.desp)
  68.             animations:setAnimationGuiVisible(true)
  69.         elseif source == self.gui.useAnimation then
  70.             setPedAnimation(localPlayer, attributes.block, attributes.anim)
  71.         end
  72.     end
  73. end
  74. function animations:visible()
  75.     DGS:dgsSetVisible(self.gui.window, not DGS:dgsGetVisible(self.gui.window))
  76.     showCursor(not isCursorShowing(), false)
  77. end
  78. function animations:constructor()
  79.     self.gui = {}
  80.  
  81.     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)
  82.         DGS:dgsWindowSetSizable(self.gui.window, false)
  83.         DGS:dgsSetVisible(self.gui.window, false)
  84.     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)
  85.     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)
  86.     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")
  87.         DGS:dgsSetFont(self.gui.animationName, font1)
  88.     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")
  89.         DGS:dgsSetFont(self.gui.animationDesp, font2)
  90.     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))
  91.         DGS:dgsSetFont(self.gui.useAnimation, font2)
  92.     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))
  93.         DGS:dgsSetFont(self.gui.favoriteButton, font2)
  94.  
  95.     self.gridListClick = function(button, state) self:onClick(button, state) end
  96.     self.windowVisible = function() self:visible() end
  97.     addEventHandler("onDgsMouseClick", root, self.gridListClick)
  98.     bindKey("L", "down", self.windowVisible)
  99. end
  100. animations = animations:new()  
  101. animations:addCategories()
  102. animations:setAnimationGuiVisible(false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement