/
dialogue.go
66 lines (53 loc) · 1.53 KB
/
dialogue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package akevitt
import (
"github.com/rivo/tview"
)
// Dialogue struct for creating dialogue-like events.
// The content is actually a UI element, so you implement merchants, dialogues, etc.
// You must call NewDialogue to get started.
type Dialogue struct {
title string
content tview.Primitive
options []*Dialogue
}
// Creates new instance of dialogue
func NewDialogue(title string) *Dialogue {
dial := &Dialogue{title: title}
dial.options = make([]*Dialogue, 0)
return dial
}
// Accepts UI element to be displayed on user.
func (dial *Dialogue) SetContent(content tview.Primitive) *Dialogue {
dial.content = content
return dial
}
// Add options to the dialogue
func (dial *Dialogue) AddOption(title string, content tview.Primitive) *Dialogue {
if dial.options == nil {
dial.options = make([]*Dialogue, 0)
}
res := NewDialogue(title).SetContent(content)
dial.options = append(dial.options, res)
return res
}
// Gets an array of options
func (dial *Dialogue) GetOptions() []*Dialogue {
return dial.options
}
// Gets the UI of dialogue
func (dial *Dialogue) GetContents() tview.Primitive {
return dial.content
}
// Gets title of an option
func (dial *Dialogue) GetTitle() string {
return dial.title
}
// Invokes engine.Dialogue of the specified index from options.
func (dial *Dialogue) Proceed(index int, session *ActiveSession, engine *Akevitt) error {
return engine.Dialogue(dial.options[index], session)
}
// Ends the dialogue with "Close" option
func (dial *Dialogue) End() *Dialogue {
dial.AddOption("Close", nil)
return dial
}