v0.8.2: big code refactor on the settings window in prep for additions
This commit is contained in:
parent
0865333774
commit
0f836e5042
|
@ -34,16 +34,14 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.Group;
|
||||
import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
import com.watabou.utils.DeviceCompat;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
//TODO seeing as a fair bit of this is platform-dependant, might be better to have a per-platform wndsettings
|
||||
public class WndSettings extends WndTabbed {
|
||||
|
||||
private static final int WIDTH = 112;
|
||||
private static final int HEIGHT = 138;
|
||||
private static final int SLIDER_HEIGHT = 24;
|
||||
private static final int BTN_HEIGHT = 18;
|
||||
private static final int GAP_TINY = 2;
|
||||
|
@ -59,15 +57,13 @@ public class WndSettings extends WndTabbed {
|
|||
public WndSettings() {
|
||||
super();
|
||||
|
||||
float height;
|
||||
|
||||
display = new DisplayTab();
|
||||
display.setSize(WIDTH, 0);
|
||||
height = display.height();
|
||||
add( display );
|
||||
|
||||
ui = new UITab();
|
||||
add( ui );
|
||||
|
||||
audio = new AudioTab();
|
||||
add( audio );
|
||||
|
||||
add( new IconTab(Icons.get(Icons.DISPLAY)){
|
||||
@Override
|
||||
protected void select(boolean value) {
|
||||
|
@ -77,6 +73,11 @@ public class WndSettings extends WndTabbed {
|
|||
}
|
||||
});
|
||||
|
||||
ui = new UITab();
|
||||
ui.setSize(WIDTH, 0);
|
||||
height = Math.max(height, ui.height());
|
||||
add( ui );
|
||||
|
||||
add( new IconTab(Icons.get(Icons.PREFS)){
|
||||
@Override
|
||||
protected void select(boolean value) {
|
||||
|
@ -86,6 +87,11 @@ public class WndSettings extends WndTabbed {
|
|||
}
|
||||
});
|
||||
|
||||
audio = new AudioTab();
|
||||
audio.setSize(WIDTH, 0);
|
||||
height = Math.max(height, audio.height());
|
||||
add( audio );
|
||||
|
||||
add( new IconTab(Icons.get(Icons.AUDIO)){
|
||||
@Override
|
||||
protected void select(boolean value) {
|
||||
|
@ -95,7 +101,7 @@ public class WndSettings extends WndTabbed {
|
|||
}
|
||||
});
|
||||
|
||||
resize(WIDTH, HEIGHT);
|
||||
resize(WIDTH, (int)Math.ceil(height));
|
||||
|
||||
layoutTabs();
|
||||
|
||||
|
@ -103,144 +109,170 @@ public class WndSettings extends WndTabbed {
|
|||
|
||||
}
|
||||
|
||||
private class DisplayTab extends Group {
|
||||
private class DisplayTab extends Component {
|
||||
|
||||
public DisplayTab() {
|
||||
super();
|
||||
OptionSlider optScale;
|
||||
CheckBox chkSaver;
|
||||
RedButton btnOrientation;
|
||||
|
||||
OptionSlider scale = new OptionSlider(Messages.get(this, "scale"),
|
||||
(int)Math.ceil(2* Game.density)+ "X",
|
||||
PixelScene.maxDefaultZoom + "X",
|
||||
(int)Math.ceil(2* Game.density),
|
||||
PixelScene.maxDefaultZoom ) {
|
||||
@Override
|
||||
protected void onChange() {
|
||||
if (getSelectedValue() != SPDSettings.scale()) {
|
||||
SPDSettings.scale(getSelectedValue());
|
||||
ShatteredPixelDungeon.seamlessResetScene();
|
||||
}
|
||||
}
|
||||
};
|
||||
OptionSlider optBrightness;
|
||||
OptionSlider optVisGrid;
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
if ((int)Math.ceil(2* Game.density) < PixelScene.maxDefaultZoom) {
|
||||
scale.setSelectedValue(PixelScene.defaultZoom);
|
||||
scale.setRect(0, 0, WIDTH, SLIDER_HEIGHT);
|
||||
add(scale);
|
||||
optScale = new OptionSlider(Messages.get(this, "scale"),
|
||||
(int)Math.ceil(2* Game.density)+ "X",
|
||||
PixelScene.maxDefaultZoom + "X",
|
||||
(int)Math.ceil(2* Game.density),
|
||||
PixelScene.maxDefaultZoom ) {
|
||||
@Override
|
||||
protected void onChange() {
|
||||
if (getSelectedValue() != SPDSettings.scale()) {
|
||||
SPDSettings.scale(getSelectedValue());
|
||||
ShatteredPixelDungeon.seamlessResetScene();
|
||||
}
|
||||
}
|
||||
};
|
||||
add(optScale);
|
||||
}
|
||||
|
||||
float bottom = scale.bottom();
|
||||
|
||||
if (!DeviceCompat.isDesktop()) {
|
||||
CheckBox chkSaver = new CheckBox( Messages.get( this, "saver" ) ) {
|
||||
if (!DeviceCompat.isDesktop() && PixelScene.maxScreenZoom >= 2) {
|
||||
chkSaver = new CheckBox(Messages.get(this, "saver")) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
if (checked()) {
|
||||
checked( !checked() );
|
||||
ShatteredPixelDungeon.scene().add( new WndOptions(
|
||||
Messages.get( DisplayTab.class, "saver" ),
|
||||
Messages.get( DisplayTab.class, "saver_desc" ),
|
||||
Messages.get( DisplayTab.class, "okay" ),
|
||||
Messages.get( DisplayTab.class, "cancel" ) ) {
|
||||
checked(!checked());
|
||||
ShatteredPixelDungeon.scene().add(new WndOptions(
|
||||
Messages.get(DisplayTab.class, "saver"),
|
||||
Messages.get(DisplayTab.class, "saver_desc"),
|
||||
Messages.get(DisplayTab.class, "okay"),
|
||||
Messages.get(DisplayTab.class, "cancel")) {
|
||||
@Override
|
||||
protected void onSelect( int index ) {
|
||||
protected void onSelect(int index) {
|
||||
if (index == 0) {
|
||||
checked( !checked() );
|
||||
SPDSettings.powerSaver( checked() );
|
||||
checked(!checked());
|
||||
SPDSettings.powerSaver(checked());
|
||||
}
|
||||
}
|
||||
} );
|
||||
});
|
||||
} else {
|
||||
SPDSettings.powerSaver( checked() );
|
||||
SPDSettings.powerSaver(checked());
|
||||
}
|
||||
}
|
||||
};
|
||||
if (PixelScene.maxScreenZoom >= 2) {
|
||||
chkSaver.setRect( 0, scale.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT );
|
||||
chkSaver.checked( SPDSettings.powerSaver() );
|
||||
add( chkSaver );
|
||||
}
|
||||
|
||||
//TODO also need to disable this in android splitscreen
|
||||
RedButton btnOrientation = new RedButton( PixelScene.landscape() ?
|
||||
Messages.get( this, "portrait" )
|
||||
: Messages.get( this, "landscape" ) ) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
SPDSettings.landscape( !PixelScene.landscape() );
|
||||
}
|
||||
};
|
||||
btnOrientation.setRect( 0, chkSaver.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT );
|
||||
add( btnOrientation );
|
||||
|
||||
bottom = btnOrientation.bottom();
|
||||
chkSaver.checked( SPDSettings.powerSaver() );
|
||||
add( chkSaver );
|
||||
}
|
||||
|
||||
OptionSlider brightness = new OptionSlider(Messages.get(this, "brightness"),
|
||||
if (!DeviceCompat.isDesktop()) {
|
||||
btnOrientation = new RedButton(PixelScene.landscape() ?
|
||||
Messages.get(this, "portrait")
|
||||
: Messages.get(this, "landscape")) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
SPDSettings.landscape(!PixelScene.landscape());
|
||||
}
|
||||
};
|
||||
add(btnOrientation);
|
||||
}
|
||||
|
||||
optBrightness = new OptionSlider(Messages.get(this, "brightness"),
|
||||
Messages.get(this, "dark"), Messages.get(this, "bright"), -1, 1) {
|
||||
@Override
|
||||
protected void onChange() {
|
||||
SPDSettings.brightness(getSelectedValue());
|
||||
}
|
||||
};
|
||||
brightness.setSelectedValue(SPDSettings.brightness());
|
||||
brightness.setRect(0, bottom + GAP_LRG, WIDTH, SLIDER_HEIGHT);
|
||||
add(brightness);
|
||||
optBrightness.setSelectedValue(SPDSettings.brightness());
|
||||
add(optBrightness);
|
||||
|
||||
OptionSlider tileGrid = new OptionSlider(Messages.get(this, "visual_grid"),
|
||||
optVisGrid = new OptionSlider(Messages.get(this, "visual_grid"),
|
||||
Messages.get(this, "off"), Messages.get(this, "high"), -1, 2) {
|
||||
@Override
|
||||
protected void onChange() {
|
||||
SPDSettings.visualGrid(getSelectedValue());
|
||||
}
|
||||
};
|
||||
tileGrid.setSelectedValue(SPDSettings.visualGrid());
|
||||
tileGrid.setRect(0, brightness.bottom() + GAP_TINY, WIDTH, SLIDER_HEIGHT);
|
||||
add(tileGrid);
|
||||
optVisGrid.setSelectedValue(SPDSettings.visualGrid());
|
||||
add(optVisGrid);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
|
||||
float bottom = 0;
|
||||
|
||||
if (optScale != null){
|
||||
optScale.setRect(0, 0, width, SLIDER_HEIGHT);
|
||||
bottom = optScale.bottom();
|
||||
}
|
||||
|
||||
if (chkSaver != null){
|
||||
chkSaver.setRect( 0, bottom + GAP_TINY, width, BTN_HEIGHT );
|
||||
bottom = chkSaver.bottom();
|
||||
}
|
||||
|
||||
if (btnOrientation != null){
|
||||
btnOrientation.setRect( 0, bottom + GAP_TINY, width, BTN_HEIGHT );
|
||||
bottom = btnOrientation.bottom();
|
||||
}
|
||||
|
||||
optBrightness.setRect(0, bottom + GAP_LRG, width, SLIDER_HEIGHT);
|
||||
optVisGrid.setRect(0, optBrightness.bottom() + GAP_TINY, width, SLIDER_HEIGHT);
|
||||
|
||||
height = optVisGrid.bottom();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class UITab extends Group {
|
||||
private class UITab extends Component {
|
||||
|
||||
public UITab(){
|
||||
super();
|
||||
RenderedTextBlock barDesc;
|
||||
RedButton btnSplit; RedButton btnGrouped; RedButton btnCentered;
|
||||
CheckBox chkFlipToolbar;
|
||||
CheckBox chkFlipTags;
|
||||
|
||||
RenderedTextBlock barDesc = PixelScene.renderTextBlock(Messages.get(this, "mode"), 9);
|
||||
barDesc.setPos((WIDTH-barDesc.width())/2f, GAP_TINY);
|
||||
PixelScene.align(barDesc);
|
||||
CheckBox chkFullscreen;
|
||||
CheckBox chkFont;
|
||||
|
||||
RedButton btnKeyBindings;
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
barDesc = PixelScene.renderTextBlock(Messages.get(this, "mode"), 9);
|
||||
add(barDesc);
|
||||
|
||||
RedButton btnSplit = new RedButton(Messages.get(this, "split")){
|
||||
btnSplit = new RedButton(Messages.get(this, "split")){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
SPDSettings.toolbarMode(Toolbar.Mode.SPLIT.name());
|
||||
Toolbar.updateLayout();
|
||||
}
|
||||
};
|
||||
btnSplit.setRect( 0, barDesc.bottom() + GAP_TINY, 36, 16);
|
||||
add(btnSplit);
|
||||
|
||||
RedButton btnGrouped = new RedButton(Messages.get(this, "group")){
|
||||
btnGrouped = new RedButton(Messages.get(this, "group")){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
SPDSettings.toolbarMode(Toolbar.Mode.GROUP.name());
|
||||
Toolbar.updateLayout();
|
||||
}
|
||||
};
|
||||
btnGrouped.setRect( btnSplit.right()+GAP_TINY, btnSplit.top(), 36, 16);
|
||||
add(btnGrouped);
|
||||
|
||||
RedButton btnCentered = new RedButton(Messages.get(this, "center")){
|
||||
btnCentered = new RedButton(Messages.get(this, "center")){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
SPDSettings.toolbarMode(Toolbar.Mode.CENTER.name());
|
||||
Toolbar.updateLayout();
|
||||
}
|
||||
};
|
||||
btnCentered.setRect(btnGrouped.right()+GAP_TINY, btnSplit.top(), 36, 16);
|
||||
add(btnCentered);
|
||||
|
||||
CheckBox chkFlipToolbar = new CheckBox(Messages.get(this, "flip_toolbar")){
|
||||
chkFlipToolbar = new CheckBox(Messages.get(this, "flip_toolbar")){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
|
@ -248,11 +280,10 @@ public class WndSettings extends WndTabbed {
|
|||
Toolbar.updateLayout();
|
||||
}
|
||||
};
|
||||
chkFlipToolbar.setRect(0, btnGrouped.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT);
|
||||
chkFlipToolbar.checked(SPDSettings.flipToolbar());
|
||||
add(chkFlipToolbar);
|
||||
|
||||
final CheckBox chkFlipTags = new CheckBox(Messages.get(this, "flip_indicators")){
|
||||
chkFlipTags = new CheckBox(Messages.get(this, "flip_indicators")){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
|
@ -260,34 +291,21 @@ public class WndSettings extends WndTabbed {
|
|||
GameScene.layoutTags();
|
||||
}
|
||||
};
|
||||
chkFlipTags.setRect(0, chkFlipToolbar.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT);
|
||||
chkFlipTags.checked(SPDSettings.flipTags());
|
||||
add(chkFlipTags);
|
||||
|
||||
/*OptionSlider slots = new OptionSlider(Messages.get(this, "quickslots"), "0", "4", 0, 4) {
|
||||
@Override
|
||||
protected void onChange() {
|
||||
SPDSettings.quickSlots(getSelectedValue());
|
||||
Toolbar.updateLayout();
|
||||
}
|
||||
};
|
||||
slots.setSelectedValue(SPDSettings.quickSlots());
|
||||
slots.setRect(0, chkFlipTags.bottom() + GAP_TINY, WIDTH, SLIDER_HEIGHT);
|
||||
add(slots);*/
|
||||
|
||||
CheckBox chkFullscreen = new CheckBox( Messages.get(this, "fullscreen") ) {
|
||||
chkFullscreen = new CheckBox( Messages.get(this, "fullscreen") ) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
SPDSettings.fullscreen(checked());
|
||||
}
|
||||
};
|
||||
chkFullscreen.setRect( 0, chkFlipTags.bottom() + GAP_SML, WIDTH, BTN_HEIGHT );
|
||||
chkFullscreen.checked(SPDSettings.fullscreen());
|
||||
chkFullscreen.enable(DeviceCompat.supportsFullScreen());
|
||||
add(chkFullscreen);
|
||||
|
||||
CheckBox chkFont = new CheckBox(Messages.get(this, "system_font")){
|
||||
chkFont = new CheckBox(Messages.get(this, "system_font")){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
|
@ -304,12 +322,12 @@ public class WndSettings extends WndTabbed {
|
|||
});
|
||||
}
|
||||
};
|
||||
chkFont.setRect(0, chkFullscreen.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT);
|
||||
|
||||
chkFont.checked(SPDSettings.systemFont());
|
||||
add(chkFont);
|
||||
|
||||
if (DeviceCompat.hasHardKeyboard()){
|
||||
RedButton btnKeyBindings = new RedButton(Messages.get(this, "key_bindings")){
|
||||
btnKeyBindings = new RedButton(Messages.get(this, "key_bindings")){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
|
@ -317,39 +335,67 @@ public class WndSettings extends WndTabbed {
|
|||
}
|
||||
};
|
||||
|
||||
btnKeyBindings.setRect(0, chkFont.bottom() + GAP_SML, WIDTH, BTN_HEIGHT);
|
||||
add(btnKeyBindings);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
barDesc.setPos((width-barDesc.width())/2f, GAP_TINY);
|
||||
PixelScene.align(barDesc);
|
||||
|
||||
int btnWidth = (int)(width - 2*GAP_TINY)/3;
|
||||
btnSplit.setRect(0, barDesc.bottom() + GAP_TINY, btnWidth, 16);
|
||||
btnGrouped.setRect(btnSplit.right()+GAP_TINY, btnSplit.top(), btnWidth, 16);
|
||||
btnCentered.setRect(btnGrouped.right()+GAP_TINY, btnSplit.top(), btnWidth, 16);
|
||||
|
||||
chkFlipToolbar.setRect(0, btnGrouped.bottom() + GAP_TINY, width, BTN_HEIGHT);
|
||||
chkFlipTags.setRect(0, chkFlipToolbar.bottom() + GAP_TINY, width, BTN_HEIGHT);
|
||||
|
||||
chkFullscreen.setRect(0, chkFlipTags.bottom() + GAP_SML, width, BTN_HEIGHT);
|
||||
|
||||
chkFont.setRect(0, chkFullscreen.bottom() + GAP_TINY, width, BTN_HEIGHT);
|
||||
|
||||
if (btnKeyBindings != null){
|
||||
btnKeyBindings.setRect(0, chkFont.bottom() + GAP_SML, width, BTN_HEIGHT);
|
||||
height = btnKeyBindings.bottom();
|
||||
} else {
|
||||
height = chkFont.bottom();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class AudioTab extends Group {
|
||||
private class AudioTab extends Component {
|
||||
|
||||
public AudioTab() {
|
||||
OptionSlider musicVol = new OptionSlider(Messages.get(this, "music_vol"), "0", "10", 0, 10) {
|
||||
OptionSlider optMusic;
|
||||
CheckBox chkMusicMute;
|
||||
|
||||
OptionSlider optSFX;
|
||||
CheckBox chkMuteSFX;
|
||||
|
||||
@Override
|
||||
protected void createChildren() {
|
||||
optMusic = new OptionSlider(Messages.get(this, "music_vol"), "0", "10", 0, 10) {
|
||||
@Override
|
||||
protected void onChange() {
|
||||
SPDSettings.musicVol(getSelectedValue());
|
||||
}
|
||||
};
|
||||
musicVol.setSelectedValue(SPDSettings.musicVol());
|
||||
musicVol.setRect(0, 0, WIDTH, SLIDER_HEIGHT);
|
||||
add(musicVol);
|
||||
optMusic.setSelectedValue(SPDSettings.musicVol());
|
||||
add(optMusic);
|
||||
|
||||
CheckBox musicMute = new CheckBox(Messages.get(this, "music_mute")){
|
||||
chkMusicMute = new CheckBox(Messages.get(this, "music_mute")){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
SPDSettings.music(!checked());
|
||||
}
|
||||
};
|
||||
musicMute.setRect(0, musicVol.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT);
|
||||
musicMute.checked(!SPDSettings.music());
|
||||
add(musicMute);
|
||||
chkMusicMute.checked(!SPDSettings.music());
|
||||
add(chkMusicMute);
|
||||
|
||||
|
||||
OptionSlider SFXVol = new OptionSlider(Messages.get(this, "sfx_vol"), "0", "10", 0, 10) {
|
||||
optSFX = new OptionSlider(Messages.get(this, "sfx_vol"), "0", "10", 0, 10) {
|
||||
@Override
|
||||
protected void onChange() {
|
||||
SPDSettings.SFXVol(getSelectedValue());
|
||||
|
@ -365,11 +411,10 @@ public class WndSettings extends WndTabbed {
|
|||
}
|
||||
}
|
||||
};
|
||||
SFXVol.setSelectedValue(SPDSettings.SFXVol());
|
||||
SFXVol.setRect(0, musicMute.bottom() + GAP_LRG, WIDTH, SLIDER_HEIGHT);
|
||||
add(SFXVol);
|
||||
optSFX.setSelectedValue(SPDSettings.SFXVol());
|
||||
add(optSFX);
|
||||
|
||||
CheckBox btnSound = new CheckBox( Messages.get(this, "sfx_mute") ) {
|
||||
chkMuteSFX = new CheckBox( Messages.get(this, "sfx_mute") ) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
|
@ -377,11 +422,19 @@ public class WndSettings extends WndTabbed {
|
|||
Sample.INSTANCE.play( Assets.Sounds.CLICK );
|
||||
}
|
||||
};
|
||||
btnSound.setRect(0, SFXVol.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT);
|
||||
btnSound.checked(!SPDSettings.soundFx());
|
||||
add( btnSound );
|
||||
chkMuteSFX.checked(!SPDSettings.soundFx());
|
||||
add( chkMuteSFX );
|
||||
}
|
||||
|
||||
resize( WIDTH, (int)btnSound.bottom());
|
||||
@Override
|
||||
protected void layout() {
|
||||
optMusic.setRect(0, 0, width, SLIDER_HEIGHT);
|
||||
chkMusicMute.setRect(0, optMusic.bottom() + GAP_TINY, width, BTN_HEIGHT);
|
||||
|
||||
optSFX.setRect(0, chkMusicMute.bottom() + GAP_LRG, width, SLIDER_HEIGHT);
|
||||
chkMuteSFX.setRect(0, optSFX.bottom() + GAP_TINY, width, BTN_HEIGHT);
|
||||
|
||||
height = chkMuteSFX.bottom();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user