diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2024-12-26 19:06:17 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:57 +0100 |
| commit | b4a257dbd9fd88a26e4f72ca6f761ca853544df5 (patch) | |
| tree | b8261a5255e5dd2c60ea5d97156e28a3ea988dcd | |
| parent | bc06cd09407de831ac30f0300cb4135cbe325120 (diff) | |
| download | muhqs-game-b4a257dbd9fd88a26e4f72ca6f761ca853544df5.tar.gz muhqs-game-b4a257dbd9fd88a26e4f72ca6f761ca853544df5.zip | |
add dummy-ui mod to test and play with ui components
| -rw-r--r-- | go/.gitignore | 1 | ||||
| -rw-r--r-- | go/Makefile | 7 | ||||
| -rw-r--r-- | go/dummy-ui/main.go | 46 |
3 files changed, 51 insertions, 3 deletions
diff --git a/go/.gitignore b/go/.gitignore index 6e729d48..7008187a 100644 --- a/go/.gitignore +++ b/go/.gitignore @@ -1,3 +1,4 @@ +dummy-ui/dummy-ui client/client client/client.wasm server/server diff --git a/go/Makefile b/go/Makefile index 88c32ebe..15343636 100644 --- a/go/Makefile +++ b/go/Makefile @@ -1,14 +1,15 @@ -PACKAGES := assets game server client ui +PACKAGES := assets game server client dummy-ui -APPS := server client +APPS := server client dummy-ui OBJS := $(foreach app,$(APPS),$(app)/$(app)) WASM := client/client.wasm webtools/webtools.wasm GOFMT := gofumpt -l -w . -.PHONY: client server +.PHONY: client server dummy-ui client: client/client server: server/server +dummy-ui: dummy-ui/dummy-ui .PHONY: all fmt test check $(OBJS) $(WASM) all: $(OBJS) $(WASM) diff --git a/go/dummy-ui/main.go b/go/dummy-ui/main.go new file mode 100644 index 00000000..48474b33 --- /dev/null +++ b/go/dummy-ui/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + + "github.com/hajimehoshi/ebiten/v2" + + "muhq.space/muhqs-game/go/font" + "muhq.space/muhqs-game/go/ui" +) + +type app struct { + ui.Collection + windowWidth int + windowHeight int +} + +func (a *app) Update() error { + if a.Widgets() == nil { + a.build() + } + + return a.Collection.Update() +} + +func (a *app) build() { + nc := ui.NewNumberChoice(a.windowWidth-ui.NUMBER_CHOICE_WIDTH, + a.windowHeight-ui.NUMBER_CHOICE_HEIGHT, + 0, + func(nc *ui.NumberChoice) { + fmt.Println(nc.GetChoosen()) + }) + a.AddWidget(nc) +} + +func (a *app) Layout(width, height int) (int, int) { + return a.windowWidth, a.windowHeight +} + +func main() { + font.InitFont() + app := &app{windowWidth: 800, windowHeight: 1000} + ebiten.SetWindowSize(app.windowWidth, app.windowHeight) + ebiten.SetWindowTitle("Muhq's Game") + ebiten.RunGame(app) +} |
