From 88cf7620bedf2a59480e5b29c5ed24beacec7898 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 4 Jul 2023 20:56:09 +0200 Subject: [PATCH] add dialog to domain --- domain/dialog.go | 40 ++++++++++++++++++++++++++++++++++++++ domain/domain.go | 30 ++++------------------------ konstructor/dialog.go | 7 +++++-- konstructor/konstructor.go | 3 ++- main.go | 4 ++-- 5 files changed, 53 insertions(+), 31 deletions(-) create mode 100644 domain/dialog.go diff --git a/domain/dialog.go b/domain/dialog.go new file mode 100644 index 0000000..56d75cf --- /dev/null +++ b/domain/dialog.go @@ -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 +} diff --git a/domain/domain.go b/domain/domain.go index 00ce04b..5939c6d 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -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() } diff --git a/konstructor/dialog.go b/konstructor/dialog.go index 518b858..a9fdfa1 100644 --- a/konstructor/dialog.go +++ b/konstructor/dialog.go @@ -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) } diff --git a/konstructor/konstructor.go b/konstructor/konstructor.go index f445b5d..4c6084b 100644 --- a/konstructor/konstructor.go +++ b/konstructor/konstructor.go @@ -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 { diff --git a/main.go b/main.go index ffb13c7..434cdfe 100644 --- a/main.go +++ b/main.go @@ -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{