TextSetting (#6503)

* tile

tile

* > Called right after load()

* TextSetting

* nvm I change the doc instead

* Fixes
This commit is contained in:
Weathercold
2022-01-18 22:26:24 -05:00
committed by GitHub
parent 3311e40906
commit 4a05c9547a
4 changed files with 92 additions and 7 deletions

View File

@@ -48,7 +48,7 @@ public class ContentLoader{
clear();
}
/** Clears all initialized content.*/
/** Clears all initialized content. */
public void clear(){
contentNameMap = new ObjectMap[ContentType.all.length];
contentMap = new Seq[ContentType.all.length];
@@ -75,7 +75,7 @@ public class ContentLoader{
}
}
/** Logs content statistics.*/
/** Logs content statistics. */
public void logContent(){
//check up ID mapping, make sure it's linear (debug only)
for(Seq<Content> arr : contentMap){
@@ -95,14 +95,14 @@ public class ContentLoader{
Log.debug("-------------------");
}
/** Calls Content#init() on everything. Use only after all modules have been created.*/
/** Calls Content#init() on everything. Use only after all modules have been created. */
public void init(){
initialize(Content::init);
if(constants != null) constants.init();
Events.fire(new ContentInitEvent());
}
/** Calls Content#load() on everything. Use only after all modules have been created on the client.*/
/** Calls Content#loadIcon() and Content#load() on everything. Use only after all modules have been created on the client. */
public void load(){
initialize(Content::loadIcon);
initialize(Content::load);
@@ -323,4 +323,4 @@ public class ContentLoader{
public Planet planet(String name){
return getByName(ContentType.planet, name);
}
}
}

View File

@@ -31,7 +31,7 @@ public abstract class Content implements Comparable<Content>{
*/
public void load(){}
/** Called right after load(). */
/** Called right before load(). */
public void loadIcon(){}
/** @return whether an error occurred during mod loading. */

View File

@@ -589,6 +589,30 @@ public class SettingsMenuDialog extends BaseDialog{
rebuild();
}
public void textPref(String name, String def){
list.add(new TextSetting(name, def, null));
settings.defaults(name, def);
rebuild();
}
public void textPref(String name, String def, Cons<String> changed){
list.add(new TextSetting(name, def, changed));
settings.defaults(name, def);
rebuild();
}
public void areaTextPref(String name, String def){
list.add(new AreaTextSetting(name, def, null));
settings.defaults(name, def);
rebuild();
}
public void areaTextPref(String name, String def, Cons<String> changed){
list.add(new AreaTextSetting(name, def, changed));
settings.defaults(name, def);
rebuild();
}
public void rebuild(){
clearChildren();
@@ -704,6 +728,67 @@ public class SettingsMenuDialog extends BaseDialog{
table.row();
}
}
public static class TextSetting extends Setting{
String def;
Cons<String> changed;
public TextSetting(String name, String def, Cons<String> changed){
super(name);
this.def = def;
this.changed = changed;
}
@Override
public void add(SettingsTable table){
TextField field = new TextField();
field.update(() -> field.setText(settings.getString(name)));
field.changed(() -> {
settings.put(name, field.getText());
if(changed != null){
changed.get(field.getText());
}
});
Table prefTable = table.table().left().padTop(3f).get();
prefTable.add(field);
prefTable.label(() -> title);
addDesc(prefTable);
table.row();
}
}
public static class AreaTextSetting extends TextSetting{
String def;
Cons<String> changed;
public AreaTextSetting(String name, String def, Cons<String> changed){
super(name, def, changed);
}
@Override
public void add(SettingsTable table){
TextArea area = new TextArea("");
area.setPrefRows(5);
area.update(() -> {
area.setText(settings.getString(name));
area.setWidth(table.getWidth());
});
area.changed(() -> {
settings.put(name, area.getText());
if(changed != null){
changed.get(area.getText());
}
});
addDesc(table.label(() -> title).left().padTop(3f).get());
table.row().add(area).left();
table.row();
}
}
}
}

View File

@@ -395,7 +395,7 @@ public class Block extends UnlockableContent{
return hasItems;
}
/** Returns whether or not this block can be place on the specified */
/** @return whether or not this block can be placed on the specified tile. */
public boolean canPlaceOn(Tile tile, Team team, int rotation){
return canPlaceOn(tile, team);
}