Merge pull request #362 from rzats/lang-icons

[OK to merge] Language selection icons
master
Tobias Nett 2016-03-30 18:42:39 +02:00
commit eb7a75d600
15 changed files with 78 additions and 8 deletions

BIN
icons/flags/cs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

BIN
icons/flags/de.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

BIN
icons/flags/en.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

BIN
icons/flags/es.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 469 B

BIN
icons/flags/fr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

BIN
icons/flags/gl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

BIN
icons/flags/it.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

BIN
icons/flags/ja.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

BIN
icons/flags/lt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

BIN
icons/flags/pl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

BIN
icons/flags/ru.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

BIN
icons/flags/tr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 B

View File

@ -21,8 +21,18 @@ import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.Tab;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.launcher.game.GameJob;
@ -31,12 +41,18 @@ import org.terasology.launcher.game.TerasologyGameVersion;
import org.terasology.launcher.game.TerasologyGameVersions;
import org.terasology.launcher.game.VersionItem;
import org.terasology.launcher.settings.BaseLauncherSettings;
import org.terasology.launcher.util.*;
import org.terasology.launcher.util.BundleUtils;
import org.terasology.launcher.util.DirectoryUtils;
import org.terasology.launcher.util.GuiUtils;
import org.terasology.launcher.util.JavaHeapSize;
import org.terasology.launcher.util.Languages;
import org.terasology.launcher.util.LogLevel;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
public class SettingsController {
@ -112,7 +128,7 @@ public class SettingsController {
@FXML
private ComboBox<JavaHeapSize> initialHeapSizeBox;
@FXML
private ChoiceBox<String> languageBox;
private ComboBox<String> languageBox;
@FXML
private CheckBox saveDownloadedFilesBox;
@FXML
@ -278,7 +294,8 @@ public class SettingsController {
populateJobBox();
populateHeapSize();
populateLanguage();
populateLanguageValues();
populateLanguageIcons();
populateSearchForLauncherUpdates();
populateCloseLauncherAfterGameStart();
populateSaveDownloadedFiles();
@ -294,7 +311,7 @@ public class SettingsController {
}
/**
* Used to assign localized label strings via BundleUtils
* Used to assign localized label strings via BundleUtils.
* Allows for fallback strings to be assigned if the localization-specific ones
* are absent/empty
*/
@ -412,7 +429,7 @@ public class SettingsController {
updateHeapSizeSelection();
}
private void populateLanguage() {
private void populateLanguageValues() {
languageBox.getItems().clear();
for (Locale locale : Languages.SUPPORTED_LOCALES) {
String item = locale.toLanguageTag() + " : " + BundleUtils.getLabel(locale, Languages.SETTINGS_LABEL_KEYS.get(locale));
@ -426,6 +443,47 @@ public class SettingsController {
}
}
}
private void populateLanguageIcons() {
languageBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
@Override
public ListCell<String> call(ListView<String> p) {
return new ListCell<String>() {
@Override
protected void updateItem(String item, boolean empty) {
// Pass along the locale text
super.updateItem(item, empty);
this.setText(item);
if (item == null || empty) {
this.setGraphic(null);
} else {
// Get the key thar represents the locale in ImageBundle (flag_xx)
String countryCode = this.getText().split(":")[0].trim();
String id = "flag_" + countryCode;
try {
// Get the appropriate flag icon via BundleUtils
Image icon = BundleUtils.getFxImage(id);
ImageView iconImageView = new ImageView(icon);
iconImageView.setFitHeight(11);
iconImageView.setPreserveRatio(true);
this.setGraphic(iconImageView);
} catch (MissingResourceException e) {
logger.warn("ImageBundle key {} not found", id);
} catch (NullPointerException e) {
logger.warn("Flag icon in ImageBundle key {} missing or corrupt", id);
}
}
}
};
}
});
// Make the icon visible in the control area for the selected locale
languageBox.setButtonCell(languageBox.getCellFactory().call(null));
}
private void populateSearchForLauncherUpdates() {
searchForUpdatesBox.setSelected(launcherSettings.isSearchForLauncherUpdates());

View File

@ -20,6 +20,18 @@ button_hovered=/org/terasology/launcher/images/button_hovered.png
button_pressed=/org/terasology/launcher/images/button_pressed.png
facebook=/org/terasology/launcher/images/facebook.png
facebook_hover=/org/terasology/launcher/images/facebook_hover.png
flag_cs=/org/terasology/launcher/icons/flags/cs.png
flag_de=/org/terasology/launcher/icons/flags/de.png
flag_en=/org/terasology/launcher/icons/flags/en.png
flag_es=/org/terasology/launcher/icons/flags/es.png
flag_fr=/org/terasology/launcher/icons/flags/fr.png
flag_gl=/org/terasology/launcher/icons/flags/gl.png
flag_it=/org/terasology/launcher/icons/flags/it.png
flag_ja=/org/terasology/launcher/icons/flags/ja.png
flag_lt=/org/terasology/launcher/icons/flags/lt.png
flag_pl=/org/terasology/launcher/icons/flags/pl.png
flag_ru=/org/terasology/launcher/icons/flags/ru.png
flag_tr=/org/terasology/launcher/icons/flags/tr.png
github=/org/terasology/launcher/images/github.png
github_hover=/org/terasology/launcher/images/github_hover.png
gplus=/org/terasology/launcher/images/gplus.png

View File

@ -273,7 +273,7 @@
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0"
spacing="8.0" GridPane.columnIndex="1" GridPane.rowIndex="0">
<children>
<ChoiceBox fx:id="languageBox" maxWidth="1.7976931348623157E308"
<ComboBox fx:id="languageBox" maxWidth="1.7976931348623157E308"
HBox.hgrow="ALWAYS">
<items>
<FXCollections fx:factory="observableArrayList">
@ -282,7 +282,7 @@
<String fx:value="Item 3"/>
</FXCollections>
</items>
</ChoiceBox>
</ComboBox>
</children>
<padding>
<Insets left="8.0" right="8.0"/>