Can get extended help/description by right clicking on certain buttons.

This commit is contained in:
UnknownShadow200 2016-01-20 14:14:56 +11:00
parent 2c30831c53
commit c1753b03b8
21 changed files with 202 additions and 83 deletions

View File

@ -4,6 +4,8 @@ using OpenTK.Input;
namespace ClassicalSharp { namespace ClassicalSharp {
public delegate void ClickHandler( Game g, Widget w, MouseButton btn );
public abstract class GuiElement : IDisposable { public abstract class GuiElement : IDisposable {
protected Game game; protected Game game;
@ -76,6 +78,13 @@ namespace ClassicalSharp {
protected static bool Contains( int recX, int recY, int width, int height, int x, int y ) { protected static bool Contains( int recX, int recY, int width, int height, int x, int y ) {
return x >= recX && y >= recY && x < recX + width && y < recY + height; return x >= recX && y >= recY && x < recX + width && y < recY + height;
} }
protected ClickHandler LeftOnly( Action<Game, Widget> action ) {
return (g, w, btn) => {
if( btn != MouseButton.Left ) return;
action( g, w );
};
}
} }
public enum Anchor { public enum Anchor {

View File

@ -10,21 +10,22 @@ namespace ClassicalSharp {
} }
protected bool HandleMouseClick( Widget[] widgets, int mouseX, int mouseY, MouseButton button ) { protected bool HandleMouseClick( Widget[] widgets, int mouseX, int mouseY, MouseButton button ) {
if( button != MouseButton.Left ) return false;
// iterate backwards (because last elements rendered are shown over others) // iterate backwards (because last elements rendered are shown over others)
for( int i = widgets.Length - 1; i >= 0; i-- ) { for( int i = widgets.Length - 1; i >= 0; i-- ) {
Widget widget = widgets[i]; Widget widget = widgets[i];
if( widget != null && widget.Bounds.Contains( mouseX, mouseY ) ) { if( widget != null && widget.Bounds.Contains( mouseX, mouseY ) ) {
if( widget.OnClick != null && !widget.Disabled ) if( widget.OnClick != null && !widget.Disabled )
widget.OnClick( game, widget ); widget.OnClick( game, widget, button );
return true; return true;
} }
} }
return false; return false;
} }
int lastX = -1, lastY = -1;
protected bool HandleMouseMove( Widget[] widgets, int mouseX, int mouseY ) { protected bool HandleMouseMove( Widget[] widgets, int mouseX, int mouseY ) {
if( lastX == mouseX && lastY == mouseY )
return true;
for( int i = 0; i < widgets.Length; i++ ) { for( int i = 0; i < widgets.Length; i++ ) {
if( widgets[i] == null ) continue; if( widgets[i] == null ) continue;
widgets[i].Active = false; widgets[i].Active = false;
@ -34,10 +35,12 @@ namespace ClassicalSharp {
Widget widget = widgets[i]; Widget widget = widgets[i];
if( widget != null && widget.Bounds.Contains( mouseX, mouseY ) ) { if( widget != null && widget.Bounds.Contains( mouseX, mouseY ) ) {
widget.Active = true; widget.Active = true;
lastX = mouseX; lastY = mouseY;
WidgetSelected( widget ); WidgetSelected( widget );
return true; return true;
} }
} }
lastX = mouseX; lastY = mouseY;
WidgetSelected( null ); WidgetSelected( null );
return false; return false;
} }
@ -49,7 +52,7 @@ namespace ClassicalSharp {
string text = toGame ? "Back to game" : "Back to menu"; string text = toGame ? "Back to game" : "Back to menu";
return ButtonWidget.Create( return ButtonWidget.Create(
game, 0, 5, 180, 35, text, game, 0, 5, 180, 35, text,
Anchor.Centre, Anchor.BottomOrRight, font, onClick ); Anchor.Centre, Anchor.BottomOrRight, font, LeftOnly( onClick ) );
} }
} }
} }

View File

