Documentation
¶
Index ¶
- type Button
- type Closer
- type Dialogue
- func (m Dialogue) Body() string
- func (m Dialogue) Buttons() []Button
- func (m Dialogue) Close(submitter Submitter, tx *world.Tx)
- func (m Dialogue) Display() DisplaySettings
- func (m Dialogue) MarshalJSON() ([]byte, error)
- func (m Dialogue) Submit(index uint, submitter Submitter, tx *world.Tx) error
- func (m Dialogue) Title() string
- func (m Dialogue) WithBody(body ...any) Dialogue
- func (m Dialogue) WithButtons(buttons ...Button) Dialogue
- func (m Dialogue) WithDisplay(display DisplaySettings) Dialogue
- type DisplaySettings
- type Submittable
- type Submitter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Button ¶
type Button struct { // Text holds the text displayed on the button. It may use Minecraft // formatting codes. Text string }
Button represents a button added to a dialogue menu and consists of just text.
type Closer ¶
type Closer interface { // Close is called when the Submitter closes a dialogue. Close(submitter Submitter, tx *world.Tx) }
Closer represents a dialogue which has special logic when being closed by a Submitter.
type Dialogue ¶
type Dialogue struct {
// contains filtered or unexported fields
}
Dialogue represents a dialogue menu. This menu can consist of a title, a body and up to 6 different buttons. The menu also shows a 3D render of the entity that is sending the dialogue.
func New ¶
func New(submittable Submittable, title ...any) Dialogue
New creates a new Dialogue menu using the Submittable passed to handle the dialogue interactions. The title passed is formatted following the rules of fmt.Sprintln.
func (Dialogue) Body ¶
Body returns the formatted text in the body passed to the menu using WithBody().
func (Dialogue) Buttons ¶
Buttons returns a slice of buttons of the Submittable. It parses them from the fields using reflection and returns them.
func (Dialogue) Close ¶
Close closes the dialogue, calling the Close method on the Submittable if it implements the Closer interface.
func (Dialogue) Display ¶
func (m Dialogue) Display() DisplaySettings
Display returns the DisplaySettings of the Dialogue as specified using WithDisplay().
func (Dialogue) Submit ¶
Submit submits an index of the pressed button to the Submittable. If the index is invalid, an error is returned.
func (Dialogue) Title ¶
Title returns the formatted title passed to the dialogue upon construction using New().
func (Dialogue) WithBody ¶
WithBody creates a copy of the Dialogue and changes its body to the body passed, after which the new Dialogue is returned. The text is formatted following the rules of fmt.Sprintln.
func (Dialogue) WithButtons ¶
WithButtons creates a copy of the Dialogue and appends the buttons passed to the existing buttons, after which the new Dialogue is returned.
func (Dialogue) WithDisplay ¶
func (m Dialogue) WithDisplay(display DisplaySettings) Dialogue
WithDisplay returns a new Dialogue with the DisplaySettings passed.
type DisplaySettings ¶
type DisplaySettings struct { // EntityScale specifies the scale of the entity displayed in the dialogue. EntityScale mgl64.Vec3 // EntityOffset specifies the offset of the entity shown in the dialogue. EntityOffset mgl64.Vec3 // EntityRotation is the rotation of the entity shown in the dialogue. This // rotation functions a bit differently to the normal entity rotation in // Minecraft: The values are still degrees, but pitch (rot[1]) values are // whole-body pitch instead of head-specific, and rot[2] is whole-body roll. EntityRotation mgl64.Vec3 }
DisplaySettings holds optional fields that change the way the dialogue, particularly the entity shown in it, is displayed.
func (DisplaySettings) MarshalJSON ¶
func (d DisplaySettings) MarshalJSON() ([]byte, error)
MarshalJSON encodes the DisplaySettings to JSON.
type Submittable ¶
type Submittable interface { // Submit is called when the Submitter submits the dialogue sent to it. The // method is called with the button that was pressed. It may be compared // with buttons in the Submittable struct to check which button was pressed. // Additionally, the world.Tx of the Submitter is passed. Submit(submitter Submitter, pressed Button, tx *world.Tx) }
Submittable is a structure which may be submitted by sending it as a dialogue using dialogue.New(). The struct will have its Submit method called with the button pressed. A struct that implements the Submittable interface must only have exported fields with the type dialogue.Button.