add dialog to domain
This commit is contained in:
40
domain/dialog.go
Normal file
40
domain/dialog.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
func (d *Domain) InitDialog() {
|
||||
d.DialogMap = konstructor.DialogMap{
|
||||
"TestDialog": {
|
||||
Layout: konstructor.DialogLayout{
|
||||
ChoiceFont: konstructor.FontLayout{
|
||||
DPI: 72,
|
||||
Size: 24,
|
||||
Color: color.White,
|
||||
SelectedColor: color.RGBA{R: 0, G: 255, B: 0, A: 100},
|
||||
},
|
||||
},
|
||||
Choices: []konstructor.DialogChoice{
|
||||
{
|
||||
ID: "one",
|
||||
Label: "One",
|
||||
},
|
||||
{
|
||||
ID: "two",
|
||||
Label: "Two",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Domain) GetDialog(name string) konstructor.Dialog {
|
||||
value, _ := d.DialogMap[name]
|
||||
return value
|
||||
}
|
||||
|
||||
func (d *Domain) SetDialog(name string, dialog konstructor.Dialog) {
|
||||
d.DialogMap[name] = dialog
|
||||
}
|
||||
@@ -2,37 +2,15 @@ package domain
|
||||
|
||||
import (
|
||||
"game/konstructor"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
type Domain struct {
|
||||
Context Context
|
||||
MenuMap konstructor.MenuMap
|
||||
Context Context
|
||||
MenuMap konstructor.MenuMap
|
||||
DialogMap konstructor.DialogMap
|
||||
}
|
||||
|
||||
func (d *Domain) Init() {
|
||||
d.InitMenu()
|
||||
}
|
||||
|
||||
func (d *Domain) GetDialog() konstructor.Dialog {
|
||||
return konstructor.Dialog{
|
||||
Layout: konstructor.DialogLayout{
|
||||
ChoiceFont: konstructor.FontLayout{
|
||||
DPI: 72,
|
||||
Size: 24,
|
||||
Color: color.White,
|
||||
SelectedColor: color.RGBA{R: 0, G: 255, B: 0, A: 100},
|
||||
},
|
||||
},
|
||||
Choices: []konstructor.DialogChoice{
|
||||
{
|
||||
ID: "one",
|
||||
Label: "One",
|
||||
},
|
||||
{
|
||||
ID: "two",
|
||||
Label: "Two",
|
||||
},
|
||||
},
|
||||
}
|
||||
d.InitDialog()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/text"
|
||||
)
|
||||
|
||||
type DialogMap map[string]Dialog
|
||||
|
||||
type DialogLayout struct {
|
||||
Background string
|
||||
ChoiceFont FontLayout
|
||||
@@ -33,7 +35,7 @@ func (dialog *Dialog) GetChoiceColor(i int) color.Color {
|
||||
}
|
||||
|
||||
func (e *Engine) DialogDraw(screen *ebiten.Image) {
|
||||
dialog := e.Domain.GetDialog()
|
||||
dialog := e.Domain.GetDialog(e.KContext.Screen.Value)
|
||||
|
||||
face := GetFontFace(dialog.Layout.ChoiceFont)
|
||||
|
||||
@@ -44,7 +46,7 @@ func (e *Engine) DialogDraw(screen *ebiten.Image) {
|
||||
}
|
||||
|
||||
func (e *Engine) DialogUpdate() {
|
||||
dialog := e.Domain.GetDialog()
|
||||
dialog := e.Domain.GetDialog(e.KContext.Screen.Value)
|
||||
|
||||
if e.Controller.UpPressed() && dialog.CurrentSelected != 0 {
|
||||
dialog.CurrentSelected--
|
||||
@@ -57,4 +59,5 @@ func (e *Engine) DialogUpdate() {
|
||||
if e.Controller.Action0Pressed() {
|
||||
dialog.Choices[dialog.CurrentSelected].Handler()
|
||||
}
|
||||
e.Domain.SetDialog(e.KContext.Screen.Value, dialog)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ type DomainInterface interface {
|
||||
Init()
|
||||
GetMenu(name string) Menu
|
||||
SetMenu(name string, menu Menu)
|
||||
GetDialog() Dialog
|
||||
GetDialog(name string) Dialog
|
||||
SetDialog(name string, menu Dialog)
|
||||
}
|
||||
|
||||
type ScreenSettings struct {
|
||||
|
||||
Reference in New Issue
Block a user