@ -52,7 +52,8 @@ namespace ClassicalSharp {
lastSecsLeft = delay; lastSecsLeft = delay;
} }
void ReconnectClick( Game g, Widget w ) { void ReconnectClick( Game g, Widget w, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
string connectString = "Connecting to " + game.IPAddress + ":" + game.Port + ".."; string connectString = "Connecting to " + game.IPAddress + ":" + game.Port + "..";
game.SetNewScreen( new LoadingMapScreen( game, connectString, "Waiting for handshake" ) ); game.SetNewScreen( new LoadingMapScreen( game, connectString, "Waiting for handshake" ) );
game.Network.Connect( game.IPAddress, game.Port ); game.Network.Connect( game.IPAddress, game.Port );

View File

@ -58,10 +58,10 @@ namespace ClassicalSharp {
ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick ) { ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, 40, 40, text, return ButtonWidget.Create( game, x, y, 40, 40, text,
Anchor.Centre, Anchor.Centre, arrowFont, onClick ); Anchor.Centre, Anchor.Centre, arrowFont, LeftOnly( onClick ) );
} }
protected abstract void TextButtonClick( Game game, Widget widget ); protected abstract void TextButtonClick( Game game, Widget widget, MouseButton mouseBtn );
protected void PageClick( bool forward ) { protected void PageClick( bool forward ) {
currentIndex += forward ? 5 : -5; currentIndex += forward ? 5 : -5;

View File

@ -118,7 +118,7 @@ namespace ClassicalSharp {
ButtonWidget Make( int x, int y, string text, int width, int height, ButtonWidget Make( int x, int y, string text, int width, int height,
Font font, Action<Game, Widget> onClick ) { Font font, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, width, height, text, return ButtonWidget.Create( game, x, y, width, height, text,
Anchor.Centre, Anchor.Centre, font, onClick ); Anchor.Centre, Anchor.Centre, font, LeftOnly( onClick ) );
} }
ButtonWidget MakeHotkey( int x, int y, int index ) { ButtonWidget MakeHotkey( int x, int y, int index ) {
@ -169,7 +169,8 @@ namespace ClassicalSharp {
Set( i ); Set( i );
} }
void TextButtonClick( Game game, Widget widget ) { void TextButtonClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
LostFocus(); LostFocus();
ButtonWidget button = (ButtonWidget)widget; ButtonWidget button = (ButtonWidget)widget;

View File

@ -1,10 +1,11 @@
using System; using System;
using System.Drawing; using System.Drawing;
using ClassicalSharp.Renderers; using ClassicalSharp.Renderers;
using OpenTK.Input;
namespace ClassicalSharp { namespace ClassicalSharp {
public class EnvSettingsScreen : MenuInputScreen { public class EnvSettingsScreen : MenuOptionsScreen {
string[] defaultValues; string[] defaultValues;
int defaultIndex; int defaultIndex;
@ -99,7 +100,8 @@ namespace ClassicalSharp {
Anchor.Centre, titleFont, DefaultButtonClick ); Anchor.Centre, titleFont, DefaultButtonClick );
} }
void DefaultButtonClick( Game game, Widget widget ) { void DefaultButtonClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
int index = Array.IndexOf<ButtonWidget>( buttons, targetWidget ); int index = Array.IndexOf<ButtonWidget>( buttons, targetWidget );
string defValue = defaultValues[index]; string defValue = defaultValues[index];
inputWidget.SetText( defValue ); inputWidget.SetText( defValue );

View File

@ -105,7 +105,8 @@ namespace ClassicalSharp {
base.Dispose(); base.Dispose();
} }
void InputClick( Game game, Widget widget ) { void InputClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
if( selectedWidget != null ) if( selectedWidget != null )
selectedWidget.Active = false; selectedWidget.Active = false;
@ -113,11 +114,13 @@ namespace ClassicalSharp {
selectedWidget.Active = true; selectedWidget.Active = true;
} }
void GenFlatgrassClick( Game game, Widget widget ) { void GenFlatgrassClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
GenerateMap( new FlatGrassGenerator() ); GenerateMap( new FlatGrassGenerator() );
} }
void GenNotchyClick( Game game, Widget widget ) { void GenNotchyClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
GenerateMap( new NotchyGenerator() ); GenerateMap( new NotchyGenerator() );
} }

View File

@ -2,7 +2,7 @@
namespace ClassicalSharp { namespace ClassicalSharp {
public class GuiOptionsScreen : MenuInputScreen { public class GuiOptionsScreen : MenuOptionsScreen {
public GuiOptionsScreen( Game game ) : base( game ) { public GuiOptionsScreen( Game game ) : base( game ) {
} }

View File

@ -4,7 +4,7 @@ using ClassicalSharp.Singleplayer;
namespace ClassicalSharp { namespace ClassicalSharp {
public class HacksSettingsScreen : MenuInputScreen { public class HacksSettingsScreen : MenuOptionsScreen {
public HacksSettingsScreen( Game game ) : base( game ) { public HacksSettingsScreen( Game game ) : base( game ) {
} }
@ -111,15 +111,21 @@ namespace ClassicalSharp {
void MakeDescriptions() { void MakeDescriptions() {
descriptions = new string[buttons.Length][]; descriptions = new string[buttons.Length][];
descriptions[5] = new [] { descriptions[5] = new [] {
"&fIf breaking liquids is set to true, then water/lava", "&aLiquids breakable",
"&fcan be deleted the same way as any regular block.", "&eIf breaking liquids is set to true, then water/lava",
"&ecan be deleted the same way as any regular block.",
}; };
descriptions[6] = new [] { descriptions[6] = new [] {
"&aDetermines whether pushback placing mode is active or not.", "&aDetermines whether pushback placing mode is active or not",
"&fWhen this is active, placing blocks that intersect your own position", "&eWhen this is active, placing blocks that intersect your own position",
"&f cause the block to be placed, and you to be moved out of the way.", "&ecause the block to be placed, and you to be moved out of the way.",
"&fThis is mainly useful for quick pillaring/towering.", "&fThis is mainly useful for quick pillaring/towering.",
}; };
descriptions[7] = new [] {
"&aDetermines whether noclip sliding is used or not.",
"&eIf sliding isn't used, you will immediately stop when",
"&eyou are in noclip mode and no movement keys are held down.",
};
} }
} }
} }

View File

@ -47,7 +47,8 @@ namespace ClassicalSharp {
} }
ButtonWidget curWidget; ButtonWidget curWidget;
void OnBindingClick( Game game, Widget realWidget ) { void OnBindingClick( Game game, Widget realWidget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
this.curWidget = (ButtonWidget)realWidget; this.curWidget = (ButtonWidget)realWidget;
int index = Array.IndexOf<ButtonWidget>( buttons, curWidget ); int index = Array.IndexOf<ButtonWidget>( buttons, curWidget );
string text = "&ePress new key binding for " + descriptions[index] + ":"; string text = "&ePress new key binding for " + descriptions[index] + ":";
@ -111,7 +112,8 @@ namespace ClassicalSharp {
Anchor.Centre, Anchor.Centre, titleFont, NextClick ); Anchor.Centre, Anchor.Centre, titleFont, NextClick );
} }
void NextClick( Game game, Widget widget ) { void NextClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
game.SetNewScreen( new AdvancedKeyBindingsScreen( game ) ); game.SetNewScreen( new AdvancedKeyBindingsScreen( game ) );
} }
} }
@ -139,7 +141,8 @@ namespace ClassicalSharp {
Anchor.Centre, Anchor.Centre, titleFont, NextClick ); Anchor.Centre, Anchor.Centre, titleFont, NextClick );
} }
void NextClick( Game game, Widget widget ) { void NextClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
game.SetNewScreen( new NormalKeyBindingsScreen( game ) ); game.SetNewScreen( new NormalKeyBindingsScreen( game ) );
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using OpenTK.Input;
namespace ClassicalSharp { namespace ClassicalSharp {
@ -25,7 +26,8 @@ namespace ClassicalSharp {
MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ); MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
} }
protected override void TextButtonClick( Game game, Widget widget ) { protected override void TextButtonClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
string path = Path.Combine( Program.AppDirectory, "maps" ); string path = Path.Combine( Program.AppDirectory, "maps" );
path = Path.Combine( path, ((ButtonWidget)widget).Text ); path = Path.Combine( path, ((ButtonWidget)widget).Text );
if( File.Exists( path ) ) if( File.Exists( path ) )

View File

@ -4,9 +4,9 @@ using OpenTK.Input;
namespace ClassicalSharp { namespace ClassicalSharp {
public abstract class MenuInputScreen : MenuScreen { public abstract class MenuOptionsScreen : MenuScreen {
public MenuInputScreen( Game game ) : base( game ) { public MenuOptionsScreen( Game game ) : base( game ) {
} }
protected MenuInputWidget inputWidget; protected MenuInputWidget inputWidget;
@ -14,21 +14,37 @@ namespace ClassicalSharp {
protected TextWidget descWidget; protected TextWidget descWidget;
protected int okayIndex; protected int okayIndex;
protected string[][] descriptions; protected string[][] descriptions;
protected ChatTextWidget[] extendedHelp;
Font extendedHelpFont;
public override void Render( double delta ) { public override void Render( double delta ) {
RenderMenuBounds(); RenderMenuBounds();
if( extendedHelp != null ) {
int x = game.Width / 2 - tableWidth / 2 - 5;
int y = game.Height / 2 + extHelpY - 5;
graphicsApi.Draw2DQuad( x, y, tableWidth + 10, tableHeight + 10, tableCol );
}
graphicsApi.Texturing = true; graphicsApi.Texturing = true;
RenderMenuButtons( delta ); RenderMenuButtons( delta );
if( inputWidget != null ) if( inputWidget != null )
inputWidget.Render( delta ); inputWidget.Render( delta );
if( descWidget != null )
if( extendedHelp != null ) {
for( int i = 0; i < extendedHelp.Length; i++ )
extendedHelp[i].Render( delta );
} else if( descWidget != null ) {
descWidget.Render( delta ); descWidget.Render( delta );
}
graphicsApi.Texturing = false; graphicsApi.Texturing = false;
} }
public override void Init() { public override void Init() {
base.Init(); base.Init();
regularFont = new Font( "Arial", 16, FontStyle.Regular ); regularFont = new Font( "Arial", 16, FontStyle.Regular );
int size = game.Drawer2D.UseBitmappedChat ? 11 : 12;
extendedHelpFont = new Font( "Arial", size, FontStyle.Regular );
game.Keyboard.KeyRepeat = true; game.Keyboard.KeyRepeat = true;
} }
@ -61,7 +77,11 @@ namespace ClassicalSharp {
descWidget.OnResize( oldWidth, oldHeight, width, height ); descWidget.OnResize( oldWidth, oldHeight, width, height );
if( inputWidget != null ) if( inputWidget != null )
inputWidget.OnResize( oldWidth, oldHeight, width, height ); inputWidget.OnResize( oldWidth, oldHeight, width, height );
base.OnResize( oldWidth, oldHeight, width, height ); base.OnResize( oldWidth, oldHeight, width, height );
if( extendedHelp == null ) return;
for( int i = 0; i < extendedHelp.Length; i++ )
extendedHelp[i].OnResize( oldWidth, oldHeight, width, height );
} }
public override void Dispose() { public override void Dispose() {
@ -70,11 +90,14 @@ namespace ClassicalSharp {
if( inputWidget != null ) if( inputWidget != null )
inputWidget.Dispose(); inputWidget.Dispose();
game.Keyboard.KeyRepeat = false; game.Keyboard.KeyRepeat = false;
extendedHelpFont.Dispose();
DisposeExtendedHelp();
base.Dispose(); base.Dispose();
} }
protected ButtonWidget selectedWidget, targetWidget; protected ButtonWidget selectedWidget, targetWidget;
protected override void WidgetSelected( Widget widget ) { protected override void WidgetSelected( Widget widget ) {
DisposeExtendedHelp();
ButtonWidget button = (ButtonWidget)widget; ButtonWidget button = (ButtonWidget)widget;
if( selectedWidget == button || button == null || if( selectedWidget == button || button == null ||
button == buttons[buttons.Length - 2] ) return; button == buttons[buttons.Length - 2] ) return;
@ -93,12 +116,79 @@ namespace ClassicalSharp {
descWidget = TextWidget.Create( game, 0, 100, text, Anchor.Centre, Anchor.Centre, regularFont ); descWidget = TextWidget.Create( game, 0, 100, text, Anchor.Centre, Anchor.Centre, regularFont );
} }
protected void OnWidgetClick( Game game, Widget widget ) { protected virtual void InputOpened() { }
protected virtual void InputClosed() { }
protected virtual ButtonWidget Make( int x, int y, string text, ClickHandler onClick,
Func<Game, string> getter, Action<Game, string> setter ) {
ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre,
Anchor.Centre, titleFont, onClick );
widget.GetValue = getter;
widget.SetValue = setter;
return widget;
}
void ShowExtendedHelp() {
bool canShow = inputWidget == null && selectedWidget != null && descriptions != null;
if( !canShow ) return;
int index = Array.IndexOf<Widget>( buttons, selectedWidget );
string[] desc = descriptions[index];
if( desc == null ) return;
MakeExtendedHelp( desc );
}
static FastColour tableCol = new FastColour( 20, 20, 20, 200 );
int tableWidth, tableHeight;
const int extHelpY = 90;
void MakeExtendedHelp( string[] desc ) {
extendedHelp = new ChatTextWidget[desc.Length];
int x = 0, y = extHelpY;
tableWidth = 0;
for( int i = 0; i < desc.Length; i++ ) {
extendedHelp[i] = ChatTextWidget.Create( game, 0, y,
desc[i], Anchor.Centre, Anchor.Centre, extendedHelpFont );
tableWidth = Math.Max( extendedHelp[i].Width, tableWidth );
y += extendedHelp[i].Height + 5;
}
tableHeight = y - extHelpY;
// Left align all body text.
int yOffset = 0;
for( int i = 0; i < desc.Length; i++ ) {
ChatTextWidget widget = extendedHelp[i];
if( i == 0 ) {
x = widget.X;
} else {
widget.XOffset = (widget.Width - tableWidth) / 2;
x = CalcOffset( game.Width, widget.Width, widget.XOffset, Anchor.Centre );
}
widget.YOffset = yOffset + extHelpY + extendedHelp[0].Height / 2;
y = CalcOffset( game.Height, widget.Height, widget.YOffset, Anchor.Centre );
yOffset += extendedHelp[i].Height + 5;
widget.MoveTo( x, y );
}
}
void DisposeExtendedHelp() {
if( extendedHelp == null ) return;
for( int i = 0; i < extendedHelp.Length; i++ )
extendedHelp[i].Dispose();
extendedHelp = null;
}
protected void OnWidgetClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn == MouseButton.Right ) { ShowExtendedHelp(); return; }
if( mouseBtn != MouseButton.Left ) return;
if( widget == buttons[okayIndex] ) { if( widget == buttons[okayIndex] ) {
ChangeSetting(); ChangeSetting();
return; return;
} }
ButtonWidget button = (ButtonWidget)widget; ButtonWidget button = (ButtonWidget)widget;
DisposeExtendedHelp();
int index = Array.IndexOf<ButtonWidget>( buttons, button ); int index = Array.IndexOf<ButtonWidget>( buttons, button );
MenuInputValidator validator = validators[index]; MenuInputValidator validator = validators[index];
@ -108,16 +198,7 @@ namespace ClassicalSharp {
UpdateDescription( button ); UpdateDescription( button );
return; return;
} else if( validator is EnumValidator ) { } else if( validator is EnumValidator ) {
string value = button.GetValue( game ); HandleEnumOption( button );
Type type = (Type)button.Metadata;
int enumValue = (int)Enum.Parse( type, value, true );
enumValue++;
// go back to first value
if( !Enum.IsDefined( type, enumValue ) )
enumValue = 0;
button.SetValue( game, Enum.GetName( type, enumValue ) );
UpdateDescription( button );
return; return;
} }
@ -133,6 +214,18 @@ namespace ClassicalSharp {
UpdateDescription( targetWidget ); UpdateDescription( targetWidget );
} }
void HandleEnumOption( ButtonWidget button ) {
string value = button.GetValue( game );
Type type = (Type)button.Metadata;
int enumValue = (int)Enum.Parse( type, value, true );
enumValue++;
// go back to first value
if( !Enum.IsDefined( type, enumValue ) )
enumValue = 0;
button.SetValue( game, Enum.GetName( type, enumValue ) );
UpdateDescription( button );
}
void ChangeSetting() { void ChangeSetting() {
string text = inputWidget.GetText(); string text = inputWidget.GetText();
if( inputWidget.Validator.IsValidValue( text ) ) if( inputWidget.Validator.IsValidValue( text ) )
@ -146,18 +239,5 @@ namespace ClassicalSharp {
buttons[okayIndex] = null; buttons[okayIndex] = null;
InputClosed(); InputClosed();
} }
protected virtual void InputOpened() { }
protected virtual void InputClosed() { }
protected virtual ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> setter ) {
ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre,
Anchor.Centre, titleFont, onClick );
widget.GetValue = getter;
widget.SetValue = setter;
return widget;
}
} }
} }

