-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Server Launcher support with per server settings and internatio…
…nalisation.
- Loading branch information
Showing
6 changed files
with
389 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
mod_name=Upkeep costs | ||
fxml_missing=UpkeepCosts.fxml not found. | ||
|
||
# 0 - property name | ||
negative={0} cannot be negative. Value will not be changed. | ||
invalid=Invalid value for %s. Value will not be changed. | ||
|
||
no_upkeep=Upkeep is not enabled on this server, upkeep costs will have no effect. | ||
free_deeds=Deeds are free on this server, costs will have no effect. | ||
# 0 - tile cost, 1 - tile upkeep, 2 - perimeter cost, 3 - perimeter upkeep, 4 - guards cost, 5 - guards upkeep, 6 - minimum upkeep | ||
all_values=Upkeep costs are as follows: Tile {0}, {1} - Perimeter {2}, {3} - Guards {4}, {5} - Minimum {6} | ||
|
||
load_properties_error=An error occurred when loading properties: | ||
save_properties_error=An error occurred when saving properties: | ||
error=An error occurred, the following may or may not help: | ||
|
||
changes_title=Save Changes | ||
changes_header=Some changes have been made | ||
changes_message=Would you like to save the changes? | ||
|
||
irons_note=All values are in irons. 100i = 1c, 100c = 1s, 100s = 1g | ||
|
||
tile_cost=Tile cost | ||
tile_cost_description=The amount charged per tile when founding a deed. | ||
tile_upkeep=Tile upkeep | ||
tile_upkeep_description=The amount charged a month per tile. | ||
perimeter_cost=Perimeter cost | ||
perimeter_cost_description=The amount charged per perimeter tile when founding a deed. | ||
perimeter_upkeep=Perimeter upkeep | ||
perimeter_upkeep_description=The amount charged a month per perimeter tile. | ||
normal_guard_cost=Guard cost (Normal) | ||
normal_guard_cost_description=The amount charged per guard when founding a deed except for Epic or Challenge type servers. | ||
normal_guard_upkeep=Guard upkeep (Normal) | ||
normal_guard_upkeep_description=The amount charged a month for each guard except on Epic or Challenge type servers. | ||
epic_guard_cost=Guard cost (Epic) | ||
epic_guard_cost_description=The amount charged per guard when founding a deed on Epic and Challenge type server. | ||
epic_guard_upkeep=Guard upkeep (Epic) | ||
epic_guard_upkeep_description=The amount charged a month for each guard on Epic or Challenge type servers. | ||
minimum_upkeep=Minimum upkeep | ||
minimum_upkeep_description=The minimum charge per month. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import java.lang.*?> | ||
<?import javafx.scene.layout.*?> | ||
<?import javafx.scene.control.*?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import javafx.scene.layout.VBox?> | ||
|
||
|
||
<VBox prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="mod.wurmonline.mods.upkeepcosts.UpkeepCostsUI"> | ||
<ScrollPane fx:id="container" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS" /> | ||
<HBox minHeight="-Infinity" minWidth="-Infinity" VBox.vgrow="NEVER"> | ||
<children> | ||
<Button mnemonicParsing="false" onAction="#initialize" text="%button.refresh" /> | ||
<Button mnemonicParsing="false" onAction="#saveUpkeep" text="%button.save" /> | ||
</children> | ||
</HBox> | ||
</VBox> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package mod.wurmonline.mods.upkeepcosts; | ||
|
||
import com.ibm.icu.text.MessageFormat; | ||
import com.wurmonline.server.villages.Villages; | ||
import javafx.fxml.FXML; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.control.ButtonBar; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.ScrollPane; | ||
import javafx.scene.layout.Pane; | ||
import javafx.scene.layout.Region; | ||
import mod.wurmonline.serverlauncher.LocaleHelper; | ||
import mod.wurmonline.serverlauncher.gui.ServerGuiController; | ||
import org.gotti.wurmunlimited.modloader.interfaces.WurmUIMod; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.lang.reflect.Field; | ||
import java.nio.file.Paths; | ||
import java.util.Properties; | ||
import java.util.ResourceBundle; | ||
import java.util.logging.Level; | ||
|
||
public class UpkeepCostsUI extends UpkeepCosts implements WurmUIMod { | ||
ServerGuiController controller; | ||
UpkeepPropertySheet upkeepPropertySheet; | ||
ResourceBundle messages = LocaleHelper.getBundle("UpkeepCosts"); | ||
|
||
public UpkeepCostsUI () { | ||
NO_UPKEEP = messages.getString("no_upkeep"); | ||
FREE_DEEDS = messages.getString("free_deeds"); | ||
} | ||
|
||
@Override | ||
public Region getRegion(ServerGuiController guiController) { | ||
controller = guiController; | ||
try { | ||
FXMLLoader fx = new FXMLLoader(UpkeepCostsUI.class.getResource("UpkeepCosts.fxml"), LocaleHelper.getBundle("UIWindow")); | ||
fx.setClassLoader(this.getClass().getClassLoader()); | ||
fx.setControllerFactory(param -> this); | ||
return fx.load(); | ||
} catch (IOException ex) { | ||
logger.log(Level.SEVERE, ex.getMessage(), ex); | ||
} | ||
Label label = new Label(messages.getString("fxml_missing")); | ||
Pane pane = new Pane(); | ||
pane.getChildren().add(label); | ||
return pane; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return messages.getString("mod_name"); | ||
} | ||
|
||
void negative (String property) { | ||
logger.warning(MessageFormat.format(messages.getString("negative"), property)); | ||
} | ||
|
||
void invalid (String property) { | ||
logger.warning(MessageFormat.format(messages.getString("invalid"), property)); | ||
} | ||
|
||
void logValues () { | ||
logger.info(MessageFormat.format(messages.getString("all_values"), | ||
Villages.TILE_COST_STRING, | ||
Villages.TILE_UPKEEP_STRING, | ||
Villages.PERIMETER_COST_STRING, | ||
Villages.PERIMETER_UPKEEP_STRING, | ||
Villages.GUARD_COST_STRING, | ||
Villages.GUARD_UPKEEP_STRING, | ||
Villages.MINIMUM_UPKEEP_STRING)); | ||
} | ||
|
||
File getFile () { | ||
return new File(Paths.get(controller.getCurrentDir(), "mods", "upkeepcosts", "upkeepcosts.properties").toUri()); | ||
} | ||
|
||
@FXML | ||
ScrollPane container; | ||
|
||
@FXML | ||
void saveUpkeep () { | ||
if (upkeepPropertySheet.haveChanges()) { | ||
File file = getFile(); | ||
Properties properties = new Properties(); | ||
|
||
try { | ||
boolean created = file.createNewFile(); | ||
if (!created) { | ||
FileInputStream stream = new FileInputStream(file.toString()); | ||
properties.load(stream); | ||
} | ||
} catch (IOException ex) { | ||
logger.warning(messages.getString("load_properties_error")); | ||
ex.printStackTrace(); | ||
} | ||
for (Field field : this.getClass().getFields()) { | ||
if (!(field.getType().isAssignableFrom(Long.class))) { | ||
continue; | ||
} | ||
try { | ||
field.set(this, upkeepPropertySheet.list.get(UpkeepPropertySheet.UpkeepPropertyType.valueOf(field.getName().toUpperCase()).ordinal()).getValue()); | ||
properties.setProperty(field.getName(), field.get(this).toString()); | ||
} catch (IllegalAccessException ex) { | ||
logger.warning(messages.getString("error")); | ||
ex.printStackTrace(); | ||
} | ||
} | ||
try (FileOutputStream stream = new FileOutputStream(file.toString())) { | ||
properties.store(stream, ""); | ||
} catch (IOException ex) { | ||
logger.warning(messages.getString("save_properties_error")); | ||
ex.printStackTrace(); | ||
} | ||
upkeepPropertySheet.clearChanges(); | ||
if (controller.serverIsRunning()) { | ||
onServerStarted(); | ||
} | ||
} | ||
} | ||
|
||
ButtonType saveCheck() { | ||
if (upkeepPropertySheet != null && upkeepPropertySheet.haveChanges()) { | ||
ButtonType result = controller.showYesNoCancel(messages.getString("changes_title"), messages.getString("changes_header"), messages.getString("changes_message")).get(); | ||
if (result == ButtonType.YES) { | ||
saveUpkeep(); | ||
} | ||
return result; | ||
} | ||
return new ButtonType("", ButtonBar.ButtonData.NO); | ||
} | ||
|
||
@FXML | ||
void initialize () { | ||
System.out.println("Initializing"); | ||
ButtonType check = saveCheck(); | ||
if (check == ButtonType.CANCEL) { | ||
return; | ||
} | ||
|
||
try { | ||
File file = getFile(); | ||
boolean created = file.getParentFile().mkdirs(); | ||
if (!created) { | ||
created = file.createNewFile(); | ||
} | ||
|
||
if (created) { | ||
upkeepPropertySheet = new UpkeepPropertySheet(this); | ||
upkeepPropertySheet.setAllToChanged(); | ||
saveUpkeep(); | ||
container.setContent(upkeepPropertySheet); | ||
return; | ||
} | ||
|
||
FileInputStream stream = new FileInputStream(file.toString()); | ||
Properties properties = new Properties(); | ||
properties.load(stream); | ||
configure(properties); | ||
upkeepPropertySheet = new UpkeepPropertySheet(this); | ||
container.setContent(upkeepPropertySheet); | ||
} catch (IOException ex) { | ||
logger.warning(messages.getString("load_properties_error")); | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} |
Oops, something went wrong.