Slimwaffle Posted July 5, 2018 Share Posted July 5, 2018 I am trying to design an inventory system using the gui widgets. The mouse locks to crosshair position when it shouldn't. And I was wondering how I fix it. I want to be able to freely move the mouse around and click on buttons. The same way I can in the main menu when I press escape. <My Code> function Script:Start() local Inventory={} local scale = 1 --Inventory GUI Inventorygui = GUI:Create(context) Inventorygui:Hide() Inventorygui:SetScale(scale) local widget Inventorygui:GetBase():SetScript("Scripts/GUI/Panel.lua") Inventorygui:GetBase():SetObject("backgroundcolor",Vec4(0,0,0,1)) local image = Inventorygui:LoadImage("Bag/bag.tex") local imagePanel = Widget:Panel(0,0,1920,1080, Inventorygui:GetBase()) imagePanel:SetImage(image) imagePanel:Redraw() Inventory.gui=gui Inventory.context = context --Create a link button Inventory.newbutton = Widget:Button("Resume Game",100,Inventorygui:GetBase():GetSize().y/2-60,300,20,Inventorygui:GetBase()) Inventory.newbutton:SetString("style","Link") Inventory.newbutton:SetAlignment(1,0,0,0) Inventory.options = Widget:Button("Inventory",100,Inventorygui:GetBase():GetSize().y/2-10,300,20,Inventorygui:GetBase()) Inventory.options:SetString("style","Link") Inventory.options:SetAlignment(1,0,0,0) optionspanel = Widget:Panel(Inventorygui:GetBase():GetClientSize().x/2-250,Inventorygui:GetBase():GetClientSize().y/2-300,500,600,Inventorygui:GetBase()) optionspanel:SetAlignment(0,0,0,0) Inventory.optionspanel=optionspanel indent=8 --Create a panel widget = Widget:Tabber(indent,indent,optionspanel:GetClientSize().x-indent*2,optionspanel:GetClientSize().y-indent*2,optionspanel) widget:AddItem("Inventory",true) optionspanel:SetObject("backgroundcolor",Vec4(0.15,0.15,0.15,1)) Inventory.tabber = widget local indent = 12 panel = Widget:Panel(indent,indent,widget:GetClientSize().x-indent*2,widget:GetClientSize().y-indent*2-30,widget) panel:SetBool("border",true) Inventory.panel={} Inventory.panel.general=panel Inventory.applyoptions = Widget:Button("Use",widget:GetClientSize().x-72*2-4-indent,widget:GetClientSize().y-28-5,72,28,widget) local y=20 local sep=40 optionspanel:Hide() end function Script:UpdateWorld() if window:KeyHit(Key.I) then Inventorygui:Show() Time:Pause() window:ShowMouse() end end Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted July 5, 2018 Share Posted July 5, 2018 I'm not sure on the exact repercussions but Time:Pause() doesn't look right to me. Why is this here? Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted July 5, 2018 Author Share Posted July 5, 2018 Its there so the game pauses while you are going through your inventory screen Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted July 5, 2018 Author Share Posted July 5, 2018 But the issue I'm pretty sure is the mouse is still being used by the first person player controller Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted July 5, 2018 Share Posted July 5, 2018 As you figured out already. Your controller update code needs to check whether the player is not paused or in the inventory. Otherwise you will reset the mouse position to the center of the screen. A simple boolean would suffice. Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted July 5, 2018 Author Share Posted July 5, 2018 So I would add something to say if Time is paused mouse does nothing? Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted July 5, 2018 Share Posted July 5, 2018 The easiest approach would be to have some sort of boolean (for instance InventoryOpen or playerMovementLocked) that stores whether the inventory is open. If it is open, the player controller should not update (or at least not the mouse updating). Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted July 5, 2018 Author Share Posted July 5, 2018 Yeah I tried that by using a variable called pause assigning it a value of 0. Then putting everything inside the update-world function on the fps controller in an if statement (so if paused = 0 it would update). And making the inventory on open pass a value of 1 to stop update. But it did nothing. So I went the easy way and just added in an inventory section into the already existing menu script. Because for some reason the menu script already does what I want. Quote Link to comment Share on other sites More sharing options...
GorzenDev Posted July 5, 2018 Share Posted July 5, 2018 the problem lies with window:HideMouse(), it is being called a couple times inside Menu.lua remove or comment out those lines and you wont have no problems anymore. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.