Remove dependency etk
This commit is contained in:
parent
8685a3e37c
commit
fe2797dd84
|
@ -84,4 +84,3 @@ Please share issues and suggestions [here](https://code.rocketnine.space/tslocum
|
|||
- [ebitengine](https://github.com/hajimehoshi/ebiten) - Game engine
|
||||
- [ggpo-go](https://github.com/assemblaj/ggpo) - Rollback networking library
|
||||
- [gohan](https://code.rocketnine.space/tslocum/gohan) - Entity Component System framework
|
||||
- [etk](https://code.rocketnine.space/tslocum/etk) - Graphical User Interface toolkit
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
"code.rocketnine.space/tslocum/boxbrawl/entity"
|
||||
"code.rocketnine.space/tslocum/boxbrawl/system"
|
||||
"code.rocketnine.space/tslocum/boxbrawl/world"
|
||||
"code.rocketnine.space/tslocum/etk"
|
||||
"code.rocketnine.space/tslocum/gohan"
|
||||
"github.com/assemblaj/ggpo"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
|
@ -90,9 +89,6 @@ func (g *Game) reset() {
|
|||
func (g *Game) Layout(_, _ int) (screenWidth, screenHeight int) {
|
||||
// Maintain constant internal resolution.
|
||||
if world.InternalScreenWidth != world.ScreenWidth || world.InternalScreenHeight != world.ScreenHeight {
|
||||
if world.ScreenWidth != 0 || world.ScreenHeight != 0 {
|
||||
etk.Layout(world.InternalScreenWidth, world.InternalScreenHeight)
|
||||
}
|
||||
world.ScreenWidth, world.ScreenHeight = world.InternalScreenWidth, world.InternalScreenHeight
|
||||
}
|
||||
return world.ScreenWidth, world.ScreenHeight
|
||||
|
@ -118,7 +114,9 @@ func (g *Game) startNetworkGame() {
|
|||
}
|
||||
p, err := strconv.Atoi(port)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to read port: %s", err)
|
||||
log.Printf("failed to read port in network address: %s", err)
|
||||
world.ConnectPromptConfirmed = false
|
||||
return
|
||||
}
|
||||
|
||||
localPort := p
|
||||
|
|
3
go.mod
3
go.mod
|
@ -3,14 +3,12 @@ module code.rocketnine.space/tslocum/boxbrawl
|
|||
go 1.19
|
||||
|
||||
require (
|
||||
code.rocketnine.space/tslocum/etk v0.0.0-20230103193701-368514415e01
|
||||
code.rocketnine.space/tslocum/gohan v1.0.0
|
||||
github.com/assemblaj/ggpo v0.0.0-20230129160025-68dbb12db83e
|
||||
github.com/hajimehoshi/ebiten/v2 v2.4.16
|
||||
)
|
||||
|
||||
require (
|
||||
code.rocketnine.space/tslocum/messeji v1.0.2 // indirect
|
||||
github.com/ebitengine/purego v0.1.1 // indirect
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
|
||||
github.com/hajimehoshi/file2byteslice v1.0.0 // indirect
|
||||
|
@ -20,7 +18,6 @@ require (
|
|||
golang.org/x/image v0.3.0 // indirect
|
||||
golang.org/x/mobile v0.0.0-20221110043201-43a038452099 // indirect
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/assemblaj/ggpo => github.com/tslocum/ggpo v0.0.0-20230130221056-9cfe5a275c31
|
||||
|
|
6
go.sum
6
go.sum
|
@ -1,9 +1,5 @@
|
|||
code.rocketnine.space/tslocum/etk v0.0.0-20230103193701-368514415e01 h1:uIe8pMDrqth/zk7e/O6kGw1wH2NNhTp6Hwad3xueLx0=
|
||||
code.rocketnine.space/tslocum/etk v0.0.0-20230103193701-368514415e01/go.mod h1:aZXxIwgveNf6Yu96khlkpXdlRKwDoee8H3bYs9y8RnU=
|
||||
code.rocketnine.space/tslocum/gohan v1.0.0 h1:WBcJq7nVfmr1EB8bew6xWlB5Q1714yWJ3a9/q6aBBrY=
|
||||
code.rocketnine.space/tslocum/gohan v1.0.0/go.mod h1:12yOt5Ygl/RVwnnZSVZRuS1W6gCaHJgezcvg8+THk10=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.2 h1:3/68FnXWaBDMhfUGb8FvNpVgAHY8DX+VL7pyA/CcY94=
|
||||
code.rocketnine.space/tslocum/messeji v1.0.2/go.mod h1:bSXsyjvKhFXQ7GsUxWZdO2JX83xOT/VTqFCR04thk+c=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/ebitengine/purego v0.0.0-20220905075623-aeed57cda744/go.mod h1:Eh8I3yvknDYZeCuXH9kRNaPuHEwvXDCk378o9xszmHg=
|
||||
github.com/ebitengine/purego v0.1.1 h1:HI8nW+LniW9Yb34k34jBs8nz+PNzsw68o7JF8jWFHHE=
|
||||
|
@ -11,7 +7,6 @@ github.com/ebitengine/purego v0.1.1/go.mod h1:Eh8I3yvknDYZeCuXH9kRNaPuHEwvXDCk37
|
|||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220806181222-55e207c401ad/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/hajimehoshi/bitmapfont/v2 v2.2.2 h1:4z08Fk1m3pjtlO7BdoP48u5bp/Y8xmKshf44aCXgYpE=
|
||||
github.com/hajimehoshi/bitmapfont/v2 v2.2.2/go.mod h1:Ua/x9Dkz7M9CU4zr1VHWOqGwjKdXbOTRsH7lWfb1Co0=
|
||||
github.com/hajimehoshi/ebiten/v2 v2.4.16 h1:vhuMtaB78N2HlNMfImV/SZkDPNJhOxgFrEIm1uh838o=
|
||||
github.com/hajimehoshi/ebiten/v2 v2.4.16/go.mod h1:BZcqCU4XHmScUi+lsKexocWcf4offMFwfp8dVGIB/G4=
|
||||
|
@ -86,7 +81,6 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
|
||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
|
|
75
system/ui.go
75
system/ui.go
|
@ -5,10 +5,10 @@ import (
|
|||
"image"
|
||||
"image/color"
|
||||
"math"
|
||||
"strings"
|
||||
|
||||
"code.rocketnine.space/tslocum/boxbrawl/component"
|
||||
"code.rocketnine.space/tslocum/boxbrawl/world"
|
||||
"code.rocketnine.space/tslocum/etk"
|
||||
"code.rocketnine.space/tslocum/gohan"
|
||||
"github.com/assemblaj/ggpo"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
|
@ -20,21 +20,25 @@ const uiStartPrompt = `BOX BRAWL`
|
|||
const uiBrowserIntro = `Click anywhere to enable keyboard input.`
|
||||
const uiComputerPrompt = `Press <Enter> to play against the computer.`
|
||||
const uiHostPrompt = `Press <H> to host a match against a remote player.`
|
||||
const uiHostInfoPrompt = `Type your opponent's IP address and port (address:port) to host a match.`
|
||||
const uiHostInfoPrompt = `Type your opponent's IP address and port
|
||||
(address:port) to host a match.`
|
||||
const uiHostStartPrompt = `Press <Enter> to start hosting.`
|
||||
const uiRemotePrompt = `Type your opponent's IP address and port (address:port) to join a match.`
|
||||
const uiRemotePrompt = `Type your opponent's IP address and port
|
||||
(address:port) to join a match.`
|
||||
const uiConnectPrompt = `Press <Enter> to connect.`
|
||||
const uiBrowserPrompt = `Playing against remote players is unavailable in the browser version.
|
||||
|
||||
Download Box Brawl for Windows or Linux to play against remote players.`
|
||||
const uiHostListeningPrompt = `Waiting for opponent to connect from %s...`
|
||||
const uiHostListeningPrompt = `Waiting for opponent to connect
|
||||
from %s...`
|
||||
const uiClientConnectingPrompt = `Connecting to %s...`
|
||||
const controlsInfo = `<H> Punch <J> Kick <K> Block <L>+<Dir> Taunt`
|
||||
|
||||
type UISystem struct {
|
||||
*component.Once
|
||||
|
||||
initialized bool
|
||||
buffer *etk.Text
|
||||
buffer string
|
||||
updateTicks int
|
||||
|
||||
tmpImg *ebiten.Image
|
||||
|
@ -43,21 +47,9 @@ type UISystem struct {
|
|||
}
|
||||
|
||||
func (u *UISystem) initialize() {
|
||||
u.buffer = etk.NewText("")
|
||||
u.updateBuffer()
|
||||
|
||||
inputDemo := etk.NewFlex()
|
||||
inputDemo.SetVertical(true)
|
||||
|
||||
inputDemo.AddChild(u.buffer)
|
||||
|
||||
etk.SetRoot(inputDemo)
|
||||
etk.Layout(world.InternalScreenWidth, world.InternalScreenHeight)
|
||||
|
||||
u.tmpImg = ebiten.NewImage(250, 100)
|
||||
|
||||
u.tmpImg = ebiten.NewImage(world.InternalScreenWidth/2, world.InternalScreenHeight/2)
|
||||
u.hitboxImg = ebiten.NewImage(32, 32)
|
||||
|
||||
u.updateBuffer()
|
||||
u.initialized = true
|
||||
}
|
||||
|
||||
|
@ -68,6 +60,7 @@ func (u *UISystem) updateBuffer() {
|
|||
prompt = append(prompt, []byte("\n\n"+uiBrowserIntro)...)
|
||||
prompt = append(prompt, []byte("\n\n"+uiComputerPrompt)...)
|
||||
prompt = append(prompt, []byte("\n\n"+uiBrowserPrompt)...)
|
||||
prompt = append(prompt, []byte("\n\n"+controlsInfo)...)
|
||||
} else if world.ConnectionActive {
|
||||
if world.ConnectPromptHost {
|
||||
prompt = append(prompt, []byte("\n\n"+fmt.Sprintf(uiHostListeningPrompt, world.ConnectPromptText))...)
|
||||
|
@ -90,10 +83,10 @@ func (u *UISystem) updateBuffer() {
|
|||
prompt = append(prompt, []byte("\n\n"+uiHostPrompt)...)
|
||||
prompt = append(prompt, []byte("\n\n"+uiRemotePrompt)...)
|
||||
}
|
||||
prompt = append(prompt, []byte("\n\n"+controlsInfo)...)
|
||||
}
|
||||
|
||||
u.buffer.Clear()
|
||||
u.buffer.Write(prompt)
|
||||
u.buffer = string(prompt)
|
||||
}
|
||||
|
||||
func (u *UISystem) Update(e gohan.Entity) error {
|
||||
|
@ -180,8 +173,7 @@ func (u *UISystem) Update(e gohan.Entity) error {
|
|||
u.updateTicks = 0
|
||||
}
|
||||
}
|
||||
|
||||
return etk.Update()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UISystem) drawBox(screen *ebiten.Image, fillColor color.Color, r image.Rectangle) {
|
||||
|
@ -208,10 +200,7 @@ func (u *UISystem) Draw(e gohan.Entity, screen *ebiten.Image) error {
|
|||
}
|
||||
|
||||
if world.ConnectPromptVisible {
|
||||
err := etk.Draw(screen)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.drawCenteredText(screen, u.buffer)
|
||||
} else if world.Debug > 1 { // In-game and debug mode is enabled
|
||||
var p, o *component.Player
|
||||
for i := 0; i < 2; i++ {
|
||||
|
@ -359,3 +348,35 @@ func (u *UISystem) Draw(e gohan.Entity, screen *ebiten.Image) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UISystem) drawCenteredText(screen *ebiten.Image, text string) {
|
||||
const (
|
||||
charWidth = 6
|
||||
charHeight = 16
|
||||
textScale = 2
|
||||
)
|
||||
|
||||
lines := strings.Split(text, "\n")
|
||||
var w int
|
||||
for _, line := range lines {
|
||||
l := len(line)
|
||||
if l > w {
|
||||
w = l
|
||||
}
|
||||
}
|
||||
|
||||
u.tmpImg.Clear()
|
||||
for i, line := range lines {
|
||||
x, y := ((w-len(line))/2)*charWidth, i*charHeight
|
||||
ebitenutil.DebugPrintAt(u.tmpImg, line, x, y)
|
||||
}
|
||||
|
||||
width := float64(w) * charWidth * textScale
|
||||
height := float64(len(lines) * charHeight * textScale)
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Scale(textScale, textScale)
|
||||
op.GeoM.Translate(world.InternalScreenWidth/2-width/2, world.InternalScreenHeight/2-height/2)
|
||||
screen.DrawImage(u.tmpImg, op)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue