From 3de9d004e99851f38f8700839fa2f7aa6f1c0172 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 6 Oct 2024 00:52:49 +0500 Subject: feat: shaking image (button) --- .../kz/ilotterytea/maxon/ui/ShakingImageButton.kt | 37 ++++++++++++++++++++++ .../ilotterytea/maxon/ui/game/QuickActionsTable.kt | 3 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 core/src/kz/ilotterytea/maxon/ui/ShakingImageButton.kt (limited to 'core/src/kz/ilotterytea/maxon/ui') diff --git a/core/src/kz/ilotterytea/maxon/ui/ShakingImageButton.kt b/core/src/kz/ilotterytea/maxon/ui/ShakingImageButton.kt new file mode 100644 index 0000000..eb8c51c --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/ui/ShakingImageButton.kt @@ -0,0 +1,37 @@ +package kz.ilotterytea.maxon.ui + +import com.badlogic.gdx.scenes.scene2d.Actor +import com.badlogic.gdx.scenes.scene2d.InputEvent +import com.badlogic.gdx.scenes.scene2d.actions.Actions +import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction +import com.badlogic.gdx.scenes.scene2d.ui.Image +import com.badlogic.gdx.scenes.scene2d.ui.Skin +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener + +class ShakingImageButton(skin: Skin, style: String) : Image(skin.getRegion(style)) { + init { + setOrigin(width / 2f, height / 2f) + + addListener(object : ClickListener() { + override fun enter(event: InputEvent?, x: Float, y: Float, pointer: Int, fromActor: Actor?) { + super.enter(event, x, y, pointer, fromActor) + + addAction( + Actions.repeat( + RepeatAction.FOREVER, + Actions.sequence( + Actions.rotateTo(-2f, 0.1f), + Actions.rotateTo(2f, 0.1f) + ) + ) + ) + } + + override fun exit(event: InputEvent?, x: Float, y: Float, pointer: Int, toActor: Actor?) { + super.exit(event, x, y, pointer, toActor) + clearActions() + addAction(Actions.rotateTo(0f, 0.1f)) + } + }) + } +} \ No newline at end of file diff --git a/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt b/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt index b5df026..c2c1667 100644 --- a/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt +++ b/core/src/kz/ilotterytea/maxon/ui/game/QuickActionsTable.kt @@ -12,11 +12,12 @@ import com.badlogic.gdx.utils.Align import kz.ilotterytea.maxon.MaxonGame import kz.ilotterytea.maxon.player.Savegame import kz.ilotterytea.maxon.screens.MenuScreen +import kz.ilotterytea.maxon.ui.ShakingImageButton class QuickActionsTable(skin: Skin) : Table() { init { val game = MaxonGame.getInstance() - val quitButton = ImageButton(skin, "quit") + val quitButton = ShakingImageButton(skin, "exit") val clickSound = game.assetManager.get("sfx/ui/click.ogg", Sound::class.java) -- cgit v1.2.3