Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

player/dialogue: Basic implementation of NPC dialogues #937

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TwistedAsylumMC
Copy link
Member

Kind of a continuation from #666 however a lot of it is different.

Whilst this code works, we need a better method of implementing the dialogueProvider interface to allow entities such as players (often used for NPCs) to be a provider. We could just make it always implement the interface but I'm open to other ideas. There are also a few names I am not sure about, like the CanShowDialogue() method to implement this interface.

I have also decided to completely hide the idea of "opening" and "closing" buttons, they only exist in Minecraft as a way of detecting opening/closing of the menus which we can already achieve through calling SendDialogue() for opening and implementing dialogue.Closer for closing.

Example usage in combination with df-mc/npc where p is a *player.Player (modifying Player to implement dialogueProvider):

type TestDialogue struct {
	Button1 dialogue.Button
	Button2 dialogue.Button
	Button3 dialogue.Button
}

func (t TestDialogue) Submit(s dialogue.Submitter, pressed dialogue.Button) {
	fmt.Println("Pressed", pressed)
	s.CloseDialogue() // The client will not close the menu automatically
}

func (t TestDialogue) Close(s dialogue.Submitter) {
	fmt.Println("Closed")
}
settings := npc.Settings{
	Name:     "Test NPC",
	Position: p.Position(),
	Scale:    1,
	Skin:     p.Skin(),
}
n := npc.Create(settings, p.World(), nil)

d := dialogue.New(TestDialogue{
	Button1: dialogue.Button{Text: "Button 1"},
	Button2: dialogue.Button{Text: "Button 2"},
	Button3: dialogue.Button{Text: "Button 3"},
}, "Dialogue Title").
	WithBody("Welcome to my dialogue!")
p.SendDialogue(d, n)

@TwistedAsylumMC TwistedAsylumMC added the feature New feature or request label Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant