Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Darktheme #50

Merged
merged 3 commits into from
Nov 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

7 changes: 1 addition & 6 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Anuto - Another Ugly Tower Defense
# Anuto - Another Ugly Tower Defense (DarkTheme)

This is a test for adding a dark theme for Anuto.

Anuto is yet another tower defense game for Android.
However it features astonishing hand-drawn graphics and a smooth gameplay.

It is [free/libre](https://www.gnu.org/philosophy/free-sw.html) and open-source software.
The license use [copyleft](https://copyleft.org/).

## Download

- [Google Play Store](https://play.google.com/store/apps/details?id=ch.logixisland.anuto)
- [F-Droid](https://f-droid.org/repository/browse/?fdid=ch.logixisland.anuto)

## How to play

Expand Down
19 changes: 19 additions & 0 deletions android-anuto-quaap.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="android-anuto-quaap" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
17 changes: 10 additions & 7 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,20 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.4.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
Expand All @@ -106,8 +105,12 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-23.4.0" level="project" />
<orderEntry type="library" exported="" name="stax-1.2.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.4.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-23.4.0" level="project" />
<orderEntry type="library" exported="" name="simple-xml-2.7.1" level="project" />
<orderEntry type="library" exported="" name="android-android-23" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.4.0" level="project" />
</component>
</module>
5 changes: 5 additions & 0 deletions app/src/main/java/ch/logixisland/anuto/GameOverFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

import java.text.DecimalFormat;

import ch.logixisland.anuto.game.GameEngine;
import ch.logixisland.anuto.game.GameManager;
import ch.logixisland.anuto.util.theme.Theme;

public class GameOverFragment extends Fragment implements GameManager.OnGameStartedListener,
GameManager.OnGameOverListener {
Expand All @@ -25,9 +27,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_game_over, container, false);

Theme theme = GameEngine.getInstance().getTheme();
txt_game_over = (TextView)v.findViewById(R.id.txt_game_over);
txt_score = (TextView)v.findViewById(R.id.txt_score);

txt_game_over.setTextColor(theme.getTextColor());
txt_score.setTextColor(theme.getTextColor());
return v;
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/ch/logixisland/anuto/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);

int themeid = getIntent().getIntExtra("theme", 0);

GameEngine.getInstance().setResources(getResources());
GameEngine.getInstance().setTheme(themeid);
GameManager.getInstance().setContext(this);
setContentView(R.layout.activity_main);

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/ch/logixisland/anuto/StatusFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
Expand All @@ -12,9 +13,11 @@
import android.widget.Button;
import android.widget.TextView;

import ch.logixisland.anuto.game.GameEngine;
import ch.logixisland.anuto.game.GameManager;
import ch.logixisland.anuto.game.data.Wave;
import ch.logixisland.anuto.util.StringUtils;
import ch.logixisland.anuto.util.theme.Theme;

public class StatusFragment extends Fragment implements GameManager.OnWaveStartedListener,
GameManager.OnCreditsChangedListener, GameManager.OnLivesChangedListener,
Expand All @@ -40,12 +43,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mHandler = new Handler();

View v = inflater.inflate(R.layout.fragment_status, container, false);
Theme theme = GameEngine.getInstance().getTheme();
v.setBackgroundColor(theme.getBackgroundColor());

txt_credits = (TextView) v.findViewById(R.id.txt_credits);
txt_lives = (TextView) v.findViewById(R.id.txt_lives);
txt_wave = (TextView) v.findViewById(R.id.txt_wave);
txt_bonus = (TextView) v.findViewById(R.id.txt_bonus);

txt_credits.setTextColor(theme.getTextColor());
txt_lives.setTextColor(theme.getTextColor());
txt_wave.setTextColor(theme.getTextColor());
txt_bonus.setTextColor(theme.getTextColor());

btn_next_wave = (Button) v.findViewById(R.id.btn_next_wave);
btn_restart = (Button) v.findViewById(R.id.btn_restart);

Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/ch/logixisland/anuto/TowerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import android.view.MotionEvent;
import android.view.View;

import ch.logixisland.anuto.game.GameEngine;
import ch.logixisland.anuto.game.GameManager;
import ch.logixisland.anuto.game.objects.Tower;
import ch.logixisland.anuto.util.theme.Theme;

public class TowerView extends View implements View.OnTouchListener {

Expand All @@ -33,7 +35,7 @@ public class TowerView extends View implements View.OnTouchListener {
public void onCreditsChanged(int credits) {
if (mTower != null) {
if (credits >= mTower.getValue()) {
mPaintText.setColor(Color.BLACK);
mPaintText.setColor(GameEngine.getInstance().getTheme().getTextColor());
} else {
mPaintText.setColor(Color.RED);
}
Expand All @@ -52,7 +54,7 @@ public TowerView(Context context, AttributeSet attrs) throws ClassNotFoundExcept

float density = context.getResources().getDisplayMetrics().density;
mPaintText = new Paint();
mPaintText.setColor(Color.BLACK);
mPaintText.setColor(GameEngine.getInstance().getTheme().getTextColor());
mPaintText.setTextAlign(Paint.Align.CENTER);
mPaintText.setTextSize(TEXT_SIZE * density);

Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/ch/logixisland/anuto/game/GameEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import ch.logixisland.anuto.util.container.ConcurrentCollectionMap;
import ch.logixisland.anuto.util.iterator.StreamIterator;
import ch.logixisland.anuto.util.math.Vector2;
import ch.logixisland.anuto.util.theme.DarkTheme;
import ch.logixisland.anuto.util.theme.Theme;

public class GameEngine {

Expand All @@ -29,7 +31,7 @@ public class GameEngine {
private final static int TARGET_FRAME_PERIOD_MS = 1000 / TARGET_FRAME_RATE;
private final static int TICKS_100MS = Math.round(TARGET_FRAME_RATE * 0.1f);

private final static int BACKGROUND_COLOR = Color.WHITE;
private int BACKGROUND_COLOR;

private final static String TAG = GameEngine.class.getSimpleName();

Expand Down Expand Up @@ -135,6 +137,7 @@ public static GameEngine getInstance() {
private final Matrix mScreenMatrix = new Matrix();
private final Matrix mScreenMatrixInverse = new Matrix();

private Theme theme;
private Resources mResources;
private final Random mRandom = new Random();

Expand All @@ -149,6 +152,8 @@ private GameEngine() {
mGameThread.start();

mGameHandler = new Handler(mGameThread.getLooper());
setTheme(Theme.getDefaultTheme());

}

/*
Expand All @@ -163,6 +168,17 @@ public void setResources(Resources res) {
mResources = res;
}

public void setTheme(int dt) {
setTheme(Theme.getTheme(dt));
}

public Theme getTheme() { return theme; }

public void setTheme(Theme theme) {
this.theme = theme;
BACKGROUND_COLOR = theme.getBackgroundColor();
}


public Random getRandom() {
return mRandom;
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/ch/logixisland/anuto/game/objects/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ch.logixisland.anuto.util.iterator.Function;
import ch.logixisland.anuto.util.math.MathUtils;
import ch.logixisland.anuto.util.math.Vector2;
import ch.logixisland.anuto.util.theme.Theme;


public abstract class Enemy extends GameObject {
Expand All @@ -31,12 +32,17 @@ public abstract class Enemy extends GameObject {
*/

private class HealthBar extends DrawObject {
private Paint mHealthBarBd;
private Paint mHealthBarBg;
private Paint mHealthBarFg;

public HealthBar() {
Theme theme = GameEngine.getInstance().getTheme();

mHealthBarBd = new Paint();
mHealthBarBd.setColor(theme.getAltBackgroundColor());
mHealthBarBg = new Paint();
mHealthBarBg.setColor(Color.BLACK);
mHealthBarBg.setColor(theme.getBackgroundColor());
mHealthBarFg = new Paint();
mHealthBarFg.setColor(Color.GREEN);
}
Expand All @@ -52,7 +58,7 @@ public void draw(Canvas canvas) {
canvas.save();
canvas.translate(getPosition().x - HEALTHBAR_WIDTH / 2f, getPosition().y + HEALTHBAR_OFFSET);

canvas.drawRect(0, 0, HEALTHBAR_WIDTH, HEALTHBAR_HEIGHT, mHealthBarBg);
canvas.drawRect(0, 0, HEALTHBAR_WIDTH, HEALTHBAR_HEIGHT, mHealthBarBd);
canvas.drawRect(0, 0, mHealth / mConfig.health * HEALTHBAR_WIDTH, HEALTHBAR_HEIGHT, mHealthBarFg);
canvas.restore();
}
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/ch/logixisland/anuto/game/objects/Sprite.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package ch.logixisland.anuto.game.objects;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import ch.logixisland.anuto.R;
import ch.logixisland.anuto.game.GameEngine;
import ch.logixisland.anuto.game.GameManager;
import ch.logixisland.anuto.game.TickTimer;
import ch.logixisland.anuto.util.math.Vector2;
import ch.logixisland.anuto.util.theme.Theme;

public class Sprite {

Expand All @@ -25,6 +36,8 @@ public class Sprite {
private static HashMap<Integer, Sprite> sSpriteCache = new HashMap<>();

public static Sprite fromResources(int id, int count) {

id = GameEngine.getInstance().getTheme().resourceMap(id);
if (sSpriteCache.containsKey(id)) {
return new Sprite(sSpriteCache.get(id));
} else {
Expand All @@ -51,6 +64,7 @@ public static Sprite fromResources(int id, int count) {
}
}


/*
------ Listener Interface ------
*/
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/ch/logixisland/anuto/menu/MenuActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.Map;

import ch.logixisland.anuto.MainActivity;
import ch.logixisland.anuto.R;
import ch.logixisland.anuto.util.theme.Theme;

public class MenuActivity extends AppCompatActivity {

Expand All @@ -18,6 +24,13 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);

Spinner dt = (Spinner)findViewById(R.id.darktheme_dd);
Map<Integer,String> themes = Theme.getThemes();

ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, themes.values().toArray(new String[0]));
dt.setAdapter(adapter);

FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().add(R.id.contentPane,levelSelectFrag).commit();
}
Expand All @@ -38,10 +51,11 @@ public void levelClicked(View view) {
default:
levelId = R.raw.level_1;
}

Spinner dt = (Spinner)findViewById(R.id.darktheme_dd);

Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(LevelSelectFragment.SELECTED_LEVEL, levelId);
intent.putExtra("theme", dt.getSelectedItemPosition());
startActivity(intent);
}
}
Loading