Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions illaclient/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ dependencies {
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: project.ext.slf4jVersion
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: project.ext.slf4jVersion
compile group: 'ch.qos.logback', name: 'logback-classic', version: project.ext.logbackVersion
compile group: 'com.badlogicgames.gdx', name: 'gdx', version: project.ext.gdxVersion
compile group: 'com.badlogicgames.gdx', name: 'gdx-backend-lwjgl3', version: project.ext.gdxVersion
runtime group: 'com.badlogicgames.gdx', name: 'gdx-platform', version: project.ext.gdxVersion, classifier: 'natives-desktop'
compile group: 'org.bushe', name: 'eventbus', version: '1.4'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile group: 'com.google.guava', name: 'guava', version: '21.0'
Expand Down
5 changes: 5 additions & 0 deletions illaclient/src/main/java/illarion/client/Servers.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public enum Servers {
*/
private final int serverPort;

/**
* The URL of character edit to launch.
*/
public static final String CHARACTER_EDIT_URL = "https://illarion.org/community/account/us_charlist.php";

/**
* Default ENUM constructor for the enumeration entries. It creates a definition of a server and stores it to the
* enumeration constants.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package illarion.client.gui.controller;

import com.badlogic.gdx.Gdx;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.controls.Button;
import de.lessvoid.nifty.controls.Label;
import de.lessvoid.nifty.controls.ListBox;
import de.lessvoid.nifty.elements.Element;
Expand All @@ -27,13 +29,19 @@
import de.lessvoid.nifty.tools.SizeValue;
import illarion.client.Game;
import illarion.client.Login;
import illarion.client.Servers;
import illarion.client.util.Lang;
import illarion.common.config.ConfigChangedEvent;
import org.bushe.swing.event.annotation.AnnotationProcessor;
import org.bushe.swing.event.annotation.EventTopicSubscriber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

/**
* This is the screen controller that takes care for the logic behind the character selection screen.
Expand All @@ -53,12 +61,55 @@ public final class CharScreenController implements ScreenController, KeyInputHan
@Nullable
private Screen screen;

/**
* The button to proceed to play the game.
*/
@Nullable
private Button playButton;

/**
* The list box that stores the character entries.
*/
@Nullable
private ListBox<String> listBox;

public static final int CHARS_LOADING = 0;
public static final int CHARS_NONE_FOUND = 1;
public static final int CHARS_SELECT = 2;

/**
* Number indicating the state: LOADING, NONE_FOUND or SELECT.
*/
private int currentState;

/**
* Text panel saying load is in progress.
*/
@Nullable
private Element loadingCharsPanel;

/**
* Text panel saying no character was loaded.
*/
@Nullable
private Element noCharacterPanel;

/**
* List box with the character list.
*/
@Nullable
private Element characterSelectPanel;

/**
* Array with the three possible panels to display (loading, no character or select).
*/
private Element[] panels;

/**
* Lock to avoid multiple calls to reload characters.
*/
private ReentrantLock lockLoadChars = new ReentrantLock();

/**
* The game instance that is used.
*/
Expand All @@ -83,6 +134,9 @@ public final class CharScreenController implements ScreenController, KeyInputHan
@Nullable
private Element popupLanguageChange;

@Nonnull
private static final Logger log = LoggerFactory.getLogger(CharScreenController.class);

/**
* Create a instance of the character screen controller.
*
Expand All @@ -98,8 +152,16 @@ public CharScreenController(@Nonnull Game game) {
public void bind(@Nonnull Nifty nifty, @Nonnull Screen screen) {
this.nifty = nifty;
this.screen = screen;

nifty.setLocale(Lang.getInstance().getLocale());

playButton = screen.findNiftyControl("playBtn", Button.class);
loadingCharsPanel = screen.findElementById("loading-chars");
noCharacterPanel = screen.findElementById("no-character-available");
characterSelectPanel = screen.findElementById("character-list");

panels = new Element[] { loadingCharsPanel, noCharacterPanel, characterSelectPanel };
updateState(CHARS_LOADING);

listBox = (ListBox<String>) screen.findNiftyControl("myListBox", ListBox.class);
statusLabel = screen.findNiftyControl("statusText", Label.class);
statusLabel.setHeight(SizeValue.px(20));
Expand All @@ -108,7 +170,19 @@ public void bind(@Nonnull Nifty nifty, @Nonnull Screen screen) {
listBox.getElement().addInputHandler(this);
popupLanguageChange = nifty.createPopup("languageChanged");

fillMyListBox();
fillCharsListBox();
}

private void updateState(int newState) {
log.debug("updateState() - {}", newState);

currentState = newState;

for (int index = 0; index < panels.length; index++) {
panels[index].setVisible(index == newState);
}

playButton.setEnabled(newState == CHARS_SELECT);
}

/**
Expand Down Expand Up @@ -147,10 +221,45 @@ public void onEndScreen() {
showLanguageChangedPopup = false;
}

public void fillMyListBox() {
if (listBox != null) {
listBox.clear();
Login.getInstance().getCharacterList().stream().filter(entry -> entry.getStatus() == 0).forEach(entry -> listBox.addItem(entry.getName()));
public void reloadCharacters() {
if (!lockLoadChars.tryLock()) {
return;
}

log.warn("reloadCharacters");
updateState(CHARS_LOADING);

Login.getInstance().requestCharacterList(_errorCode -> {
log.debug("requestCharacterList - " + _errorCode);
fillCharsListBox();
lockLoadChars.unlock();
});
}

public void fillCharsListBox() {
log.debug("fillCharsListBox()");

if (listBox == null) {
return;
}

listBox.clear();

List<Login.CharEntry> data = Login.getInstance().getCharacterList().stream().filter(entry -> entry.getStatus() == 0).collect(Collectors.toList());
log.info("Character data downloaded - {}", data.stream().map(Login.CharEntry::getName).collect(Collectors.toList()));

if (data.isEmpty()) {
updateState(CHARS_NONE_FOUND);
} else {
data.forEach(entry -> listBox.addItem(entry.getName()));
updateState(CHARS_SELECT);
}
}

public void openEditor() {
boolean openOk = Gdx.net.openURI(Servers.CHARACTER_EDIT_URL);
if (!openOk) {
log.warn("Can't launch browser");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void update() {
}
@Nonnull ScreenController charScreenController = charSelectScreen.getScreenController();
if (charScreenController instanceof CharScreenController) {
((CharScreenController) charScreenController).fillMyListBox();
((CharScreenController) charScreenController).fillCharsListBox();
}
nifty.gotoScreen(charSelectScreen.getScreenId());
}
Expand Down
8 changes: 6 additions & 2 deletions illaclient/src/main/resources/charselect_de.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This file is part of the Illarion project.
#
# Copyright � 2014 - Illarion e.V.
# Copyright � 2014 - Illarion e.V.
#
# Illarion is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand All @@ -14,4 +14,8 @@
# GNU General Public License for more details.
#
play=Spielen
logout=Ausloggen
logout=Ausloggen
reload=Neu laden
editor=Online-Editor\n\u00f6ffnen
no-character-found=Es wurde keine Charaktere gefunden.\n\u00D6ffne die Editor, um einen Charakter anzulegen.
receivingCharacters=Charaktere werden vom Server empfangen.
6 changes: 5 additions & 1 deletion illaclient/src/main/resources/charselect_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
# GNU General Public License for more details.
#
play=Play
logout=Logout
logout=Logout
reload=Reload
editor=Open online\neditor
no-character-found=No character was found.\nOpen the online editor to set up a character.
receivingCharacters=Characters are being received from the server.
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,61 @@
imageMode="repeat:0,0,1024,422"/>
</layer>

<layer id="layer2" childLayout="center">
<layer id="character-select" childLayout="center">
<effect>
<onStartScreen name="fade" start="#00" end="#ff" inherit="true"/>
</effect>
<panel height="300px" width="400px" align="center" valign="center" backgroundColor="#0000"
<panel height="500px" width="540px" align="center" valign="center" backgroundColor="#0000"
childLayout="vertical" visibleToMouse="true">
<image filename="gui/illarion_title.png" imageMode="normal" align="center"/>
<control name="label" id="statusText" text=""/>
<panel height="30px"/>
<panel height="300px" width="400px" align="center" valign="center" backgroundColor="#0000"
childLayout="vertical" visibleToMouse="true">
<panel childLayout="center" visibleToMouse="true" align="center">
<control id="myListBox" name="listBox" vertical="on" horizontal="off"
displayItems="5" selection="Single" forceSelection="true"/>
<panel width="100%" align="center" valign="center"
childLayout="horizontal" visibleToMouse="true">
<panel width="400px" align="center" valign="center" backgroundColor="#0000"
childLayout="absolute" visibleToMouse="true">
<panel id="character-list" childLayout="center" visibleToMouse="true" align="center"
x="0px" y="0px" width="100%" height="100%">
<control id="myListBox" name="listBox" vertical="on" horizontal="off"
displayItems="5" selection="Single" forceSelection="true"/>
</panel>
<panel id="no-character-available" childLayout="center" visibleToMouse="true" align="center"
x="0px" y="0px" width="100%" height="100%">
<control name="label" text="${charselect-bundle.no-character-found}"/>
</panel>
<panel id="loading-chars" childLayout="center" visibleToMouse="true" align="center"
x="0px" y="0px" width="100%" height="100%">
<control name="label" text="${charselect-bundle.receivingCharacters}"/>
</panel>
</panel>

<panel height="30px"/>
<panel width="25px">
</panel>

<panel childLayout="horizontal" visibleToMouse="true">
<panel width="90px"/>
<control id="playBtn" name="button" label="${charselect-bundle.play}" width="100" height="35">
<interact onRelease="play()"/>
<panel width="115px" align="center" valign="center" backgroundColor="#0000"
childLayout="vertical" visibleToMouse="true">
<control id="reloadBtn" name="button" label="${charselect-bundle.reload}" width="100%" height="35">
<interact onRelease="reloadCharacters()"/>
</control>
<panel width="20px"/>
<control id="logoutBtn" name="button" label="${charselect-bundle.logout}" width="100"
height="35">
<interact onRelease="logout()"/>
<control id="editorBtn" name="button" label="${charselect-bundle.editor}" width="100%" height="70">
<interact onRelease="openEditor()"/>
</control>
</panel>
</panel>

<panel height="30px"/>

<panel childLayout="horizontal" visibleToMouse="true">
<panel width="90px"/>
<control id="playBtn" name="button" label="${charselect-bundle.play}" width="100" height="35">
<interact onRelease="play()"/>
</control>
<panel width="20px"/>
<control id="logoutBtn" name="button" label="${charselect-bundle.logout}" width="100"
height="35">
<interact onRelease="logout()"/>
</control>
</panel>
</panel>
</layer>
</screen>
Expand Down
1 change: 1 addition & 0 deletions versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ext {
slf4jVersion = '1.7.25'
logbackVersion = '1.2.2'
gdxVersion='1.13.1'
janinoVersion = '3.0.7'
illarionResourcesVersion = '[2.0, )'
niftyGuiVersion = '1.4.2'
Expand Down