Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.09 KB | None | 0 0
  1. dofile('ui/uistoreacceptbox')
  2.  
  3. local storeWindow = nil
  4. local indexDescription = nil
  5. local indexList = nil
  6. local imageDesc = nil
  7. local titleDesc = nil
  8. local description = nil
  9. local acceptWindow = nil
  10. local transferPointsWindow = nil
  11.  
  12. local function short(value)
  13. local text = value
  14. if string.len(text) >= 13 then
  15. shorten = string.sub(text, 1, 10)
  16. return shorten .. "..."
  17. else
  18. return text
  19. end
  20. end
  21.  
  22. local function formatNumbers(number)
  23. local ret = number
  24. while true do
  25. ret, k = string.gsub(ret, "^(-?%d+)(%d%d%d)", '%1,%2')
  26. if k == 0 then
  27. break
  28. end
  29. end
  30. return ret
  31. end
  32.  
  33. function init()
  34. g_ui.importStyle('ui/acceptwindow')
  35.  
  36. storeWindow = g_ui.displayUI('store_module')
  37. storeWindow:hide()
  38. storeButton = modules.client_topmenu.addRightGameToggleButton('storeButton', tr('Diamond Store') .. ' (Ctrl+X)', '/images/topbuttons/market', toggle)
  39. storeButton:setOn(true)
  40.  
  41. g_keyboard.bindKeyPress('Ctrl+X', toggle)
  42. ProtocolGame.registerExtendedOpcode(COINS_OPCODE, coinsBalance)
  43.  
  44. transferPointsWindow = g_ui.displayUI('transferpoints')
  45.  
  46. indexList = storeWindow:getChildById('indexList')
  47. indexDescription = storeWindow:getChildById('indexDescription')
  48. imageDesc = storeWindow:getChildById('indexDescription'):getChildById('imageDesc')
  49. titleDesc = storeWindow:getChildById('indexDescription'):getChildById('titleDesc')
  50. description = storeWindow:getChildById('indexDescription'):getChildById('description')
  51.  
  52. productList = storeWindow:getChildById('productList')
  53.  
  54.  
  55. ProtocolGame.registerExtendedOpcode(185, listar)
  56.  
  57. for i = 1, #storeIndex do
  58. local label = g_ui.createWidget('StoreButton', indexList)
  59.  
  60. label:setId(i)
  61. label:setIcon(storeIndex[i].imageList)
  62. label:setText(tr(storeIndex[i].name))
  63. label.index = i
  64.  
  65. local labelId = storeWindow:getChildById('indexList'):getChildById(i)
  66. labelId.onClick = function(self)
  67. local descriptionImage = storeWindow:getChildById('indexDescription'):getChildById('imageDesc')
  68. descriptionImage:setImageSource(storeIndex[i].image)
  69.  
  70. local descriptionTitle = storeWindow:getChildById('indexDescription'):getChildById('titleDesc')
  71. descriptionTitle:setText(storeIndex[i].name)
  72.  
  73. local description = storeWindow:getChildById('indexDescription'):getChildById('description')
  74. description:setText(storeIndex[i].description)
  75.  
  76. local productsPanel = storeWindow:getChildById('productList')
  77. local children = productsPanel:getChildren()
  78. for k = 1, #children do
  79. children[k]:destroy()
  80. end
  81.  
  82. for j=1, #storeProducts do
  83. if storeIndex[i].id == storeProducts[j].category_id then
  84. local productLabel = g_ui.createWidget('ProductButton', productList)
  85.  
  86.  
  87. productLabel:setId(j)
  88. productLabel:setTooltip(storeProducts[j].tooltip)
  89.  
  90. local productLabelTitle = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelTitle')
  91. productLabelTitle:setText(short(storeProducts[j].name))
  92.  
  93. local productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImage')
  94.  
  95. if storeProducts[j].category_type == "item" then
  96. productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImageItem')
  97. productLabelImage:setItemId(storeProducts[j].image)
  98. elseif storeProducts[j].category_type == "outfit" then
  99. productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImageOutfit')
  100.  
  101. outfit = {type = 958, head = 0, body = 0, legs = 0, feet = 0, addons = 0}
  102. outfit.type = storeProducts[j].image
  103. outfit.head = 0
  104. outfit.body = 0
  105. outfit.legs = 0
  106. outfit.feet = 0
  107. outfit.addons = 0
  108.  
  109. productLabelImage:recursiveGetChildById('creature'):setOutfit(outfit)
  110. productLabelImage:recursiveGetChildById('creature'):getCreature():setOutfit(outfit)
  111. else
  112. productLabelImage:setImageSource(storeIndex[i].image)
  113. end
  114.  
  115.  
  116. local productLabelTokenPrice = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelTokenPrice')
  117. productLabelTokenPrice:setText(formatNumbers(storeProducts[j].price))
  118.  
  119.  
  120.  
  121. local buyWindow = storeWindow:getChildById('productList'):getChildById(j)
  122. buyWindow.onClick = function(self)
  123. if acceptWindow then
  124. return true
  125. end
  126.  
  127. local acceptFunc = function()
  128. local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
  129. local unformatted = balance:gsub(',', '')
  130. local balanceInfo = tonumber(unformatted)
  131. if storeProducts[j].price then
  132. g_game.talk(COMMAND_BUYITEM .. ' ' .. storeIndex[i].id .. ', ' .. storeProducts[j].id)
  133. acceptWindow:destroy()
  134. acceptWindow = nil
  135.  
  136. local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
  137. local unformatted = balance:gsub(',', '')
  138. local balanceInfo = tonumber(unformatted)
  139. local balanceAfterPurchase = balanceInfo - storeProducts[j].price
  140.  
  141. local balanceLabel = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance')
  142. balanceLabel:setText((formatNumbers(balanceAfterPurchase)))
  143. else
  144. io.popen('start ' .. WEBSITE_GETCOINS)
  145. acceptWindow:destroy()
  146. acceptWindow = nil
  147. end
  148. end
  149.  
  150. local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end
  151.  
  152. transferPointsWindow:setVisible(false)
  153.  
  154. acceptWindow = displayAcceptBox(tr('Buy ' .. storeProducts[j].name), tr(storeProducts[j].description),
  155. { { text=tr('Buy'), callback=acceptFunc },
  156. { text=tr('Cancel'), callback=cancelFunc },
  157. anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  158. return true
  159. end
  160. end
  161. end
  162. end
  163. end
  164.  
  165. connect(g_game, {
  166. onGameStart = refresh,
  167. onGameEnd = offline
  168. })
  169.  
  170. refresh()
  171.  
  172. end
  173.  
  174. function terminate()
  175. storeWindow:hide()
  176. g_keyboard.unbindKeyPress('Ctrl+U')
  177. ProtocolGame.unregisterExtendedOpcode(COINS_OPCODE)
  178. ProtocolGame.unregisterExtendedOpcode(185)
  179.  
  180. disconnect(g_game, {
  181. onGameStart = refresh,
  182. onGameEnd = offline
  183. })
  184.  
  185. end
  186.  
  187. function coinsBalance(protocol, opcode, buffer)
  188. local balanceLabel = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance')
  189. balanceLabel:setText(formatNumbers(buffer))
  190. end
  191.  
  192. function refresh()
  193. local player = g_game.getLocalPlayer()
  194. if not player then
  195. return
  196. end
  197. end
  198.  
  199. function offline()
  200. storeWindow:hide()
  201. end
  202.  
  203. function toggle()
  204. if storeWindow:isVisible() then
  205. onCloseStore()
  206. else
  207. onOpenStore()
  208. end
  209. end
  210.  
  211. function listar(protocol, opcode, buffer)
  212. local _items = string.explode(buffer, "@")
  213. print(_items[1])
  214. --for l = 1,
  215. for i = 1, #_items do
  216. local list = string.explode(_items[i], "&")
  217. storeProducts[i] = {
  218. name = list[1],
  219. id = list[2],
  220. category_id = list[3],
  221. description = list[4],
  222. tooltip = list[5],
  223. price = list[6],
  224. image = list[7],
  225. category_type = list[8],
  226. }
  227. end
  228. end
  229.  
  230. function onOpenStore()
  231. storeWindow:show()
  232. storeWindow:raise()
  233. storeWindow:focus()
  234. --listar('30x Vitamin H& 2357&10&Do you really want to buy "Shiny Arch Heatran"?\n\nNote: The Pokemon will only be received by the character\nwho purchased it in the Store.&Shiny Arch Heatran\n Held X Epic, Held Y Epic, Held Z Epic, Held W Hallow Tier 2 \n Boost 400 \n Vitamin 30 \n Card Random \n Maestria 10 \n Shiny Level 10 \n With random bonus catalyst ground force from 50.&100&/images/shop/offer/pokemons/shinyarch_heatran@')
  235. local descriptionImage = storeWindow:getChildById('indexDescription'):getChildById('imageDesc')
  236. descriptionImage:setImageSource(storeIndex[1].image)
  237.  
  238. local descriptionTitle = storeWindow:getChildById('indexDescription'):getChildById('titleDesc')
  239. descriptionTitle:setText(storeIndex[1].name)
  240.  
  241. local description = storeWindow:getChildById('indexDescription'):getChildById('description')
  242. description:setText(storeIndex[1].description)
  243.  
  244. local productsPanel = storeWindow:getChildById('productList')
  245. local children = productsPanel:getChildren()
  246. for k = 1, #children do
  247. children[k]:destroy()
  248. end
  249.  
  250. for j=1, #storeProducts do
  251. if storeIndex[1].id == storeProducts[j].category_id then
  252. local productLabel = g_ui.createWidget('ProductButton', productList)
  253.  
  254. productLabel:setId(j)
  255. productLabel:setTooltip(storeProducts[j].tooltip)
  256. local productLabelTitle = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelTitle')
  257. productLabelTitle:setText(short(storeProducts[j].name))
  258.  
  259. local productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImage')
  260.  
  261. if storeProducts[j].category_type == "item" then
  262. productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImageItem')
  263. productLabelImage:setItemId(storeProducts[j].image)
  264. --productLabelImage:setImageSource(storeIndex[i].image)
  265. --productLabelImage.onClick = function(self)
  266. elseif storeProducts[j].category_type == "outfit" then
  267. productLabelImage:setImageSource(storeIndex[i].image)
  268. --productLabelImage.onClick = function(self)
  269. else
  270. productLabelImage:setImageSource(storeIndex[i].image)
  271. --productLabelImage.onClick = function(self)
  272. --productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImageItem')
  273. --productLabelImage:setItemId(2160)
  274. end
  275.  
  276. local productLabelTokenPrice = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelTokenPrice')
  277. productLabelTokenPrice:setText(formatNumbers(storeProducts[j].price))
  278.  
  279. local buyWindow = storeWindow:getChildById('productList'):getChildById(j)
  280. buyWindow.onClick = function(self)
  281. if acceptWindow then
  282. return true
  283. end
  284.  
  285. local acceptFunc = function()
  286. local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
  287. local unformatted = balance:gsub(',', '')
  288. local balanceInfo = tonumber(unformatted)
  289. if storeProducts[j].price then
  290. g_game.talk(COMMAND_BUYITEM .. ' ' .. storeIndex[1].id .. ', ' .. storeProducts[j].id)
  291. acceptWindow:destroy()
  292. acceptWindow = nil
  293.  
  294. local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
  295. local unformatted = balance:gsub(',', '')
  296. local balanceInfo = tonumber(unformatted)
  297. local balanceAfterPurchase = balanceInfo - storeProducts[j].price
  298.  
  299. local balanceLabel = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance')
  300. balanceLabel:setText((formatNumbers(balanceAfterPurchase)))
  301. else
  302. io.popen('start ' .. WEBSITE_GETCOINS)
  303. acceptWindow:destroy()
  304. acceptWindow = nil
  305. end
  306. end
  307.  
  308. local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end
  309.  
  310. transferPointsWindow:setVisible(false)
  311.  
  312. acceptWindow = displayAcceptBox(tr('Buy ' .. storeProducts[j].name), tr(storeProducts[j].description),
  313. { { text=tr('Buy'), callback=acceptFunc },
  314. { text=tr('Cancel'), callback=cancelFunc },
  315. anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
  316. return true
  317. end
  318. end
  319. end
  320. end
  321.  
  322. function onCloseStore()
  323. storeWindow:hide()
  324. transferPointsWindow:setVisible(false)
  325. if acceptWindow then
  326. acceptWindow:destroy()
  327. acceptWindow = nil
  328. end
  329. end
  330.  
  331. function transferPoints()
  332. local value = transferPointsWindow:getChildById('transferPointsValue')
  333. value:setText(tr('0'))
  334.  
  335. local balanceInfo = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
  336. local balance = transferPointsWindow:getChildById('coinBalance2')
  337. balance:setText(formatNumbers(balanceInfo))
  338. transferPointsWindow:setVisible(true)
  339. transferPointsWindow:focus()
  340. transferPointsWindow:raise()
  341.  
  342. acceptWindow:destroy()
  343. acceptWindow = nil
  344. end
  345.  
  346. function transferAccept()
  347. local nickname = transferPointsWindow:getChildById('transferPointsText'):getText()
  348. local value = transferPointsWindow:getChildById('transferPointsValue'):getText()
  349. g_game.talk(COMMAND_TRANSFER .. ' ' .. nickname .. ', '.. value)
  350.  
  351. local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
  352. local unformatted = balance:gsub(',', '')
  353. local balanceInfo = tonumber(unformatted)
  354. local getValue = tonumber(value)
  355. local balanceAfterSend = balanceInfo - getValue
  356.  
  357. local balanceLabel = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance')
  358. balanceLabel:setText((formatNumbers(balanceAfterSend)))
  359. transferPointsWindow:setVisible(false)
  360. end
  361.  
  362. function transferCancel()
  363. transferPointsWindow:setVisible(false)
  364. end
  365.  
  366. function getCoins()
  367. io.popen('start ' .. WEBSITE_GETCOINS)
  368. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement