Skip to content

Commit

Permalink
Add potential touch support
Browse files Browse the repository at this point in the history
  • Loading branch information
kettek committed Jun 30, 2024
1 parent c6d1cd5 commit fb71c9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ func (g *Game) DrawTower(screen *ebiten.Image) {

func (g *Game) CheckUI() (bool, UICheckKind) {
mx, my := IntToFloat2(ebiten.CursorPosition())
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
tx, ty := IntToFloat2(ebiten.TouchPosition(0))
if tx != 0 || ty != 0 {
mx, my = tx, ty
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) || inpututil.IsTouchJustReleased(0) {
if g.ui.Check(mx, my, UICheckClick) {
return true, UICheckClick
}
Expand Down
6 changes: 5 additions & 1 deletion internal/game/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,17 @@ func (mp *MessagePanel) Update(o *UIOptions) {

rpx, rpy := mp.Position()
mx, my := IntToFloat2(ebiten.CursorPosition())
tx, ty := IntToFloat2(ebiten.TouchPosition(0))
if tx != 0 || ty != 0 {
mx, my = tx, ty
}

maxX := rpx + float64(mp.width)
maxY := rpy + mp.height

//_, ph := mp.topleft.Size()

if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) || inpututil.IsTouchJustReleased(0) {
if mx > rpx && mx < maxX && my > rpy && my < maxY {
mp.pinned = !mp.pinned
/*if mp.drawered {
Expand Down

0 comments on commit fb71c9f

Please sign in to comment.