0 votes

Hello...

Spent 3 days trying to get this right, hoping someone can help.

I have a 'Being' class. It is the NPC's.
I have a 'BeingHub' which is the canvas layer that is the hud and various menus.
I have a 'mainPlay' class - it is all the nodes together to form the game.

I am trying to implement: When you click on NPC (Being), a little window (BeingHud) pops up. And then when you click on a button on BeingHud, the little window hides. I have the hide working with no issue via a signal between BeingHud and mainPlay.

What I cannot get working ... is when you click on a Being, I need the little window to open. I am for sure - able to get the being selected. I've done this code in the Being script.

func inputevent(viewport, event, shapeidx):
if event is InputEventMouseButton:
if event.button
index == BUTTONLEFT:
emit
signal("beingwasclicked")
print("clicked on " + firstname)

Ive realized, the mainPlay node is not picking up the signal.

Is there a better way to implement such a simple thing?

asked Jan 19 in Engine by mattkw80 (83 points)

1 Answer

0 votes

I've got this working, but it's fairly sketchy I think.

I created a variable (singleton) in autoload called npcselected

When an npc (being) is selected it's true, other wise it's false.
When it's true - the process(delta) of BeingHud .show() otherwise
it will .hide().

Pretty sketchy. I can't imagine this is proper.

answered Jan 20 by mattkw80 (83 points)

Somebody sent me a really great reply to this.... I received it in email , but it's not showing here...

mattkw80,

Your question on Godot Engine - Q&A has been answered by end
ragor:

You have omitted in your example how you determine which cha
racter is clicked. You have to ray-cast from the position of the click into
the world and see which objects are intersected by the ray. Then, you may
dispatch the click to the object closest to the ray origin (or have some ot
her logic to determine which object has to accept the click, if multiple ob
jects are intersected). Ray-casting from screen is described here: https://
docs.godotengine.org/en/3.1/tutorials/physics/ray-casting.html#d-ray-castin
g-from-screen . The way to organize this in code is, for example, to have a
WorldInputManager that implements unhandledinput() and stores mouse clic
k positions, which are then processed in physicsprocess (which is where r
ay casting should happen). unhandledinput must be used to ensure that you
are not handling clicks that were already processed by UI elements. When W
orldInputManager determines that a ray intersects a clickable object, it di
spatches the event (calls a method) on the object in question. The object m
ay then display a HUD (BeingHud) near its location. To ensure there is only
one HUD shown at a time, showing a HUD would also have to be centralized i
n some kind of UIController.

Your question was:

Simple dial
og box based on clicking an NPC (like in Rimworld game)

If you lik
e this answer, you may select it as the best:

http://godotengine.org/q
a/59165/simple-dialog-box-based-on-clicking-an-npc-like-rimworld-game?show
=59193#a59193

Thank you,

Godot Engine - Q&A

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.