/
scene_character_creation.go
79 lines (67 loc) · 2.13 KB
/
scene_character_creation.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
67
68
69
70
71
72
73
74
75
76
77
78
79
package gamerogueish
import (
"log"
"github.com/BigJk/ramen/components"
"github.com/BigJk/ramen/concolor"
"github.com/BigJk/ramen/console"
"github.com/BigJk/ramen/t"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/inpututil"
)
type SceneCharacterCreation struct {
*Game
*console.ComponentBase
tb *components.TextBox
}
func NewSceneCharacterCreation(rootView *console.Console, world *Game) *SceneCharacterCreation {
return &SceneCharacterCreation{
Game: world,
ComponentBase: console.NewComponentBase(10, 10, 10, 10),
}
}
func (s *SceneCharacterCreation) NewTextbox(con *console.Console) {
textBox := components.NewTextbox(7, 3, 20, 1)
textBox.SetBackground(concolor.RGB(50, 50, 50).P(), concolor.RGB(70, 70, 70).P(), concolor.RGB(30, 30, 30).P())
textBox.SetForeground(concolor.White.P(), concolor.RGB(90, 90, 90).P())
textBox.SetText(s.player.Name)
textBox.SetEnterCallback(func(text string) {
s.player.Name = text
log.Println("Name set to", text)
textBox.Close()
s.tb = nil
con.RemoveComponent(textBox)
})
s.tb = textBox
log.Println("New textbox created")
con.AddComponent(textBox)
}
func (s *SceneCharacterCreation) Update(con *console.Console, timeElapsed float64) bool {
// Logic for updating the scene.
if inpututil.IsKeyJustPressed(ebiten.KeyTab) {
s.NewTextbox(con)
s.tb.SetFocus(true)
}
if s.tb != nil && inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
s.setViewMode(ViewModeMap)
}
return true
}
func (s *SceneCharacterCreation) Draw(con *console.Console, timeElapsed float64) {
if s.tb != nil {
return
}
con.ClearAll()
con.TransformAll(t.Background(concolor.RGB(55, 55, 55)), t.Char(0))
// Logic for drawing the scene.
con.Print(1, 1, "Character Creation", t.Foreground(concolor.White))
con.Print(1, 3, "Name: "+s.player.Name, t.Foreground(concolor.White))
con.Print(1, 4, "Press TAB to change name", t.Foreground(concolor.White))
con.Print(1, 5, "Press ENTER to start game", t.Foreground(concolor.White))
}
func (g *SceneCharacterCreation) Close() error {
if g.tb != nil {
g.tb.Close()
}
return nil
}
func (s *SceneCharacterCreation) FocusOnClick() bool { return false }