Skip to content

Commit

Permalink
Added the star map library
Browse files Browse the repository at this point in the history
  • Loading branch information
fusion44 committed May 14, 2016
1 parent 3aa278b commit 34cf30b
Show file tree
Hide file tree
Showing 49 changed files with 3,094 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .idea/gradle.xml

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

1 change: 1 addition & 0 deletions .idea/modules.xml

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

3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ android {
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}

signingConfigs {
Expand Down Expand Up @@ -48,6 +49,7 @@ dependencies {
compile 'com.android.support:customtabs:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:multidex:1.0.1'

// For setting up the background task which fetches latest comm links every n times
compile 'com.google.android.gms:play-services-gcm:8.4.0'
Expand Down Expand Up @@ -86,6 +88,7 @@ dependencies {
debugCompile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
testCompile 'junit:junit:4.12'
compile project(path: ':imglib')
compile project(':mapcore')
}

apply plugin: 'com.google.gms.google-services'
1,098 changes: 1,098 additions & 0 deletions app/src/main/assets/TestFont.fnt

Large diffs are not rendered by default.

Binary file added app/src/main/assets/TestFont.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/space_background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Application;
import android.content.Context;
import android.content.ContextWrapper;
import android.support.multidex.MultiDex;
import android.util.Log;

import com.google.android.gms.analytics.GoogleAnalytics;
Expand Down Expand Up @@ -118,6 +119,12 @@ public void onCreate() {
mInstance = this;
}

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

/**
* Initializes StorIO with all necessary resolvers
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.view.Menu;
import android.view.MenuItem;

import com.badlogic.gdx.backends.android.AndroidFragmentApplication;
import com.hardsoftstudio.rxflux.action.RxError;
import com.hardsoftstudio.rxflux.dispatcher.Dispatcher;
import com.hardsoftstudio.rxflux.dispatcher.RxViewDispatch;
Expand Down Expand Up @@ -53,8 +54,8 @@
* pass those on to the currently displayed {@link Fragment}
*/
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener
, RxViewDispatch {
implements NavigationView.OnNavigationItemSelectedListener,
RxViewDispatch, AndroidFragmentApplication.Callbacks {

private static final String TRACKING_SCREEN_COMM_LINK_FRAGMENT = "CommLinkFragment";
private static final String TRACKING_SCREEN_SHIPS_FRAGMENT = "ShipsFragment";
Expand Down Expand Up @@ -134,6 +135,8 @@ protected void onCreate(Bundle savedInstanceState) {
openForumsFragment();
} else if (fragment.equals(OrgsFragment.class.getSimpleName())) {
openOrgFragment();
} else if (fragment.equals(MapFragment.class.getSimpleName())) {
openMapFragment();
}
}
} else {
Expand All @@ -148,6 +151,8 @@ protected void onCreate(Bundle savedInstanceState) {
openForumsFragment();
} else if (f.equals(OrgsFragment.class.getSimpleName())) {
openOrgFragment();
} else if (f.equals(MapFragment.class.getSimpleName())) {
openMapFragment();
}
}

Expand Down Expand Up @@ -190,6 +195,8 @@ protected void onResume() {
GtApplication.getInstance().trackScreen(TRACKING_SCREEN_FORUMS_FRAGMENT);
} else if (fragment.equals(OrgsFragment.class.getSimpleName())) {
GtApplication.getInstance().trackScreen(TRACKING_SCREEN_ORG_FRAGMENT);
} else if (fragment.equals(MapFragment.class.getSimpleName())) {
GtApplication.getInstance().trackScreen(TRACKING_SCREEN_MAPS_FRAGMENT);
}
}
registerReceiver();
Expand Down Expand Up @@ -260,7 +267,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
} else if (id == R.id.nav_orgs) {
openOrgFragment();
} else if (id == R.id.nav_starmap) {
openStarmapFragment();
openMapFragment();
} else if (id == R.id.nav_settings) {
openSettings();
}
Expand Down Expand Up @@ -390,7 +397,7 @@ private void openOrgFragment() {
/**
* Creates and shows the {@link .MapsFragment}
*/
private void openStarmapFragment() {
private void openMapFragment() {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
String simpleClassName = MapFragment.class.getSimpleName();
Expand Down Expand Up @@ -511,4 +518,8 @@ public void onRxStoresRegister() {
mForumsStore = ForumStore.get(dispatcher);
mForumsStore.register();
}

@Override
public void exit() {
}
}
38 changes: 28 additions & 10 deletions app/src/main/java/me/stammberger/galactictavern/ui/MapFragment.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
package me.stammberger.galactictavern.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.badlogic.gdx.backends.android.AndroidFragmentApplication;

import me.stammberger.galactictavern.R;
import me.stammberger.starcitizencompact.map.GtStarMap;
import timber.log.Timber;

/**
* Fragment for displaying starmap data.
* <p>
* Use the {@link MapFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class MapFragment extends Fragment {
public class MapFragment extends AndroidFragmentApplication {
public MapFragment() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @return A new instance of fragment MapFragment.
*/
public static MapFragment newInstance() {
return new MapFragment();
}
Expand All @@ -38,6 +35,27 @@ public void onCreate(Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_map, container, false);

View v = inflater.inflate(R.layout.fragment_map, container, false);
FrameLayout starMapView = (FrameLayout) v.findViewById(R.id.starMapFrameLayout);
GtStarMap gtStarMap = new GtStarMap(new GtStarMap.StatusCallback() {
@Override
public void onStartedLoading() {
Timber.d("started loading");
}

@Override
public void onFinishedLoading() {
Timber.d("finished loading");
}

@Override
public void onError(String error) {

}
});
View view = initializeForView(gtStarMap);
starMapView.addView(view);
return v;
}
}
Binary file not shown.
Binary file added app/src/main/jniLibs/arm64-v8a/libgdx.so
Binary file not shown.
Binary file not shown.
Binary file added app/src/main/jniLibs/armeabi-v7a/libgdx.so
Binary file not shown.
Binary file added app/src/main/jniLibs/armeabi/libgdx-freetype.so
Binary file not shown.
Binary file added app/src/main/jniLibs/armeabi/libgdx.so
Binary file not shown.
Binary file added app/src/main/jniLibs/x86/libgdx-freetype.so
Binary file not shown.
Binary file added app/src/main/jniLibs/x86/libgdx.so
Binary file not shown.
Binary file added app/src/main/jniLibs/x86_64/libgdx-freetype.so
Binary file not shown.
Binary file added app/src/main/jniLibs/x86_64/libgdx.so
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="me.stammberger.galactictavern.ui.MapFragment">
tools:context=".ui.MapFragment">

