-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodal.go
50 lines (41 loc) · 958 Bytes
/
modal.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
package main
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text"
"image/color"
)
type Modal struct {
Title string
Text string
CloseKeys Keys
isClosed bool
}
func NewModal(title string, text string, closeKeys Keys) *Modal {
return &Modal{
Title: title,
Text: text,
CloseKeys: closeKeys,
}
}
func (m *Modal) Update(keys Keys) {
found := false
for key := range m.CloseKeys {
if keys.IsPressed(key) {
found = true
break
}
}
if found {
m.isClosed = true
}
}
func (m *Modal) Draw(screen *ebiten.Image) {
if m.isClosed {
return
}
screen.DrawImage(modalImg, nil)
titleBounds := text.BoundString(modalTitleFace, m.Title)
text.Draw(screen, m.Title, modalTitleFace, ScreenWidth/2-titleBounds.Max.X/2, 280, color.White)
textBounds := text.BoundString(modalTextFace, m.Text)
text.Draw(screen, m.Text, modalTextFace, ScreenWidth/2-textBounds.Max.X/2, 500, color.White)
}