Skip to content

Commit

Permalink
"Fixed" game level spinner positioning problem
Browse files Browse the repository at this point in the history
For some reason whenever the game level spinner contains more than 15 items, it ignores the width of the "Select" option text. Consequently, the spinner's width shrinks. I don't know yet why this happens.
  • Loading branch information
SpiritualForest committed Jun 3, 2022
1 parent 1cebfef commit 0848742
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener {

// Game level
val gameLevels: MutableList<String> = mutableListOf(defaultSpinnerSelection)
for(i in 1 until 20) { gameLevels.add(i.toString()) }
for(i in 1 until 15) { gameLevels.add(i.toString()) }
// Set the adapter
setAdapter(gameLevelSpinner, gameLevels)
val gameLevelSetValue: Int = SettingsHandler.getGameLevel() // Returns 1 by default
Expand Down Expand Up @@ -120,7 +120,7 @@ class MainActivity : AppCompatActivity(), OnItemSelectedListener {
}

override fun onNothingSelected(parent: AdapterView<*>?) {
TODO("Not yet implemented")
/* Not implemented */
}

private fun getSpinnerIndex(spinner: Spinner, string: String): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ class GridCanvas(context: Context, attrs: AttributeSet?) : View(context, attrs)

private fun isGhostCollision(coordinates: List<Point>): Boolean {
// Checks if there's a collision for every y+1, x of the supplied coordinates, in the grid.
// y+1 because if we checked y, that's where the tetromino's lowest y point is, and therefore it
// is guaranteed to not be occupied in the grid. If we did this, the bottom-most line of the ghost
// would be drawn on the next line.
// This function is used solely for the ghost piece's hard-dropping.
for(point in coordinates) {
val y = point.y+1
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.AndroidTetris"
tools:context=".MainActivity">
tools:context="com.androidtetris.activity.main.MainActivity">

<Button
android:id="@+id/btn_startgame"
Expand Down Expand Up @@ -128,7 +128,6 @@
android:layout_marginEnd="9dp"
android:background="@drawable/rounded_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/gridSizeLayout">

Expand All @@ -154,12 +153,10 @@
android:layout_marginEnd="123dp"
android:layout_marginBottom="8dp"
android:minHeight="48dp"
android:dropDownWidth="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/txt_startingHeight"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="SpeakableTextPresentCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down Expand Up @@ -196,6 +193,7 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="123dp"
android:layout_marginBottom="8dp"
android:dropDownWidth="wrap_content"
android:minHeight="48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down

0 comments on commit 0848742

Please sign in to comment.