refactored gui

This commit is contained in:
Raybz@Raybz 2013-05-17 12:57:49 +02:00
parent 6e786112de
commit 665e11b6c2
13 changed files with 492 additions and 133 deletions

View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui;
import com.jme3.math.Vector2f;
import org.wyrez.shootingstars.gui.controls.PanelBase;
import org.wyrez.shootingstars.gui.listener.GameListener;
import tonegod.gui.controls.windows.Panel;
import tonegod.gui.core.Screen;
/**
*
* @author Darth Affe
*/
public class GameGUI extends Panel {
private GameListener listener;
public GameGUI(Screen screen, GameListener listener) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
this.listener = listener;
this.setIgnoreMouse(true);
this.setIsVisible(false);
create();
this.resize(screen.getWidth(), screen.getHeight(), Borders.SE);
}
private void create() {
//Panel panel = new PanelBase(screen, new Vector2f(15, 15), new Vector2f(800, 500));
//panel.setIgnoreMouse(true);
//this.addChild(panel);
}
public void attach() {
screen.addElement(this);
}
public void detach() {
screen.removeElement(this);
}
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui;
/**
*
* @author Darth Affe
*/
public interface Gui {
public void attach();
public void detach();
}

View File

@ -0,0 +1,108 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui;
import com.jme3.font.BitmapFont;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.controls.IndicatorBase;
import org.wyrez.shootingstars.gui.controls.PanelBase;
import org.wyrez.shootingstars.gui.listener.LoadingListener;
import org.wyrez.shootingstars.states.util.LoadingProgress;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.extras.Indicator;
import tonegod.gui.controls.text.Label;
import tonegod.gui.controls.windows.Panel;
import tonegod.gui.core.Screen;
/**
*
* @author Darth Affe
*/
public class LoadingGui extends Panel {
private LoadingListener listener;
private Label lblStatus;
private Indicator indProgress;
private Button btnStart;
public LoadingGui(Screen screen, LoadingListener listener) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
this.listener = listener;
this.setIgnoreMouse(true);
this.setIsVisible(false);
create();
this.resize(screen.getWidth(), screen.getHeight(), Borders.SE);
}
private void create() {
Panel panel = new PanelBase(screen, new Vector2f(15, 15), new Vector2f(800, 500));
panel.setIgnoreMouse(true);
indProgress = new IndicatorBase(screen, new Vector2f(360f, 360f),
new Vector2f(200f, 30f), Indicator.Orientation.HORIZONTAL);
indProgress.setDisplayValues();
indProgress.setMaxValue(LoadingProgress.getProgressCount());
indProgress.setIndicatorColor(ColorRGBA.Black);
lblStatus = new Label(screen, new Vector2f(360f, 400f), new Vector2f(200f, 30f));
lblStatus.setTextAlign(BitmapFont.Align.Center);
btnStart = new ButtonBase(screen, new Vector2f(360f, 360f),
new Vector2f(200f, 30f)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
listener.startGame();
}
};
btnStart.setText("Start Game");
btnStart.setTextAlign(BitmapFont.Align.Center);
panel.addChild(indProgress);
panel.addChild(lblStatus);
panel.addChild(btnStart);
this.addChild(panel);
}
public void attach() {
screen.addElement(this);
}
public void detach() {
screen.removeElement(this);
}
public void updateProgress(LoadingProgress progress) {
lblStatus.setText(progress.getText());
indProgress.setCurrentValue(progress.getValue());
}
public void setLoadingStart() {
btnStart.hide();
indProgress.show();
lblStatus.show();
}
public void setLoadingDone() {
btnStart.show();
indProgress.hide();
lblStatus.hide();
}
}

View File