<FrameLayout
android:id="@+id/starMapFrameLayout"
Expand Down
30 changes: 30 additions & 0 deletions mapcore/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: "java"

buildscript {
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}

//noinspection GroovyUnusedAssignment
sourceCompatibility = 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = ["src/"]

ext {
gdxVersion = '1.9.2'
}

dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"

compile 'io.reactivex:rxjava:1.1.1'
compile 'com.google.code.gson:gson:2.6.2'
}
110 changes: 110 additions & 0 deletions mapcore/src/com/rahul/libgdx/parallax/ParallaxBackground.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.rahul.libgdx.parallax;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.rahul.libgdx.parallax.ParallaxLayer.TileMode;

/**
* A ParallaxBacground encapsulates the logic to Render ParallaxLayers.
* It owns a collection of ParallaxLayers.
* These Layers a rendered on screen showing parallax effect based on scrolling characteristics of individual layers.
* This rendering module does not owns any Batch ,you need to provide one in the draw method.
* <p>
* Also see {@link ParallaxLayer}.
*
* @author Rahul Verma
*/
public class ParallaxBackground {

/**
* this array contains the parallax scrolling layers that are drawn on the screen. Layers are rendered in the order they are present in this array.
*/
public Array<ParallaxLayer> layers;
private Matrix4 cachedProjectionView;
private Vector3 cachedPos;
private float cachedZoom;

/**
* Create a ParallaxBackground without any layers
*/
public ParallaxBackground() {
initialize();
}


/**
* Create a ParallaxBackground instance with the layers added
*
* @param layers layers to be added to the parallaxBackground
*/
public ParallaxBackground(ParallaxLayer... layers) {
initialize();
this.layers.addAll(layers);
}

private void initialize() {
layers = new Array<ParallaxLayer>();
cachedPos = new Vector3();
cachedProjectionView = new Matrix4();
}

/**
* Add the layers to the {@link #layers} array. These layers are rendered over the layers previously in the layers array
*
* @param layers layers to be added to the parallaxBackground
*/
public void addLayers(ParallaxLayer... layers) {
this.layers.addAll(layers);
}

/**
* render the layers held by this module. Of course the layers are rendered in parallax scrolling manner. The worldCamera and batch provided are unaffected by the method
*
* @param worldCamera The Orthographic WorldCamera , all layers are rendered relative to its position.
* @param batch The batch which is used to render the layers.
*/
public void draw(OrthographicCamera worldCamera, Batch batch) {
cachedProjectionView.set(worldCamera.combined);
cachedPos.set(worldCamera.position);
cachedZoom = worldCamera.zoom;


for (int i = 0; i < layers.size; i++) {
ParallaxLayer layer = layers.get(i);
Vector2 origCameraPos = new Vector2(cachedPos.x, cachedPos.y);
worldCamera.position.set(origCameraPos.scl(layer.getParallaxRatio()), cachedPos.z);
worldCamera.update();
batch.setProjectionMatrix(worldCamera.combined);
float currentX = (layer.getTileModeX().equals(TileMode.single) ? 0 : ((int) ((worldCamera.position.x - worldCamera.viewportWidth * .5f * worldCamera.zoom) / layer.getWidth())) * layer.getWidth()) - (Math.abs((1 - layer.getParallaxRatio().x) % 1) * worldCamera.viewportWidth * .5f);
do {
float currentY = (layer.getTileModeY().equals(TileMode.single) ? 0 : ((int) ((worldCamera.position.y - worldCamera.viewportHeight * .5f * worldCamera.zoom) / layer.getHeight())) * layer.getHeight()) - (((1 - layer.getParallaxRatio().y) % 1) * worldCamera.viewportHeight * .5f);
do {
if (!((worldCamera.position.x - worldCamera.viewportWidth * worldCamera.zoom * .5f > currentX + layer.getWidth()) || (worldCamera.position.x + worldCamera.viewportWidth * worldCamera.zoom * .5f < currentX) || (worldCamera.position.y - worldCamera.viewportHeight * worldCamera.zoom * .5f > currentY + layer.getHeight()) || (worldCamera.position.y + worldCamera.viewportHeight * worldCamera.zoom * .5f < currentY)))
layer.draw(batch, currentX, currentY);
currentY += layer.getHeight();
if (layer.getTileModeY().equals(TileMode.single))
break;
}
while (currentY < worldCamera.position.y + worldCamera.viewportHeight * worldCamera.zoom * .5f);
currentX += layer.getWidth();
if (layer.getTileModeX().equals(TileMode.single))
break;
}
while (currentX < worldCamera.position.x + worldCamera.viewportWidth * worldCamera.zoom * .5f);

}

worldCamera.combined.set(cachedProjectionView);
worldCamera.position.set(cachedPos);
worldCamera.zoom = cachedZoom;
worldCamera.update();
batch.setProjectionMatrix(worldCamera.combined);

}


}
Loading

0 comments on commit 34cf30b

Please sign in to comment.