Guest User

Untitled

a guest
Jul 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.64 KB | None | 0 0
  1.  
  2. local InvSlot = require "widgets/invslot"
  3. local TileBG = require "widgets/tilebg"
  4. local Image = require "widgets/image"
  5. local Widget = require "widgets/widget"
  6. local EquipSlot = require "widgets/equipslot"
  7. local ItemTile = require "widgets/itemtile"
  8. local Text = require "widgets/text"
  9. local ThreeSlice = require "widgets/threeslice"
  10.  
  11. local HUD_ATLAS = "images/hud.xml"
  12.  
  13. local W = 68
  14. local SEP = 12
  15. local YSEP = 8
  16. local INTERSEP = 28
  17. local CURSOR_STRING_DELAY = 10
  18. local TIP_YFUDGE = 16
  19. local HINT_UPDATE_INTERVAL = 2.0 -- once per second
  20.  
  21. local oldOpenBoat = nil
  22.  
  23. local function NewOpenBoat(inst, boat, riding)
  24.     if oldOpenBoat then
  25.         oldOpenBoat(inst, boat, riding)
  26.         if inst and inst.controls and inst.controls.inv and inst.controls.inv.boatwidget and inst.controls.inv.boatwidget.SetPosition then
  27.             inst.controls.inv.boatwidget:SetPosition(300,180,0)
  28.         end
  29.     end
  30. end
  31.  
  32. inventorybarpostconstruct=nil
  33.  
  34.  
  35. local function BackpackGet(inst, data)
  36.     local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner
  37.    
  38.     if owner then
  39.         local inv = owner.HUD.controls.inv
  40.         if inv then
  41.             inv:OnItemGet(data.item, inv.backpackinv[data.slot], data.src_pos)
  42.         end
  43.     end    
  44. end
  45.  
  46. local function BackpackLose(inst, data)
  47.     local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner
  48.     if owner then
  49.         local inv = owner.HUD.controls.inv
  50.         if inv then
  51.             inv:OnItemLose(inv.backpackinv[data.slot])
  52.         end
  53.     end    
  54. end
  55.  
  56. local function commonpostconstruct(self,owner)
  57. --just kill it off completely again
  58.         self.equipslotinfo={}
  59.  
  60.         self:AddEquipSlot(EQUIPSLOTS.HANDS, "images/equipslots.xml", "equip_slot_hand.tex")
  61.         self:AddEquipSlot(EQUIPSLOTS.BODY, "images/equipslots.xml", "equip_slot_body.tex")  
  62.         self:AddEquipSlot(EQUIPSLOTS.HEAD, "images/equipslots.xml", "equip_slot_head.tex")  
  63.         self:AddEquipSlot(EQUIPSLOTS.NECK, "images/equipslots.xml", "equip_slot_neck.tex")  
  64.         self:AddEquipSlot(EQUIPSLOTS.PACK, "images/equipslots.xml", "equip_slot_pack.tex")  
  65.         self:AddEquipSlot(EQUIPSLOTS.RING, "images/equipslots.xml", "equip_slot_ring.tex")  
  66.         self:AddEquipSlot(EQUIPSLOTS.BOOT, "images/equipslots.xml", "equip_slot_boot.tex")  
  67.         self:AddEquipSlot(EQUIPSLOTS.QUIVER, "images/equipslots.xml", "equip_slot_quiver.tex")  
  68.  
  69. end
  70.  
  71. if(not FA_ModCompat.rpghudmod)then
  72.  
  73. inventorybarpostconstruct=function(self, owner)
  74.  
  75. --  self.bg = self.root:AddChild(Image(HUD_ATLAS, "inventory_bg.tex"))
  76.         self.bg:SetScale(0.97,1,1)
  77. --      self.bgcover = self.root:AddChild(Image(HUD_ATLAS, "inventory_bg_cover.tex"))
  78.         self.bgcover:SetScale(0.97,1,1)
  79.  
  80.         self.bgequip = self.root:AddChild(Image("images/fa_equipbar_bg.xml", "fa_equipbar_bg.tex"))
  81.         self.bgequip:SetScale(0.5,1,1)
  82.         self.bgequip:MoveToBack()
  83.  
  84.         commonpostconstruct(self,owner)
  85. --TODO this likely does not need to be rewritten
  86.  
  87. function self:Rebuild()
  88.    
  89.     if not oldOpenBoat then
  90.         if self.owner and self.owner.HUD and self.owner.HUD.OpenBoat then
  91.             oldOpenBoat = self.owner.HUD.OpenBoat
  92.             self.owner.HUD.OpenBoat = NewOpenBoat
  93.         end
  94.     end
  95.  
  96.     if self.cursor then
  97.         self.cursor:Kill()
  98.         self.cursor = nil
  99.     end
  100.    
  101.     if self.toprow then
  102.         self.toprow:Kill()
  103.     end
  104.  
  105.     if self.bottomrow then
  106.         self.bottomrow:Kill()
  107.     end
  108.  
  109.     self.toprow = self.root:AddChild(Widget("toprow"))
  110.     self.bottomrow = self.root:AddChild(Widget("toprow"))
  111.  
  112.     self.inv = {}
  113.     self.equip = {}
  114.     self.backpackinv = {}
  115.  
  116. --    local y = self.owner.components.inventory.overflow and (W/2+YSEP/2) or 0
  117.     local y = 0
  118.     local eslot_order = {}
  119.  
  120.     local num_slots = self.owner.components.inventory:GetNumSlots()
  121.     local num_equip = #self.equipslotinfo
  122.     local num_intersep = math.floor(num_slots / 5) + 1
  123. --    local total_w = (num_slots + num_equip)*(W) + (num_slots + num_equip - 2 - num_intersep) *(SEP) + INTERSEP*num_intersep
  124.     local total_w = (num_slots )*(W) + (num_slots - 2 - num_intersep) *(SEP) + INTERSEP*num_intersep
  125.     local total_e = num_equip*W + (num_equip - 1)*SEP
  126.  
  127.  
  128.     for k, v in ipairs(self.equipslotinfo) do
  129.         local slot = EquipSlot(v.slot, v.atlas, v.image, self.owner)
  130.         self.equip[v.slot] = self.toprow:AddChild(slot)
  131.         local x = -total_e/2 + W/2 + (k-1)*W + (k-1)*SEP   
  132.         slot:SetPosition(x,y+85,0)                         
  133.         table.insert(eslot_order, slot)                    
  134.        
  135.         local item = self.owner.components.inventory:GetEquippedItem(v.slot)
  136.         if item then
  137.             slot:SetTile(ItemTile(item, self.owner.components.inventory))
  138.         end
  139.  
  140.     end    
  141.  
  142.     for k = 1,num_slots do
  143.         local slot = InvSlot(k, HUD_ATLAS, "inv_slot.tex", self.owner, self.owner.components.inventory)
  144.         self.inv[k] = self.toprow:AddChild(slot)
  145.         local interseps = math.floor((k-1) / 5)
  146.         local x = -total_w/2 + W/2 + interseps*(INTERSEP - SEP) + (k-1)*W + (k-1)*SEP
  147.         slot:SetPosition(x,0,0)
  148.        
  149.         slot.top_align_tip = W*0.5 + YSEP
  150.  
  151.         local item = self.owner.components.inventory:GetItemInSlot(k)
  152.         if item then
  153.             slot:SetTile(ItemTile(item))
  154.         end
  155.        
  156.     end
  157.  
  158.  
  159.     local old_backpack = self.backpack
  160.     if self.backpack then
  161.         self.inst:RemoveEventCallback("itemget", BackpackGet, self.backpack)
  162.         self.inst:ListenForEvent("itemlose", BackpackLose, self.backpack)
  163.         self.backpack = nil
  164.     end
  165.  
  166.  
  167.     local new_backpack = self.owner.components.inventory.overflow
  168.     local do_integrated_backpack = TheInput:ControllerAttached() and new_backpack
  169.     if do_integrated_backpack then
  170.         local num = new_backpack.components.container.numslots
  171.  
  172.         local x = - (num * (W+SEP) / 2)
  173.         --local offset = #self.inv >= num and 1 or 0 --math.ceil((#self.inv - num)/2)
  174.         local offset = 1 + #self.inv - num
  175.  
  176.         for k = 1, num do
  177.             local slot = InvSlot(k, HUD_ATLAS, "inv_slot.tex", self.owner, new_backpack.components.container)
  178.             self.backpackinv[k] = self.bottomrow:AddChild(slot)
  179.  
  180.             slot.top_align_tip = W*1.5 + YSEP*2
  181.            
  182.             if offset > 0 then
  183.                 slot:SetPosition(self.inv[offset+k-1]:GetPosition().x,0,0)
  184.             else
  185.                 slot:SetPosition(x,0,0)
  186.                 x = x + W + SEP
  187.             end
  188.            
  189.             local item = new_backpack.components.container:GetItemInSlot(k)
  190.             if item then
  191.                 slot:SetTile(ItemTile(item))
  192.             end
  193.            
  194.         end
  195.        
  196.         self.backpack = self.owner.components.inventory.overflow
  197.         self.inst:ListenForEvent("itemget", BackpackGet, self.backpack)
  198.         self.inst:ListenForEvent("itemlose", BackpackLose, self.backpack)
  199.     end
  200.  
  201.  
  202.  
  203.     if old_backpack and not self.backpack then
  204.         self:SelectSlot(self.inv[1])
  205.         self.current_list = self.inv
  206.     end
  207.  
  208.     --self.bg:Flow(total_w+60, 256, true)
  209.     --what am i supposed to do here? controllers have diff positioning and ive no idea how they look like.
  210.  
  211.     if do_integrated_backpack then
  212.         self.bgequip:SetPosition(Vector3(0, 40, 0))
  213.         self.bg:SetPosition(Vector3(0,-24,0))
  214.         self.bgcover:SetPosition(Vector3(0, -135, 0))
  215.         self.toprow:SetPosition(Vector3(0,W/2 + YSEP/2,0))
  216.         self.bottomrow:SetPosition(Vector3(0,-W/2 - YSEP/2,0))
  217.         self.root:MoveTo(self.out_pos, self.in_pos, .5)
  218.     else
  219.         self.bgequip:SetPosition(Vector3(0, 30, 0))
  220.         self.bg:SetPosition(Vector3(0, -64, 0))
  221.         self.bgcover:SetPosition(Vector3(0, -100, 0))
  222.         self.toprow:SetPosition(Vector3(0,0,0))
  223.         self.bottomrow:SetPosition(0,0,0)
  224.        
  225.         if TheInput:ControllerAttached() then
  226.             self.root:MoveTo(self.in_pos, self.out_pos, .2)
  227.         else
  228.             self.root:SetPosition(self.out_pos)
  229.         end
  230.        
  231.        
  232.     end
  233.    
  234.     self.actionstring:MoveToFront()
  235.    
  236.     self:SelectSlot(self.inv[1])
  237.     self.current_list = self.inv
  238.     self:UpdateCursor()
  239.    
  240.     if self.cursor then
  241.         self.cursor:MoveToFront()
  242.     end
  243.  
  244.  
  245.     self.rebuild_pending = false
  246. end
  247.  
  248.     self.rebuild_pending=true
  249.    
  250. end
  251.  
  252. else
  253.  
  254.  
  255. W = 64          --MOD
  256. SEP = 7         --MOD
  257. YSEP = 8
  258. INTERSEP = 11       --MOD
  259.  
  260.     inventorybarpostconstruct=function(self, owner)
  261.  
  262.  
  263.         self.bgequip = self.root:AddChild(Image("images/fa_equipbar_bg.xml", "fa_equipbar_bg.tex"))
  264.         self.bgequip:SetScale(0.48,1,1)
  265.         commonpostconstruct(self,owner)
  266.  
  267.    
  268.         local old_build=self.Rebuild
  269.         function self:Rebuild()
  270.             old_build(self)
  271. -- now the point this gets called, is the point when we already have all postinits and stuff executed, so i *should* be able to get the version from the
  272. -- player inventory size. If 'something else' pops in between rpg hud and me and changes it... well that something is likely clashing with my code regardless
  273. -- WTB SWITCH/CASE...
  274.     local y = self.owner.components.inventory.overflow and (W/2+YSEP/2) or W/2+YSEP/2
  275.     local num_equip = #self.equipslotinfo
  276.     local num_slots = self.owner.components.inventory:GetNumSlots()
  277.     local total_e = num_equip*W + (num_equip - 1)*SEP
  278.  
  279.  
  280.     if(GetPlayer().components.inventory.maxslots==60)then
  281.    
  282.     self.bgequip:SetPosition(Vector3(0, 60, 0))
  283.     --being that i have overwritten all that crap up already, i should be able to just...
  284.     for k, v in ipairs(self.equipslotinfo) do
  285. --      local slot = EquipSlot(v.slot, v.atlas, v.image, self.owner)
  286. --      self.equip[v.slot] = self.toprow:AddChild(slot)
  287.         local slot=self.equip[v.slot]
  288.         local x = -total_e/2 + W/2 + (k-1)*W + (k-1)*SEP   
  289. --      local x = total_w/2 - W/2 - (5-k)*W - (5-k)*SEP --MOD
  290.         slot:SetPosition(x,y+131,0)                     --MOD
  291. --      table.insert(eslot_order, slot)
  292.     end
  293.  
  294.     --AFTER THIS POINT EVERYTHING IS FUCKED UP
  295.     for k = 1,55 do
  296.         local pos=self.inv[k]:GetPosition()
  297.         self.inv[k]:SetPosition(pos.x+175,pos.y,pos.z)
  298.     end
  299.  
  300.     local num_intersep = math.floor(.2*(num_slots - 30))                                                                                --MOD
  301.     local total_w = (num_slots + num_equip - 30)*(W) + (num_slots + num_equip - 30 - 1 - num_intersep)*(SEP) + (INTERSEP*num_intersep)  --MOD
  302.  
  303.     for k = 56,60 do
  304.         local slot = InvSlot(k, HUD_ATLAS, "inv_slot.tex", self.owner, self.owner.components.inventory)
  305.         self.inv[k] = self.toprow:AddChild(slot)
  306.         local interseps = math.floor((k-1-30) / 5)
  307.         local x = -total_w/2 + W/2 + interseps*(INTERSEP - SEP) + (k-1-30)*W + (k-1-30)*SEP
  308.         slot:SetPosition(x+280,y + 71,0)
  309.        
  310.         local item = self.owner.components.inventory:GetItemInSlot(k)
  311.         if item then
  312.             slot:SetTile(ItemTile(item, self.owner.components.inventory))
  313.         end
  314.        
  315.     end
  316.     elseif(GetPlayer().components.inventory.maxslots==55)then
  317.  
  318.         self.bgequip:SetPosition(Vector3(0, 70, 0))
  319.     --being that i have overwritten all that crap up already, i should be able to just...
  320.         for k, v in ipairs(self.equipslotinfo) do
  321. --      local slot = EquipSlot(v.slot, v.atlas, v.image, self.owner)
  322. --      self.equip[v.slot] = self.toprow:AddChild(slot)
  323.             local slot=self.equip[v.slot]
  324.             local x = -total_e/2 + W/2 + (k-1)*W + (k-1)*SEP   
  325. --      local x = total_w/2 - W/2 - (5-k)*W - (5-k)*SEP --MOD
  326.             slot:SetPosition(x,y+100,0)                     --MOD
  327. --      table.insert(eslot_order, slot)
  328.         end
  329.  
  330.             elseif(GetPlayer().components.inventory.maxslots==45 and string.find(FA_ModCompat.rpghudmod.modinfo.description,"Custom UI"))then
  331.  
  332.                 self.bgequip:SetPosition(Vector3(0, 90, 0))
  333.                 for k, v in ipairs(self.equipslotinfo) do
  334.                     local slot=self.equip[v.slot]
  335.                     local x = -total_e/2 + W/2 + (k-1)*W + (k-1)*SEP   
  336.                     slot:SetPosition(x,y+146,0)                    
  337.                 end
  338.  
  339.             elseif(GetPlayer().components.inventory.maxslots==25 and string.find(FA_ModCompat.rpghudmod.modinfo.description,"Custom UI"))then
  340.  
  341.                 self.bgequip:SetPosition(Vector3(0, 90, 0))
  342.                 for k, v in ipairs(self.equipslotinfo) do
  343.                     local slot=self.equip[v.slot]
  344.                     local x = -total_e/2 + W/2 + (k-1)*W + (k-1)*SEP   
  345.                     slot:SetPosition(x,y+151,0)                    
  346.                 end
  347.  
  348.             elseif(GetPlayer().components.inventory.maxslots==25)then
  349.  
  350.                 self.bgequip:SetPosition(Vector3(0, 00, 0))
  351.                 for k, v in ipairs(self.equipslotinfo) do
  352.                     local slot=self.equip[v.slot]
  353.                     local x = -total_e/2 + W/2 + (k-1)*W + (k-1)*SEP   
  354.                     slot:SetPosition(x,y+80,0)                 
  355.                 end
  356.             elseif(GetPlayer().components.inventory.maxslots==15)then
  357.  
  358.                 self.bgequip:Kill()
  359.             end
  360.         end
  361.     end
  362. end
Advertisement
Add Comment
Please, Sign In to add comment