[go: up one dir, main page]

Skip to content

Commit

Permalink
Rework loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Externius committed Nov 24, 2017
1 parent 3526559 commit 1d18c2f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "externius.rdmg"
minSdkVersion 19
targetSdkVersion 26
versionCode 12
versionName '1.0.11'
versionCode 13
versionName '1.0.12'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
74 changes: 57 additions & 17 deletions app/src/main/java/externius/rdmg/activities/DungeonActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Random;
import java.util.Scanner;

import externius.rdmg.R;
Expand Down Expand Up @@ -96,6 +97,7 @@ public class DungeonActivity extends AppCompatActivity {
private static long mLastClickTime = 0;
private static int area;
private static Dialog dialog;
private RelativeLayout layout;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -104,15 +106,63 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
addLoadingScreen();
addScreenText();
createDungeonTask = new CreateDungeon(this);
createDungeonTask.execute();
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}

private void addScreenText() {
layout = findViewById(R.id.dungeon_layout);
TextView screenText = new TextView(this);
setScreenText(screenText);
RelativeLayout.LayoutParams params = getScreenTextLayoutParams();
screenText.setLayoutParams(params);
layout.addView(screenText);
}

@NonNull
private RelativeLayout.LayoutParams getScreenTextLayoutParams() {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
Point size = getScreenSize();
setArea(size);
params.setMargins(10, 10, 10, size.y / 12);
return params;
}

@NonNull
private Point getScreenSize() {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size;
}

private void setArea(Point size) {
if (size.x > size.y) {
area = size.y;
} else {
area = size.x;
}
}

private void setScreenText(TextView screenText) {
String[] text = getResources().getStringArray(R.array.loading_screen_gen_array);
Random random = new Random();
if (getIntent().getExtras() != null && getIntent().getExtras().getString("URI") != null) {
screenText.setText(R.string.loading_text);
} else {
screenText.setText(text[random.nextInt(text.length)]);
}
screenText.setTextColor(Color.WHITE);
}

private void addLoadingScreen() {
RelativeLayout layout = findViewById(R.id.dungeon_layout);
layout = findViewById(R.id.dungeon_layout);
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.generating_screen);
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
Expand Down Expand Up @@ -169,15 +219,14 @@ protected Object doInBackground(Void... args) {

@Override
protected void onPostExecute(Object result) {
RelativeLayout layout = activity.get().findViewById(R.id.dungeon_layout);
layout.removeAllViews(); // remove the loading screen + text view
layout.setBackgroundColor(Color.WHITE);
if (result != null) { // not a loaded dungeon
RelativeLayout layout = activity.get().findViewById(R.id.dungeon_layout);
layout.removeAllViews();
layout.addView((View) result);
addButtons(layout);
addDescription(layout, dungeonView.getRoomDescription(), dungeonView.getTrapDescription());
layout.setBackgroundColor(Color.WHITE);
} else if (loadedDungeon != null) { // its a loaded dungeon
RelativeLayout layout = activity.get().findViewById(R.id.dungeon_layout);
layout.addView(getDungeonView(true));
addButtons(layout);
addDescription(layout, loadedRoomDescription, loadedTrapDescription);
Expand Down Expand Up @@ -398,9 +447,9 @@ private static View.OnTouchListener getTouch() {
public boolean onTouch(View view, MotionEvent motionEvent) {
float x = motionEvent.getX();
float y = motionEvent.getY();
int imgSize = area / dungeonSize;
int xIndex = ((int) y / imgSize) + 1;
int yIndex = ((int) x / imgSize) + 1;
int imgSize = area / dungeonSize; // get the image size on the dungeon tiles
int xIndex = ((int) y / imgSize) + 1; // get the dungeonTile 2D array x index
int yIndex = ((int) x / imgSize) + 1; // get the dungeonTile 2D array y index
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Textures texture = loadedDungeon[xIndex][yIndex].getTexture();
switch (texture) {
Expand Down Expand Up @@ -699,14 +748,6 @@ private static DungeonMapView getDungeonView(Boolean load) {
if (activity.get() == null) {
return null;
}
Display display = activity.get().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
if (size.x > size.y) {
area = size.y;
} else {
area = size.x;
}
dungeonView = new DungeonMapView(activity.get());
dungeonView.setDungeonHeight(area);
dungeonView.setDungeonWidth(area);
Expand Down Expand Up @@ -736,7 +777,6 @@ private static DungeonMapView getDungeonView(Boolean load) {
return dungeonView;
}


private static void addDescription(RelativeLayout layout, List<RoomDescription> roomDescription, List<TrapDescription> trapDescription) {
List<TextView> rooms = getRoomTextViews(layout, roomDescription);
for (int i = 4; i < rooms.size(); i += 4) { // 4 because the first 4 manually added
Expand Down
Binary file modified app/src/main/res/drawable-nodpi/generating_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
<string name="delete_confirmation_single_text">Do you want to delete this dungeon?</string>
<string name="all_deleted">All saved dungeons deleted</string>
<string name="selected_deleted">Dungeon deleted</string>
<string name="loading_text">Loading…</string>
<string-array name="loading_screen_gen_array">
<item>Generating…</item>
<item>Work, work, work…</item>
<item>During the construction of your dungeon 3 dwarfs lost their job on account of automation…</item>
<item>No goblins were harmed during the making of this dungeon…</item>
</string-array>
<string name="about_content">Have an entire dungeon up your sleeve! Add parameters, generate with one click!\n\n
You can find the source code at GitHub: \n https://github.com/externius/DungeonMap\n\n
Please feel free to contact me if you have any recommendation at t.andras@outlook.com. </string>
Expand Down

0 comments on commit 1d18c2f

Please sign in to comment.