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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
| public class MenuScreen extends AbstractGameScreen {
private Stage stage; private Skin snakeSkin; private Skin defaultSkin;
private Image imgBackground; private Image imgLogo; private Button endlessModel; private Button teamModel; private Button challengeModel; private Button robcoinModel; private Button setting;
private Window winSetting; private CheckBox chkSound; private CheckBox chkMusic; private CheckBox leftOp; private CheckBox rightOp; private TextButton btnWinSave; private TextButton btnWinCancel;
private boolean debugEnable = false;
public MenuScreen(DirectedGame game) { super(game); }
@Override public void show() { GamePreferences.instance.load(); stage = new Stage(new StretchViewport(Constants.VIEWPORT_GUI_WIDTH, Constants.VIEWPORT_GUI_HEIGHT)); buildStage(); }
private void buildStage() { snakeSkin = new Skin(Gdx.files.internal(Constants.SKIN_TOUCHPAD_UI), new TextureAtlas(Gdx.files.internal(Constants.TEXTURE_ATLAS_TOUCHPAD_UI))); defaultSkin = new Skin(Gdx.files.internal(Constants.SKIN_LIBGDX_UI), new TextureAtlas(Constants.TEXTURE_ATLAS_LIBGDX_UI)); Table layerBackground = buildBackgroundLayer(); Table layerLogo = buildLogoLayer(); Table layerGame = buildGameModelLayer(); Table layerSetting = buildSettingLayer(); Table layerSettingWin = buildSettingWindowLayer();
stage.clear(); Stack stack = new Stack(); stage.addActor(stack); stack.setSize(Constants.VIEWPORT_GUI_WIDTH, Constants.VIEWPORT_GUI_HEIGHT); stack.add(layerBackground); stack.add(layerLogo); stack.add(layerGame); stack.add(layerSetting); stage.addActor(layerSettingWin); }
private Table buildBackgroundLayer() { Table layer = new Table(); imgBackground = new Image(snakeSkin, "home_bg"); layer.add(imgBackground); return layer; }
private Table buildLogoLayer() { Table layer = new Table(); layer.center().top(); imgLogo = new Image(snakeSkin, "snake_name_icon"); imgLogo.setOrigin(imgLogo.getWidth() / 2, imgLogo.getHeight() / 2); imgLogo.setScale(0.5f); layer.add(imgLogo); if (debugEnable) layer.debug(); return layer; }
private Table buildGameModelLayer() { Table layer = new Table(); layer.center(); endlessModel = new Button(snakeSkin, "endless"); layer.add(endlessModel).width(100).height(140).padLeft(5); teamModel = new Button(snakeSkin, "team"); layer.add(teamModel).width(100).height(140).padLeft(5); Table childTable = new Table(); challengeModel = new Button(snakeSkin, "challenge"); childTable.add(challengeModel).width(120).height(70); childTable.row(); robcoinModel = new Button(snakeSkin, "robcoin"); childTable.add(robcoinModel).width(120).height(70); layer.add(childTable).padLeft(5); if (debugEnable) layer.debug();
endlessModel.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { playGame(); } }); teamModel.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { playGame(); } }); challengeModel.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { playGame(); } }); robcoinModel.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { playGame(); } }); return layer; }
private void playGame() { ScreenTransition transition = ScreenTransitionFade.init(0.75f); game.setScreen(new GameScreen(game), transition); }
private Table buildSettingLayer() { Table layer = new Table(); layer.top().right(); setting = new Button(snakeSkin, "setting"); layer.add(setting).padRight(20).padTop(20); setting.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { showOptionsWindow(true, true); } }); return layer; }
private Table buildSettingWindowLayer() { winSetting = new Window("Setting", defaultSkin); winSetting.center(); winSetting.add(buildSetWinAudioSettings()).row(); winSetting.add(buildSetWinOpreateSettings()).row(); winSetting.add(buildWinBtn()); showOptionsWindow(false, false); winSetting.pack(); winSetting.setPosition((Constants.VIEWPORT_GUI_WIDTH - winSetting.getWidth()) / 2, (Constants.VIEWPORT_GUI_HEIGHT - winSetting.getHeight()) / 2); return winSetting; }
private Table buildSetWinAudioSettings() { Table table = new Table(); table.pad(10, 10, 0, 10); table.add(new Label("Audio", snakeSkin, "default-font", Color.RED)).colspan(3); table.row(); chkSound = new CheckBox("", defaultSkin); table.add(chkSound).padLeft(10); table.add(new Label("Sound", defaultSkin)).padLeft(5); chkMusic = new CheckBox("", defaultSkin); table.add(chkMusic).padLeft(10); table.add(new Label("Music", defaultSkin)).padLeft(5); chkSound.setChecked(GamePreferences.instance.sound); chkMusic.setChecked(GamePreferences.instance.music); return table; }
private Table buildSetWinOpreateSettings() { Table table = new Table(); table.pad(10, 10, 0, 10); table.add(new Label("Operation", snakeSkin, "default-font", Color.RED)).colspan(3); table.row(); leftOp = new CheckBox("", defaultSkin); table.add(leftOp).padLeft(10); table.add(new Label("Left", defaultSkin)).padLeft(5); rightOp = new CheckBox("", defaultSkin); table.add(rightOp).padLeft(10); table.add(new Label("Right", defaultSkin)).padLeft(5); ButtonGroup<CheckBox> buttonGroup = new ButtonGroup<CheckBox>(); buttonGroup.add(leftOp, rightOp); leftOp.setChecked(GamePreferences.instance.touchPadLeft); rightOp.setChecked(!GamePreferences.instance.touchPadLeft); return table; }
private Table buildWinBtn() { Table tbl = new Table(); Label lbl = null; lbl = new Label("", defaultSkin); lbl.setColor(0.75f, 0.75f, 0.75f, 1); lbl.setStyle(new Label.LabelStyle(lbl.getStyle())); lbl.getStyle().background = defaultSkin.newDrawable("white"); tbl.add(lbl).colspan(2).height(1).width(220).pad(0, 0, 0, 1); tbl.row(); lbl = new Label("", defaultSkin); lbl.setColor(0.5f, 0.5f, 0.5f, 1); lbl.setStyle(new Label.LabelStyle(lbl.getStyle())); lbl.getStyle().background = defaultSkin.newDrawable("white"); tbl.add(lbl).colspan(2).height(1).width(220).pad(0, 1, 5, 0); tbl.row(); btnWinSave = new TextButton("Save", defaultSkin); tbl.add(btnWinSave).padRight(30); btnWinSave.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { onSaveClicked(); } }); btnWinCancel = new TextButton("Cancel", defaultSkin); tbl.add(btnWinCancel); btnWinCancel.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { showOptionsWindow(false, false); } }); return tbl; }
private void onSaveClicked() { showOptionsWindow(false, false); saveSettings(); }
private void saveSettings() { GamePreferences prefs = GamePreferences.instance; prefs.sound = chkSound.isChecked(); prefs.music = chkMusic.isChecked(); prefs.touchPadLeft = leftOp.isChecked(); prefs.save(); }
@Override public void render(float delta) { Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); stage.act(delta); stage.draw(); }
@Override public void resize(int width, int height) { stage.getViewport().update(width, height, true); }
@Override public void hide() { stage.dispose(); snakeSkin.dispose(); defaultSkin.dispose(); }
@Override public void pause() {
}
@Override public InputProcessor getInputProcessor() { return stage; }
public void showOptionsWindow(boolean visible, boolean animated) { float alphaTo = visible ? 0.8f : 0.0f; float duration = animated ? 1.0f : 0.0f; final Touchable touchEnable = visible ? Touchable.enabled : Touchable.disabled; winSetting.addAction(sequence(touchable(touchEnable), alpha(alphaTo, duration))); } }
|