/
sheet.go
157 lines (136 loc) · 4.53 KB
/
sheet.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package console
import (
"fmt"
"github.com/MichaelDiBernardo/srl/lib/game"
"github.com/nsf/termbox-go"
)
func newSheetScreen(display display) *screen {
return &screen{
display: display,
panels: []panel{
newSkillEditPanel(display),
newSheetPanel(display),
},
}
}
type sheetPanel struct {
display display
}
func newSheetPanel(display display) *sheetPanel {
return &sheetPanel{display: display}
}
func (s *sheetPanel) HandleInput(tboxev termbox.Event) (game.Command, error) {
if tboxev.Type == termbox.EventKey && tboxev.Key == termbox.KeyEsc {
return game.ModeCommand{Mode: game.ModeHud}, nil
}
return nocommand()
}
func (s *sheetPanel) HandleEvent(e game.Event) {
}
func (s *sheetPanel) Render(g *game.Game) {
p := g.Player
sheet := g.Player.Sheet
s.display.Write(1, 2, fmt.Sprintf("NAME %v", p.Spec.Name), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(1, 3, fmt.Sprintf("RACE %v", p.Spec.Species.Describe()), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(22, 2, fmt.Sprintf("STR %d", sheet.Stat(game.Str)), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(22, 3, fmt.Sprintf("AGI %d", sheet.Stat(game.Agi)), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(22, 4, fmt.Sprintf("VIT %d", sheet.Stat(game.Vit)), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(22, 5, fmt.Sprintf("MND %d", sheet.Stat(game.Mnd)), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(1, 7, fmt.Sprintf("TURN %13d", g.Progress.Turns), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(1, 8, fmt.Sprintf("XP LEFT %10d", p.Learner.XP()), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(1, 9, fmt.Sprintf("XP TOTAL %9d", p.Learner.TotalXP()), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(1, 10, fmt.Sprintf("FLOOR %11dF", g.Progress.Floor), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(1, 11, fmt.Sprintf("MIN FLOOR %7dF", 1), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(1, 12, fmt.Sprintf("MAX FLOOR %7dF", g.Progress.MaxFloor), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(22, 7, fmt.Sprintf("FIGHT %9s", sheet.Attack().Describe()), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(22, 8, fmt.Sprintf("DEF %11s", sheet.Defense().Describe()), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(22, 10, fmt.Sprintf("HP %12s", fmt.Sprintf("%d:%d", sheet.HP(), sheet.MaxHP())), termbox.ColorWhite, termbox.ColorBlack)
s.display.Write(22, 11, fmt.Sprintf("MP %12s", fmt.Sprintf("%d:%d", sheet.MP(), sheet.MaxMP())), termbox.ColorWhite, termbox.ColorBlack)
for sk := game.Melee; sk < game.NumSkills; sk++ {
rowfmt := "%-5s %3d = %2d %3s"
row := fmt.Sprintf(rowfmt, skillname(sk), sheet.Skill(sk), sheet.UnmodSkill(sk), extrasign(sheet.SkillMod(sk)))
s.display.Write(40, 7+int(sk), row, termbox.ColorWhite, termbox.ColorBlack)
}
}
type skillEditPanel struct {
display display
editing bool
cur game.SkillName
change *game.SkillChange
}
func newSkillEditPanel(display display) *skillEditPanel {
return &skillEditPanel{display: display}
}
func (s *skillEditPanel) HandleInput(tboxev termbox.Event) (game.Command, error) {
if !s.editing {
switch tboxev.Ch {
case 'i':
s.editing = true
return game.StartLearningCommand{}, nil
}
} else {
switch tboxev.Key {
case termbox.KeyEsc:
s.editing = false
s.change = nil
return game.CancelLearningCommand{}, nil
case termbox.KeyEnter:
s.editing = false
s.change = nil
return game.FinishLearningCommand{}, nil
}
switch tboxev.Ch {
case 'j':
s.cur = (s.cur + 1) % game.NumSkills
case 'k':
if s.cur == game.Melee {
s.cur = game.Song
} else {
s.cur--
}
case 'h':
return game.UnlearnSkillCommand{Skill: s.cur}, nil
case 'l':
return game.LearnSkillCommand{Skill: s.cur}, nil
}
}
return nocommand()
}
func (s *skillEditPanel) HandleEvent(e game.Event) {
switch ev := e.(type) {
case game.SkillChangeEvent:
s.change = ev.Change
}
}
func (s *skillEditPanel) Render(g *game.Game) {
if !s.editing || s.change == nil {
return
}
for sk := game.Melee; sk < game.NumSkills; sk++ {
row, fg := fmt.Sprintf("%5d", s.change.Changes[sk].Cost), termbox.ColorWhite
if sk == s.cur {
fg = termbox.ColorBlue
}
s.display.Write(60, 7+int(sk), row, fg, termbox.ColorBlack)
}
}
func extrasign(x int) string {
s := fmt.Sprintf("%d", x)
if x >= 0 {
s = "+" + s
}
return s
}
func skillname(s game.SkillName) string {
skillnames := []string{
"FIGHT",
"DODGE",
"SHOOT",
"SNEAK",
"CHI",
"SENSE",
"MAGIC",
"SONG",
}
return skillnames[s]
}