/
JmESurfaceViewExample.java
123 lines (107 loc) · 5.91 KB
/
JmESurfaceViewExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.myGame.JMESurfaceViewExampleActivity;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.myGame.JmEGamePadExample.JmeGame;
import com.myGame.R;
import com.myGame.SystemVisibilityUI;
import com.scrappers.superiorExtendedEngine.gamePad.ControlButtonsView;
import com.scrappers.superiorExtendedEngine.jmeSurfaceView.dialog.OptionPane;
import com.scrappers.superiorExtendedEngine.jmeSurfaceView.JmeSurfaceView;
import com.scrappers.superiorExtendedEngine.jmeSurfaceView.splashScreen.SplashScreen;
import com.scrappers.superiorExtendedEngine.misc.GullWing;
public class JmESurfaceViewExample extends AppCompatActivity {
private JmeSurfaceView jmESurfaceView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
final JmeGame jmeGame=new JmeGame(this);
jmESurfaceView=findViewById(R.id.jmeSurfaceView);
jmESurfaceView.setIgnoreAssertions(true);
jmESurfaceView.setEglBitsPerPixel(24);
jmESurfaceView.setEglAlphaBits(0);
jmESurfaceView.setEglDepthBits(16);
jmESurfaceView.setEglSamples(0);
jmESurfaceView.setEglStencilBits(0);
jmESurfaceView.setFrameRate(-1);
jmESurfaceView.setOnExceptionThrown(System.out::println);
SplashScreen splashScreen =new SplashScreen(this,jmESurfaceView);
splashScreen.setOnSplashScreenDisplayed((splashScreen1)->{
ControlButtonsView.GamePadSoundEffects gamePadSoundEffects=new ControlButtonsView.GamePadSoundEffects(JmESurfaceViewExample.this);
gamePadSoundEffects.initializeSoundEffects();
gamePadSoundEffects.playEffect(R.raw.intro);
});
splashScreen.displayProgressedSplash();
splashScreen.getSplashScreen().setBackground(ContextCompat.getDrawable(this,R.mipmap.power1));
jmESurfaceView.setOnRendererCompleted(application -> {
splashScreen.getSplashScreen().animate().
setDuration(1000).
rotation(90).
withEndAction(splashScreen::hideSplashScreen);
(findViewById(R.id.gameStickView)).setVisibility(View.VISIBLE);
(findViewById(R.id.speedometer)).setVisibility(View.VISIBLE);
(findViewById(R.id.gamePadbtns)).setVisibility(View.VISIBLE);
findViewById(R.id.steeringWheel).setVisibility(View.VISIBLE);
((GullWing)findViewById(R.id.steeringWheel)).getHorn().setOnClickListener(v -> {
ControlButtonsView.GamePadSoundEffects gamePadSoundEffects=new ControlButtonsView.GamePadSoundEffects(JmESurfaceViewExample.this);
gamePadSoundEffects.initializeSoundEffects();
gamePadSoundEffects.playEffect(R.raw.horn);
});
});
jmESurfaceView.setSimpleApplication(jmeGame);
jmESurfaceView.startRenderer(100);
// ImageView pause=findViewById(R.id.pause);
// pause.setOnClickListener(v -> {
// final OptionPane optionPane=new OptionPane(JmESurfaceViewExample.this);
// optionPane.showDialog(R.layout.dialog_exception, Gravity.CENTER);
// optionPane.getAlertDialog().getWindow().setBackgroundDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.dialog_exception_background));
// EditText errorContainer=optionPane.getInflater().findViewById(R.id.errorText);
// errorContainer.setText("Are You sure ?");
// ((Button)optionPane.getInflater().findViewById(R.id.closeApp)).setText("yes");
// ((Button)optionPane.getInflater().findViewById(R.id.ignoreError)).setText("no");
// optionPane.getInflater().findViewById(R.id.closeApp).setOnClickListener(
// view -> {
// optionPane.getAlertDialog().dismiss();
// jmESurfaceView.getSimpleApplication().stop(jmESurfaceView.isGLThreadPaused());
// jmESurfaceView.getSimpleApplication().destroy();
// finish();
// });
// optionPane.getInflater().findViewById(R.id.ignoreError).setOnClickListener(view -> optionPane.getAlertDialog().dismiss());
//
// });
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
SystemVisibilityUI systemVisibilityUI=new SystemVisibilityUI(JmESurfaceViewExample.this);
systemVisibilityUI.setGameMode();
}
@SuppressLint("SetTextI18n")
@Override
public void onBackPressed() {
final OptionPane optionPane=new OptionPane(JmESurfaceViewExample.this);
optionPane.showDialog(R.layout.dialog_exception, Gravity.CENTER);
optionPane.getAlertDialog().getWindow().setBackgroundDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.dialog_exception_background));
EditText errorContainer=optionPane.getInflater().findViewById(R.id.errorText);
errorContainer.setText("Are You sure ?");
((Button)optionPane.getInflater().findViewById(R.id.closeApp)).setText("yes");
((Button)optionPane.getInflater().findViewById(R.id.ignoreError)).setText("no");
optionPane.getInflater().findViewById(R.id.closeApp).setOnClickListener(
view -> {
optionPane.getAlertDialog().dismiss();
jmESurfaceView.getSimpleApplication().stop(jmESurfaceView.isGLThreadPaused());
jmESurfaceView.getSimpleApplication().destroy();
finish();
});
optionPane.getInflater().findViewById(R.id.ignoreError).setOnClickListener(view -> optionPane.getAlertDialog().dismiss());
}
}