Commit bd672c71 authored by Matyáš Latner's avatar Matyáš Latner

Výběr obtížnosti při spuštění hry bez přihlášeného uživatele

parent 0fe3408c
......@@ -83,6 +83,7 @@
<string name="difficulty_easy">Lehká</string>
<string name="difficulty_normal">Střední</string>
<string name="difficulty_hard">Těžká</string>
<string name="difficultydialog_question">Vyberte obtížnost hry</string>
<!-- COMMON DIALOG -->
<string name="dialog_question_yes">Ano</string>
......
......@@ -56,9 +56,11 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cz.nic.tablexia.R;
......@@ -81,6 +83,7 @@ import cz.nic.tablexia.trophy.GameTrophy;
import cz.nic.tablexia.trophy.TrophyEnum;
import cz.nic.tablexia.trophy.UserTrophyDefinition;
import cz.nic.tablexia.util.BugSenseHelper;
import cz.nic.tablexia.widget.TablexiaDialog;
import cz.nic.tablexia.widget.TablexiaDrawerLayout;
import cz.nic.tablexia.widget.TablexiaQuestionBannerDialog;
......@@ -115,6 +118,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
private static final String GAMEMANAGER_KEY = "gamemanager";
protected GameManager gameManager;
private GameDifficulty gameDifficulty;
private GamesDefinition gamesDefinition;
private Rectangle hider;
private Music gameMusic;
......@@ -411,7 +415,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
}
}
lowProfileMode();
showLoadingScreen();
loadGameDifficulty();
}
@Override
......@@ -723,14 +727,107 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
}
/* //////////////////////////////////////////// DIFFICULTY */
/**
* Dialog for choosing difficulty
*
* @author Matyáš Latner
*/
public static class DifficultyChooser extends TablexiaDialog {
public DifficultyChooser() {
super();
setCancelable(false);
}
@Override
protected void prepareDialogContent(LayoutInflater inflater, ViewGroup contentView) {
super.prepareDialogContent(inflater, contentView);
addDifficultySelectorView(inflater, contentView);
}
@Override
protected int getTextResource() {
return R.string.difficultydialog_question;
}
protected void addDifficultySelectorView(LayoutInflater inflater, ViewGroup contentView) {
LinearLayout difficultyButtonsContainer = new LinearLayout(getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = 100;
difficultyButtonsContainer.setLayoutParams(params);
for (final GameDifficulty gameDifficulty : GameDifficulty.values()) {
final Button difficultyButton = new Button(getActivity());
difficultyButton.setBackgroundResource(R.drawable.button_blank_green);
difficultyButton.setText(gameDifficulty.getDescriptionResourceId());
difficultyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
difficultyButton.setSelected(true);
GameActivity gameActivity = (GameActivity)getActivity();
gameActivity.selectDifficulty(gameDifficulty);
gameActivity.getSoundControl().playSound(PermanentSounds.BUTTON_SOUND, false);
DifficultyChooser.this.dismiss();
}
});
difficultyButtonsContainer.addView(difficultyButton);
}
contentView.addView(difficultyButtonsContainer);
}
}
/**
* Try to load difficulty from intent.
* If difficulty is not set in intent opens difficulty chooser dialog.
* @return
*/
private void loadGameDifficulty() {
GameDifficulty difficulty = GameDifficulty.extractFromIntentExtra(getIntent());
if (difficulty != null) {
selectDifficulty(difficulty);
} else {
new DifficultyChooser().show(getFragmentManager(), null);
}
}
/**
* Method for selecting difficulty from difficulty dialog.
* Notify all paused threads in difficulty getter waiting for difficulty selection.
*
* @param gameDifficulty
*/
private void selectDifficulty(GameDifficulty gameDifficulty) {
this.gameDifficulty = gameDifficulty;
synchronized (this) {
this.notifyAll();
}
showLoadingScreen();
}
/**
* Returns current game difficulty
* Returns current game difficulty.
* If difficulty is not set wait until is difficulty set.
*
* @return current game difficulty
*/
protected GameDifficulty getDifficulty() {
return GameDifficulty.extractFromIntentExtra(getIntent());
if (gameDifficulty == null) {
synchronized (this) {
try {
this.wait();
} catch (InterruptedException e) {
Log.e(GameActivity.class.getName(), "Cannot pause thread!", e);
}
}
}
return gameDifficulty;
}
/* //////////////////////////////////////////// MUSIC */
......
......@@ -125,10 +125,11 @@ public enum GameDifficulty {
Bundle extras = intent.getExtras();
if (extras != null) {
Serializable difficulty = extras.getSerializable(getIntentKey());
return difficulty != null ? (GameDifficulty) difficulty : null;
} else {
return GameDifficulty.EASY;
if (difficulty != null) {
return (GameDifficulty) difficulty;
}
}
return null;
}
}
......@@ -332,7 +332,7 @@ public class ResourceManager {
}
private enum BackgroundImage {
private static enum BackgroundImage {
NEWSSTAND_S1(GameDifficulty.EASY, 512, 510, "newsstand_s1.png", "newsstand_s1_bottom.png", "door_background_s1.png"),
NEWSSTAND_S2(GameDifficulty.EASY, 1024, 800, "newsstand_s2.png", "newsstand_s2_bottom.png", "door_background_s2.png"),
......
......@@ -75,10 +75,10 @@ public abstract class TablexiaDialog extends DialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(getLayourId(), null);
View backgroundView = view.findViewById(R.id.tablexiadialog_content);
ViewGroup backgroundView = (ViewGroup) view.findViewById(R.id.tablexiadialog_content);
backgroundView.setBackgroundResource(getBackgroundResource());
prepareDialogContent(inflater, (ViewGroup) view.findViewById(R.id.tablexiadialog_content));
prepareDialogContent(inflater, backgroundView);
view.setOnClickListener(new OnClickListener() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment