Took about a week off to be depressed and play dwarf fortress (also try desperately to keep Spookyfort up and running) Anyway, the rest did me some good because I did the following without any mistakes. NO MISTAKES!
YOU HEAR ME?
I separated the keybindings slightly - and have set up an inventory key (I, E, and right click) and an interact key (interact is left click, space, or enter). Now, whenever they're pressed, the game will send to these functions. But what are these functions, you ask -
Inventory does nothing - just passes as if the button wasn't pressed at all.
Interact will only trigger if you're within battlin' range of a cubeboy. It, in this image, only does what it used to do - go straight to combat. So let's change that.
We need a dialog screen to overlap the 3D scene. Luckily, any 2D object will just get plastered on top of the window. That means if we throw a 2D object up there, and freeze the controls, we have a simple dialog window we can use.
This scene is exceptionally simple - which is really all we need. The background is a colored rectangle that is black but at about 80% opaque - meaning it is only slightly transparent (the screenshots are mid-tweaks, as I started at much more transparent and slowly cranked it up.
And to freeze it, we actually just check a boolean every button press/mouse movement.
We get a simple version of it here:
Next, we set up a signal. Signals call upwards in the chain - to lay it out clearly, it looks something like this:
-main (always running)
- - gameshop (child of main)
- - - player (child of gameshop)
- - - Control (dialog scene, child of gameshop)
player has a signal called "talk" that signal is emitted when you're next to a cubeboy and press an interact key. It also passes the trainer information.
gameshop receives the signal "talk" and does this:
It checks which trainer it is and then looks at Control (the dialog scene) and fills in the text for the buttons and label. Nifty neat and easy!
This is very bad code, as everything is very explicit - Control is the generic name for a 2D UI node. So if I want to change it, I'll need to come back and change it in every one of those green texts! Gasp!
(I'm going to do this, don't worry. It bugs me too much to just leave it.)
The first button is an escape option - it'll drop the dialog screen and return you to normal.
The second button starts combat. This is the same code from the old E button press - and since the global handles all the trainers and stuff, that should work just fine.
But! If we just hide the screen, the game is still frozen! You can't move! Now you know what Major Chongus' victims feel like!
Easy peasy:
This is a new feature I didn't know. Since Control is a separate scene, it's a bit inconvenient to connect a signal back up to the gameshop or main (it is possible, just a few extra lines of code). Instead, instanced scenes (such as this one) will basically emit a signal whenever they're hidden, and since button1 hides the scene, we can use that to tell the gameshop to set the freeze to false within the player. It just works!
Hope that was all clear!
I'm uploading files now for a playable version...I unfortunately need to do it through my phone today, so...bare with me.