View File

@ -4,7 +4,7 @@ using ClassicalSharp.Singleplayer;
namespace ClassicalSharp { namespace ClassicalSharp {
public class MiscOptionsScreen : MenuInputScreen { public class MiscOptionsScreen : MenuOptionsScreen {
public MiscOptionsScreen( Game game ) : base( game ) { public MiscOptionsScreen( Game game ) : base( game ) {
} }
@ -108,23 +108,23 @@ namespace ClassicalSharp {
void MakeDescriptions() { void MakeDescriptions() {
descriptions = new string[buttons.Length][]; descriptions = new string[buttons.Length][];
descriptions[0] = new[] { descriptions[0] = new[] {
"&aControls how far away you can place/delete blocks.", "&aControls how far away you can place/delete blocks",
"&eThe default click distance is 5 blocks.", "&eThe default click distance is 5 blocks.",
}; };
descriptions[2] = new[] { descriptions[2] = new[] {
"&aDetermines how the names of other players/entities are drawn.", "&aDetermines how the names of other players are drawn",
"&eNoNames: &fNo player names are drawn.", "&eNoNames: &fNo player names are drawn.",
"&eHoveredOnly: &fThe name of the player you are looking at is drawn without depth testing.", "&eHoveredOnly: &fName of the targeted player is drawn see-through.",
"&eAllNames: &fAll names are drawn without depth testing.", "&eAllNames: &fAll player names are drawn normally.",
"&eAllNamesAndHovered: &fThe name of the player you are looking at is drawn without depth testing,", "&eAllNamesAndHovered: &fName of the targeted player is drawn see-through.",
"&f all other player names are drawn with depth testing.", "&f All other player names are drawn normally.",
}; };
descriptions[3] = new[] { descriptions[3] = new[] {
"&aDetermines the method used to limit the number of frames rendered each second.", "&aDetermines the method used to limit the number of FPS",
"&eVSync: &fNumber of frames rendered is equal to the refresh rate of the monitor.", "&eVSync: &fNumber of frames rendered is at most the monitor's refresh rate.",
"&e30/60/120 FPS: &f30/60/120 frames are rendered at most each second.", "&e30/60/120 FPS: &f30/60/120 frames rendered at most each second.",
"&eNoLimit: &Renders as many frames as the GPU can handle each second.", "&eNoLimit: &Renders as many frames as the GPU can handle each second.",
"&cUsing NoLimit mode is strongly discouraged for general usage.", "&cUsing NoLimit mode is discouraged for general usage.",
}; };
} }
} }

View File

@ -4,7 +4,7 @@ using ClassicalSharp.Singleplayer;
namespace ClassicalSharp { namespace ClassicalSharp {
public sealed class NostalgiaScreen : MenuInputScreen { public sealed class NostalgiaScreen : MenuOptionsScreen {
TextWidget infoWidget; TextWidget infoWidget;
public NostalgiaScreen( Game game ) : base( game ) { public NostalgiaScreen( Game game ) : base( game ) {

View File

@ -71,12 +71,12 @@ namespace ClassicalSharp {
ButtonWidget Make( int x, int y, string text, Anchor vDocking, Action<Game, Widget> onClick ) { ButtonWidget Make( int x, int y, string text, Anchor vDocking, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, 240, 35, text, return ButtonWidget.Create( game, x, y, 240, 35, text,
Anchor.Centre, vDocking, titleFont, onClick ); Anchor.Centre, vDocking, titleFont, LeftOnly( onClick ) );
} }
ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action<Game, Widget> onClick ) { ButtonWidget MakeOther( int x, int y, int width, string text, Anchor hAnchor, Action<Game, Widget> onClick ) {
return ButtonWidget.Create( game, x, y, width, 35, text, return ButtonWidget.Create( game, x, y, width, 35, text,
hAnchor, Anchor.BottomOrRight, titleFont, onClick ); hAnchor, Anchor.BottomOrRight, titleFont, LeftOnly( onClick ) );
} }
public override bool HandlesKeyDown( Key key ) { public override bool HandlesKeyDown( Key key ) {

View File

@ -77,7 +77,8 @@ namespace ClassicalSharp {
base.Dispose(); base.Dispose();
} }
void OkButtonClick( Game game, Widget widget ) { void OkButtonClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
string text = inputWidget.GetText(); string text = inputWidget.GetText();
if( text.Length == 0 ) { if( text.Length == 0 ) {
MakeDescWidget( "Please enter a filename" ); MakeDescWidget( "Please enter a filename" );
@ -99,7 +100,8 @@ namespace ClassicalSharp {
} }
} }
void OverwriteButtonClick( Game game, Widget widget ) { void OverwriteButtonClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
string text = inputWidget.GetText(); string text = inputWidget.GetText();
string file = Path.ChangeExtension( text, ".cw" ); string file = Path.ChangeExtension( text, ".cw" );
text = Path.Combine( Program.AppDirectory, "maps" ); text = Path.Combine( Program.AppDirectory, "maps" );

View File

@ -23,7 +23,8 @@ namespace ClassicalSharp {
MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ); MakeBack( false, titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
} }
protected override void TextButtonClick( Game game, Widget widget ) { protected override void TextButtonClick( Game game, Widget widget, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
string file = ((ButtonWidget)widget).Text; string file = ((ButtonWidget)widget).Text;
string dir = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir ); string dir = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir );
string path = Path.Combine( dir, file ); string path = Path.Combine( dir, file );

View File

@ -113,14 +113,16 @@ namespace ClassicalSharp {
} }
Action<WarningScreen> yesClick, noClick, renderFrame; Action<WarningScreen> yesClick, noClick, renderFrame;
void OnYesClick( Game g, Widget w ) { void OnYesClick( Game g, Widget w, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
if( yesClick != null ) if( yesClick != null )
yesClick( this ); yesClick( this );
Dispose(); Dispose();
CloseScreen(); CloseScreen();
} }
void OnNoClick( Game g, Widget w ) { void OnNoClick( Game g, Widget w, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
if( confirmNo && !confirmMode ) { if( confirmNo && !confirmMode ) {
InitConfirmButtons( false ); return; InitConfirmButtons( false ); return;
} }
@ -131,19 +133,21 @@ namespace ClassicalSharp {
CloseScreen(); CloseScreen();
} }
void OnYesAlwaysClick( Game g, Widget w ) { void OnYesAlwaysClick( Game g, Widget w, MouseButton mouseBtn ) {
OnYesClick( g, w ); if( mouseBtn != MouseButton.Left ) return;
OnYesClick( g, w, mouseBtn );
string url = ((string)Metadata).Substring( 3 ); string url = ((string)Metadata).Substring( 3 );
if( !game.AcceptedUrls.HasUrl( url ) ) if( !game.AcceptedUrls.HasUrl( url ) )
game.AcceptedUrls.AddUrl( url ); game.AcceptedUrls.AddUrl( url );
} }
void OnNoAlwaysClick( Game g, Widget w ) { void OnNoAlwaysClick( Game g, Widget w, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
if( confirmNo && !confirmMode ) { if( confirmNo && !confirmMode ) {
InitConfirmButtons( true ); return; InitConfirmButtons( true ); return;
} }
OnNoClick( g, w ); OnNoClick( g, w, mouseBtn );
string url = ((string)Metadata).Substring( 3 ); string url = ((string)Metadata).Substring( 3 );
if( !game.DeniedUrls.HasUrl( url ) ) if( !game.DeniedUrls.HasUrl( url ) )
game.DeniedUrls.AddUrl( url ); game.DeniedUrls.AddUrl( url );
@ -151,8 +155,7 @@ namespace ClassicalSharp {
void InitConfirmButtons( bool always ) { void InitConfirmButtons( bool always ) {
Action<Game, Widget> noHandler = always ? (Action<Game, Widget>)OnNoAlwaysClick ClickHandler noHandler = always ? (ClickHandler)OnNoAlwaysClick: (ClickHandler)OnNoClick;
: (Action<Game, Widget>)OnNoClick;
buttons = new ButtonWidget[] { buttons = new ButtonWidget[] {
ButtonWidget.Create( game, -110, 30, 160, 35, "I'm sure", Anchor.Centre, ButtonWidget.Create( game, -110, 30, 160, 35, "I'm sure", Anchor.Centre,
Anchor.Centre, titleFont, noHandler ), Anchor.Centre, titleFont, noHandler ),
@ -163,7 +166,8 @@ namespace ClassicalSharp {
SetText( lastTitle, lastBody ); SetText( lastTitle, lastBody );
} }
void GoBackClick( Game g, Widget w ) { void GoBackClick( Game g, Widget w, MouseButton mouseBtn ) {
if( mouseBtn != MouseButton.Left ) return;
InitStandardButtons(); InitStandardButtons();
confirmMode = false; confirmMode = false;
SetText( lastTitle, lastBody ); SetText( lastTitle, lastBody );

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using OpenTK.Input;
#if ANDROID #if ANDROID
using Android.Graphics; using Android.Graphics;
#endif #endif
@ -13,7 +14,7 @@ namespace ClassicalSharp {
} }
public static ButtonWidget Create( Game game, int x, int y, int width, int height, string text, Anchor horizontal, public static ButtonWidget Create( Game game, int x, int y, int width, int height, string text, Anchor horizontal,
Anchor vertical, Font font, Action<Game, Widget> onClick ) { Anchor vertical, Font font, ClickHandler onClick ) {
ButtonWidget widget = new ButtonWidget( game, font ); ButtonWidget widget = new ButtonWidget( game, font );
widget.Init(); widget.Init();
widget.HorizontalAnchor = horizontal; widget.HorizontalAnchor = horizontal;

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using OpenTK.Input;
namespace ClassicalSharp { namespace ClassicalSharp {
@ -17,8 +18,8 @@ namespace ClassicalSharp {
/// <summary> Whether this widget is prevented from being interacted with. </summary> /// <summary> Whether this widget is prevented from being interacted with. </summary>
public bool Disabled; public bool Disabled;
/// <summary> Invoked when this widget is clicked on. Can be left null. </summary> /// <summary> Invoked when this widget is clicked on. Can be null. </summary>
public Action<Game, Widget> OnClick; public ClickHandler OnClick;
/// <summary> Horizontal coordinate of top left corner in window space. </summary> /// <summary> Horizontal coordinate of top left corner in window space. </summary>
public int X; public int X;

View File

@ -101,7 +101,7 @@
<Compile Include="2D\Screens\Menu\HacksSettingsScreen.cs" /> <Compile Include="2D\Screens\Menu\HacksSettingsScreen.cs" />
<Compile Include="2D\Screens\Menu\KeyBindingsScreen.cs" /> <Compile Include="2D\Screens\Menu\KeyBindingsScreen.cs" />
<Compile Include="2D\Screens\Menu\LoadLevelScreen.cs" /> <Compile Include="2D\Screens\Menu\LoadLevelScreen.cs" />
<Compile Include="2D\Screens\Menu\MenuInputScreen.cs" /> <Compile Include="2D\Screens\Menu\MenuOptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\MenuScreen.cs" /> <Compile Include="2D\Screens\Menu\MenuScreen.cs" />
<Compile Include="2D\Screens\Menu\NostalgiaScreen.cs" /> <Compile Include="2D\Screens\Menu\NostalgiaScreen.cs" />
<Compile Include="2D\Screens\Menu\PauseScreen.cs" /> <Compile Include="2D\Screens\Menu\PauseScreen.cs" />