Make 'edit hotkey' menu nice, and consistent with rest of gui.

This commit is contained in:
UnknownShadow200 2016-05-15 00:04:45 +10:00
parent 5c0df54013
commit f7dafcde0e
6 changed files with 54 additions and 59 deletions

View File

@ -8,8 +8,12 @@ namespace ClassicalSharp.Gui {
public sealed class EditHotkeyScreen : MenuScreen {
const int keyI = 0, modifyI = 1;
const int keyI = 0, modifyI = 1, actionI = 2;
HotkeyList hotkeys;
Hotkey curHotkey, origHotkey;
Widget focusWidget;
static FastColour grey = new FastColour( 150, 150, 150 );
public EditHotkeyScreen( Game game, Hotkey original ) : base( game ) {
hotkeys = game.InputHandler.Hotkeys;
origHotkey = original;
@ -20,8 +24,11 @@ namespace ClassicalSharp.Gui {
RenderMenuBounds();
api.Texturing = true;
RenderMenuWidgets( delta );
currentAction.Render( delta );
api.Texturing = false;
float cX = game.Width / 2, cY = game.Height / 2;
api.Draw2DQuad( cX - 250, cY - 65, 500, 2, grey );
api.Draw2DQuad( cX - 250, cY + 45, 500, 2, grey );
}
public override bool HandlesMouseMove( int mouseX, int mouseY ) {
@ -33,13 +40,12 @@ namespace ClassicalSharp.Gui {
}
bool supressNextPress;
const int numButtons = 5;
public override bool HandlesKeyPress( char key ) {
if( supressNextPress ) {
supressNextPress = false;
return true;
}
return currentAction.HandlesKeyPress( key );
return widgets[actionI].HandlesKeyPress( key );
}
public override bool HandlesKeyDown( Key key ) {
@ -50,54 +56,46 @@ namespace ClassicalSharp.Gui {
FocusKeyDown( key );
return true;
}
return currentAction.HandlesKeyDown( key );
return widgets[actionI].HandlesKeyDown( key );
}
public override bool HandlesKeyUp( Key key ) {
return currentAction.HandlesKeyUp( key );
return widgets[actionI].HandlesKeyUp( key );
}
public override void Init() {
game.Keyboard.KeyRepeat = true;
base.Init();
regularFont = new Font( game.FontName, 16, FontStyle.Regular );
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
string flags = HotkeyListScreen.MakeFlagsString( curHotkey.Flags );
if( curHotkey.Text == null ) curHotkey.Text = "";
string staysOpen = curHotkey.StaysOpen ? "yes" : "no";
widgets = new Widget[] {
Make( -140, 45, "Key: " + curHotkey.BaseKey,
250, 35, titleFont, BaseKeyClick ),
Make( 140, 45, "Modifiers: " + flags,
250, 35, titleFont, ModifiersClick ),
Make( -10, 110, curHotkey.MoreInput ? "yes" : "no",
50, 25, titleFont, LeaveOpenClick ),
Make( -120, 150, "Save changes",
180, 35, titleFont, SaveChangesClick ),
Make( 120, 150, "Remove hotkey",
180, 35, titleFont, RemoveHotkeyClick ),
ChatTextWidget.Create(
game, -150, 110, "Keep input bar open:",
Anchor.Centre, Anchor.Centre, titleFont ),
Make( 0, -150, "Key: " + curHotkey.BaseKey,
301, 40, titleFont, BaseKeyClick ),
Make( 0, -100, "Modifiers:" + flags,
301, 40, titleFont, ModifiersClick ),
MenuInputWidget.Create(
game, 0, -35, 500, 30, curHotkey.Text,
Anchor.Centre, Anchor.Centre,
regularFont, titleFont, new StringValidator( 64 ) ),
Make( -100, 10, "Input stays open: " + staysOpen,
301, 40, titleFont, LeaveOpenClick ),
Make( 0, 80, "Save changes",
301, 40, titleFont, SaveChangesClick ),
Make( 0, 130, "Remove hotkey",
301, 40, titleFont, RemoveHotkeyClick ),
MakeBack( false, titleFont,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
};
currentAction = MenuInputWidget.Create(
game, 0, 80, 600, 30, "", Anchor.Centre, Anchor.Centre,
regularFont, titleFont, new StringValidator( 64 ) );
if( curHotkey.Text == null ) curHotkey.Text = "";
currentAction.SetText( curHotkey.Text );
}
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
currentAction.OnResize( oldWidth, oldHeight, width, height );
base.OnResize( oldWidth, oldHeight, width, height );
}
public override void Dispose() {
game.Keyboard.KeyRepeat = false;
currentAction.Dispose();
focusWidget = null;
base.Dispose();
}
@ -108,14 +106,12 @@ namespace ClassicalSharp.Gui {
Anchor.Centre, Anchor.Centre, font, LeftOnly( onClick ) );
}
Hotkey curHotkey, origHotkey;
MenuInputWidget currentAction;
Widget focusWidget;
void LeaveOpenClick( Game game, Widget widget ) {
LostFocus();
curHotkey.MoreInput = !curHotkey.MoreInput;
SetButton( widgets[2], curHotkey.MoreInput ? "yes" : "no" );
curHotkey.StaysOpen = !curHotkey.StaysOpen;
string staysOpen = curHotkey.StaysOpen ? "yes" : "no";
staysOpen = "Input stays open: " + staysOpen;
SetButton( widgets[3], staysOpen );
}
void SaveChangesClick( Game game, Widget widget ) {
@ -123,12 +119,13 @@ namespace ClassicalSharp.Gui {
hotkeys.RemoveHotkey( origHotkey.BaseKey, origHotkey.Flags );
hotkeys.UserRemovedHotkey( origHotkey.BaseKey, origHotkey.Flags );
}
MenuInputWidget input = (MenuInputWidget)widgets[actionI];
if( curHotkey.BaseKey != Key.Unknown ) {
hotkeys.AddHotkey( curHotkey.BaseKey, curHotkey.Flags,
currentAction.GetText(), curHotkey.MoreInput );
input.GetText(), curHotkey.StaysOpen );
hotkeys.UserAddedHotkey( curHotkey.BaseKey, curHotkey.Flags,
curHotkey.MoreInput, currentAction.GetText() );
curHotkey.StaysOpen, input.GetText() );
}
game.SetNewScreen( new HotkeyListScreen( game ) );
}
@ -158,14 +155,14 @@ namespace ClassicalSharp.Gui {
curHotkey.BaseKey = key;
SetButton( widgets[keyI], "Key: " + curHotkey.BaseKey );
supressNextPress = true;
} else if( focusWidget == widgets[9] ) {
} else if( focusWidget == widgets[modifyI] ) {
if( key == Key.ControlLeft || key == Key.ControlRight ) curHotkey.Flags |= 1;
else if( key == Key.ShiftLeft || key == Key.ShiftRight ) curHotkey.Flags |= 2;
else if( key == Key.AltLeft || key == Key.AltRight ) curHotkey.Flags |= 4;
else curHotkey.Flags = 0;
string flags = HotkeyListScreen.MakeFlagsString( curHotkey.Flags );
SetButton( widgets[modifyI], "Modifiers: " + flags );
SetButton( widgets[modifyI], "Modifiers:" + flags );
supressNextPress = true;
}
focusWidget = null;
@ -178,7 +175,7 @@ namespace ClassicalSharp.Gui {
SetButton( widgets[keyI], "Key: " + curHotkey.BaseKey );
} else if( focusWidget == widgets[modifyI] ) {
string flags = HotkeyListScreen.MakeFlagsString( curHotkey.Flags );
SetButton( widgets[modifyI], "Modifiers: " + flags );
SetButton( widgets[modifyI], "Modifiers:" + flags );
}
focusWidget = null;
supressNextPress = false;

View File

@ -15,16 +15,16 @@ namespace ClassicalSharp.Gui {
entries = new string[hotkeys.Hotkeys.Count];
for( int i = 0; i < entries.Length; i++ ) {
Hotkey hKey = hotkeys.Hotkeys[i];
entries[i] = hKey.BaseKey + " | " + MakeFlagsString( hKey.Flags );
entries[i] = hKey.BaseKey + " |" + MakeFlagsString( hKey.Flags );
}
}
internal static string MakeFlagsString( byte flags ) {
if( flags == 0 ) return "None";
if( flags == 0 ) return " None";
return ((flags & 1) == 0 ? " " : "Ctrl ") +
((flags & 2) == 0 ? " " : "Shift ") +
((flags & 4) == 0 ? " " : "Alt ");
return ((flags & 1) == 0 ? "" : " Ctrl") +
((flags & 2) == 0 ? "" : " Shift") +
((flags & 4) == 0 ? "" : " Alt");
}
protected override void TextButtonClick( Game game, Widget widget, MouseButton mouseBtn ) {

View File

@ -15,7 +15,7 @@ namespace ClassicalSharp.Gui {
MenuInputWidget inputWidget;
TextWidget descWidget;
const int overwriteIndex = 2;
FastColour grey = new FastColour( 150, 150, 150 );
static FastColour grey = new FastColour( 150, 150, 150 );
public override void Render( double delta ) {
RenderMenuBounds();

View File

@ -88,21 +88,21 @@
<Compile Include="2D\Drawing\IDrawer2D.cs" />
<Compile Include="2D\Screens\ChatScreen.cs" />
<Compile Include="2D\Screens\ClickableScreen.cs" />
<Compile Include="2D\Screens\EditHotkeyScreen.cs" />
<Compile Include="2D\Screens\ErrorScreen.cs" />
<Compile Include="2D\Screens\FilesScreen.cs" />
<Compile Include="2D\Screens\FpsScreen.cs" />
<Compile Include="2D\Screens\HotkeyListScreen.cs" />
<Compile Include="2D\Screens\Inventory\InventoryScreen.cs" />
<Compile Include="2D\Screens\Inventory\InventoryScreen.Input.cs" />
<Compile Include="2D\Screens\Inventory\InventoryScreen.Scrolling.cs" />
<Compile Include="2D\Screens\LoadingMapScreen.cs" />
<Compile Include="2D\Screens\Menu\ClassicOptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\EditHotkeyScreen.cs" />
<Compile Include="2D\Screens\Menu\EnvSettingsScreen.cs" />
<Compile Include="2D\Screens\Menu\GenLevelScreen.cs" />
<Compile Include="2D\Screens\Menu\GraphicsOptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\GuiOptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\HacksSettingsScreen.cs" />
<Compile Include="2D\Screens\Menu\HotkeyListScreen.cs" />
<Compile Include="2D\Screens\Menu\KeyBindingsScreen.cs" />
<Compile Include="2D\Screens\Menu\KeyBindingsScreens.cs" />
<Compile Include="2D\Screens\Menu\LoadLevelScreen.cs" />

View File

@ -35,7 +35,7 @@ namespace ClassicalSharp.Hotkeys {
Hotkey hKey = Hotkeys[i];
if( hKey.BaseKey == baseKey && hKey.Flags == flags ) {
hKey.Text = text;
hKey.MoreInput = more;
hKey.StaysOpen = more;
Hotkeys[i] = hKey;
return true;
}
@ -48,7 +48,7 @@ namespace ClassicalSharp.Hotkeys {
hotkey.BaseKey = baseKey;
hotkey.Flags = flags;
hotkey.Text = text;
hotkey.MoreInput = more;
hotkey.StaysOpen = more;
Hotkeys.Add( hotkey );
// sort so that hotkeys with largest modifiers are first
@ -67,7 +67,7 @@ namespace ClassicalSharp.Hotkeys {
foreach( Hotkey hKey in Hotkeys ) {
if( (hKey.Flags & flags) == hKey.Flags && hKey.BaseKey == key ) {
text = hKey.Text;
moreInput = hKey.MoreInput;
moreInput = hKey.StaysOpen;
return true;
}
}
@ -127,7 +127,7 @@ namespace ClassicalSharp.Hotkeys {
public struct Hotkey {
public Key BaseKey;
public byte Flags; // ctrl 1, shift 2, alt 4
public bool MoreInput; // whether the user is able to enter further input
public bool StaysOpen; // whether the user is able to enter further input
public string Text; // contents to copy directly into the input bar
}
}

View File

@ -121,7 +121,7 @@ namespace ClassicalSharp {
if( item.Data != null ) {
Bitmap bmp = (Bitmap)item.Data;
game.World.TextureUrl = item.Url;
game.Animations.Clear();
game.Events.RaiseTexturePackChanged();
if( !FastBitmap.CheckFormat( bmp.PixelFormat ) ) {
Utils.LogDebug( "Converting terrain atlas to 32bpp image" );
@ -135,7 +135,7 @@ namespace ClassicalSharp {
if( bmp == null ) {// Should never happen, but handle anyways.
ExtractDefault();
} else if( item.Url != game.World.TextureUrl ) {
game.Animations.Clear();
game.Events.RaiseTexturePackChanged();
if( !game.ChangeTerrainAtlas( bmp ) ) { bmp.Dispose(); return; }
}
@ -148,7 +148,6 @@ namespace ClassicalSharp {
if( game.AsyncDownloader.TryGetItem( "texturePack", out item ) ) {
if( item.Data != null ) {
game.World.TextureUrl = item.Url;
game.Animations.Clear();
TexturePackExtractor extractor = new TexturePackExtractor();
extractor.Extract( (byte[])item.Data, game );
@ -159,7 +158,6 @@ namespace ClassicalSharp {
if( data == null ) { // Should never happen, but handle anyways.
ExtractDefault();
} else if( item.Url != game.World.TextureUrl ) {
game.Animations.Clear();
TexturePackExtractor extractor = new TexturePackExtractor();
extractor.Extract( data, game );
}