mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-05 07:48:05 +07:00
Added basic multiplayer lobby support
This commit is contained in:
@ -188,6 +188,7 @@ project(":server") {
|
||||
dependencies {
|
||||
compile project(":core")
|
||||
compile group: 'commons-cli', name: 'commons-cli', version: cliVersion
|
||||
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ public class Fonts {
|
||||
public final FontTBL.BitmapFont font24;
|
||||
public final FontTBL.BitmapFont font30;
|
||||
public final FontTBL.BitmapFont font42;
|
||||
public final FontTBL.BitmapFont fontformal10;
|
||||
public final FontTBL.BitmapFont fontformal12;
|
||||
public final FontTBL.BitmapFont fontexocet10;
|
||||
public final FontTBL.BitmapFont fontridiculous;
|
||||
@ -24,6 +25,7 @@ public class Fonts {
|
||||
font24 = load(assets, "font24", BlendMode.ID);
|
||||
font30 = load(assets, "font30", BlendMode.ID);
|
||||
font42 = load(assets, "font42", BlendMode.ID);
|
||||
fontformal10 = load(assets, "fontformal10", BlendMode.LUMINOSITY_TINT);
|
||||
fontformal12 = load(assets, "fontformal12", BlendMode.LUMINOSITY_TINT);
|
||||
fontexocet10 = load(assets, "fontexocet10", BlendMode.TINT_BLACKS);
|
||||
fontridiculous = load(assets, "fontridiculous", BlendMode.TINT_BLACKS);
|
||||
|
@ -41,7 +41,7 @@ public class RenderedConsole extends Console implements Disposable, InputProcess
|
||||
|
||||
public Texture modalBackground;
|
||||
private Texture hintBackground;
|
||||
private Texture cursorTexture;
|
||||
public Texture cursorTexture;
|
||||
|
||||
private boolean visible;
|
||||
private float height;
|
||||
|
420
core/src/gdx/diablo/screen/LobbyScreen.java
Normal file
420
core/src/gdx/diablo/screen/LobbyScreen.java
Normal file
@ -0,0 +1,420 @@
|
||||
package gdx.diablo.screen;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Net;
|
||||
import com.badlogic.gdx.ScreenAdapter;
|
||||
import com.badlogic.gdx.assets.AssetDescriptor;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.net.HttpRequestBuilder;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.Group;
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Container;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.List;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
import gdx.diablo.Diablo;
|
||||
import gdx.diablo.codec.DC6;
|
||||
import gdx.diablo.graphics.PaletteIndexedBatch;
|
||||
import gdx.diablo.loader.DC6Loader;
|
||||
import gdx.diablo.server.Session;
|
||||
import gdx.diablo.widget.Label;
|
||||
import gdx.diablo.widget.TextButton;
|
||||
|
||||
public class LobbyScreen extends ScreenAdapter {
|
||||
private static final String TAG = "LobbyScreen";
|
||||
|
||||
// FIXME: This background is not feasible and will always require shaving, easier to just use
|
||||
// component panels and button groups to create my own?
|
||||
final AssetDescriptor<DC6> waitingroombkgdDescriptor = new AssetDescriptor<>("data\\global\\ui\\BIGMENU\\waitingroombkgd.dc6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
|
||||
TextureRegion waitingroombkgd;
|
||||
|
||||
final AssetDescriptor<DC6> blankbckgDescriptor = new AssetDescriptor<>("data\\global\\ui\\BIGMENU\\blankbckg2.dc6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
|
||||
TextureRegion blankbckg;
|
||||
|
||||
final AssetDescriptor<DC6> creategamebckgDescriptor = new AssetDescriptor<>("data\\global\\ui\\BIGMENU\\creategamebckg.DC6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
|
||||
TextureRegion creategamebckg;
|
||||
|
||||
final AssetDescriptor<DC6> joingamebckgDescriptor = new AssetDescriptor<>("data\\global\\ui\\BIGMENU\\joingamebckg.DC6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
|
||||
TextureRegion joingamebckg;
|
||||
|
||||
final AssetDescriptor<DC6> chatrighttopbuttonsDescriptor = new AssetDescriptor<>("data\\global\\ui\\BIGMENU\\chatrighttopbuttons.dc6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
|
||||
private TextButton btnCreate;
|
||||
private TextButton btnJoin;
|
||||
|
||||
final AssetDescriptor<DC6> chatleftbuttonsDescriptor = new AssetDescriptor<>("data\\global\\ui\\BIGMENU\\chatleftbuttons.DC6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
|
||||
private Button btnChannel;
|
||||
private Button btnLadder;
|
||||
private Button btnQuit;
|
||||
|
||||
final AssetDescriptor<DC6> cancelbuttonblankDescriptor = new AssetDescriptor<>("data\\global\\ui\\BIGMENU\\cancelbuttonblank.dc6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
|
||||
final AssetDescriptor<DC6> gamebuttonblankDescriptor = new AssetDescriptor<>("data\\global\\ui\\BIGMENU\\gamebuttonblank.dc6", DC6.class, DC6Loader.DC6Parameters.COMBINE);
|
||||
|
||||
private Stage stage;
|
||||
|
||||
public LobbyScreen() {
|
||||
Diablo.assets.load(waitingroombkgdDescriptor);
|
||||
Diablo.assets.load(blankbckgDescriptor);
|
||||
Diablo.assets.load(creategamebckgDescriptor);
|
||||
Diablo.assets.load(joingamebckgDescriptor);
|
||||
Diablo.assets.load(chatleftbuttonsDescriptor);
|
||||
Diablo.assets.load(chatrighttopbuttonsDescriptor);
|
||||
Diablo.assets.load(cancelbuttonblankDescriptor);
|
||||
Diablo.assets.load(gamebuttonblankDescriptor);
|
||||
|
||||
stage = new Stage(Diablo.viewport, Diablo.batch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Diablo.assets.finishLoadingAsset(waitingroombkgdDescriptor);
|
||||
waitingroombkgd = Diablo.assets.get(waitingroombkgdDescriptor).getTexture();
|
||||
|
||||
Diablo.assets.finishLoadingAsset(blankbckgDescriptor);
|
||||
blankbckg = Diablo.assets.get(blankbckgDescriptor).getTexture();
|
||||
|
||||
Diablo.assets.finishLoadingAsset(creategamebckgDescriptor);
|
||||
creategamebckg = Diablo.assets.get(creategamebckgDescriptor).getTexture();
|
||||
|
||||
Diablo.assets.finishLoadingAsset(joingamebckgDescriptor);
|
||||
joingamebckg = Diablo.assets.get(joingamebckgDescriptor).getTexture();
|
||||
|
||||
stage.setDebugAll(true);
|
||||
|
||||
ClickListener clickListener = new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
Actor actor = event.getListenerActor();
|
||||
if (actor == btnChannel) {
|
||||
} else if (actor == btnLadder) {
|
||||
} else if (actor == btnQuit) {
|
||||
Diablo.client.popScreen();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// FIXME: disabled buttons look like a tinted up, which isn't possible now, maybe in future?
|
||||
final TextButton.TextButtonStyle style2 = new TextButton.TextButtonStyle() {{
|
||||
Diablo.assets.finishLoadingAsset(chatrighttopbuttonsDescriptor);
|
||||
DC6 chatrighttopbuttons = Diablo.assets.get(chatrighttopbuttonsDescriptor);
|
||||
up = new TextureRegionDrawable(chatrighttopbuttons.getTexture(0));
|
||||
down = new TextureRegionDrawable(chatrighttopbuttons.getTexture(1));
|
||||
checked = down;
|
||||
disabled = down;
|
||||
font = Diablo.fonts.fontridiculous;
|
||||
|
||||
unpressedOffsetY = 0;
|
||||
pressedOffsetX = pressedOffsetY = -1;
|
||||
checkedOffsetX = pressedOffsetX;
|
||||
checkedOffsetY = pressedOffsetY;
|
||||
}};
|
||||
btnCreate = new TextButton(5312, style2);
|
||||
btnJoin = new TextButton(5313, style2);
|
||||
|
||||
final TextButton.TextButtonStyle style = new TextButton.TextButtonStyle() {{
|
||||
Diablo.assets.finishLoadingAsset(chatleftbuttonsDescriptor);
|
||||
DC6 chatleftbuttons = Diablo.assets.get(chatleftbuttonsDescriptor);
|
||||
up = new TextureRegionDrawable(chatleftbuttons.getTexture(0));
|
||||
down = new TextureRegionDrawable(chatleftbuttons.getTexture(1));
|
||||
disabled = down;
|
||||
font = Diablo.fonts.fontridiculous;
|
||||
|
||||
checkedOffsetY = unpressedOffsetY = 0;
|
||||
pressedOffsetX = pressedOffsetY = -1;
|
||||
}};
|
||||
btnChannel = new TextButton(5314, style);
|
||||
btnChannel.setDisabled(true);
|
||||
btnChannel.addListener(clickListener);
|
||||
btnLadder = new TextButton(5315, style);
|
||||
btnLadder.setDisabled(true);
|
||||
btnLadder.addListener(clickListener);
|
||||
btnQuit = new TextButton(5316, style);
|
||||
btnQuit.toggle();
|
||||
btnQuit.addListener(clickListener);
|
||||
|
||||
Table panel = new Table() {{
|
||||
add(new Table() {{
|
||||
add(btnCreate).space(1);
|
||||
add(btnJoin).space(1);
|
||||
}}).space(1).row();
|
||||
add(new Table() {{
|
||||
add(btnChannel).space(1);
|
||||
add(btnLadder).space(1);
|
||||
add(btnQuit).space(1);
|
||||
}}).space(1).row();
|
||||
pack();
|
||||
setPosition(Diablo.VIRTUAL_WIDTH - getWidth() - 55, 109 - 48);
|
||||
}};
|
||||
stage.addActor(panel);
|
||||
|
||||
final TextButton.TextButtonStyle cancelbuttonblankStyle = new TextButton.TextButtonStyle() {{
|
||||
Diablo.assets.finishLoadingAsset(cancelbuttonblankDescriptor);
|
||||
DC6 cancelbuttonblank = Diablo.assets.get(cancelbuttonblankDescriptor);
|
||||
up = new TextureRegionDrawable(cancelbuttonblank.getTexture(0));
|
||||
down = new TextureRegionDrawable(cancelbuttonblank.getTexture(1));
|
||||
disabled = down;
|
||||
font = Diablo.fonts.fontridiculous;
|
||||
|
||||
checkedOffsetY = unpressedOffsetY = 0;
|
||||
pressedOffsetX = pressedOffsetY = -1;
|
||||
}};
|
||||
|
||||
final TextButton.TextButtonStyle gamebuttonblankStyle = new TextButton.TextButtonStyle() {{
|
||||
Diablo.assets.finishLoadingAsset(gamebuttonblankDescriptor);
|
||||
DC6 gamebuttonblank = Diablo.assets.get(gamebuttonblankDescriptor);
|
||||
up = new TextureRegionDrawable(gamebuttonblank.getTexture(0));
|
||||
down = new TextureRegionDrawable(gamebuttonblank.getTexture(1));
|
||||
disabled = down;
|
||||
font = Diablo.fonts.fontridiculous;
|
||||
|
||||
checkedOffsetY = unpressedOffsetY = 0;
|
||||
pressedOffsetX = pressedOffsetY = -1;
|
||||
}};
|
||||
|
||||
final TabbedPane right = new TabbedPane(blankbckg) {{
|
||||
pack();
|
||||
setPosition(Diablo.VIRTUAL_WIDTH - getWidth() - 39, 105);
|
||||
final ClickListener cancelListener = new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
clearSelection();
|
||||
}
|
||||
};
|
||||
|
||||
addTab(btnCreate, new TabGroup() {{
|
||||
setBackground(creategamebckg);
|
||||
addActor(new Label(5150, Diablo.fonts.font30) {{
|
||||
setPosition(
|
||||
joingamebckg.getRegionWidth() / 2 - getWidth() / 2,
|
||||
joingamebckg.getRegionHeight() - getHeight());
|
||||
}});
|
||||
addActor(new Label(5274, Diablo.fonts.font16, Diablo.colors.unique) {{
|
||||
setPosition(12, 315);
|
||||
}});
|
||||
addActor(new Label(5256, Diablo.fonts.font16, Diablo.colors.unique) {{
|
||||
setPosition(12, 260);
|
||||
}});
|
||||
addActor(new Label(5257, Diablo.fonts.font16, Diablo.colors.unique) {{
|
||||
setPosition(12, 205);
|
||||
}});
|
||||
addActor(new Label(5258, Diablo.fonts.font16, Diablo.colors.unique) {{
|
||||
setPosition(20, 140);
|
||||
}});
|
||||
addActor(new Label(5259, Diablo.fonts.font16, Diablo.colors.unique) {{
|
||||
setPosition(20, 105);
|
||||
}});
|
||||
|
||||
final TextButton btnCancel = new TextButton(5134, cancelbuttonblankStyle);
|
||||
btnCancel.addListener(cancelListener);
|
||||
btnCancel.setPosition(18, 14);
|
||||
addActor(btnCancel);
|
||||
final TextButton btnCreateGame = new TextButton(5150, gamebuttonblankStyle);
|
||||
btnCreateGame.setPosition(179, 14);
|
||||
btnCreateGame.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
Net.HttpRequest request = new HttpRequestBuilder()
|
||||
.newRequest()
|
||||
.method(Net.HttpMethods.POST)
|
||||
.url("http://hydra:6112/create-session")
|
||||
.jsonContent(new Session("New Game!"))
|
||||
.build();
|
||||
Gdx.net.sendHttpRequest(request, null);
|
||||
}
|
||||
});
|
||||
addActor(btnCreateGame);
|
||||
setSize(getBackground().getMinWidth(), getBackground().getMinHeight());
|
||||
}});
|
||||
addTab(btnJoin, new TabGroup() {{
|
||||
setBackground(joingamebckg);
|
||||
addActor(new Label(5151, Diablo.fonts.font30) {{
|
||||
setPosition(
|
||||
joingamebckg.getRegionWidth() / 2 - getWidth() / 2,
|
||||
joingamebckg.getRegionHeight() - getHeight());
|
||||
}});
|
||||
addActor(new Label(5274, Diablo.fonts.font16, Diablo.colors.unique) {{
|
||||
setPosition(12, 328);
|
||||
}});
|
||||
addActor(new Label(5225, Diablo.fonts.font16, Diablo.colors.unique) {{
|
||||
setPosition(188, 328);
|
||||
}});
|
||||
addActor(new Label(5275, Diablo.fonts.font16, Diablo.colors.unique) {{
|
||||
setPosition(16, 236);
|
||||
}});
|
||||
|
||||
List.ListStyle style3 = new List.ListStyle(Diablo.fonts.fontformal10, Diablo.colors.unique, Diablo.colors.white,
|
||||
new TextureRegionDrawable(Diablo.console.cursorTexture));
|
||||
final List<Session> list = new List<>(style3);
|
||||
list.setPosition(14, 54);
|
||||
list.setSize(158, 177);
|
||||
addActor(list);
|
||||
|
||||
final TextButton btnCancel = new TextButton(5134, cancelbuttonblankStyle);
|
||||
btnCancel.addListener(cancelListener);
|
||||
btnCancel.setPosition(18, 14);
|
||||
addActor(btnCancel);
|
||||
final TextButton btnJoinGame = new TextButton(5151, gamebuttonblankStyle);
|
||||
btnJoinGame.setPosition(179, 14);
|
||||
addActor(btnJoinGame);
|
||||
setSize(getBackground().getMinWidth(), getBackground().getMinHeight());
|
||||
|
||||
btnJoinGame.setDisabled(true);
|
||||
list.addListener(new ChangeListener() {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
list.getSelection().setRequired(true);
|
||||
btnJoinGame.setDisabled(list.getSelection().isEmpty());
|
||||
}
|
||||
});
|
||||
|
||||
setListener(new TabListener() {
|
||||
@Override
|
||||
public void entered() {
|
||||
list.clearItems();
|
||||
list.getSelection().setRequired(false);
|
||||
Net.HttpRequest request = new HttpRequestBuilder()
|
||||
.newRequest()
|
||||
.method(Net.HttpMethods.GET)
|
||||
.url("http://hydra:6112/get-sessions")
|
||||
.build();
|
||||
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
|
||||
@Override
|
||||
public void handleHttpResponse(Net.HttpResponse httpResponse) {
|
||||
Array<Session> sessions = (Array<Session>) new Json().fromJson(Array.class, httpResponse.getResultAsStream());
|
||||
Gdx.app.log(TAG, sessions.toString());
|
||||
list.setItems(sessions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable t) {
|
||||
if (t.getClass() == SocketTimeoutException.class
|
||||
|| t.getClass() == ConnectException.class) {
|
||||
Gdx.app.log(TAG, t.getMessage());
|
||||
} else {
|
||||
Gdx.app.log(TAG, t.getMessage(), t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelled() {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}});
|
||||
}};
|
||||
stage.addActor(right);
|
||||
|
||||
Diablo.input.addProcessor(stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
Diablo.input.removeProcessor(stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
Diablo.assets.unload(waitingroombkgdDescriptor.fileName);
|
||||
Diablo.assets.unload(blankbckgDescriptor.fileName);
|
||||
Diablo.assets.unload(creategamebckgDescriptor.fileName);
|
||||
Diablo.assets.unload(joingamebckgDescriptor.fileName);
|
||||
Diablo.assets.unload(chatleftbuttonsDescriptor.fileName);
|
||||
Diablo.assets.unload(chatrighttopbuttonsDescriptor.fileName);
|
||||
Diablo.assets.unload(cancelbuttonblankDescriptor.fileName);
|
||||
Diablo.assets.unload(gamebuttonblankDescriptor.fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
PaletteIndexedBatch b = Diablo.batch;
|
||||
b.begin(Diablo.palettes.act1);
|
||||
b.draw(waitingroombkgd, Diablo.VIRTUAL_WIDTH_CENTER - (waitingroombkgd.getRegionWidth() / 2), Diablo.VIRTUAL_HEIGHT - waitingroombkgd.getRegionHeight() + 72);
|
||||
b.end();
|
||||
|
||||
stage.act(delta);
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
static class TabbedPane extends Container<Group> {
|
||||
TextureRegion defaultBackground;
|
||||
ClickListener clickListener;
|
||||
ButtonGroup buttons = new ButtonGroup();
|
||||
ObjectMap<String, TabGroup> map = new ObjectMap<>();
|
||||
TextureRegionDrawable background = new TextureRegionDrawable();
|
||||
TabbedPane(TextureRegion defaultBackground) {
|
||||
background.setRegion(this.defaultBackground = defaultBackground);
|
||||
setBackground(background);
|
||||
buttons.setMinCheckCount(0);
|
||||
clickListener = new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
Button button = (Button) event.getListenerActor();
|
||||
TabGroup content = map.get(button.getName());
|
||||
setActor(content);
|
||||
setBackground(content.background);
|
||||
content.entered();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void addTab(TextButton button, TabGroup content) {
|
||||
button.setName(button.getText());
|
||||
button.setProgrammaticChangeEvents(false);
|
||||
button.addListener(clickListener);
|
||||
|
||||
buttons.add(button);
|
||||
buttons.setMinCheckCount(1);
|
||||
map.put(button.getName(), content);
|
||||
}
|
||||
|
||||
public void clearSelection() {
|
||||
setActor(null);
|
||||
setBackground(defaultBackground);
|
||||
buttons.setMinCheckCount(0);
|
||||
buttons.uncheckAll();
|
||||
}
|
||||
|
||||
public Object getSelected() {
|
||||
return buttons.getChecked();
|
||||
}
|
||||
|
||||
public void setBackground(TextureRegion texture) {
|
||||
background.setRegion(texture);
|
||||
}
|
||||
|
||||
static class TabGroup extends Group implements TabListener {
|
||||
TextureRegion background;
|
||||
TabListener listener;
|
||||
|
||||
void setBackground(TextureRegion background) {
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
void setListener(TabListener l) {
|
||||
this.listener = l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entered() {
|
||||
if (listener != null) listener.entered();
|
||||
}
|
||||
}
|
||||
|
||||
interface TabListener {
|
||||
void entered();
|
||||
}
|
||||
}
|
||||
}
|
@ -95,6 +95,7 @@ public class MultiplayerScreen extends ScreenAdapter {
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
Actor actor = event.getListenerActor();
|
||||
if (actor == btnOpenBattlenet) {
|
||||
Diablo.client.pushScreen(new LobbyScreen());
|
||||
} else if (actor == btnTCPIP) {
|
||||
Diablo.client.pushScreen(new TCPIPScreen(D2logoLeft, D2logoRight));
|
||||
} else if (actor == btnCancel) {
|
||||
|
17
core/src/gdx/diablo/server/Session.java
Normal file
17
core/src/gdx/diablo/server/Session.java
Normal file
@ -0,0 +1,17 @@
|
||||
package gdx.diablo.server;
|
||||
|
||||
public class Session {
|
||||
|
||||
private String name;
|
||||
|
||||
private Session() {}
|
||||
|
||||
public Session(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package gdx.diablo.widget;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFontCache;
|
||||
@ -14,6 +15,11 @@ public class Label extends com.badlogic.gdx.scenes.scene2d.ui.Label {
|
||||
this(id == -1 ? "" : Diablo.string.lookup(id), font);
|
||||
}
|
||||
|
||||
public Label(int id, BitmapFont font, Color color) {
|
||||
this(id, font);
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
public Label(String text, BitmapFont font) {
|
||||
super(text, new LabelStyle(font, null));
|
||||
}
|
||||
|
88
core/src/gdx/diablo/widget/TabbedPane.java
Normal file
88
core/src/gdx/diablo/widget/TabbedPane.java
Normal file
@ -0,0 +1,88 @@
|
||||
package gdx.diablo.widget;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Button;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Container;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import gdx.diablo.widget.TextButton.TextButtonStyle;
|
||||
|
||||
public class TabbedPane extends Table {
|
||||
|
||||
private Table tabs;
|
||||
private Container<Table> contentPanel;
|
||||
|
||||
ClickListener clickListener;
|
||||
ButtonGroup<TextButton> buttons = new ButtonGroup<>();
|
||||
ObjectMap<String, Table> map = new ObjectMap<>();
|
||||
CopyOnWriteArrayList<TabListener> listeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
public TabbedPane() {
|
||||
clickListener = new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
Button button = (Button) event.getListenerActor();
|
||||
contentPanel.setActor(map.get(button.getName()));
|
||||
notifyTabSwitched(buttons.getChecked().getName(), button.getName());
|
||||
}
|
||||
};
|
||||
|
||||
add(tabs = new Table()).growX().row();
|
||||
add(contentPanel = new Container<>()).align(Align.top).row();
|
||||
}
|
||||
|
||||
public void addTab(int id, TextButtonStyle style, Table content) {
|
||||
TextButton button = new TextButton(id, style) {{
|
||||
setName(getText());
|
||||
setStyle(new TextButtonStyle(getStyle()) {{
|
||||
checked = down;
|
||||
}});
|
||||
setProgrammaticChangeEvents(false);
|
||||
addListener(clickListener);
|
||||
}};
|
||||
if (buttons.getCheckedIndex() == -1) {
|
||||
contentPanel.setActor(content);
|
||||
notifyTabSwitched(null, button.getName());
|
||||
}
|
||||
buttons.add(button);
|
||||
tabs.add(button).growX();
|
||||
map.put(button.getName(), content);
|
||||
}
|
||||
|
||||
public void switchTo(String tab) {
|
||||
buttons.setChecked(tab); // Doesn't actually fire button
|
||||
|
||||
// TODO: This could be cleaned up, but it works fine for now
|
||||
InputEvent event = new InputEvent();
|
||||
event.setListenerActor(buttons.getChecked());
|
||||
clickListener.clicked(event, 0, 0);
|
||||
}
|
||||
|
||||
public String getTab() {
|
||||
return buttons.getChecked().getName();
|
||||
}
|
||||
|
||||
public void addListener(TabListener l) {
|
||||
listeners.add(l);
|
||||
}
|
||||
|
||||
public boolean removeListener(TabListener l) {
|
||||
return listeners.remove(l);
|
||||
}
|
||||
|
||||
private void notifyTabSwitched(String fromTab, String toTab) {
|
||||
for (TabListener l : listeners) {
|
||||
l.switchedTab(fromTab, toTab);
|
||||
}
|
||||
}
|
||||
|
||||
public interface TabListener {
|
||||
void switchedTab(String fromTab, String toTab);
|
||||
}
|
||||
}
|
@ -43,6 +43,10 @@ public class TextButton extends Button {
|
||||
return style;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return label.getText().toString();
|
||||
}
|
||||
|
||||
public void setText(int id) {
|
||||
label.setText(id);
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ public class DesktopLauncher {
|
||||
config.addIcon("ic_launcher_32.png", Files.FileType.Internal);
|
||||
config.addIcon("ic_launcher_16.png", Files.FileType.Internal);
|
||||
config.resizable = false;
|
||||
config.width = 1280;
|
||||
config.height = 720;
|
||||
config.width = 853;
|
||||
config.height = 480;
|
||||
//config.width = Diablo.VIRTUAL_WIDTH;
|
||||
//config.height = Diablo.VIRTUAL_HEIGHT;
|
||||
config.allowSoftwareMode = cmd != null && cmd.hasOption("allowSoftwareMode");
|
||||
|
@ -6,10 +6,16 @@ import com.badlogic.gdx.Net;
|
||||
import com.badlogic.gdx.backends.headless.HeadlessApplication;
|
||||
import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration;
|
||||
import com.badlogic.gdx.net.ServerSocket;
|
||||
import com.badlogic.gdx.net.ServerSocketHints;
|
||||
import com.badlogic.gdx.net.Socket;
|
||||
import com.badlogic.gdx.net.SocketHints;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.DateFormat;
|
||||
@ -41,20 +47,67 @@ public class Server extends ApplicationAdapter {
|
||||
|
||||
Gdx.app.log(TAG, "awaiting connection...");
|
||||
|
||||
ServerSocketHints hints = new ServerSocketHints();
|
||||
hints.acceptTimeout = 0;
|
||||
ServerSocket server = Gdx.net.newServerSocket(Net.Protocol.TCP, 6112, null);
|
||||
while (true) {
|
||||
Socket socket = null;
|
||||
BufferedReader in = null;
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
socket = server.accept(null);
|
||||
|
||||
ServerSocket server = Gdx.net.newServerSocket(Net.Protocol.TCP, 6112, hints);
|
||||
|
||||
Socket socket = server.accept(new SocketHints());
|
||||
Gdx.app.log(TAG, "connection from " + socket.getRemoteAddress());
|
||||
socket.dispose();
|
||||
|
||||
Gdx.app.exit();
|
||||
in = IOUtils.buffer(new InputStreamReader(socket.getInputStream()));
|
||||
out = new PrintWriter(socket.getOutputStream(), true);
|
||||
|
||||
String statusLine = in.readLine();
|
||||
Gdx.app.log(TAG, statusLine);
|
||||
String[] parts = statusLine.split("\\s+", 3);
|
||||
|
||||
String path = parts[1];
|
||||
if (path.startsWith("/get-sessions")) {
|
||||
getSessions(out);
|
||||
} else if (path.startsWith("/create-session")) {
|
||||
createSession(in, out);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
Gdx.app.error(TAG, t.getMessage(), t);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(out);
|
||||
IOUtils.closeQuietly(in);
|
||||
socket.dispose();
|
||||
}
|
||||
|
||||
try {
|
||||
} finally {
|
||||
}
|
||||
|
||||
socket.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
Gdx.app.log(TAG, "shutting down...");
|
||||
}
|
||||
|
||||
private void getSessions(PrintWriter out) {
|
||||
Array<Session> games = new Array<>();
|
||||
games.add(new Session("Kmbaal-33"));
|
||||
games.add(new Session("Cbaalz73"));
|
||||
games.add(new Session("Killin Foos"));
|
||||
games.add(new Session("Skulders 4 Scri"));
|
||||
|
||||
out.print("HTTP/1.1 200\r\n");
|
||||
out.print("\r\n");
|
||||
out.print(new Json().toJson(games));
|
||||
}
|
||||
|
||||
private void createSession(BufferedReader in, PrintWriter out) {
|
||||
try {
|
||||
for (String str; (str = in.readLine()) != null && !str.isEmpty(););
|
||||
Session session = new Json().fromJson(Session.class, in);
|
||||
System.out.println(session);
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user