Coder Social home page Coder Social logo

3d2d button isn't pressing. about 3d2d-imgui HOT 13 CLOSED

wyozi avatar wyozi commented on June 12, 2024
3d2d button isn't pressing.

from 3d2d-imgui.

Comments (13)

wyozi avatar wyozi commented on June 12, 2024

Your code seems a bit weird. For instance you should not need cam.Start3D2D or End3D2D at all when using TDUI. Secondly it seems like your whole code is inside ENT:Paint or something similar. If that is the case it's not going to work because you're creating the hook inside a paint function.

Try looking at https://github.com/wyozi/3d2d-imgui/blob/master/examples/rendertomat.lua for how I use TDUI with entities (obviously replace the RenderToTexture part with Render call and don't call _UpdatePAS but pass the position and angle to the Render call)

from 3d2d-imgui.

Zer0nix avatar Zer0nix commented on June 12, 2024

I removed the 3d2d part, the button is being draw in ENT:Draw but it still doesnt do anything if I hover over it or press E or my physgun. What i noticed tho is if I change the scale of the button to something like 2, it works perfectly, but if i change it back to 0.15 ( cause that's the size of the button I want) it doesn't work once again.

from 3d2d-imgui.

wyozi avatar wyozi commented on June 12, 2024

If you scale it up to 2 do the button boundaries obey to your mouse cursor (i.e. does the button change to hover color if you move your mouse to just inside the border of the button on all sides or does it only change to hover color around the middle or some other part of the button)?

from 3d2d-imgui.

Zer0nix avatar Zer0nix commented on June 12, 2024

it does obey my mouse cursor and yes the hover colors and button pressing work just fine but only if the scale is set to 2

from 3d2d-imgui.

wyozi avatar wyozi commented on June 12, 2024

Hmm, I guess it's possible that the UI is partially covered by the model's hitbox but still visible. Can you try moving the UI a few units further away from the model?

from 3d2d-imgui.

Zer0nix avatar Zer0nix commented on June 12, 2024

Yeah i did that by a lot and its doing the same thing, now it only works when I'm in the middle and some parts don't register my mouse ( with scale 2)

With scale 0.15 and far away from the model, it doesn't change its color on hover at all but on some parts of the border when I click it, it only says hi in chat, no color change or anything ( with scale 0.15)

from 3d2d-imgui.

wyozi avatar wyozi commented on June 12, 2024

Try running r_WaterDrawReflection 0 in client console and see if it works better.

from 3d2d-imgui.

Zer0nix avatar Zer0nix commented on June 12, 2024

Nope, didn't seem to do anything :c

from 3d2d-imgui.

wyozi avatar wyozi commented on June 12, 2024

Can you give me the whole code for the entity (you can strip all functionality and leave just the model initialization and 3d2d ui) and I'll see how it works for me.

from 3d2d-imgui.

Zer0nix avatar Zer0nix commented on June 12, 2024

include("shared.lua")
local tdui = include("tdui.lua")

surface.CreateFont( "NewFontsz", {
	font = "Bebas", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
	extended = false,
	size = 45,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )


surface.CreateFont( "Ammo", {
	font = "Bebas", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
	extended = false,
	size = 35,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )

surface.CreateFont( "AmmoS", {
	font = "Bebas", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
	extended = false,
	size = 15,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )

surface.CreateFont( "AmmoM", {
	font = "Bebas", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
	extended = false,
	size = 30,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )



--0, -45, -230, "Ammo", "NewFontsz", Color(34,34,34,200), Color(230,230,230,255) )

function ENT:Draw()

     self:DrawModel()
     local pos = self:GetPos()
	 local ang = self:GetAngles()
	 local offset = ang:Up() + ang:Forward() * 21.6 + ang:Right() * 1.9 ;

    ang:RotateAroundAxis(self:GetAngles():Up(),90)
    ang:RotateAroundAxis(self:GetAngles():Right(),-90)
    ang:RotateAroundAxis(self:GetAngles():Forward(),360)



    cam.Start3D2D(pos + offset , ang, 0.17 )

    draw.WordBox( 0, -132.5, -270, "Vending Machine", "NewFontsz", Color(0,0,0,220), Color(255,255,255,255) )
    
    
     
    cam.End3D2D()

   local poss = self:GetPos()
    local angs = self:GetAngles()
    local offset2 = angs:Up() + angs:Forward() * 21.6 + angs:Right() * 1.9;

    angs:RotateAroundAxis(self:GetAngles():Up(),90)
    angs:RotateAroundAxis(self:GetAngles():Right(),-90)
    angs:RotateAroundAxis(self:GetAngles():Forward(),360)
     
    cam.Start3D2D(poss + offset2 ,angs,0.15)
    
    draw.RoundedBox(0,-148,-250,265,35,Color(0,0,0,220))
    draw.SimpleText("Ammo","Ammo",-10,-251,Color(255,255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_TOP)

    draw.RoundedBox(0,-148,-210,265,50,Color(0,0,0,220))
    draw.SimpleText("Pistol","Ammo",-75,-216,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
    draw.SimpleText("30 pistol ammunition","AmmoS",-43,-175,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
   -- draw.RoundedBox(0,67,-210,50,50,Color(54,54,54,255))
   -- draw.SimpleText("$100","AmmoM",73,-200,Color(255,255,255,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_TOP)

    draw.RoundedBox(0,-148,-155,265,50,Color(0,0,0,220))
    draw.SimpleText("Assault","Ammo",-50,-160,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
    draw.SimpleText("30 assault ammunition","AmmoS",-34,-120,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
    --draw.RoundedBox(0,67,-155,50,50,Color(54,54,54,255))
    --draw.SimpleText("$250","AmmoM",71,-148,Color(255,255,255,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_TOP)

    draw.RoundedBox(0,-148,-100,265,50,Color(0,0,0,220))
    draw.SimpleText("Shotgun","Ammo",-50,-100,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
    draw.SimpleText("30 shotgun ammunition","AmmoS",-34,-65,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
   --draw.RoundedBox(0,67,-100,50,50,Color(54,54,54,255))
    --draw.SimpleText("$350","AmmoM",71,-90,Color(255,255,255,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_TOP)

    draw.RoundedBox(0,-148,-45,265,50,Color(0,0,0,220))
    draw.SimpleText("Sniper","Ammo",-71,-45,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
    draw.SimpleText("30 sniper ammunition","AmmoS",-44,-10,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
    --draw.RoundedBox(0,67,-45,50,50,Color(54,54,54,255))
    --draw.SimpleText("$500","AmmoM",71,-40,Color(255,255,255,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_TOP)

    draw.RoundedBox(0,-148,10,265,50,Color(0,0,0,220))
    draw.SimpleText("SMG","Ammo",-98,5,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
    draw.SimpleText("60 smg ammunition","AmmoS",-56,45,Color(255,255,255,255),TEXT_ALIGN_RIGHT,TEXT_ALIGN_TOP)
    --draw.RoundedBox(0,67,10,50,50,Color(54,54,54,255))
    --draw.SimpleText("$500","AmmoM",71,15,Color(255,255,255,255),TEXT_ALIGN_LEFT,TEXT_ALIGN_TOP)

   


    cam.End3D2D()     


    local posss = self:GetPos()
    local angss = self:GetAngles()
    local offset3 = angss:Up() + angss:Forward() * 22 + angss:Right() * 1.9;

    angss:RotateAroundAxis(self:GetAngles():Up(),180)
    angss:RotateAroundAxis(self:GetAngles():Right(),360)
    angss:RotateAroundAxis(self:GetAngles():Forward(),360)
    


     local p
hook.Add("PostDrawTranslucentRenderables", "Paint3D2DUI", function(bDrawingSkybox, bDrawingDepth)
    -- This is required so that TDUI isn't drawn twice (which would break input)
   if bDrawingDepth then return end

    -- Create a 3D2D-IMGUI instance and cache it
    -- Note: if drawing TDUI inside a ENT:Draw(), you should cache the
    --       panel to the entity instance (self) instead of a local variable.
    --       That way there will be one panel per entity.
    p = p or tdui.Create()
    -- Draw a button (text, font, x, y, w, h, [color])
    -- Return value is boolean indicating whether left mouse or +use was pressed during this frame
   if p:Button("$500", "AmmoM", 60,9.5, 50, 50) then
        RunConsoleCommand("say", "hi!")
    end
p:Render(posss+offset3 ,angss, 0.15)
end)    

    

end

from 3d2d-imgui.

Zer0nix avatar Zer0nix commented on June 12, 2024

that was the cl_init, this is what i have for the init

AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
local tdui = include("tdui.lua")
include("shared.lua")

function ENT:Initialize()

      self:SetModel("models/props_interiors/VendingMachineSoda01a.mdl")
      self:PhysicsInit(SOLID_VPHYSICS)
      self:SetMoveType(MOVETYPE_VPHYSICS)
      self:SetSolid(SOLID_VPHYSICS)

      local phys = self:GetPhysicsObject()

      if phys:IsValid() then

      	phys:Wake()

      end

end

and the shared:

ENT.Type = "Anim"
ENT.Base = "base_gmodentity"

ENT.PrintName = "Vending Machine"

ENT.Spawnable = true
ENT.AdminSpawnable = true

from 3d2d-imgui.

wyozi avatar wyozi commented on June 12, 2024

Your Draw function has a few issues:

  • Instead of storing the 'p' panel in a local variable (which is then shared with all entities) you should instead store it inside the entity so that each entity has its own TDUI panel.
  • Don't create a hook inside Draw, instead draw the TDUI directly.

Here's a fixed Draw function (I removed most of the other, irrelevant here, things which you can readd)

function ENT:Draw()

	self:DrawModel()
	
	local pos = self:GetPos()
	local ang = self:GetAngles()
	local offset = ang:Up() + ang:Forward() * 21.6 + ang:Right() * 1.9 ;
	
	ang:RotateAroundAxis(self:GetAngles():Up(),90)
	ang:RotateAroundAxis(self:GetAngles():Right(),-90)
	ang:RotateAroundAxis(self:GetAngles():Forward(),360)
	
	
	local posss = self:GetPos()
	local angss = self:GetAngles()
	local offset3 = angss:Up() + angss:Forward() * 22 + angss:Right() * 1.9;
	
	angss:RotateAroundAxis(self:GetAngles():Up(),180)
	angss:RotateAroundAxis(self:GetAngles():Right(),360)
	angss:RotateAroundAxis(self:GetAngles():Forward(),360)
	
	self.p = self.p or tdui.Create()
	
	local p = self.p
	-- Draw a button (text, font, x, y, w, h, [color])
	-- Return value is boolean indicating whether left mouse or +use was pressed during this frame
	if p:Button("$500", "AmmoM", 60,9.5, 50, 50) then
		RunConsoleCommand("say", "hi!")
	end
	p:Cursor()
	p:Render(posss + offset3, angss, 0.15)
end

from 3d2d-imgui.

Zer0nix avatar Zer0nix commented on June 12, 2024

Thank you so much!

from 3d2d-imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.