mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-09 15:28:18 +07:00
Added partial support for changing acts
Added partial support for changing acts (levels will come after waypoint are added) Added a click lister to waypoint buttons and set their user object to referenced level Changed from static loading screen to a dynamic one that is pushed over game screen and popped off to hide loads Changed disposing strategy of GameLoadingScreen to always keep loading descriptor in memory Client#clearAndSet(Screen) now disposes existing screens and clears before setting new one
This commit is contained in:
@ -195,9 +195,9 @@ public class Client extends Game {
|
||||
}
|
||||
|
||||
public void clearAndSet(Screen screen) {
|
||||
setScreen(screen);
|
||||
for (Screen s : screens) s.dispose();
|
||||
screens.clear();
|
||||
setScreen(screen);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -188,7 +188,7 @@ public class CreateCharacterScreen extends ScreenAdapter {
|
||||
Riiablo.client.popScreen();
|
||||
} else if (actor == btnOK) {
|
||||
if (selected == null) return;
|
||||
Riiablo.client.clearAndSet(new GameLoadingScreen(new GameScreen(Riiablo.charData.createD2S(tfCharName.getText(), selected.charClass))));
|
||||
Riiablo.client.clearAndSet(new GameScreen(Riiablo.charData.createD2S(tfCharName.getText(), selected.charClass)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.riiablo.screen;
|
||||
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.assets.AssetDescriptor;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
@ -12,21 +12,20 @@ import com.riiablo.map.Map;
|
||||
import com.riiablo.widget.AnimationWrapper;
|
||||
|
||||
public class GameLoadingScreen extends ScreenAdapter {
|
||||
private static final String TAG = "GameLoadingScreen";
|
||||
|
||||
private final AssetDescriptor<DC6> loadingscreenDescriptor = new AssetDescriptor<>("data\\local\\ui\\loadingscreen.dc6", DC6.class);
|
||||
|
||||
private Screen screen;
|
||||
private Array<AssetDescriptor> assets;
|
||||
private Array<AssetDescriptor> dependencies;
|
||||
|
||||
private Stage stage;
|
||||
private AnimationWrapper loadingscreenWrapper;
|
||||
|
||||
private Map map;
|
||||
private int act;
|
||||
|
||||
public GameLoadingScreen(Array<AssetDescriptor> assets, GameScreen screen) {
|
||||
this.screen = screen;
|
||||
this.map = screen.map;
|
||||
|
||||
public GameLoadingScreen(Map map, Array<AssetDescriptor> dependencies) {
|
||||
this.map = map;
|
||||
stage = new Stage(Riiablo.defaultViewport, Riiablo.batch);
|
||||
|
||||
Riiablo.assets.load(loadingscreenDescriptor);
|
||||
@ -47,42 +46,44 @@ public class GameLoadingScreen extends ScreenAdapter {
|
||||
(stage.getHeight() / 2) - (loadingscreen.getMinHeight() / 2));
|
||||
stage.addActor(loadingscreenWrapper);
|
||||
|
||||
this.assets = assets;
|
||||
if (assets != null) {
|
||||
for (AssetDescriptor asset : assets) {
|
||||
Riiablo.assets.load(asset);
|
||||
}
|
||||
}
|
||||
|
||||
map.setAct(0);
|
||||
map.load();
|
||||
this.dependencies = new Array<>(dependencies);
|
||||
}
|
||||
|
||||
public GameLoadingScreen(GameScreen screen) {
|
||||
this(screen.getDependencies(), screen);
|
||||
public void loadAct(int act) {
|
||||
this.act = act;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.app.log(TAG, "Loading act " + (act + 1));
|
||||
Riiablo.viewport = Riiablo.defaultViewport;
|
||||
if (assets == null) {
|
||||
Riiablo.client.clearAndSet(screen);
|
||||
|
||||
Riiablo.assets.load(loadingscreenDescriptor);
|
||||
if (dependencies != null) {
|
||||
for (AssetDescriptor asset : dependencies) {
|
||||
Riiablo.assets.load(asset);
|
||||
}
|
||||
dependencies = null;
|
||||
}
|
||||
|
||||
map.setAct(act);
|
||||
map.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
if (assets != null) {
|
||||
Riiablo.assets.unload(loadingscreenDescriptor.fileName);
|
||||
}
|
||||
Riiablo.assets.unload(loadingscreenDescriptor.fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
if (Riiablo.assets.update()) {
|
||||
map.finishLoading();
|
||||
map.generate();
|
||||
Riiablo.client.clearAndSet(screen);
|
||||
Riiablo.client.popScreen();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,8 @@ import com.riiablo.Keys;
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.camera.IsometricCamera;
|
||||
import com.riiablo.codec.D2S;
|
||||
import com.riiablo.codec.DC6;
|
||||
import com.riiablo.codec.excel.Levels;
|
||||
import com.riiablo.codec.excel.Sounds;
|
||||
import com.riiablo.cvar.Cvar;
|
||||
import com.riiablo.cvar.CvarStateAdapter;
|
||||
@ -101,7 +103,7 @@ import com.riiablo.widget.NpcDialogBox;
|
||||
import com.riiablo.widget.NpcMenu;
|
||||
import com.riiablo.widget.TextArea;
|
||||
|
||||
public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable {
|
||||
public class GameScreen extends ScreenAdapter implements GameLoadingScreen.Loadable {
|
||||
private static final String TAG = "GameScreen";
|
||||
private static final boolean DEBUG = true;
|
||||
private static final boolean DEBUG_TOUCHPAD = !true;
|
||||
@ -121,6 +123,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
private final Vector2 tmpVec2 = new Vector2();
|
||||
private final Vector2 tmpVec2b = new Vector2();
|
||||
|
||||
final AssetDescriptor<DC6> loadingscreenDescriptor = new AssetDescriptor<>("data\\local\\ui\\loadingscreen.dc6", DC6.class);
|
||||
final AssetDescriptor<Sound> windowopenDescriptor = new AssetDescriptor<>("data\\global\\sfx\\cursor\\windowopen.wav", Sound.class);
|
||||
|
||||
final AssetDescriptor<Texture> touchpadBackgroundDescriptor = new AssetDescriptor<>("textures/touchBackground.png", Texture.class);
|
||||
@ -128,6 +131,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
Touchpad touchpad;
|
||||
|
||||
final Array<AssetDescriptor> preloadedAssets = new Array<AssetDescriptor>() {{
|
||||
add(loadingscreenDescriptor);
|
||||
add(windowopenDescriptor);
|
||||
if (Gdx.app.getType() == Application.ApplicationType.Android || DEBUG_TOUCHPAD) {
|
||||
add(touchpadBackgroundDescriptor);
|
||||
@ -151,6 +155,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
Stage stage;
|
||||
Stage scaledStage;
|
||||
Viewport viewport;
|
||||
GameLoadingScreen loadingScreen;
|
||||
boolean isDebug;
|
||||
MappedKeyStateAdapter debugKeyListener = new MappedKeyStateAdapter() {
|
||||
@Override
|
||||
@ -501,6 +506,8 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
engine.addSystem(new SequenceSystem());
|
||||
engine.addSystem(new Box2DDebugRenderSystem(renderer));
|
||||
engine.addSystem(new PathfindDebugSystem(iso, renderer, Riiablo.batch, Riiablo.shapes));
|
||||
|
||||
loadingScreen = new GameLoadingScreen(map, getDependencies());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -687,6 +694,11 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
if (map.getAct() == -1) {
|
||||
setAct(0);
|
||||
return;
|
||||
}
|
||||
|
||||
Riiablo.game = this;
|
||||
isDebug = DEBUG && Gdx.app.getType() == Application.ApplicationType.Desktop;
|
||||
Keys.DebugMode.addStateListener(debugKeyListener);
|
||||
@ -923,4 +935,44 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAct(int act) {
|
||||
loadingScreen.loadAct(act);
|
||||
Riiablo.client.pushScreen(loadingScreen);
|
||||
}
|
||||
|
||||
public void setLevel(Levels.Entry target) {
|
||||
assert target.Waypoint != 0xFF;
|
||||
//if (target.Act != map.getAct()) {
|
||||
// setAct(target.Act);
|
||||
// return;
|
||||
//}
|
||||
|
||||
// Riiablo.engine.removeAllEntities(Family.exclude(PlayerComponent.class).get());
|
||||
// Box2DPhysicsSystem system = engine.getSystem(Box2DPhysicsSystem.class);
|
||||
// World body2dWorld = system.world;
|
||||
// Array<Body> bodies = new Array<>(32768);
|
||||
// body2dWorld.getBodies(bodies);
|
||||
// for (Body body : bodies) body2dWorld.destroyBody(body);
|
||||
// player.getComponent(Box2DComponent.class).body = null;
|
||||
// system.entityAdded(player);
|
||||
//
|
||||
// loadingScreen.loadAct(target.Act);
|
||||
// Riiablo.client.pushScreen(loadingScreen);
|
||||
/*
|
||||
map.clear();
|
||||
map.setAct(target.Act);
|
||||
map.load();
|
||||
map.finishLoading();
|
||||
map.generate();
|
||||
*/
|
||||
|
||||
// Vector2 origin = map.find(Map.ID.TOWN_ENTRY_1);
|
||||
// if (origin == null) origin = map.find(Map.ID.TOWN_ENTRY_2);
|
||||
// if (origin == null) origin = map.find(Map.ID.TP_LOCATION);
|
||||
// player.getComponent(PositionComponent.class).position.set(origin);
|
||||
// player.getComponent(Box2DComponent.class).body.setTransform(origin, 0);
|
||||
// player.getComponent(MapComponent.class).zone = map.getZone(origin);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -57,8 +57,7 @@ public class SelectCharacterScreen extends ScreenAdapter {
|
||||
Riiablo.client.popScreen();
|
||||
} else if (actor == btnOK) {
|
||||
assert selected != null;
|
||||
GameScreen game = new GameScreen(Riiablo.charData.setD2S(selected.getD2S()));
|
||||
Riiablo.client.clearAndSet(new GameLoadingScreen(game));
|
||||
Riiablo.client.clearAndSet(new GameScreen(Riiablo.charData.setD2S(selected.getD2S())));
|
||||
} else if (actor == btnCreateNewCharacter) {
|
||||
Riiablo.client.pushScreen(new CreateCharacterScreen());
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.assets.AssetDescriptor;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
|
||||
@ -41,6 +42,8 @@ public class WaygatePanel extends WidgetGroup implements Disposable {
|
||||
final AssetDescriptor<DC6> buysellbtnDescriptor = new AssetDescriptor<>("data\\global\\ui\\PANEL\\buysellbtn.DC6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
|
||||
Button btnExit;
|
||||
|
||||
ClickListener clickListener;
|
||||
|
||||
public WaygatePanel() {
|
||||
Riiablo.assets.load(waygatebackgroundDescriptor);
|
||||
Riiablo.assets.finishLoadingAsset(waygatebackgroundDescriptor);
|
||||
@ -78,6 +81,15 @@ public class WaygatePanel extends WidgetGroup implements Disposable {
|
||||
down = new TextureRegionDrawable(waygateicons.getTexture(4));
|
||||
}};
|
||||
|
||||
clickListener = new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
IconTextButton button = (IconTextButton) event.getListenerActor();
|
||||
Levels.Entry target = (Levels.Entry) button.getUserObject();
|
||||
Riiablo.game.setLevel(target);
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Array<Levels.Entry>[] waypoints = (Array<Levels.Entry>[]) new Array[5];
|
||||
for (int i = 0; i < waypoints.length; i++) waypoints[i] = new Array<>(9);
|
||||
@ -100,7 +112,9 @@ public class WaygatePanel extends WidgetGroup implements Disposable {
|
||||
for (int i = 0; i < tabs.length; i++) {
|
||||
Tab tab = tabs[i] = new Tab();
|
||||
for (Levels.Entry entry : waypoints[i]) {
|
||||
tab.addWaypoint(entry.LevelName);
|
||||
Actor controller = tab.addWaypoint(entry.LevelName);
|
||||
controller.setUserObject(entry);
|
||||
controller.addListener(clickListener);
|
||||
}
|
||||
|
||||
tab.pack();
|
||||
@ -164,8 +178,10 @@ public class WaygatePanel extends WidgetGroup implements Disposable {
|
||||
columnDefaults(0).height(32).spaceBottom(4).growX();
|
||||
}
|
||||
|
||||
void addWaypoint(String descId) {
|
||||
add(new IconTextButton(waygateButtonStyle, Riiablo.string.lookup(descId), Riiablo.fonts.font16)).row();
|
||||
Actor addWaypoint(String descId) {
|
||||
IconTextButton button = new IconTextButton(waygateButtonStyle, Riiablo.string.lookup(descId), Riiablo.fonts.font16);
|
||||
add(button).row();
|
||||
return button;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user