Feature/last usecases (#29)
* implemented hard reset * implemented custom button sound * Added Options Screen and Mute Button concept. * Refactored Units class for metrics improvement. * Added CollectionHelper Test * Redesigned UI a bit and added resource icons. Co-authored-by: D45Hub <denis.thiessen@gmx.de>dev 0.0.3
-
14app/src/main/AndroidManifest.xml
-
6app/src/main/java/com/futurumgame/base/MainActivity.java
-
200app/src/main/java/com/futurumgame/base/additionalDatatypes/Units.java
-
9app/src/main/java/com/futurumgame/base/enums/DataFile.java
-
3app/src/main/java/com/futurumgame/base/gameinternals/FactoryNode.java
-
27app/src/main/java/com/futurumgame/base/gameinternals/GameRoutine.java
-
29app/src/main/java/com/futurumgame/base/resources/Resource.java
-
63app/src/main/java/com/futurumgame/base/ui/activities/OptionsViewActivity.java
-
9app/src/main/java/com/futurumgame/base/ui/activities/ResourceViewActivity.java
-
6app/src/main/java/com/futurumgame/base/ui/activities/UpdatableViewActivity.java
-
1app/src/main/java/com/futurumgame/base/ui/adapter/ResourceAdapter.java
-
3app/src/main/java/com/futurumgame/base/ui/listeners/onclicklisteners/GoBackListener.java
-
3app/src/main/java/com/futurumgame/base/ui/listeners/onclicklisteners/GoToViewListener.java
-
25app/src/main/java/com/futurumgame/base/ui/listeners/onclicklisteners/HardResetListener.java
-
3app/src/main/java/com/futurumgame/base/ui/listeners/onclicklisteners/ManualCollectClickListener.java
-
3app/src/main/java/com/futurumgame/base/ui/listeners/onclicklisteners/ManualWorkClickListener.java
-
46app/src/main/java/com/futurumgame/base/ui/listeners/onclicklisteners/SoundListener.java
-
3app/src/main/java/com/futurumgame/base/ui/listeners/onclicklisteners/UnlockListener.java
-
3app/src/main/java/com/futurumgame/base/ui/listeners/onclicklisteners/UpgradeFactoryListener.java
-
6app/src/main/java/com/futurumgame/base/ui/viewholder/ResourceViewHolder.java
-
14app/src/main/java/com/futurumgame/base/ui/viewholder/UnlockableViewHolder.java
-
2app/src/main/java/com/futurumgame/base/unlockables/ResourceUnlockable.java
-
BINapp/src/main/res/drawable/ingot_base.png
-
BINapp/src/main/res/drawable/reset_button.png
-
BINapp/src/main/res/drawable/settings_button.png
-
BINapp/src/main/res/drawable/soil_icon.png
-
BINapp/src/main/res/drawable/sound_off_button.png
-
BINapp/src/main/res/drawable/sound_on_button.png
-
BINapp/src/main/res/drawable/water_icon.png
-
BINapp/src/main/res/drawable/wood_icon.png
-
35app/src/main/res/layout/activity_main.xml
-
11app/src/main/res/layout/factory_manager_view.xml
-
4app/src/main/res/layout/list_item_view.xml
-
8app/src/main/res/layout/list_price_item_view.xml
-
77app/src/main/res/layout/options_view.xml
-
18app/src/main/res/layout/resource_view.xml
-
9app/src/main/res/layout/unlock_view.xml
-
BINapp/src/main/res/raw/click.ogg
-
109app/src/test/java/com/futurumgame/base/CollectionHelperTest.java
@ -0,0 +1,63 @@ |
|||
package com.futurumgame.base.ui.activities; |
|||
|
|||
import androidx.appcompat.app.AppCompatActivity; |
|||
import android.os.Bundle; |
|||
import android.view.View; |
|||
import android.widget.Button; |
|||
import android.widget.ImageButton; |
|||
import android.widget.ImageView; |
|||
|
|||
import com.futurumgame.base.R; |
|||
import com.futurumgame.base.gameinternals.GameRoutine; |
|||
import com.futurumgame.base.gameinternals.WareHouse; |
|||
import com.futurumgame.base.ui.listeners.onclicklisteners.GoBackListener; |
|||
import com.futurumgame.base.ui.listeners.onclicklisteners.GoToViewListener; |
|||
import com.futurumgame.base.ui.listeners.onclicklisteners.HardResetListener; |
|||
import com.futurumgame.base.ui.listeners.onclicklisteners.SoundListener; |
|||
|
|||
public class OptionsViewActivity extends UpdatableViewActivity { |
|||
|
|||
@Override |
|||
protected void onCreate(Bundle savedInstanceState) { |
|||
super.onCreate(savedInstanceState); |
|||
GameRoutine.setNewCurrent(this); |
|||
allowUpdates(); |
|||
|
|||
setContentView(R.layout.options_view); |
|||
|
|||
ImageButton soundButton = findViewById(R.id.soundButton); |
|||
updateSoundButton(soundButton); |
|||
|
|||
ImageButton returnButton = findViewById(R.id.optionsReturnButton); |
|||
returnButton.setOnClickListener(GoBackListener.newListener()); |
|||
|
|||
ImageButton hardResetButton = findViewById(R.id.HardReset); |
|||
hardResetButton.setOnClickListener(HardResetListener.newListener(this)); |
|||
|
|||
soundButton.setOnClickListener(new View.OnClickListener() { |
|||
|
|||
@Override |
|||
public void onClick(View view) { |
|||
SoundListener.toggleSoundMute(); |
|||
updateSoundButton(soundButton); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
private void updateSoundButton(ImageButton soundButton) { |
|||
|
|||
if (SoundListener.muted) |
|||
{ |
|||
soundButton.setBackgroundResource(R.drawable.sound_off_button); |
|||
} |
|||
else |
|||
{ |
|||
soundButton.setBackgroundResource(R.drawable.sound_on_button); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void updateUi(WareHouse wareHouse) { |
|||
|
|||
} |
|||
} |
@ -0,0 +1,25 @@ |
|||
package com.futurumgame.base.ui.listeners.onclicklisteners; |
|||
|
|||
import android.content.Context; |
|||
import android.view.View; |
|||
|
|||
import com.futurumgame.base.gameinternals.GameRoutine; |
|||
|
|||
public class HardResetListener extends SoundListener { |
|||
|
|||
private final Context context; |
|||
|
|||
private HardResetListener(Context context) { |
|||
this.context = context; |
|||
} |
|||
|
|||
@Override |
|||
public void onClick(View v) { |
|||
super.onClick(v); |
|||
GameRoutine.requestHardReset(); |
|||
} |
|||
|
|||
public static HardResetListener newListener(Context context) { |
|||
return new HardResetListener(context); |
|||
} |
|||
} |
@ -0,0 +1,46 @@ |
|||
package com.futurumgame.base.ui.listeners.onclicklisteners; |
|||
|
|||
import android.media.SoundPool; |
|||
import android.view.View; |
|||
|
|||
import com.futurumgame.base.R; |
|||
import com.futurumgame.base.gameinternals.GameRoutine; |
|||
|
|||
public abstract class SoundListener implements View.OnClickListener, SoundPool.OnLoadCompleteListener { |
|||
|
|||
public static boolean muted = false; |
|||
|
|||
private static final float MaxVolume = 1.0f; |
|||
private static final float NormalPlayBackRate = 1.0f; |
|||
|
|||
private final SoundPool pool; |
|||
|
|||
protected SoundListener(){ |
|||
SoundPool.Builder builder = new SoundPool.Builder(); |
|||
builder.setMaxStreams(20); |
|||
pool = builder.build(); |
|||
pool.setOnLoadCompleteListener(this); |
|||
} |
|||
|
|||
public static void toggleSoundMute() { |
|||
muted = !muted; |
|||
} |
|||
|
|||
@Override |
|||
public void onClick(View v) { |
|||
|
|||
if (muted) { |
|||
return; |
|||
} |
|||
|
|||
pool.load(v.getContext(), R.raw.click, 1); |
|||
} |
|||
|
|||
@Override |
|||
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { |
|||
if(status!= 0){ |
|||
return; |
|||
} |
|||
soundPool.play(sampleId, MaxVolume,MaxVolume, 1,0, NormalPlayBackRate); |
|||
} |
|||
} |
After Width: 64 | Height: 64 | Size: 745 B |
After Width: 128 | Height: 128 | Size: 3.6 KiB |
After Width: 568 | Height: 422 | Size: 35 KiB |
After Width: 64 | Height: 64 | Size: 458 B |
After Width: 449 | Height: 449 | Size: 18 KiB |
After Width: 449 | Height: 449 | Size: 15 KiB |
After Width: 64 | Height: 64 | Size: 795 B |
After Width: 64 | Height: 64 | Size: 681 B |
@ -0,0 +1,77 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
xmlns:tools="http://schemas.android.com/tools" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="match_parent" |
|||
android:background="#131313" |
|||
tools:context=".ui.activities.OptionsViewActivity"> |
|||
|
|||
<ImageButton |
|||
android:id="@+id/soundButton" |
|||
android:layout_width="75dp" |
|||
android:layout_height="75dp" |
|||
android:background="@drawable/sound_on_button" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.217" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
app:layout_constraintVertical_bias="0.153" /> |
|||
|
|||
<ImageButton |
|||
android:id="@+id/optionsReturnButton" |
|||
android:layout_width="70dp" |
|||
android:layout_height="70dp" |
|||
android:background="@drawable/back_button" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.176" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
app:layout_constraintVertical_bias="0.927" /> |
|||
|
|||
<ImageButton |
|||
android:id="@+id/HardReset" |
|||
android:layout_width="75dp" |
|||
android:layout_height="75dp" |
|||
android:background="@drawable/reset_button" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.217" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
app:layout_constraintVertical_bias="0.339" /> |
|||
|
|||
<TextView |
|||
android:id="@+id/muteTextView" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:fontFamily="@font/muli" |
|||
android:text="Mute\nSound" |
|||
android:textAlignment="center" |
|||
android:textColor="#E5E5E5" |
|||
android:textSize="26sp" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.625" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
app:layout_constraintVertical_bias="0.152" /> |
|||
|
|||
<TextView |
|||
android:id="@+id/HardResetTextView" |
|||
android:layout_width="wrap_content" |
|||
android:layout_height="wrap_content" |
|||
android:fontFamily="@font/muli" |
|||
android:text="Hardreset" |
|||
android:textColor="#E5E5E5" |
|||
android:textSize="26sp" |
|||
app:layout_constraintBottom_toBottomOf="parent" |
|||
app:layout_constraintEnd_toEndOf="parent" |
|||
app:layout_constraintHorizontal_bias="0.718" |
|||
app:layout_constraintStart_toStartOf="parent" |
|||
app:layout_constraintTop_toTopOf="parent" |
|||
app:layout_constraintVertical_bias="0.342" /> |
|||
|
|||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -0,0 +1,109 @@ |
|||
package com.futurumgame.base; |
|||
|
|||
import com.futurumgame.base.interfaces.IMapper; |
|||
import com.futurumgame.base.util.CollectionHelper; |
|||
|
|||
import org.junit.Test; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
import static org.junit.Assert.assertEquals; |
|||
import static org.junit.Assert.assertFalse; |
|||
import static org.junit.Assert.assertTrue; |
|||
|
|||
public class CollectionHelperTest { |
|||
|
|||
@Test |
|||
public void testAddAll() { |
|||
List<String> testList1 = new ArrayList<>(Arrays.asList("Hello", "World", "or", "test")); |
|||
List<Integer> testList2 = new ArrayList<>(Arrays.asList(1, 5, -2, 0, 15)); |
|||
List<Object> testList3 = new ArrayList<>(Arrays.asList(1, 5.6, -56.2, "Hi", true)); |
|||
|
|||
CollectionHelper.addAll(testList1, "Does", "This", "Work"); |
|||
CollectionHelper.addAll(testList2, 34, 42, -42); |
|||
CollectionHelper.addAll(testList3, "17", 4); |
|||
|
|||
assertEquals("World", testList1.get(1)); |
|||
assertEquals("Does", testList1.get(4)); |
|||
|
|||
assertTrue(1 == new Integer(testList2.get(0))); |
|||
assertTrue(42 == new Integer(testList2.get(6))); |
|||
|
|||
assertTrue(5.6 == (double)testList3.get(1)); |
|||
assertTrue("17" == (String)testList3.get(5)); |
|||
|
|||
List<String> addedList = new ArrayList<>(Arrays.asList("Hi", "What's up")); |
|||
|
|||
CollectionHelper.addAll(testList1, addedList); |
|||
|
|||
assertEquals("This", testList1.get(5)); |
|||
assertEquals("Hi", testList1.get(7)); |
|||
} |
|||
|
|||
@Test |
|||
public void testAsCollection() { |
|||
Iterable<String> generatedIterable = CollectionHelper.asIterable("Hello", "World"); |
|||
List<String> generatedList = CollectionHelper.asList(generatedIterable); |
|||
|
|||
assertEquals("Hello", generatedList.get(0)); |
|||
assertEquals("World", generatedList.get(1)); |
|||
} |
|||
|
|||
@Test |
|||
public void testContains() { |
|||
List<String> testList1 = new ArrayList<>(Arrays.asList("Hello", "World", "or", "test")); |
|||
assertTrue(CollectionHelper.contains(testList1, p -> p.equals("Hello"))); |
|||
assertFalse(CollectionHelper.contains(testList1, p -> p.equals("Hi"))); |
|||
} |
|||
|
|||
@Test |
|||
public void testListEquals() { |
|||
List<String> testList1 = new ArrayList<>(Arrays.asList("Hello", "World", "or", "test")); |
|||
List<String> testList2 = new ArrayList<>(Arrays.asList("Hello", "World", "or", "test")); |
|||
List<String> testList3 = new ArrayList<>(Arrays.asList("Hi", "What's up")); |
|||
|
|||
assertTrue(CollectionHelper.sequenceEquals(testList1, testList2)); |
|||
assertFalse(CollectionHelper.sequenceEquals(testList1, testList3)); |
|||
} |
|||
|
|||
@Test |
|||
public void testToMap() { |
|||
List<String> testList1 = new ArrayList<>(Arrays.asList("Hello", "World", "or", "test")); |
|||
Map<Integer, String> generatedMap = CollectionHelper.toMap(testList1, u -> testList1.indexOf(u)); |
|||
|
|||
assertEquals("Hello", generatedMap.get(0)); |
|||
assertEquals("World", generatedMap.get(1)); |
|||
assertEquals("or", generatedMap.get(2)); |
|||
assertEquals("test", generatedMap.get(3)); |
|||
} |
|||
|
|||
@Test |
|||
public void testWhere() { |
|||
List<String> testList1 = new ArrayList<>(Arrays.asList("Hello", "World", "or", "test")); |
|||
List<String> testList2 = new ArrayList<>(Arrays.asList("Hello", "World", null, "test")); |
|||
|
|||
assertEquals(testList1, CollectionHelper.whereNotNull(testList1)); |
|||
|
|||
List<String> nullStrippedList = new ArrayList<>(Arrays.asList("Hello", "World", "test")); |
|||
assertTrue(CollectionHelper.sequenceEquals(CollectionHelper.whereNotNull(testList2), nullStrippedList)); |
|||
} |
|||
|
|||
@Test |
|||
public void testToString() { |
|||
List<String> testList1 = new ArrayList<>(Arrays.asList("Hello", "World", "or", "test")); |
|||
List<Integer> testList2 = new ArrayList<>(Arrays.asList(1, 5, -2, 0, 15)); |
|||
List<Object> testList3 = new ArrayList<>(Arrays.asList(1, 5.6, -56.2, "Hi", true)); |
|||
|
|||
String[] testArray1 = {"Hello", "World", "or", "test"}; |
|||
Object[] testArray2 = {1, 5.6, -56.2, "Hi", true}; |
|||
|
|||
assertEquals("Hello, World, or, test", CollectionHelper.toString(testList1)); |
|||
assertEquals("1, 5, -2, 0, 15", CollectionHelper.toString(testList2)); |
|||
assertEquals("1, 5.6, -56.2, Hi, true", CollectionHelper.toString(testList3)); |
|||
assertEquals("Hello, World, or, test", CollectionHelper.toString(testArray1)); |
|||
assertEquals("1, 5.6, -56.2, Hi, true", CollectionHelper.toString(testArray2)); |
|||
} |
|||
} |