v0.8.0: added an initial window for key bindings, more work needed
This commit is contained in:
parent
d726efb948
commit
b4739b766d
|
@ -28,4 +28,6 @@ public class GameAction {
|
|||
public static final int BACK = 1;
|
||||
public static final int MENU = 2;
|
||||
|
||||
public static final int TOTAL_ACTIONS = 3;
|
||||
|
||||
}
|
||||
|
|
|
@ -21,11 +21,16 @@
|
|||
|
||||
package com.watabou.input;
|
||||
|
||||
import java.util.HashMap;
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
//TODO maybe just move to game action?
|
||||
public class KeyBindings {
|
||||
|
||||
private static HashMap<Integer, Integer> bindings = new HashMap<>();
|
||||
private static LinkedHashMap<Integer, Integer> bindings = new LinkedHashMap<>();
|
||||
private static HashMap<Integer, String> names = new HashMap<>();
|
||||
|
||||
public static void addBinding( int keyCode, int keyAction){
|
||||
|
@ -40,6 +45,26 @@ public class KeyBindings {
|
|||
return bindings.get( event.code );
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> getBindings( int gameAction ){
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for( int i : bindings.keySet()){
|
||||
if (bindings.get(i) == gameAction){
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getKeyName( int keyCode ){
|
||||
String result = Input.Keys.toString(keyCode);
|
||||
|
||||
if (result.equals("Plus")){
|
||||
return "+";
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static void addName( int keyAction, String name ){
|
||||
names.put(keyAction, name);
|
||||
}
|
||||
|
|
|
@ -54,18 +54,19 @@ public class SPDAction extends GameAction {
|
|||
|
||||
public static final int ZOOM_IN = 17;
|
||||
public static final int ZOOM_OUT = 18;
|
||||
public static final int ZOOM_DEFAULT= 19;
|
||||
|
||||
public static final int N = 20;
|
||||
public static final int NE = 21;
|
||||
public static final int E = 22;
|
||||
public static final int SE = 23;
|
||||
public static final int S = 24;
|
||||
public static final int N = 19;
|
||||
public static final int E = 20;
|
||||
public static final int S = 21;
|
||||
public static final int W = 22;
|
||||
public static final int NE = 23;
|
||||
public static final int SE = 24;
|
||||
public static final int SW = 25;
|
||||
public static final int W = 26;
|
||||
public static final int NW = 27;
|
||||
public static final int NW = 26;
|
||||
|
||||
public static void initialize() {
|
||||
public static final int TOTAL_ACTIONS = 27;
|
||||
|
||||
public static void initDefaults() {
|
||||
|
||||
KeyBindings.addName(NONE, "none");
|
||||
|
||||
|
@ -92,16 +93,15 @@ public class SPDAction extends GameAction {
|
|||
|
||||
KeyBindings.addName(ZOOM_IN, "zoom_in");
|
||||
KeyBindings.addName(ZOOM_OUT, "zoom_out");
|
||||
KeyBindings.addName(ZOOM_DEFAULT, "zoom_default");
|
||||
|
||||
KeyBindings.addName(N, "none");
|
||||
KeyBindings.addName(NE, "none");
|
||||
KeyBindings.addName(E, "none");
|
||||
KeyBindings.addName(SE, "none");
|
||||
KeyBindings.addName(S, "none");
|
||||
KeyBindings.addName(SW, "none");
|
||||
KeyBindings.addName(W, "none");
|
||||
KeyBindings.addName(NW, "none");
|
||||
KeyBindings.addName(N, "n");
|
||||
KeyBindings.addName(E, "e");
|
||||
KeyBindings.addName(S, "s");
|
||||
KeyBindings.addName(W, "w");
|
||||
KeyBindings.addName(NE, "ne");
|
||||
KeyBindings.addName(SE, "se");
|
||||
KeyBindings.addName(SW, "sw");
|
||||
KeyBindings.addName(NW, "nw");
|
||||
|
||||
//default key bindings
|
||||
KeyBindings.addBinding( Input.Keys.BACK, GameAction.BACK );
|
||||
|
@ -110,7 +110,6 @@ public class SPDAction extends GameAction {
|
|||
KeyBindings.addBinding( Input.Keys.H, SPDAction.HERO_INFO );
|
||||
KeyBindings.addBinding( Input.Keys.J, SPDAction.JOURNAL );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_5, SPDAction.WAIT );
|
||||
KeyBindings.addBinding( Input.Keys.SPACE, SPDAction.WAIT );
|
||||
KeyBindings.addBinding( Input.Keys.S, SPDAction.SEARCH );
|
||||
|
||||
|
@ -129,12 +128,13 @@ public class SPDAction extends GameAction {
|
|||
KeyBindings.addBinding( Input.Keys.PLUS, SPDAction.ZOOM_IN );
|
||||
KeyBindings.addBinding( Input.Keys.EQUALS, SPDAction.ZOOM_IN );
|
||||
KeyBindings.addBinding( Input.Keys.MINUS, SPDAction.ZOOM_OUT );
|
||||
KeyBindings.addBinding( Input.Keys.SLASH, SPDAction.ZOOM_DEFAULT );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.UP, SPDAction.N );
|
||||
KeyBindings.addBinding( Input.Keys.RIGHT, SPDAction.E );
|
||||
KeyBindings.addBinding( Input.Keys.DOWN, SPDAction.S );
|
||||
KeyBindings.addBinding( Input.Keys.LEFT, SPDAction.W );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_5, SPDAction.WAIT );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_8, SPDAction.N );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_9, SPDAction.NE );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_6, SPDAction.E );
|
||||
|
@ -146,4 +146,14 @@ public class SPDAction extends GameAction {
|
|||
|
||||
}
|
||||
|
||||
//file name? perhaps
|
||||
|
||||
public static void loadBindings(){
|
||||
|
||||
}
|
||||
|
||||
public static void saveBindings(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ public class ShatteredPixelDungeon extends Game {
|
|||
super.create();
|
||||
|
||||
updateSystemUI();
|
||||
SPDAction.initialize();
|
||||
SPDAction.initDefaults();
|
||||
|
||||
Music.INSTANCE.enable( SPDSettings.music() );
|
||||
Music.INSTANCE.volume( SPDSettings.musicVol()/10f );
|
||||
|
|
|
@ -228,9 +228,6 @@ public class CellSelector extends ScrollArea {
|
|||
case SPDAction.ZOOM_OUT:
|
||||
zoom( camera.zoom-1 );
|
||||
return true;
|
||||
case SPDAction.ZOOM_DEFAULT:
|
||||
zoom( PixelScene.defaultZoom );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (moveFromKey(action)) {
|
||||
|
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
* Pixel Dungeon
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* Shattered Pixel Dungeon
|
||||
* Copyright (C) 2014-2019 Evan Debenham
|
||||
*
|
||||
* 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;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||
import com.watabou.input.KeyBindings;
|
||||
import com.watabou.noosa.ColorBlock;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class WndKeyBindings extends Window {
|
||||
|
||||
private static final int WIDTH = 120;
|
||||
|
||||
private static final int TTL_HEIGHT = 16;
|
||||
|
||||
private static final int COL1_CENTER = WIDTH/4;
|
||||
private static final int COL2_CENTER = 5*WIDTH/8;
|
||||
private static final int COL3_CENTER = 7*WIDTH/8;
|
||||
|
||||
private Component bindingsList;
|
||||
|
||||
public WndKeyBindings() {
|
||||
|
||||
resize(WIDTH, Math.min(340, PixelScene.uiCamera.height-20));
|
||||
|
||||
RenderedTextBlock ttlAction = PixelScene.renderTextBlock(Messages.get(this, "ttl_action"), 9);
|
||||
ttlAction.setPos( COL1_CENTER - ttlAction.width()/2, (TTL_HEIGHT - ttlAction.height())/2);
|
||||
add(ttlAction);
|
||||
|
||||
ColorBlock ttlSep1 = new ColorBlock(1, TTL_HEIGHT, 0xFF222222);
|
||||
ttlSep1.x = WIDTH/2;
|
||||
add(ttlSep1);
|
||||
|
||||
RenderedTextBlock ttlKey1 = PixelScene.renderTextBlock(Messages.get(this, "ttl_key1"), 9);
|
||||
ttlKey1.setPos(COL2_CENTER - ttlKey1.width()/2, (TTL_HEIGHT - ttlKey1.height())/2);
|
||||
add(ttlKey1);
|
||||
|
||||
ColorBlock ttlSep2 = new ColorBlock(1, TTL_HEIGHT, 0xFF222222);
|
||||
ttlSep2.x = 3*WIDTH/4;
|
||||
add(ttlSep2);
|
||||
|
||||
RenderedTextBlock ttlKey2 = PixelScene.renderTextBlock(Messages.get(this, "ttl_key2"), 9);
|
||||
ttlKey2.setPos(COL3_CENTER - ttlKey2.width()/2, (TTL_HEIGHT - ttlKey2.height())/2);
|
||||
add(ttlKey2);
|
||||
|
||||
ColorBlock ttlSep3 = new ColorBlock(WIDTH, 1, 0xFF222222);
|
||||
ttlSep3.y = TTL_HEIGHT;
|
||||
add(ttlSep3);
|
||||
|
||||
bindingsList = new Component();
|
||||
|
||||
ScrollPane scrollingList = new ScrollPane(bindingsList){
|
||||
@Override
|
||||
public void onClick(float x, float y) {
|
||||
//TODO
|
||||
}
|
||||
};
|
||||
|
||||
add(scrollingList);
|
||||
|
||||
int y = 0;
|
||||
//start at 3. No bindings for NONE, BACK, and MENU.
|
||||
for (int action = 3; action < SPDAction.TOTAL_ACTIONS; action++){
|
||||
BindingListItem item = new BindingListItem(action);
|
||||
item.setRect(0, y, WIDTH, 12);
|
||||
bindingsList.add(item);
|
||||
y += item.height();
|
||||
}
|
||||
bindingsList.setSize(WIDTH, y);
|
||||
|
||||
RedButton btnDefaults = new RedButton(Messages.get(this, "default"), 9){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
//TODO reset to default functionality
|
||||
}
|
||||
};
|
||||
btnDefaults.setRect(0, height - TTL_HEIGHT*2 -1, WIDTH, TTL_HEIGHT);
|
||||
add(btnDefaults);
|
||||
|
||||
RedButton btnConfirm = new RedButton(Messages.get(this, "confirm"), 9){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
//TODO save changed bindings
|
||||
hide();
|
||||
}
|
||||
};
|
||||
btnConfirm.setRect(0, height - TTL_HEIGHT, WIDTH/2 - 1, TTL_HEIGHT);
|
||||
add(btnConfirm);
|
||||
|
||||
RedButton btnCancel = new RedButton(Messages.get(this, "cancel"), 9){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
hide(); //close and don't save
|
||||
}
|
||||
};
|
||||
btnCancel.setRect(WIDTH/2, height - TTL_HEIGHT, WIDTH/2, TTL_HEIGHT);
|
||||
add(btnCancel);
|
||||
|
||||
scrollingList.setRect(0, TTL_HEIGHT+1, WIDTH, btnDefaults.top()-TTL_HEIGHT-1);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
//do nothing, avoids accidental back presses which would lose progress.
|
||||
}
|
||||
|
||||
private class BindingListItem extends Component {
|
||||
|
||||
private static final int CHANGED = TITLE_COLOR;
|
||||
private static final int DEFAULT = 0xFFFFFF;
|
||||
private static final int UNBOUND = 0x888888;
|
||||
|
||||
private int gameAction;
|
||||
private int key1;
|
||||
private int key2;
|
||||
|
||||
private RenderedTextBlock actionName;
|
||||
private RenderedTextBlock key1Name;
|
||||
private RenderedTextBlock key2Name;
|
||||
|
||||
private ColorBlock sep1;
|
||||
private ColorBlock sep2;
|
||||
private ColorBlock sep3;
|
||||
|
||||
public BindingListItem( int action ){
|
||||
gameAction = action;
|
||||
|
||||
actionName = PixelScene.renderTextBlock(Messages.get(WndKeyBindings.class, KeyBindings.getName(action)), 6 );
|
||||
actionName.setHightlighting(false);
|
||||
add(actionName);
|
||||
|
||||
ArrayList<Integer> keys = KeyBindings.getBindings(action);
|
||||
|
||||
if (keys.size() >= 1){
|
||||
key1Name = PixelScene.renderTextBlock( KeyBindings.getKeyName(keys.get(0)), 6 );
|
||||
key1 = keys.get(0);
|
||||
} else {
|
||||
key1Name = PixelScene.renderTextBlock( Messages.get(WndKeyBindings.class, "unbound"), 6 );
|
||||
key1Name.hardlight(UNBOUND);
|
||||
key1 = SPDAction.NONE;
|
||||
}
|
||||
add(key1Name);
|
||||
|
||||
if (keys.size() >= 2){
|
||||
key2Name = PixelScene.renderTextBlock( KeyBindings.getKeyName(keys.get(1)), 6 );
|
||||
key2 = keys.get(1);
|
||||
} else {
|
||||
key2Name = PixelScene.renderTextBlock( Messages.get(WndKeyBindings.class, "unbound"), 6 );
|
||||
key2Name.hardlight(UNBOUND);
|
||||
key2 = SPDAction.NONE;
|
||||
}
|
||||
add(key2Name);
|
||||
|
||||
sep1 = new ColorBlock(1, 1, 0xFF222222);
|
||||
add(sep1);
|
||||
|
||||
sep2 = new ColorBlock(1, 1, 0xFF222222);
|
||||
add(sep2);
|
||||
|
||||
sep3 = new ColorBlock(1, 1, 0xFF222222);
|
||||
add(sep3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
super.layout();
|
||||
|
||||
actionName.setPos( x, y + (height() - actionName.height())/2);
|
||||
key1Name.setPos(x + width()/2 + 2, y + (height() - key1Name.height())/2);
|
||||
key2Name.setPos(x + 3*width()/4 + 2, y + (height() - key2Name.height())/2);
|
||||
|
||||
sep1.size(width, 1);
|
||||
sep1.x = x;
|
||||
sep1.y = bottom();
|
||||
|
||||
sep2.size(1, height);
|
||||
sep2.x = key1Name.left()-2;
|
||||
sep2.y = y;
|
||||
|
||||
sep3.size(1, height);
|
||||
sep3.x = key2Name.left()-2;
|
||||
sep3.y = y;
|
||||
}
|
||||
|
||||
//onclick opens a new window depending on whether you pressed key 1 or 2.
|
||||
//give you the option to change that binding by pressing a key, then lets your confirm/cancel/unbind
|
||||
//warns you if a new binding conflicts with an old one
|
||||
}
|
||||
}
|
|
@ -280,7 +280,7 @@ public class WndSettings extends WndTabbed {
|
|||
SPDSettings.fullscreen(checked());
|
||||
}
|
||||
};
|
||||
chkFullscreen.setRect( 0, chkFlipTags.bottom() + GAP_LRG, WIDTH, BTN_HEIGHT );
|
||||
chkFullscreen.setRect( 0, chkFlipTags.bottom() + GAP_SML, WIDTH, BTN_HEIGHT );
|
||||
chkFullscreen.checked(SPDSettings.fullscreen());
|
||||
chkFullscreen.enable(DeviceCompat.supportsFullScreen());
|
||||
add(chkFullscreen);
|
||||
|
@ -305,6 +305,19 @@ public class WndSettings extends WndTabbed {
|
|||
chkFont.setRect(0, chkFullscreen.bottom() + GAP_TINY, WIDTH, BTN_HEIGHT);
|
||||
chkFont.checked(SPDSettings.systemFont());
|
||||
add(chkFont);
|
||||
|
||||
if (DeviceCompat.isDesktop()){
|
||||
RedButton btnKeyBindings = new RedButton(Messages.get(this, "key_bindings")){
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
ShatteredPixelDungeon.scene().addToFront(new WndKeyBindings());
|
||||
}
|
||||
};
|
||||
|
||||
btnKeyBindings.setRect(0, chkFont.bottom() + GAP_SML, WIDTH, BTN_HEIGHT);
|
||||
add(btnKeyBindings);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,6 +59,41 @@ windows.wndjournal$guidetab$guideitem.missing=page missing
|
|||
windows.wndjournal$notestab.keys=Keys
|
||||
windows.wndjournal$notestab.landmarks=Landmarks
|
||||
|
||||
windows.wndkeybindings.ttl_action=Action
|
||||
windows.wndkeybindings.ttl_key1=Key 1
|
||||
windows.wndkeybindings.ttl_key2=Key 2
|
||||
windows.wndkeybindings.default=Default Bindings
|
||||
windows.wndkeybindings.confirm=Confirm
|
||||
windows.wndkeybindings.cancel=Cancel
|
||||
windows.wndkeybindings.unbound=Unbound
|
||||
windows.wndkeybindings.none=None
|
||||
windows.wndkeybindings.back=Back
|
||||
windows.wndkeybindings.menu=Menu
|
||||
windows.wndkeybindings.hero_info=Hero Info
|
||||
windows.wndkeybindings.journal=Journal
|
||||
windows.wndkeybindings.wait=Wait
|
||||
windows.wndkeybindings.search=Search
|
||||
windows.wndkeybindings.inventory=Inventory
|
||||
windows.wndkeybindings.quickslot_1=Quickslot 1
|
||||
windows.wndkeybindings.quickslot_2=Quickslot 2
|
||||
windows.wndkeybindings.quickslot_3=Quickslot 3
|
||||
windows.wndkeybindings.quickslot_4=Quickslot 4
|
||||
windows.wndkeybindings.tag_attack=Attack Enemy
|
||||
windows.wndkeybindings.tag_danger=Switch Enemy
|
||||
windows.wndkeybindings.tag_action=Special Action
|
||||
windows.wndkeybindings.tag_loot=Pickup Item
|
||||
windows.wndkeybindings.tag_resume=Resume Motion
|
||||
windows.wndkeybindings.zoom_in=Zoom In
|
||||
windows.wndkeybindings.zoom_out=Zoom Out
|
||||
windows.wndkeybindings.n=Go North
|
||||
windows.wndkeybindings.e=Go East
|
||||
windows.wndkeybindings.s=Go South
|
||||
windows.wndkeybindings.w=Go West
|
||||
windows.wndkeybindings.ne=Go NE
|
||||
windows.wndkeybindings.se=Go SE
|
||||
windows.wndkeybindings.sw=Go SW
|
||||
windows.wndkeybindings.nw=Go NW
|
||||
|
||||
windows.wndlangs.completed=This language has been fully translated and reviewed.
|
||||
windows.wndlangs.unreviewed=This language has not yet been reviewed.\n\nIt may contain errors, but all text has been translated.
|
||||
windows.wndlangs.unfinished=This language has not been fully translated.\n\nLarge amounts of text may still be in English.
|
||||
|
@ -123,6 +158,7 @@ windows.wndsettings$uitab.flip_indicators=Flip Indicators
|
|||
windows.wndsettings$uitab.quickslots=Quickslots
|
||||
windows.wndsettings$uitab.fullscreen=Fullscreen
|
||||
windows.wndsettings$uitab.system_font=System Font
|
||||
windows.wndsettings$uitab.key_bindings=Key Bindings
|
||||
windows.wndsettings$audiotab.music_vol=Music Volume
|
||||
windows.wndsettings$audiotab.music_mute=Mute Music
|
||||
windows.wndsettings$audiotab.sfx_vol=SFX Volume
|
||||
|
|
Loading…
Reference in New Issue
Block a user