add dialog to domain

This commit is contained in:
2023-07-04 20:56:09 +02:00
parent 74272c09f2
commit 88cf7620be
5 changed files with 53 additions and 31 deletions

40
domain/dialog.go Normal file
View 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
}

View File

@@ -2,37 +2,15 @@ package domain
import (
"game/konstructor"
"image/color"
)
type Domain struct {
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()
}

View File

@@ -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)
}

View File

@@ -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 {

View File

@@ -12,8 +12,8 @@ func main() {
k := konstructor.Konstructor{
KContext: &konstructor.KContext{
Screen: konstructor.KContextScreen{
Type: "menu",
Value: "MainMenu",
Type: "dialog",
Value: "TestDialog",
},
},
Domain: &domain.Domain{