Skip to content

Commit

Permalink
Improve UI:
Browse files Browse the repository at this point in the history
- Refactors Main Menu
- Adds logo
- Adds links
- refactors points display
- Add darkmode
- Update README
  • Loading branch information
Joel Schutz committed Apr 26, 2023
1 parent 4d52fab commit f76d0a2
Show file tree
Hide file tree
Showing 24 changed files with 556 additions and 193 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tmp/
bin/
bin/
vendor/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ To start a game, run the following command:
```

## Roadmap
- Finish main Menu
- ~~Finish main Menu~~
- Improve board ui
- Show Last move
- Show points better
- ~~Show points better~~
- Add helpers for liberties, hints and Atari
- Add endgame behaviour
- Allow human player to start as white
Expand Down
Binary file added assets/DejaVuSansCondensed.ttf
Binary file not shown.
Binary file added assets/icons8-github-60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons8-idea-60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons8-itch-io-60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion component/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ type ConfigurationData struct {
BoardSize int
AIEnabled bool
Assets fs.FS
DarkMode bool
}

var Configuration = donburi.NewComponentType[ConfigurationData](
ConfigurationData{BoardSize: 9},
ConfigurationData{BoardSize: 9, DarkMode: true},
)
95 changes: 88 additions & 7 deletions gameScene.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"fmt"
"image"
"image/color"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/audio"
Expand All @@ -10,9 +12,11 @@ import (
"github.com/joelschutz/goingo/layers"
"github.com/joelschutz/goingo/system"
"github.com/joelschutz/goingo/util"
"github.com/joelschutz/goingo/widgets"
"github.com/yohamta/donburi"
"github.com/yohamta/donburi/ecs"
"github.com/yohamta/donburi/features/events"
"github.com/yohamta/furex/v2"
)

type GameScene struct {
Expand All @@ -33,23 +37,100 @@ func (g *GameScene) Load(w donburi.World, sm *util.SceneManager[donburi.World])
conf := component.Configuration.Get(entry)
boardSize := conf.BoardSize
assets := conf.Assets
w, board := spawnWorld(w, boardSize)

g.ecs = ecs.NewECS(spawnWorld(w, boardSize))
g.ecs = ecs.NewECS(w)

rules := system.NewRuleSystem(g.ecs)
event.InteractionEvent.Subscribe(g.ecs.World, rules.HandleInput)

// Load Sounds
sound := system.NewAudioPlayer(assets, audio.NewContext(48000))
event.MoveEvent.Subscribe(g.ecs.World, sound.HandleMove)
event.PointsEvent.Subscribe(g.ecs.World, sound.HandleCapture)

ai, _ := system.NewAIConn(g.ecs, boardSize)
event.MoveEvent.Subscribe(g.ecs.World, ai.HandleMove)
// Load Images
iBulb, _, err := util.LoadImage("assets/icons8-idea-60.png", conf.Assets)
if err != nil {
panic(err)
}

// Load AI
ai, err := system.NewAIConn(g.ecs, boardSize)
if err == nil {
event.MoveEvent.Subscribe(g.ecs.World, ai.HandleMove)
}

ui := system.NewMenuRender(&g.bounds,
func(r *system.MenuRender) {
// Create UI
r.GameUI = &furex.View{
Width: r.Bounds.Dx(),
Height: r.Bounds.Dy(),
Direction: furex.Column,
Justify: furex.JustifyStart,
Wrap: furex.Wrap,
}

// Add Header
header := &furex.View{
Grow: 1,
Justify: furex.JustifyStart,
MarginTop: 10,
}
header.AddChild(&furex.View{
Width: 90,
Handler: &widgets.Label{
Box: widgets.Box{
PColor: color.Black,
SColor: color.White,
Inverted: func() bool { return false },
},
Font: widgets.GetDefaultFont(18),
TextFunc: func() string {
return fmt.Sprint(board.Points[0])
},
},
})
header.AddChild(&furex.View{
Width: 90,
Handler: &widgets.Label{
Box: widgets.Box{
PColor: color.White,
SColor: color.Black,
Inverted: func() bool { return false },
},
Font: widgets.GetDefaultFont(18),
TextFunc: func() string {
return fmt.Sprint(board.Points[1])
},
},
})
header.AddChild(&furex.View{Grow: 1})
header.AddChild(&furex.View{
Width: 90,
Handler: &widgets.SpriteButton{
Action: func() { conf.DarkMode = !conf.DarkMode },
Sprite: widgets.Sprite{
Inverted: func() bool { return conf.DarkMode },
Image: iBulb,
Scale: 1,
},
},
})
r.GameUI.AddChild(header)

// Add Board
r.GameUI.AddChild(&furex.View{
Grow: float64(conf.BoardSize + 5),
})
})
g.ecs.
AddSystem(ui.Update).
AddSystem(system.NewInputManager(&g.bounds).Update).
AddRenderer(layers.LayerBackground, system.DrawBackground).
AddRenderer(layers.LayerBackground, system.Background.DrawBackground).
AddRenderer(layers.LayerBoard, system.NewRender(&g.bounds).Draw).
AddRenderer(layers.LayerUI, system.NewUIRender(&g.bounds).Draw)
AddRenderer(layers.LayerUI, ui.Draw)
}

func (g *GameScene) Update() error {
Expand All @@ -70,7 +151,7 @@ func (g *GameScene) Layout(width, height int) (int, int) {
return width, height
}

func spawnWorld(world donburi.World, boardSize int) donburi.World {
func spawnWorld(world donburi.World, boardSize int) (donburi.World, *component.BoardState) {
board := world.Entry(world.Create(component.Board))
donburi.SetValue(
board,
Expand All @@ -80,5 +161,5 @@ func spawnWorld(world donburi.World, boardSize int) donburi.World {
})
world.Create(component.PositionComponent)

return world
return world, component.Board.Get(board)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/jezek/xgb v1.1.0 // indirect
github.com/jfreymuth/oggvorbis v1.0.5 // indirect
github.com/jfreymuth/vorbis v1.0.2 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/vanng822/css v1.0.1 // indirect
github.com/vanng822/go-premailer v1.20.2 // indirect
github.com/yohamta/furex v0.6.3 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -433,6 +435,7 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func main() {
component.Configuration,
component.ConfigurationData{
BoardSize: _boardSize,
AIEnabled: true,
Assets: _assets,
},
)
Expand Down
Loading

0 comments on commit f76d0a2

Please sign in to comment.