initial AdventureMode port

- todo needed adventure application startup upon pressing the adventure mode button
This commit is contained in:
Anthony Calosa
2022-02-06 11:10:52 +08:00
parent 5c3aeb508e
commit 3c6af87e9d
97 changed files with 266 additions and 101 deletions

View File

@@ -0,0 +1,138 @@
package forge.adventure.util;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import java.util.function.Function;
/**
* Class to create ui elements in the correct style
*/
public class Controls {
private static Skin SelectedSkin = null;
static public TextButton newTextButton(String text) {
return new TextButton(text, GetSkin());
}
static public SelectBox newComboBox(String[] text, String item, Function<Object, Void> func) {
SelectBox ret = new SelectBox<String>(GetSkin());
ret.setItems(text);
ret.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
try {
func.apply(((SelectBox) actor).getSelected());
} catch (Exception e) {
e.printStackTrace();
}
}
});
func.apply(item);
ret.setSelected(item);
return ret;
}
static public TextField newTextField(String text) {
return new TextField(text, GetSkin());
}
static public TextField newTextField(String text, Function<String, Void> func) {
TextField ret = new TextField(text, GetSkin());
ret.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
try {
func.apply(((TextField) actor).getText());
} catch (Exception e) {
e.printStackTrace();
}
}
});
return ret;
}
static public TextButton newTextButton(String text, Runnable func) {
TextButton ret = newTextButton(text);
ret.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
try {
func.run();
} catch (Exception e) {
e.printStackTrace();
}
}
});
return ret;
}
static public Slider newSlider(float min, float max, float step, boolean vertical) {
Slider ret = new Slider(min, max, step, vertical, GetSkin());
return ret;
}
static public CheckBox newCheckBox(String text) {
CheckBox ret = new CheckBox(text, GetSkin());
return ret;
}
static public BitmapFont bigFont()
{
return SelectedSkin.getFont("big");
}
static public BitmapFont font()
{
return SelectedSkin.getFont("default");
}
static public Skin GetSkin() {
if (SelectedSkin == null) {
SelectedSkin = new Skin();
FileHandle skinFile = Config.instance().getFile(Paths.SKIN);
FileHandle atlasFile = skinFile.sibling(skinFile.nameWithoutExtension() + ".atlas");
TextureAtlas atlas = new TextureAtlas(atlasFile);
SelectedSkin.addRegions(atlas);
SelectedSkin.load(skinFile);
}
return SelectedSkin;
}
public static Label newLabel(String name) {
Label ret = new Label(name, GetSkin());
return ret;
}
public static Dialog newDialog(String title) {
Dialog ret = new Dialog(title, GetSkin());
return ret;
}
}