Magic_Ling_Pixel_Dungeon/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java

200 lines
6.0 KiB
Java
Raw Normal View History

2014-07-27 13:39:07 +00:00
/*
* Pixel Dungeon
* Copyright (C) 2012-2014 Oleg Dolya
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.windows;
2014-07-27 13:39:07 +00:00
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
2014-07-27 13:39:07 +00:00
import com.watabou.noosa.Camera;
import com.watabou.noosa.audio.Sample;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.CheckBox;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
2014-07-27 13:39:07 +00:00
public class WndSettings extends Window {
private static final String TXT_ZOOM_IN = "+";
private static final String TXT_ZOOM_OUT = "-";
private static final String TXT_ZOOM_DEFAULT = "Default Zoom";
private static final String TXT_SCALE_UP = "Scale up UI";
2014-10-20 07:24:59 +00:00
private static final String TXT_IMMERSIVE = "Immersive mode";
2014-07-27 13:39:07 +00:00
private static final String TXT_MUSIC = "Music";
private static final String TXT_SOUND = "Sound FX";
private static final String TXT_BRIGHTNESS = "Brightness";
private static final String TXT_QUICKSLOT = "Second QuickSlot";
2014-07-27 13:39:07 +00:00
private static final String TXT_SWITCH_PORT = "Switch to portrait";
private static final String TXT_SWITCH_LAND = "Switch to landscape";
private static final int WIDTH = 112;
private static final int BTN_HEIGHT = 20;
private static final int GAP = 2;
private RedButton btnZoomOut;
private RedButton btnZoomIn;
public WndSettings( boolean inGame ) {
super();
2014-10-20 07:24:59 +00:00
CheckBox btnImmersive = null;
2014-07-27 13:39:07 +00:00
if (inGame) {
int w = BTN_HEIGHT;
// Zoom out
btnZoomOut = new RedButton( TXT_ZOOM_OUT ) {
@Override
protected void onClick() {
zoom( Camera.main.zoom - 1 );
}
};
add( btnZoomOut.setRect( 0, 0, w, BTN_HEIGHT) );
// Zoom in
btnZoomIn = new RedButton( TXT_ZOOM_IN ) {
@Override
protected void onClick() {
zoom( Camera.main.zoom + 1 );
}
};
add( btnZoomIn.setRect( WIDTH - w, 0, w, BTN_HEIGHT) );
// Default zoom
add( new RedButton( TXT_ZOOM_DEFAULT ) {
@Override
protected void onClick() {
zoom( PixelScene.defaultZoom );
}
}.setRect( btnZoomOut.right(), 0, WIDTH - btnZoomIn.width() - btnZoomOut.width(), BTN_HEIGHT ) );
} else {
CheckBox btnScaleUp = new CheckBox( TXT_SCALE_UP ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.scaleUp(checked());
2014-07-27 13:39:07 +00:00
}
};
btnScaleUp.setRect( 0, 0, WIDTH, BTN_HEIGHT );
btnScaleUp.checked( ShatteredPixelDungeon.scaleUp() );
2014-07-27 13:39:07 +00:00
add( btnScaleUp );
2014-10-20 07:24:59 +00:00
btnImmersive = new CheckBox( TXT_IMMERSIVE ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.immerse( checked() );
}
};
btnImmersive.setRect( 0, btnScaleUp.bottom() + GAP, WIDTH, BTN_HEIGHT );
btnImmersive.checked( ShatteredPixelDungeon.immersed() );
btnImmersive.enable( android.os.Build.VERSION.SDK_INT >= 19 );
add( btnImmersive );
}
2014-07-27 13:39:07 +00:00
CheckBox btnMusic = new CheckBox( TXT_MUSIC ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.music(checked());
2014-07-27 13:39:07 +00:00
}
};
2014-10-20 07:24:59 +00:00
btnMusic.setRect( 0, (btnImmersive != null ? btnImmersive.bottom() : BTN_HEIGHT) + GAP, WIDTH, BTN_HEIGHT );
btnMusic.checked( ShatteredPixelDungeon.music() );
2014-07-27 13:39:07 +00:00
add( btnMusic );
CheckBox btnSound = new CheckBox( TXT_SOUND ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.soundFx(checked());
2014-07-27 13:39:07 +00:00
Sample.INSTANCE.play( Assets.SND_CLICK );
}
};
btnSound.setRect( 0, btnMusic.bottom() + GAP, WIDTH, BTN_HEIGHT );
btnSound.checked( ShatteredPixelDungeon.soundFx() );
2014-07-27 13:39:07 +00:00
add( btnSound );
if (!inGame) {
RedButton btnOrientation = new RedButton( orientationText() ) {
@Override
protected void onClick() {
ShatteredPixelDungeon.landscape(!ShatteredPixelDungeon.landscape());
2014-07-27 13:39:07 +00:00
}
};
btnOrientation.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT );
add( btnOrientation );
resize( WIDTH, (int)btnOrientation.bottom() );
} else {
CheckBox btnBrightness = new CheckBox( TXT_BRIGHTNESS ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.brightness(checked());
2014-07-27 13:39:07 +00:00
}
};
btnBrightness.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT );
btnBrightness.checked( ShatteredPixelDungeon.brightness() );
2014-07-27 13:39:07 +00:00
add( btnBrightness );
CheckBox btnQuickSlot = new CheckBox( TXT_QUICKSLOT ) {
@Override
protected void onClick() {
super.onClick();
ShatteredPixelDungeon.quickSlots(checked() ? 2 : 1);
}
};
btnQuickSlot.setRect( 0, btnBrightness.bottom() + GAP, WIDTH, BTN_HEIGHT );
btnQuickSlot.checked( ShatteredPixelDungeon.quickSlots() == 1 );
add( btnQuickSlot );
2014-07-27 13:39:07 +00:00
resize( WIDTH, (int)btnQuickSlot.bottom() );
2014-07-27 13:39:07 +00:00
}
}
private void zoom( float value ) {
Camera.main.zoom( value );
ShatteredPixelDungeon.zoom((int) (value - PixelScene.defaultZoom));
2014-07-27 13:39:07 +00:00
updateEnabled();
}
private void updateEnabled() {
float zoom = Camera.main.zoom;
btnZoomIn.enable( zoom < PixelScene.maxZoom );
btnZoomOut.enable( zoom > PixelScene.minZoom );
}
private String orientationText() {
return ShatteredPixelDungeon.landscape() ? TXT_SWITCH_PORT : TXT_SWITCH_LAND;
2014-07-27 13:39:07 +00:00
}
}