Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.71 KB | None | 0 0
  1. var ItemList = {},
  2. ItemData = {},
  3. Itembuilds = {},
  4. SmallItems = [],
  5. SmallItemsAlwaysUpdated = [],
  6. SearchingFor = null,
  7. TabIndex = null,
  8. QuickBuyTarget = null,
  9. QuickBuyTargetAmount = 0,
  10. LastHero = null,
  11. ItemStocks = [];
  12.  
  13. function OpenCloseShop() {
  14. $("#ShopBase").ToggleClass("ShopBase_Out")
  15. if ($("#ShopBase").BHasClass("ShopBase_Out")) {
  16. Game.EmitSound("Shop.PanelUp");
  17. UpdateShop();
  18. } else
  19. Game.EmitSound("Shop.PanelDown")
  20. }
  21.  
  22. function SearchItems() {
  23. var searchStr = $("#ShopSearchEntry").text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  24. if (SearchingFor != searchStr) {
  25. SearchingFor = searchStr
  26. var ShopSearchOverlay = $("#ShopSearchOverlay")
  27. $.Each(ShopSearchOverlay.Children(), function(child) {
  28. child.DestroyItemPanel()
  29. })
  30. $.GetContextPanel().SetHasClass("InSearchMode", searchStr.length > 0)
  31. if (searchStr.length > 0) {
  32. var FoundItems = []
  33. for (var itemName in ItemData) {
  34. if (itemName.lastIndexOf("item_recipe_")) {
  35. for (var key in ItemData[itemName].names) {
  36. if (ItemData[itemName].names[key].search(new RegExp(searchStr, "i")) > -1) {
  37. FoundItems.push({
  38. itemName: itemName,
  39. cost: ItemData[itemName].cost
  40. })
  41. break;
  42. }
  43. }
  44. }
  45. }
  46. FoundItems.sort(dynamicSort("cost"))
  47. $.Each(FoundItems, function(itemTable) {
  48. SnippetCreate_SmallItem($.CreatePanel("Panel", ShopSearchOverlay, "ShopSearchOverlay_item_" + itemTable.itemName), itemTable.itemName)
  49. })
  50. }
  51. }
  52. }
  53.  
  54. function PushItemsToList() {
  55. var isTabSelected = false
  56. for (var shopName in ItemList) {
  57. var TabButton = $.CreatePanel('RadioButton', $("#ShopTabs"), "shop_tab_" + shopName)
  58. TabButton.AddClass("ShopTabButton")
  59. TabButton.style.width = (100 / Object.keys(ItemList).length) + "%";
  60. var TabButtonLabel = $.CreatePanel('Label', TabButton, "")
  61. TabButtonLabel.text = $.Localize("panorama_shop_shop_tab_" + shopName)
  62. TabButtonLabel.hittest = false;
  63. var SelectShopTabAction = (function(_shopName) {
  64. return function() {
  65. SelectShopTab(_shopName)
  66. }
  67. })(shopName)
  68. TabButton.SetPanelEvent('onactivate', SelectShopTabAction)
  69. var TabShopItemlistPanel = $.CreatePanel('Panel', $("#ShopItemsBase"), "shop_panels_tab_" + shopName)
  70. TabShopItemlistPanel.AddClass("ItemsPageInnerContainer")
  71. FillShopTable(TabShopItemlistPanel, ItemList[shopName])
  72.  
  73. if (!isTabSelected) {
  74. SelectShopTab(shopName)
  75. isTabSelected = true
  76. }
  77. }
  78.  
  79. }
  80.  
  81. function SelectShopTab(tabIndex) {
  82. if (TabIndex != tabIndex) {
  83. if (TabIndex != null) {
  84. $("#shop_panels_tab_" + TabIndex).RemoveClass("SelectedPage")
  85. $("#shop_tab_" + TabIndex).RemoveClass("ShopTabButtonSelected")
  86. }
  87. $("#shop_panels_tab_" + tabIndex).AddClass("SelectedPage")
  88. $("#shop_tab_" + tabIndex).AddClass("ShopTabButtonSelected")
  89. TabIndex = tabIndex
  90. }
  91. }
  92.  
  93. function FillShopTable(panel, shopData) {
  94. for (var groupName in shopData) {
  95. var groupPanel = $.CreatePanel("Panel", panel, panel.id + "_group_" + groupName)
  96. groupPanel.AddClass("ShopItemGroup")
  97. $.Each(shopData[groupName], function(itemName) {
  98. var itemPanel = $.CreatePanel("Panel", groupPanel, groupPanel.id + "_item_" + itemName)
  99. SnippetCreate_SmallItem(itemPanel, itemName)
  100. //groupPanel.AddClass("ShopItemGroup")
  101. })
  102. }
  103. }
  104.  
  105. function SnippetCreate_SmallItem(panel, itemName, skipPush) {
  106. panel.BLoadLayoutSnippet("SmallItem")
  107. panel.itemName = itemName
  108. panel.FindChildTraverse("SmallItemImage").itemname = itemName;
  109. if (itemName.lastIndexOf("item_recipe", 0) === 0)
  110. panel.FindChildTraverse("SmallItemImage").SetImage("raw://resource/flash3/images/items/recipe.png")
  111. panel.SetPanelEvent("onactivate", function() {
  112. if (!$.GetContextPanel().BHasClass("InSearchMode")) {
  113. panel.SetFocus();
  114. }
  115. if (GameUI.IsAltDown()) {
  116. GameEvents.SendCustomGameEventToServer("custom_chat_send_message", {
  117. shop_item_name: panel.IsInQuickbuy ? QuickBuyTarget : itemName,
  118. isQuickbuy: panel.IsInQuickbuy,
  119. gold: GetRemainingPrice(panel.IsInQuickbuy ? QuickBuyTarget : itemName, {})
  120. })
  121. } else {
  122. ShowItemRecipe(itemName)
  123. if (GameUI.IsShiftDown()) {
  124. SetQuickbuyTarget(itemName)
  125. }
  126. }
  127. })
  128. panel.SetPanelEvent("oncontextmenu", function() {
  129. if (panel.BHasClass("CanBuy")) {
  130. SendItemBuyOrder(itemName)
  131. } else {
  132. GameEvents.SendEventClientSide("dota_hud_error_message", {
  133. "splitscreenplayer": 0,
  134. "reason": 80,
  135. "message": "#dota_hud_error_not_enough_gold"
  136. });
  137. Game.EmitSound("General.NoGold")
  138. }
  139. })
  140. panel.SetPanelEvent("onmouseover", function() {
  141. ItemShowTooltip(panel)
  142. })
  143. panel.SetPanelEvent("onmouseout", function() {
  144. ItemHideTooltip(panel)
  145. })
  146. panel.DestroyItemPanel = function() {
  147. var id1 = SmallItemsAlwaysUpdated.indexOf(panel);
  148. var id2 = SmallItems.indexOf(panel);
  149. if (id1 > -1)
  150. SmallItemsAlwaysUpdated.splice(id1, 1);
  151. if (id2 > -1)
  152. SmallItems.splice(id2, 1);
  153. panel.visible = false
  154. panel.DeleteAsync(0)
  155. }
  156. if (!panel.IsInQuickbuy) {
  157. $.RegisterEventHandler('DragStart', panel, SmallItemOnDragStart);
  158. $.RegisterEventHandler('DragEnd', panel, SmallItemOnDragEnd);
  159. }
  160. UpdateSmallItem(panel)
  161. if (!skipPush)
  162. SmallItems.push(panel)
  163. }
  164.  
  165. function SmallItemOnDragStart(panelId, dragCallbacks) {
  166. $.GetContextPanel().AddClass("DropDownMode")
  167. var panel = $("#" + panelId)
  168. var itemName = panel.itemName
  169. ItemHideTooltip(panel);
  170.  
  171. var displayPanel = $.CreatePanel("DOTAItemImage", panel, "dragImage");
  172. displayPanel.itemname = itemName;
  173. if (itemName.lastIndexOf("item_recipe_", 0) === 0)
  174. displayPanel.SetImage("raw://resource/flash3/images/items/recipe.png")
  175.  
  176. dragCallbacks.displayPanel = displayPanel;
  177. dragCallbacks.offsetX = 0;
  178. dragCallbacks.offsetY = 0;
  179. return true;
  180. }
  181.  
  182. function SmallItemOnDragEnd(panelId, draggedPanel) {
  183. $.GetContextPanel().RemoveClass("DropDownMode")
  184. draggedPanel.DeleteAsync(0);
  185. return true;
  186. }
  187.  
  188. function ShowItemRecipe(itemName) {
  189. var currentItemData = ItemData[itemName]
  190. if (currentItemData == null)
  191. return;
  192. var RecipeData = currentItemData.Recipe
  193. var BuildsIntoData = currentItemData.BuildsInto
  194. var DropListData = currentItemData.DropListData
  195. $.Each($("#ItemRecipeBoxRow1").Children(), function(child) {
  196. if (child.DestroyItemPanel != null)
  197. child.DestroyItemPanel();
  198. else
  199. child.DeleteAsync(0);
  200. })
  201. $.Each($("#ItemRecipeBoxRow2").Children(), function(child) {
  202. if (child.DestroyItemPanel != null)
  203. child.DestroyItemPanel();
  204. else
  205. child.DeleteAsync(0);
  206. })
  207. $.Each($("#ItemRecipeBoxRow3").Children(), function(child) {
  208. if (child.DestroyItemPanel != null)
  209. child.DestroyItemPanel();
  210. else
  211. child.DeleteAsync(0);
  212. })
  213.  
  214. $("#ItemRecipeBoxRow1").RemoveAndDeleteChildren();
  215. $("#ItemRecipeBoxRow2").RemoveAndDeleteChildren();
  216. $("#ItemRecipeBoxRow3").RemoveAndDeleteChildren();
  217.  
  218. var itemPanel = $.CreatePanel("Panel", $("#ItemRecipeBoxRow2"), "ItemRecipeBoxRow2_item_" + itemName);
  219. SnippetCreate_SmallItem(itemPanel, itemName);
  220. itemPanel.style.align = "center center";
  221. var len = 0;
  222. $("#ItemRecipeBoxDrops").visible = false;
  223. if (RecipeData != null && RecipeData.items != null) {
  224. $.Each(RecipeData.items[1], function(childName) {
  225. var itemPanel = $.CreatePanel("Panel", $("#ItemRecipeBoxRow3"), "ItemRecipeBoxRow3_item_" + childName)
  226. SnippetCreate_SmallItem(itemPanel, childName);
  227. itemPanel.style.align = "center center";
  228. });
  229. len = Object.keys(RecipeData.items).length;
  230. if (RecipeData.visible && RecipeData.recipeItemName != null) {
  231. len++;
  232. var itemPanel = $.CreatePanel("Panel", $("#ItemRecipeBoxRow3"), "ItemRecipeBoxRow3_item_" + RecipeData.recipeItemName);
  233. SnippetCreate_SmallItem(itemPanel, RecipeData.recipeItemName);
  234. itemPanel.style.align = "center center";
  235. }
  236. } else if (DropListData != null) {
  237. $("#ItemRecipeBoxDrops").visible = true;
  238. $.Each($("#ItemRecipeBoxDrops").Children(), function(pan) {
  239. var unit = pan.id.replace("ItemRecipeBoxDrops_", "")
  240. pan.enabled = DropListData[unit] != null;
  241. pan.RemoveAndDeleteChildren()
  242. if (DropListData[unit] != null)
  243. $.Each(DropListData[unit], function(chance) {
  244. var chancePanel = $.CreatePanel("Label", pan, "");
  245. chancePanel.AddClass("UnitItemlikeRecipePanelChance");
  246. chancePanel.text = chance + "%";
  247. })
  248. })
  249. }
  250. $("#ItemRecipeBoxRow3").SetHasClass("ItemRecipeBoxRowLength7", len >= 7);
  251. $("#ItemRecipeBoxRow3").SetHasClass("ItemRecipeBoxRowLength8", len >= 8);
  252. $("#ItemRecipeBoxRow3").SetHasClass("ItemRecipeBoxRowLength9", len >= 9);
  253. if (BuildsIntoData != null) {
  254. $.Each(BuildsIntoData, function(childName) {
  255. var itemPanel = $.CreatePanel("Panel", $("#ItemRecipeBoxRow1"), "ItemRecipeBoxRow1_item_" + childName);
  256. SnippetCreate_SmallItem(itemPanel, childName);
  257. itemPanel.style.align = "center center";
  258. });
  259. $("#ItemRecipeBoxRow1").SetHasClass("ItemRecipeBoxRowLength7", Object.keys(BuildsIntoData).length >= 7);
  260. $("#ItemRecipeBoxRow1").SetHasClass("ItemRecipeBoxRowLength8", Object.keys(BuildsIntoData).length >= 8);
  261. $("#ItemRecipeBoxRow1").SetHasClass("ItemRecipeBoxRowLength9", Object.keys(BuildsIntoData).length >= 9);
  262. }
  263. }
  264.  
  265. function SendItemBuyOrder(itemName) {
  266. var pid = Game.GetLocalPlayerID();
  267. var unit = Players.GetLocalPlayerPortraitUnit()
  268. unit = Entities.IsControllableByPlayer(unit, pid) ? unit : Players.GetPlayerHeroEntityIndex(pid);
  269. GameEvents.SendCustomGameEventToServer("panorama_shop_item_buy", {
  270. "itemName": itemName,
  271. "unit": unit,
  272. });
  273. }
  274.  
  275. function ItemShowTooltip(panel) {
  276. $.DispatchEvent("DOTAShowAbilityTooltipForEntityIndex", panel, panel.itemName, Players.GetLocalPlayerPortraitUnit());
  277. }
  278.  
  279. function ItemHideTooltip(panel) {
  280. $.DispatchEvent("DOTAHideAbilityTooltip", panel);
  281. }
  282.  
  283. function LoadItemsFromTable(panorama_shop_data) {
  284. ItemList = panorama_shop_data.ShopList
  285. ItemData = panorama_shop_data.ItemData
  286. Itembuilds = panorama_shop_data.Itembuilds
  287. PushItemsToList()
  288. }
  289.  
  290. function UpdateSmallItem(panel, gold) {
  291. try {
  292. var notpurchasable = !ItemData[panel.itemName].purchasable
  293. panel.SetHasClass("CanBuy", GetRemainingPrice(panel.itemName, {}) <= (gold || PlayerTables.GetTableValue("arena", "gold")[Game.GetLocalPlayerID()]) || notpurchasable);
  294. panel.SetHasClass("NotPurchasableItem", notpurchasable);
  295. if (ItemStocks[panel.itemName] != null) {
  296. var CurrentTime = Game.GetGameTime();
  297. var RemainingTime = ItemStocks[panel.itemName].current_cooldown - (CurrentTime - ItemStocks[panel.itemName].current_last_purchased_time)
  298. var stock = ItemStocks[panel.itemName].current_stock;
  299. panel.FindChildTraverse("SmallItemStock").text = stock
  300. if (stock == 0 && RemainingTime > 0) {
  301. panel.FindChildTraverse("StockTimer").text = Math.round(RemainingTime);
  302. panel.FindChildTraverse("StockOverlay").style.width = (RemainingTime / ItemStocks[panel.itemName].current_cooldown * 100) + "%";
  303. } else {
  304. panel.FindChildTraverse("StockTimer").text = "";
  305. panel.FindChildTraverse("StockOverlay").style.width = 0;
  306. }
  307. }
  308. } catch (err) {
  309. var index = SmallItems.indexOf(panel);
  310. if (index > -1)
  311. SmallItems.splice(index, 1);
  312. else {
  313. index = SmallItemsAlwaysUpdated.indexOf(panel);
  314. if (index > -1)
  315. SmallItemsAlwaysUpdated.splice(index, 1);
  316. }
  317. }
  318. }
  319.  
  320. function GetRemainingPrice(itemName, ItemCounter, baseItem) {
  321. if (ItemCounter[itemName] == null)
  322. ItemCounter[itemName] = 0
  323. ItemCounter[itemName] = ItemCounter[itemName] + 1
  324.  
  325. var itemCount = GetItemCountInInventory(Players.GetPlayerHeroEntityIndex(Game.GetLocalPlayerID()), itemName, true)
  326. var val = 0
  327. if (itemCount < ItemCounter[itemName] || !baseItem) {
  328. if (ItemData[itemName] == null) {
  329. throw new Error("Unable to find item " + itemName + "!")
  330. }
  331. var RecipeData = ItemData[itemName].Recipe
  332. if (RecipeData != null && RecipeData.items != null) {
  333. $.Each(RecipeData.items[1], function(childName) {
  334. val += GetRemainingPrice(childName, ItemCounter, baseItem || itemName)
  335. })
  336. if (RecipeData.visible && RecipeData.recipeItemName != null) {
  337. val += GetRemainingPrice(RecipeData.recipeItemName, ItemCounter, baseItem || itemName)
  338. }
  339. } else {
  340. val += ItemData[itemName].cost
  341. }
  342. }
  343. return val
  344. }
  345.  
  346. function SetQuickbuyStickyItem(itemName) {
  347. $.Each($("#QuickBuyStickyButtonPanel").Children(), function(child) {
  348. child.DestroyItemPanel()
  349. })
  350. var itemPanel = $.CreatePanel("Panel", $("#QuickBuyStickyButtonPanel"), "QuickBuyStickyButtonPanel_item_" + itemName)
  351. SnippetCreate_SmallItem(itemPanel, itemName, true)
  352. itemPanel.AddClass("QuickBuyStickyItem")
  353. SmallItemsAlwaysUpdated.push(itemPanel);
  354. }
  355.  
  356. function ClearQuickbuyItems() {
  357. QuickBuyTarget = null
  358. QuickBuyTargetAmount = null
  359. $.Each($("#QuickBuyPanelItems").Children(), function(child) {
  360. if (!child.BHasClass("DropDownValidTarget")) {
  361. child.DestroyItemPanel()
  362. } else {
  363. //child.visible = false
  364. }
  365. })
  366. }
  367.  
  368. function RefreshQuickbuyItem(itemName) {
  369. MakeQuickbuyCheckItem(itemName, {}, {}, QuickBuyTargetAmount)
  370. }
  371.  
  372. function MakeQuickbuyCheckItem(itemName, ItemCounter, ItemIndexer, sourceExpectedCount) {
  373. var RecipeData = ItemData[itemName].Recipe
  374. if (ItemCounter[itemName] == null)
  375. ItemCounter[itemName] = 0
  376. if (ItemIndexer[itemName] == null)
  377. ItemIndexer[itemName] = 0
  378. ItemCounter[itemName] = ItemCounter[itemName] + 1
  379. ItemIndexer[itemName] = ItemIndexer[itemName] + 1
  380. var itemCount = GetItemCountInCourier(Players.GetPlayerHeroEntityIndex(Game.GetLocalPlayerID()), itemName, true) + GetItemCountInInventory(Players.GetPlayerHeroEntityIndex(Game.GetLocalPlayerID()), itemName, true)
  381. if ((itemCount < ItemCounter[itemName] || (itemName == QuickBuyTarget && itemCount - (sourceExpectedCount - 1) < ItemCounter[itemName]))) {
  382. if (RecipeData != null && RecipeData.items != null) {
  383. $.Each(RecipeData.items[1], function(childName) {
  384. MakeQuickbuyCheckItem(childName, ItemCounter, ItemIndexer)
  385. })
  386. if (RecipeData.visible && RecipeData.recipeItemName != null) {
  387. MakeQuickbuyCheckItem(RecipeData.recipeItemName, ItemCounter, ItemIndexer)
  388. }
  389. } else if ($("#QuickBuyPanelItems").FindChildTraverse("QuickBuyPanelItems_item_" + itemName + "_id_" + ItemIndexer[itemName]) == null) {
  390. var itemPanel = $.CreatePanel("Panel", $("#QuickBuyPanelItems"), "QuickBuyPanelItems_item_" + itemName + "_id_" + ItemIndexer[itemName])
  391. itemPanel.IsInQuickbuy = true
  392. SnippetCreate_SmallItem(itemPanel, itemName)
  393. itemPanel.AddClass("QuickbuyItemPanel")
  394. SmallItemsAlwaysUpdated.push(itemPanel);
  395. }
  396. } else {
  397. if (itemName == QuickBuyTarget) {
  398. ClearQuickbuyItems()
  399. } else {
  400. RemoveQuickbuyItemChildren(itemName, ItemIndexer, false)
  401. }
  402. }
  403. }
  404.  
  405. function RemoveQuickbuyItemChildren(itemName, ItemIndexer, bIncrease) {
  406. var RecipeData = ItemData[itemName].Recipe
  407. if (bIncrease)
  408. ItemIndexer[itemName] = (ItemIndexer[itemName] || 0) + 1
  409. RemoveQuckbuyPanel(itemName, ItemIndexer[itemName])
  410. if (RecipeData != null && RecipeData.items != null) {
  411. $.Each(RecipeData.items[1], function(childName) {
  412. RemoveQuickbuyItemChildren(childName, ItemIndexer, true)
  413. })
  414. if (RecipeData.visible && RecipeData.recipeItemName != null) {
  415. RemoveQuickbuyItemChildren(RecipeData.recipeItemName, ItemIndexer, true)
  416. }
  417. }
  418. }
  419.  
  420. function RemoveQuckbuyPanel(itemName, index) {
  421. var panel = $("#QuickBuyPanelItems").FindChildTraverse("QuickBuyPanelItems_item_" + itemName + "_id_" + index)
  422. if (panel != null) {
  423. panel.DestroyItemPanel()
  424. }
  425. }
  426.  
  427. function SetQuickbuyTarget(itemName) {
  428. ClearQuickbuyItems()
  429. Game.EmitSound("Quickbuy.Confirmation")
  430. QuickBuyTarget = itemName
  431. QuickBuyTargetAmount = GetItemCountInCourier(Players.GetPlayerHeroEntityIndex(Game.GetLocalPlayerID()), itemName, true) + GetItemCountInInventory(Players.GetPlayerHeroEntityIndex(Game.GetLocalPlayerID()), itemName, true) + 1
  432. RefreshQuickbuyItem(itemName)
  433. }
  434.  
  435. function ShowItemInShop(data) {
  436. if (data && data.itemName != null) {
  437. $("#ShopBase").RemoveClass("ShopBase_Out")
  438. ShowItemRecipe(String(data.itemName))
  439. }
  440. }
  441.  
  442. function UpdateShop() {
  443. SearchItems()
  444. UpdateItembuildsForHero();
  445. var gold = GetPlayerGold(Game.GetLocalPlayerID())
  446. $.Each(SmallItemsAlwaysUpdated, function(panel) {
  447. UpdateSmallItem(panel, gold)
  448. });
  449. if (!$("#ShopBase").BHasClass("ShopBase_Out"))
  450. $.Each(SmallItems, function(panel) {
  451. UpdateSmallItem(panel, gold)
  452. });
  453. //$.GetContextPanel().SetHasClass("InRangeOfShop", Entities.IsInRangeOfShop(m_QueryUnit, 0, true))
  454. }
  455.  
  456. function AutoUpdateShop() {
  457. UpdateShop()
  458. $.Schedule(0.5, AutoUpdateShop)
  459. }
  460.  
  461. function AutoUpdateQuickbuy() {
  462. if (QuickBuyTarget != null) {
  463. RefreshQuickbuyItem(QuickBuyTarget)
  464. }
  465. $.Schedule(0.15, AutoUpdateQuickbuy)
  466. }
  467.  
  468. function UpdateItembuildsForHero() {
  469. var heroName = GetPlayerHeroName(Game.GetLocalPlayerID())
  470. if (LastHero != heroName) {
  471. LastHero = heroName;
  472. var DropRoot = $("#Itembuild_selectBox");
  473. var content = "";
  474. var SelectedTable;
  475. if (Itembuilds[heroName]) {
  476. $.Each(Itembuilds[heroName], function(build, i) {
  477. content = content + "<Label text='" + build.title + "' id='Itembuild_select_element_index_" + i + "'/>";
  478. if (SelectedTable == null)
  479. SelectedTable = build;
  480. });
  481. }
  482. DropRoot.BLoadLayoutFromString("<root><Panel><DropDown id='Itembuild_select'> " + content + "</DropDown></Panel></root>", true, true);
  483. DropRoot.FindChildTraverse("Itembuild_select").SetPanelEvent("oninputsubmit", function() {
  484. var index = Number(DropRoot.FindChildTraverse("Itembuild_select").GetSelected().id.replace("Itembuild_select_element_index_", ""))
  485. if (Itembuilds[heroName] != null && Itembuilds[heroName][index] != null) {
  486. SelectItembuild(Itembuilds[heroName][index]);
  487. }
  488. });
  489. $.GetContextPanel().SetHasClass("ItembuildsHidden", SelectedTable == null);
  490. SelectItembuild(SelectedTable);
  491. }
  492. }
  493.  
  494. function SelectItembuild(t) {
  495. var groupsRoot = $("#ItembuildPanelsRoot")
  496. groupsRoot.RemoveAndDeleteChildren();
  497. if (t != null) {
  498. $("#Itembuild_author").text = t.author || "?";
  499. $("#Itembuild_patch").text = t.patch || "?";
  500. $.Each(t.items, function(groupData) {
  501. var groupRoot = $.CreatePanel("Panel", groupsRoot, "");
  502. groupRoot.AddClass("ItembuildItemGroup");
  503. var groupTitle = $.CreatePanel("Label", groupRoot, "");
  504. groupTitle.AddClass("ItembuildItemGroupTitle");
  505. groupTitle.text = $.Localize(groupData.title);
  506. var itemsRoot = $.CreatePanel("Panel", groupRoot, "");
  507. itemsRoot.AddClass("ItembuildItemGroupItemRoot");
  508.  
  509. $.Each(groupData.content, function(itemName) {
  510. var itemPanel = $.CreatePanel("Panel", itemsRoot, "shop_itembuild_items_" + itemName)
  511. SnippetCreate_SmallItem(itemPanel, itemName)
  512. })
  513. })
  514. } else {
  515. $("#Itembuild_author").text = "";
  516. $("#Itembuild_patch").text = "";
  517. }
  518. }
  519.  
  520. function SetItemStock(item, ItemStock) {
  521. ItemStocks[item] = ItemStock;
  522. }
  523.  
  524. (function() {
  525. GameUI.SetDefaultUIEnabled(DotaDefaultUIElement_t.DOTA_DEFAULT_UI_INVENTORY_SHOP, true)
  526. GameUI.SetDefaultUIEnabled(DotaDefaultUIElement_t.DOTA_DEFAULT_UI_SHOP_SUGGESTEDITEMS, true)
  527. GameUI.SetDefaultUIEnabled(DotaDefaultUIElement_t.DOTA_DEFAULT_UI_INVENTORY_QUICKBUY, true)
  528. Game.Events.F4Pressed.push(OpenCloseShop)
  529. GameEvents.Subscribe("panorama_shop_open_close", OpenCloseShop)
  530. Game.Events.F5Pressed.push(function() {
  531. var bought = false;
  532. $.Each($("#QuickBuyPanelItems").Children(), function(child) {
  533. if (!child.BHasClass("DropDownValidTarget")) {
  534. UpdateSmallItem(child)
  535. if (child.BHasClass("CanBuy")) {
  536. SendItemBuyOrder(child.itemName)
  537. bought = true;
  538. return false
  539. }
  540. }
  541. })
  542. if (!bought) {
  543. GameEvents.SendEventClientSide("dota_hud_error_message", {
  544. "splitscreenplayer": 0,
  545. "reason": 80,
  546. "message": "#dota_hud_error_not_enough_gold"
  547. });
  548. Game.EmitSound("General.NoGold")
  549. }
  550. })
  551. Game.Events.F8Pressed.push(function() {
  552. SendItemBuyOrder($("#QuickBuyStickyButtonPanel").GetChild(0).itemName)
  553. })
  554. Game.MouseEvents.OnLeftPressed.push(function(ClickBehaviors, eventName, arg) {
  555. if (ClickBehaviors === CLICK_BEHAVIORS.DOTA_CLICK_BEHAVIOR_NONE) {
  556. $("#ShopBase").AddClass("ShopBase_Out")
  557. }
  558. })
  559.  
  560. GameEvents.Subscribe("panorama_shop_show_item", ShowItemInShop)
  561. GameEvents.Subscribe("dota_link_clicked", function(data) {
  562. if (data != null && data.link != null && data.link.lastIndexOf("dota.item.", 0) === 0) {
  563. $("#ShopBase").RemoveClass("ShopBase_Out")
  564. ShowItemRecipe(data.link.replace("dota.item.", ""))
  565. }
  566. })
  567. GameEvents.Subscribe("panorama_shop_show_item_if_open", function(data) {
  568. if (!$("#ShopBase").BHasClass("ShopBase_Out"))
  569. ShowItemInShop(data)
  570. })
  571. DynamicSubscribePTListener("panorama_shop_data", function(tableName, changesObject, deletionsObject) {
  572. if (changesObject.ShopList != null) {
  573. LoadItemsFromTable(changesObject);
  574. SetQuickbuyStickyItem("item_shard_level");
  575. };
  576. var stocksChanges = changesObject["ItemStocks_team" + Players.GetTeam(Game.GetLocalPlayerID())];
  577. if (stocksChanges != null) {
  578. for (var item in stocksChanges) {
  579. var ItemStock = stocksChanges[item];
  580. SetItemStock(item, ItemStock);
  581. }
  582. };
  583. });
  584.  
  585. GameEvents.Subscribe("arena_team_changed_update", function() {
  586. var stockdata = PlayerTables.GetTableValue("panorama_shop_data", "ItemStocks_team" + Players.GetTeam(Game.GetLocalPlayerID()))
  587. for (var item in stockdata) {
  588. var ItemStock = stockdata[item];
  589. SetItemStock(item, ItemStock);
  590. }
  591. })
  592.  
  593. AutoUpdateShop()
  594. AutoUpdateQuickbuy()
  595.  
  596. $.RegisterEventHandler('DragDrop', $("#QuickBuyStickyButtonPanel"), function(panelId, draggedPanel) {
  597. if (draggedPanel.itemname != null) {
  598. SetQuickbuyStickyItem(draggedPanel.itemname)
  599. }
  600. draggedPanel.DeleteAsync(0);
  601. });
  602.  
  603. $.RegisterEventHandler('DragDrop', $("#QuickBuyPanelItems"), function(panelId, draggedPanel) {
  604. if (draggedPanel.itemname != null) {
  605. SetQuickbuyTarget(draggedPanel.itemname)
  606. }
  607. draggedPanel.DeleteAsync(0);
  608. });
  609. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement