Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
Osc: Add mouse button to hide osc temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzz committed May 4, 2019
1 parent 42dfc94 commit a10d6f9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ Original Java code written by sandstranger. Build scripts originally written by
### Icons

Some of the icons used in this project (keyboard.xml, load.xml, pause.xml, save.xml) are Font Awesome icons, distributed under the terms of the CC-BY 4.0 license. See https://fontawesome.com/license/free for more details.

mouse.png - https://github.com/FortAwesome/Font-Awesome/issues/2376#issuecomment-215401368
5 changes: 1 addition & 4 deletions app/src/main/java/cursor/MouseCursor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ class MouseCursor(activity: GameActivity, private val osc: Osc?) : Choreographer
// Check if we need to switch osc widgets visibility
val mouseShown = SDLActivity.isMouseShown()
if (osc != null && mouseShown != prevMouseShown) {
if (mouseShown == 0)
osc.showNonEssential()
else
osc.hideNonEssential()
osc.showBasedOnMouse()
}

if (mouseShown == 0 || (osc != null && osc.keyboardVisible)) {
Expand Down
75 changes: 62 additions & 13 deletions app/src/main/java/ui/controls/Osc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,31 @@ class OscKeyboardButton(

}

class OscMouseButton(
uniqueId: String,
visibility: OscVisibility,
private val imageSrc: Int,
defaultX: Int,
defaultY: Int,
private val osc: Osc
) : OscElement(uniqueId, visibility, defaultX, defaultY) {

override fun makeView(ctx: Context) {
val v = ImageView(ctx)
v.setImageResource(imageSrc)
v.setOnTouchListener(View.OnTouchListener { _, motionEvent ->
if (motionEvent.action == MotionEvent.ACTION_UP) {
osc.toggleMouse()
}
return@OnTouchListener true
})
v.tag = this

view = v
}

}

class OscJoystickLeft(
uniqueId: String,
visibility: OscVisibility,
Expand Down Expand Up @@ -323,14 +348,16 @@ enum class OscVisibility(val v: Int) {
KEYBOARD(2),
ESSENTIAL_KEYBOARD(ESSENTIAL.v or KEYBOARD.v),
// Widgets visible during gameplay
NORMAL(4)
NORMAL(4),
// Nothing except mouse icon is visible
MOUSE(8),
ESSENTIAL_MOUSE(ESSENTIAL.v or MOUSE.v),
}

class Osc {
private var osk = Osk()
public var keyboardVisible = false
private var keyboardButton = OscKeyboardButton("keyboard", OscVisibility.ESSENTIAL_KEYBOARD,
R.drawable.keyboard, 586, 0, this)
var keyboardVisible = false //< Mode where only keyboard is visible
var mouseVisible = false //< Mode where only mouse-switch icon is visible
private var visibilityState = 0

private var elements = arrayListOf(
Expand Down Expand Up @@ -361,7 +388,10 @@ class Osc {
R.drawable.sneak, 940, 670, 113),
OscImageButton("diary", OscVisibility.NORMAL,
R.drawable.journal, 414, 0, KeyEvent.KEYCODE_J),
keyboardButton,
OscKeyboardButton("keyboard", OscVisibility.ESSENTIAL_KEYBOARD,
R.drawable.keyboard, 586, 0, this),
OscMouseButton("mouse", OscVisibility.ESSENTIAL_MOUSE,
R.drawable.mouse, 660, 0, this),
OscImageButton("use", OscVisibility.ESSENTIAL,
R.drawable.use, 940, 368, KeyEvent.KEYCODE_SPACE),

Expand Down Expand Up @@ -419,10 +449,31 @@ class Osc {
setVisibility(OscVisibility.KEYBOARD.v)
} else {
keyboardVisible = false
if (SDLActivity.isMouseShown() == 0)
showNonEssential()
else
hideNonEssential()
showBasedOnMouse()
}
}

/**
* Displays different controls depending on whether the mouse-cursor is visible
*/
fun showBasedOnMouse() {
// Don't do anything if keyboard or mouse are visible
if (keyboardVisible || mouseVisible)
return

if (SDLActivity.isMouseShown() == 0)
showNonEssential()
else
hideNonEssential()
}

fun toggleMouse() {
if (!mouseVisible) {
mouseVisible = true
setVisibility(OscVisibility.MOUSE.v)
} else {
mouseVisible = false
showBasedOnMouse()
}
}

Expand Down Expand Up @@ -466,16 +517,14 @@ class Osc {
* Hides everything except the widgets that should be visible in inventory screen
*/
fun hideNonEssential() {
if (!keyboardVisible)
setVisibility(OscVisibility.ESSENTIAL.v)
setVisibility(OscVisibility.ESSENTIAL.v)
}

/**
* Shows all widgets again
*/
fun showNonEssential() {
if (!keyboardVisible)
setVisibility(OscVisibility.ESSENTIAL.v or OscVisibility.NORMAL.v)
setVisibility(OscVisibility.ESSENTIAL.v or OscVisibility.NORMAL.v)
}

private fun relayout(l: Int, t: Int, r: Int, b: Int, ol: Int, ot: Int, or: Int, ob: Int) {
Expand Down
Binary file added app/src/main/res/drawable/mouse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a10d6f9

Please sign in to comment.