2016-06-11 17:56:37 +10:00
|
|
|
|
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
2016-09-15 12:15:58 +10:00
|
|
|
|
#if !ANDROID
|
2016-06-11 17:56:37 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using ClassicalSharp.Hotkeys;
|
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
|
|
|
|
|
namespace ClassicalSharp.Gui {
|
|
|
|
|
|
|
|
|
|
// TODO: Hotkey added event for CPE
|
|
|
|
|
public sealed class HotkeyListScreen : FilesScreen {
|
|
|
|
|
|
|
|
|
|
public HotkeyListScreen( Game game ) : base( game ) {
|
|
|
|
|
titleText = "Modify hotkeys";
|
|
|
|
|
HotkeyList hotkeys = game.InputHandler.Hotkeys;
|
|
|
|
|
int count = hotkeys.Hotkeys.Count;
|
|
|
|
|
entries = new string[hotkeys.Hotkeys.Count + items];
|
|
|
|
|
|
|
|
|
|
for( int i = 0; i < count; i++ ) {
|
|
|
|
|
Hotkey hKey = hotkeys.Hotkeys[i];
|
|
|
|
|
entries[i] = hKey.BaseKey + " |" + MakeFlagsString( hKey.Flags );
|
|
|
|
|
}
|
|
|
|
|
for( int i = 0; i < items; i++ )
|
|
|
|
|
entries[count + i] = "-----";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string MakeFlagsString( byte flags ) {
|
|
|
|
|
if( flags == 0 ) return " None";
|
|
|
|
|
|
|
|
|
|
return ((flags & 1) == 0 ? "" : " Ctrl") +
|
|
|
|
|
((flags & 2) == 0 ? "" : " Shift") +
|
|
|
|
|
((flags & 4) == 0 ? "" : " Alt");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void TextButtonClick( Game game, Widget widget, MouseButton mouseBtn ) {
|
|
|
|
|
if( mouseBtn != MouseButton.Left ) return;
|
|
|
|
|
string text = ((ButtonWidget)widget).Text;
|
|
|
|
|
Hotkey original = default(Hotkey);
|
|
|
|
|
if( text != "-----" )
|
|
|
|
|
original = Parse( text );
|
2016-07-25 12:11:55 +10:00
|
|
|
|
game.Gui.SetNewScreen( new EditHotkeyScreen( game, original ) );
|
2016-06-11 17:56:37 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Hotkey Parse( string text ) {
|
|
|
|
|
int sepIndex = text.IndexOf( '|' );
|
|
|
|
|
string key = text.Substring( 0, sepIndex - 1 );
|
|
|
|
|
string value = text.Substring( sepIndex + 1 );
|
|
|
|
|
|
|
|
|
|
byte flags = 0;
|
|
|
|
|
if( value.Contains( "Ctrl" ) ) flags |= 1;
|
|
|
|
|
if( value.Contains( "Shift" ) ) flags |= 2;
|
|
|
|
|
if( value.Contains( "Alt" ) ) flags |= 4;
|
|
|
|
|
|
|
|
|
|
Key hKey = (Key)Enum.Parse( typeof( Key ), key );
|
|
|
|
|
HotkeyList hotkeys = game.InputHandler.Hotkeys;
|
|
|
|
|
return hotkeys.Hotkeys.Find( h => h.BaseKey == hKey && h.Flags == flags );
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-15 12:15:58 +10:00
|
|
|
|
}
|
|
|
|
|
#endif
|