mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-17 23:55:21 +01:00
Add hollow border to selected menu items and fix scroll view in landscape mode
This commit is contained in:
parent
c4f103ae1e
commit
7e4423efce
3 changed files with 94 additions and 44 deletions
|
@ -38,6 +38,11 @@ import android.widget.Toast
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
|
import android.graphics.drawable.ColorDrawable
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import android.widget.Button
|
||||||
|
import android.widget.ScrollView
|
||||||
|
import android.widget.ImageButton
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity(),
|
class MainActivity : AppCompatActivity(),
|
||||||
GamepadController.GamepadConnectionListener,
|
GamepadController.GamepadConnectionListener,
|
||||||
|
@ -61,6 +66,7 @@ class MainActivity : AppCompatActivity(),
|
||||||
private lateinit var progressionScreen: ProgressionScreen
|
private lateinit var progressionScreen: ProgressionScreen
|
||||||
private lateinit var themeSelector: ThemeSelector
|
private lateinit var themeSelector: ThemeSelector
|
||||||
private lateinit var blockSkinSelector: BlockSkinSelector
|
private lateinit var blockSkinSelector: BlockSkinSelector
|
||||||
|
private var pauseMenuScrollView: ScrollView? = null
|
||||||
|
|
||||||
// Game state
|
// Game state
|
||||||
private var isSoundEnabled = true
|
private var isSoundEnabled = true
|
||||||
|
@ -124,6 +130,7 @@ class MainActivity : AppCompatActivity(),
|
||||||
progressionManager = PlayerProgressionManager(this)
|
progressionManager = PlayerProgressionManager(this)
|
||||||
themeSelector = binding.themeSelector
|
themeSelector = binding.themeSelector
|
||||||
blockSkinSelector = binding.blockSkinSelector
|
blockSkinSelector = binding.blockSkinSelector
|
||||||
|
pauseMenuScrollView = binding.pauseMenuScrollView
|
||||||
|
|
||||||
// Initialize gamepad controller
|
// Initialize gamepad controller
|
||||||
gamepadController = GamepadController(gameView)
|
gamepadController = GamepadController(gameView)
|
||||||
|
@ -1227,6 +1234,14 @@ class MainActivity : AppCompatActivity(),
|
||||||
item.alpha = if (i == index) 1.0f else 0.7f
|
item.alpha = if (i == index) 1.0f else 0.7f
|
||||||
item.scaleX = if (i == index) 1.2f else 1.0f
|
item.scaleX = if (i == index) 1.2f else 1.0f
|
||||||
item.scaleY = if (i == index) 1.2f else 1.0f
|
item.scaleY = if (i == index) 1.2f else 1.0f
|
||||||
|
// Add or remove border based on selection
|
||||||
|
if (item is Button) {
|
||||||
|
item.background = if (i == index) {
|
||||||
|
ContextCompat.getDrawable(this, R.drawable.menu_item_selected)
|
||||||
|
} else {
|
||||||
|
ColorDrawable(Color.TRANSPARENT)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1237,6 +1252,7 @@ class MainActivity : AppCompatActivity(),
|
||||||
if (pauseMenuItems.isEmpty()) return
|
if (pauseMenuItems.isEmpty()) return
|
||||||
currentMenuSelection = (currentMenuSelection - 1 + pauseMenuItems.size) % pauseMenuItems.size
|
currentMenuSelection = (currentMenuSelection - 1 + pauseMenuItems.size) % pauseMenuItems.size
|
||||||
highlightMenuItem(currentMenuSelection)
|
highlightMenuItem(currentMenuSelection)
|
||||||
|
scrollToSelectedItem()
|
||||||
gameHaptics.vibrateForPieceMove()
|
gameHaptics.vibrateForPieceMove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1247,9 +1263,31 @@ class MainActivity : AppCompatActivity(),
|
||||||
if (pauseMenuItems.isEmpty()) return
|
if (pauseMenuItems.isEmpty()) return
|
||||||
currentMenuSelection = (currentMenuSelection + 1) % pauseMenuItems.size
|
currentMenuSelection = (currentMenuSelection + 1) % pauseMenuItems.size
|
||||||
highlightMenuItem(currentMenuSelection)
|
highlightMenuItem(currentMenuSelection)
|
||||||
|
scrollToSelectedItem()
|
||||||
gameHaptics.vibrateForPieceMove()
|
gameHaptics.vibrateForPieceMove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun scrollToSelectedItem() {
|
||||||
|
if (pauseMenuItems.isEmpty()) return
|
||||||
|
|
||||||
|
val selectedItem = pauseMenuItems[currentMenuSelection]
|
||||||
|
val scrollView = pauseMenuScrollView ?: return
|
||||||
|
|
||||||
|
// Calculate the item's position relative to the scroll view
|
||||||
|
val itemTop = selectedItem.top
|
||||||
|
val itemBottom = selectedItem.bottom
|
||||||
|
val scrollViewHeight = scrollView.height
|
||||||
|
|
||||||
|
// If the item is partially or fully below the visible area, scroll down
|
||||||
|
if (itemBottom > scrollViewHeight) {
|
||||||
|
scrollView.smoothScrollTo(0, itemBottom - scrollViewHeight)
|
||||||
|
}
|
||||||
|
// If the item is partially or fully above the visible area, scroll up
|
||||||
|
else if (itemTop < 0) {
|
||||||
|
scrollView.smoothScrollTo(0, itemTop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activate the currently selected menu item
|
* Activate the currently selected menu item
|
||||||
*/
|
*/
|
||||||
|
|
9
app/src/main/res/drawable/menu_item_selected.xml
Normal file
9
app/src/main/res/drawable/menu_item_selected.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<stroke
|
||||||
|
android:width="2dp"
|
||||||
|
android:color="@color/white" />
|
||||||
|
<corners android:radius="8dp" />
|
||||||
|
<solid android:color="@android:color/transparent" />
|
||||||
|
</shape>
|
|
@ -242,8 +242,12 @@
|
||||||
|
|
||||||
<!-- Scrollable content for pause menu -->
|
<!-- Scrollable content for pause menu -->
|
||||||
<ScrollView
|
<ScrollView
|
||||||
|
android:id="@+id/pauseMenuScrollView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:scrollbars="none"
|
||||||
|
android:overScrollMode="never"
|
||||||
|
android:fillViewport="true">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -316,13 +320,13 @@
|
||||||
android:fontFamily="sans-serif"
|
android:fontFamily="sans-serif"
|
||||||
android:textAllCaps="false" />
|
android:textAllCaps="false" />
|
||||||
|
|
||||||
|
<!-- Level Selection -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/levelSelectorContainer"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="32dp"
|
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:gravity="center">
|
android:gravity="center"
|
||||||
|
android:layout_marginTop="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/selectLevelText"
|
android:id="@+id/selectLevelText"
|
||||||
|
@ -330,15 +334,15 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/select_level"
|
android:text="@string/select_level"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="24sp"
|
android:textSize="16sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:fontFamily="sans-serif"
|
android:fontFamily="sans-serif" />
|
||||||
android:textAllCaps="false" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center"
|
||||||
android:layout_marginTop="8dp">
|
android:layout_marginTop="8dp">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
@ -346,7 +350,7 @@
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:background="@color/transparent"
|
android:background="@color/transparent"
|
||||||
android:text="−"
|
android:text="-"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
|
@ -354,14 +358,13 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/pauseLevelText"
|
android:id="@+id/pauseLevelText"
|
||||||
android:layout_width="48dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="48dp"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
|
||||||
android:text="1"
|
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:fontFamily="sans-serif" />
|
android:fontFamily="sans-serif"
|
||||||
|
android:layout_marginHorizontal="16dp" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/pauseLevelUpButton"
|
android:id="@+id/pauseLevelUpButton"
|
||||||
|
@ -389,9 +392,38 @@
|
||||||
android:id="@+id/inPauseBlockSkinSelector"
|
android:id="@+id/inPauseBlockSkinSelector"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="24dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginBottom="16dp" />
|
android:layout_marginBottom="16dp" />
|
||||||
|
|
||||||
|
<!-- Sound Settings -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_marginTop="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/musicText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/music"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:fontFamily="sans-serif" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/musicToggle"
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:background="@color/transparent"
|
||||||
|
android:contentDescription="@string/toggle_music"
|
||||||
|
android:src="@drawable/ic_volume_up" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- Sound Toggle -->
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/settingsButton"
|
android:id="@+id/settingsButton"
|
||||||
android:layout_width="200dp"
|
android:layout_width="200dp"
|
||||||
|
@ -404,35 +436,6 @@
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:fontFamily="sans-serif"
|
android:fontFamily="sans-serif"
|
||||||
android:textAllCaps="false" />
|
android:textAllCaps="false" />
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:layout_marginTop="16dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/musicText"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/music"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="24sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:fontFamily="sans-serif"
|
|
||||||
android:textAllCaps="false"
|
|
||||||
android:layout_marginEnd="16dp" />
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/musicToggle"
|
|
||||||
android:layout_width="48dp"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
|
||||||
android:contentDescription="@string/toggle_music"
|
|
||||||
android:padding="12dp"
|
|
||||||
android:src="@drawable/ic_volume_up" />
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue