collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 59 forks source link

Conversation Tree #111

Open racingcow opened 10 years ago

racingcow commented 10 years ago

Hi @collinhover,

I have need of a conversation/dialogue tree in my top-down RPG game. An example might be if my PC was playing the part of the bridgekeeper from Monty Python and the Holy Grail...

conversation state transition 2

While I could probably achieve this by careful manipulation of the EntityConversation.steps array on the fly, it would be nice if there was a way for the conversation entity to handle a dialogue tree structure 'out of the box'.

If you don't already have plans for it, and don't mind me giving it a shot, I could take a look at extending EntityConversation to handle something like this. My thoughts on it so far are below. If you have some time, maybe you could take a look and give me some feedback/thoughts? Just let me know if there is a way that better fits with what you have done so far.

If the above makes sense, this might be an example of how to set it up in Weltmeister...

step.1.name = 'talker'
step.1.text = 'I seek to cross the bridge.'
step.1.next = 11
step.11.name = 'player'
step.11.text = 'Stop! Who would cross the Bridge of Death must answer me these questions three, ere the other side he see.'
step.11.next = 7
step.12.name = 'talker'
step.12.text = 'Ask me the questions, bridgekeeper. I am not afraid.'
step.12.next = [2,3,4,5]
step.2.name = 'player'
step.2.text = 'What... is your name?'
step.2.next = 7
step.3.name = 'player'
step.3.text = 'What... is your quest?'
step.3.next = 8
step.4.name = 'player'
step.4.text = 'What... is your favourite colour?'
step.4.next = 9
step.5.name = 'player'
step.5.text = 'Go on. Off you go.'
step.5.usedSteps = [2,3,4]
step.5.next = 6
step.6.name = 'talker'
step.6.text = 'Oh, thank you. Thank you very much.' 
step.7.name = 'talker'
step.7.text = 'My name is Sir Lancelot of Camelot.'
step.7.next = [3,4,10,5]
step.8.name = 'talker'
step.8.text = 'To seek the Holy Grail.'
step.8.next = [2,4,10,5]
step.9.name = 'talker'
step.9.text = 'Blue.'
step.9.next = [2,3,10,5]
step.10.name = 'player'
step.10.text = 'I want to ask you something else.'
step.10.next = 12
collinhover commented 10 years ago

Neat! I don't have plans for this at the moment, and I've always found it works best to develop features within the game you need them for, so feel free to give it a shot.

It might be useful to add a few more things to each conversation step, such as target which is just like trigger's target property so that each step can activate triggers, and a per step messageContainerEntity so that not all steps would need to be text bubbles with choices. I'd also rename usedSteps to requiredSteps for clarity.

Keep us updated =)

racingcow commented 10 years ago

Thanks, @collinhover. I'll do some work on it in the evenings this week and let you know when I have something to show.

racingcow commented 10 years ago

It took me a bit longer than I thought it would, but I have an update of sorts. Take a look at this video of the conversation described above inserted into the first level of the supercollider demo.

image

If this looks good, I'll try and get it into its own level in supercollider, and get a PR going soon.

Let me know what you think.

collinhover commented 10 years ago

Cool demo :-) looks good to me. Did you check for bugs such as layout errors when the window is resized in the middle of a conversation?

racingcow commented 10 years ago

No, I haven't tested that yet. Now that you mention it, I suspect there will be some more work to do around that. I'll take a look at that as soon as I can.

collinhover commented 10 years ago

I did make a few changes to the dev just now that fixed some resize bugs, so you may want to grab the latest when you get a chance.

racingcow commented 10 years ago

Thanks, @collinhover. I synced my fork up to the dev branch and re-ran my grunt script to setup supercollider to run this evening. My new conversation code definitely still has issues when resizing. I was away on business last week, but should be able to get some time this week to look into this issue. Hopefully it is something simple, and I'll have a PR soon.

racingcow commented 10 years ago

Okay, so after looking at this again it either isn't simple or I have missed something.

After updating Conversation and creating UITextBubbleChoice, which derives from UITextBubble, I still have a resize issue.

The issue seems to be that whenever a choice (just a UIText) inside of the UITextBubbleChoice gets resized such that it takes up a different number of lines (size.y/getDrawSizeY() change), the choices aren't moved down to the new locations correctly.

If you take a look at this video, it illustrates the issue. In this particular case, the UITextBubbleChoice narrows, which causes each of the choices to wrap to two lines instead of one. The height of the UITextBubbleChoice is correct, but for whatever reason, the choices aren't moved down to the correct locations, and instead overlap each other as if they are being left in the same positions that would be correct if they were each still a single line.

What seems strange is that when I look at the console.log(); messages that I have put in there, it appears that they are being moved to the correct locations when the resize happens (at least as far as I can tell).

If you get some time, could you take a look at my code in my fork and see if you can see anything I am doing wrong? Perhaps I have a scaling issue going on. If you need/want to setup SUPERCOLLIDER! to reproduce the issue, I have temporarily updated examples\supercollider\lib\game\levels\title.js to start the game with the conversation from the example in the video.

Any help you could give to nudge me in the right direction on this would be much appreciated.

collinhover commented 10 years ago

Your issue may be related to #112. Let me see if I can figure out a good solution for that first and maybe it'll fix this as well.