@ -0,0 +1,78 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f;
import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.controls.PanelBase;
import org.wyrez.shootingstars.gui.listener.MenuListener;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.windows.Panel;
import tonegod.gui.core.Screen;
/**
*
* @author Darth Affe
*/
public class MenuGUI extends Panel implements Gui {
private MenuListener listener;
public MenuGUI(Screen screen, MenuListener listener) {
super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
this.listener = listener;
this.setIgnoreMouse(true);
this.setIsVisible(false);
create();
this.resize(screen.getWidth(), screen.getHeight(), Borders.SE);
}
private void create() {
Panel panel = new PanelBase(screen, new Vector2f(15, 15), new Vector2f(800, 500));
panel.setIgnoreMouse(true);
Button btnExit = new ButtonBase(screen, new Vector2f(600, 400), new Vector2f(120, 40)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
listener.exitGame();
}
};
btnExit.setText("Exit");
Button btnStart = new ButtonBase(screen, new Vector2f(600, 300), new Vector2f(120, 40)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
listener.startGame();
}
};
btnStart.setText("Start");
panel.addChild(btnStart);
panel.addChild(btnExit);
this.addChild(panel);
}
public void attach() {
screen.addElement(this);
}
public void detach() {
screen.removeElement(this);
}
}

View File

@ -14,66 +14,54 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui;
package org.wyrez.shootingstars.gui.controls;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector4f;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.buttons.ButtonAdapter;
import tonegod.gui.core.Screen;
/**
*
* @author Darth Affe
*/
public class ButtonBase extends Button {
public class ButtonBase extends ButtonAdapter {
public ButtonBase(Screen screen, Vector2f position) {
super(screen, position);
init();
}
public ButtonBase(Screen screen, Vector2f position, Vector2f dimensions) {
super(screen, position, dimensions);
init();
}
public ButtonBase(Screen screen, Vector2f position, Vector2f dimensions, Vector4f resizeBorders, String defaultImg) {
super(screen, position, dimensions, resizeBorders, defaultImg);
init();
}
public ButtonBase(Screen screen, String UID, Vector2f position) {
super(screen, UID, position);
init();
}
public ButtonBase(Screen screen, String UID, Vector2f position, Vector2f dimensions) {
super(screen, UID, position, dimensions);
init();
}
public ButtonBase(Screen screen, String UID, Vector2f position, Vector2f dimensions, Vector4f resizeBorders, String defaultImg) {
super(screen, UID, position, dimensions, resizeBorders, defaultImg);
init();
}
@Override
public void onButtonMouseLeftDown(MouseButtonEvent evt, boolean toggled) {
}
@Override
public void onButtonMouseRightDown(MouseButtonEvent evt, boolean toggled) {
}
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
}
@Override
public void onButtonMouseRightUp(MouseButtonEvent evt, boolean toggled) {
}
@Override
public void onButtonFocus(MouseMotionEvent evt) {
}
@Override
public void onButtonLostFocus(MouseMotionEvent evt) {
private void init() {
// this.setScaleNS(true);
//this.setScaleEW(true);
}
}

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui;
package org.wyrez.shootingstars.gui.controls;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector4f;
@ -29,26 +29,39 @@ public class IndicatorBase extends Indicator {
public IndicatorBase(Screen screen, Vector2f position, Orientation orientation) {
super(screen, position, orientation);
init();
}
public IndicatorBase(Screen screen, Vector2f position, Vector2f dimensions, Orientation orientation) {
super(screen, position, dimensions, orientation);
init();
}
public IndicatorBase(Screen screen, Vector2f position, Vector2f dimensions, Vector4f resizeBorders, String defaultImg, Orientation orientation) {
super(screen, position, dimensions, resizeBorders, defaultImg, orientation);
init();
}
public IndicatorBase(Screen screen, String UID, Vector2f position, Orientation orientation) {
super(screen, UID, position, orientation);
init();
}
public IndicatorBase(Screen screen, String UID, Vector2f position, Vector2f dimensions, Orientation orientation) {
super(screen, UID, position, dimensions, orientation);
init();
}
public IndicatorBase(Screen screen, String UID, Vector2f position, Vector2f dimensions, Vector4f resizeBorders, String defaultImg, Orientation orientation) {
super(screen, UID, position, dimensions, resizeBorders, defaultImg, orientation);
init();
}
private void init() {
this.setScaleNS(true);
this.setScaleEW(true);
this.setDockE(true);
this.setDockS(true);
}
@Override

View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui.controls;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector4f;
import tonegod.gui.controls.windows.Panel;
import tonegod.gui.core.Screen;
/**
*
* @author Darth Affe
*/
public class PanelBase extends Panel {
public PanelBase(Screen screen, Vector2f position) {
super(screen, position);
init();
}
public PanelBase(Screen screen, Vector2f position, Vector2f dimensions) {
super(screen, position, dimensions);
init();
}
public PanelBase(Screen screen, Vector2f position, Vector2f dimensions, Vector4f resizeBorders, String defaultImg) {
super(screen, position, dimensions, resizeBorders, defaultImg);
init();
}
public PanelBase(Screen screen, String UID, Vector2f position) {
super(screen, UID, position);
init();
}
public PanelBase(Screen screen, String UID, Vector2f position, Vector2f dimensions) {
super(screen, UID, position, dimensions);
init();
}
public PanelBase(Screen screen, String UID, Vector2f position, Vector2f dimensions, Vector4f resizeBorders, String defaultImg) {
super(screen, UID, position, dimensions, resizeBorders, defaultImg);
init();
}
private void init() {
this.setScaleEW(true);
this.setScaleNS(true);
this.setDockE(true);
this.setDockS(true);
}
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui.listener;
/**
*
* @author Darth Affe
*/
public interface GameListener {
}

View File

@ -0,0 +1,26 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui.listener;
/**
*
* @author Darth Affe
*/
public interface LoadingListener {
public void startGame();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (C) 2013 Darth Affe <http://wyrez.org> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.wyrez.shootingstars.gui.listener;
/**
*
* @author Darth Affe
*/
public interface MenuListener {
public void exitGame();
public void startGame();
}

View File

@ -17,10 +17,39 @@
package org.wyrez.shootingstars.states;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.scene.Node;
import org.wyrez.shootingstars.gui.GameGUI;
import org.wyrez.shootingstars.gui.listener.GameListener;
import tonegod.gui.core.Screen;
/**
*
* @author Darth Affe
*/
public class GameState extends AbstractAppState {
public class GameState extends AbstractAppState implements GameListener {
private StateManager stateManager;
private Node rootNode;
private GameGUI gui;
public GameState(Node rootNode, Screen screen, StateManager stateManager) {
this.rootNode = rootNode;
this.gui = new GameGUI(screen, this);
this.stateManager = stateManager;
}
@Override
public void stateAttached(AppStateManager stateManager) {
gui.attach();
}
@Override
public void stateDetached(AppStateManager stateManager) {
gui.detach();
}
@Override
public void update(float tpf) {
}
}

View File

@ -18,83 +18,42 @@ package org.wyrez.shootingstars.states;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.font.BitmapFont;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import org.wyrez.shootingstars.gui.ButtonBase;
import org.wyrez.shootingstars.gui.IndicatorBase;
import org.wyrez.shootingstars.gui.LoadingGui;
import org.wyrez.shootingstars.gui.listener.LoadingListener;
import org.wyrez.shootingstars.states.util.LoadingProgress;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.extras.Indicator;
import tonegod.gui.controls.text.Label;
import tonegod.gui.controls.windows.Panel;
import tonegod.gui.core.Screen;
/**
*
* @author Darth Affe
*/
public class LoadingState extends AbstractAppState {
public class LoadingState extends AbstractAppState implements LoadingListener {
private StateManager stateManager;
private Screen screen;
private Panel loadingPanel;
private Label lblStatus;
private Indicator indProgress;
private Button btnStart;
private LoadingGui gui;
private LoadingProgress currentProgress;
public LoadingState(Screen screen, StateManager stateManager) {
this.screen = screen;
this.stateManager = stateManager;
createGUI();
}
private void createGUI() {
loadingPanel = new Panel(screen, new Vector2f(15, 15), new Vector2f(800, 500));
loadingPanel.setIgnoreMouse(true);
indProgress = new IndicatorBase(screen, new Vector2f(360f, 360f),
new Vector2f(200f, 30f), Indicator.Orientation.HORIZONTAL);
indProgress.setDisplayValues();
indProgress.setMaxValue(LoadingProgress.getProgressCount());
indProgress.setIndicatorColor(ColorRGBA.Black);
lblStatus = new Label(screen, new Vector2f(360f, 400f), new Vector2f(200f, 30f));
lblStatus.setTextAlign(BitmapFont.Align.Center);
btnStart = new ButtonBase(screen, new Vector2f(360f, 360f),
new Vector2f(200f, 30f)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
startGame();
}
};
btnStart.setText("Start Game");
btnStart.setTextAlign(BitmapFont.Align.Center);
loadingPanel.addChild(indProgress);
loadingPanel.addChild(lblStatus);
loadingPanel.addChild(btnStart);
this.gui = new LoadingGui(screen, this);
}
@Override
public void stateAttached(AppStateManager stateManager) {
currentProgress = LoadingProgress.START;
screen.addElement(loadingPanel);
gui.attach();
}
@Override
public void stateDetached(AppStateManager stateManager) {
screen.removeElement(loadingPanel);
gui.detach();
}
@Override
public void update(float tpf) {
switch (currentProgress) {
case START:
setLoadingStart();
gui.setLoadingStart();
currentProgress = LoadingProgress.ANALYSE_LOW_BAND;
break;
case ANALYSE_LOW_BAND:
@ -110,10 +69,10 @@ public class LoadingState extends AbstractAppState {
currentProgress = LoadingProgress.DONE;
break;
case DONE:
setLoadingDone();
gui.setLoadingDone();
break;
}
updateProgress(currentProgress);
gui.updateProgress(currentProgress);
}
private void analyseLowBand() {
@ -140,24 +99,7 @@ public class LoadingState extends AbstractAppState {
}
}
private void setLoadingStart() {
btnStart.hide();
indProgress.show();
lblStatus.show();
}
private void setLoadingDone() {
btnStart.show();
indProgress.hide();
lblStatus.hide();
}
private void startGame() {
public void startGame() {
stateManager.setState(State.GAME);
}
private void updateProgress(LoadingProgress progress) {
lblStatus.setText(progress.getText());
indProgress.setCurrentValue(progress.getValue());
}
}

View File

@ -18,69 +18,41 @@ package org.wyrez.shootingstars.states;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f;
import org.wyrez.shootingstars.gui.ButtonBase;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.windows.Panel;
import org.wyrez.shootingstars.gui.Gui;
import org.wyrez.shootingstars.gui.MenuGUI;
import org.wyrez.shootingstars.gui.listener.MenuListener;
import tonegod.gui.core.Screen;
/**
*
* @author Darth Affe
*/
public class MenuState extends AbstractAppState {
public class MenuState extends AbstractAppState implements MenuListener {
private StateManager stateManager;
private Screen screen;
private Panel menuPanel;
private Gui gui;
public MenuState(Screen screen, StateManager stateManager) {
this.screen = screen;
this.stateManager = stateManager;
createGUI();
this.gui = new MenuGUI(screen, this);
}
private void createGUI() {
menuPanel = new Panel(screen, new Vector2f(15, 15), new Vector2f(800, 500));
menuPanel.setIgnoreMouse(true);
Button btnExit = new ButtonBase(screen, new Vector2f(600, 400), new Vector2f(120, 40)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
exitGame();
}
};
btnExit.setText("Exit");
Button btnStart = new ButtonBase(screen, new Vector2f(600, 300), new Vector2f(120, 40)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
startGame();
}
};
btnStart.setText("Start");
menuPanel.addChild(btnStart);
menuPanel.addChild(btnExit);
}
private void startGame() {
public void startGame() {
stateManager.setState(State.LOADING);
}
private void exitGame() {
public void exitGame() {
//TODO ss.stop();
}
@Override
public void stateAttached(AppStateManager stateManager) {
screen.addElement(menuPanel);
gui.attach();
}
@Override
public void stateDetached(AppStateManager stateManager) {
screen.removeElement(menuPanel);
gui.detach();
}
@Override