mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -04:00
Add 'default value' to EnvSettings screen.
This commit is contained in:
parent
86a7b49c08
commit
5f1ee54faf
@ -6,6 +6,8 @@ namespace ClassicalSharp {
|
||||
|
||||
public class EnvSettingsScreen : MenuInputScreen {
|
||||
|
||||
string[] defaultValues;
|
||||
int defaultIndex;
|
||||
public EnvSettingsScreen( Game game ) : base( game ) {
|
||||
}
|
||||
|
||||
@ -13,47 +15,63 @@ namespace ClassicalSharp {
|
||||
base.Init();
|
||||
|
||||
buttons = new ButtonWidget[] {
|
||||
Make( -140, -150, "Clouds colour", Anchor.Centre, OnWidgetClick,
|
||||
Make( -140, -150, "Clouds colour", OnWidgetClick,
|
||||
g => g.Map.CloudsCol.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetCloudsColour( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( -140, -100, "Sky colour", Anchor.Centre, OnWidgetClick,
|
||||
Make( -140, -100, "Sky colour", OnWidgetClick,
|
||||
g => g.Map.SkyCol.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetSkyColour( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( -140, -50, "Fog colour", Anchor.Centre, OnWidgetClick,
|
||||
Make( -140, -50, "Fog colour", OnWidgetClick,
|
||||
g => g.Map.FogCol.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetFogColour( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( -140, 0, "Clouds speed", Anchor.Centre, OnWidgetClick,
|
||||
Make( -140, 0, "Clouds speed", OnWidgetClick,
|
||||
g => g.Map.CloudsSpeed.ToString(),
|
||||
(g, v) => g.Map.SetCloudsSpeed( Single.Parse( v ) ) ),
|
||||
|
||||
Make( -140, 50, "Clouds height", Anchor.Centre, OnWidgetClick,
|
||||
Make( -140, 50, "Clouds height", OnWidgetClick,
|
||||
g => g.Map.CloudHeight.ToString(),
|
||||
(g, v) => g.Map.SetCloudsLevel( Int32.Parse( v ) ) ),
|
||||
|
||||
Make( 140, -150, "Sunlight colour", Anchor.Centre, OnWidgetClick,
|
||||
Make( 140, -150, "Sunlight colour", OnWidgetClick,
|
||||
g => g.Map.Sunlight.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetSunlight( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( 140, -100, "Shadow colour", Anchor.Centre, OnWidgetClick,
|
||||
Make( 140, -100, "Shadow colour", OnWidgetClick,
|
||||
g => g.Map.Shadowlight.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetShadowlight( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( 140, -50, "Weather", Anchor.Centre, OnWidgetClick,
|
||||
Make( 140, -50, "Weather", OnWidgetClick,
|
||||
g => g.Map.Weather.ToString(),
|
||||
(g, v) => g.Map.SetWeather( (Weather)Enum.Parse( typeof(Weather), v ) ) ),
|
||||
|
||||
Make( 140, 0, "Water level", Anchor.Centre, OnWidgetClick,
|
||||
Make( 140, 0, "Water level", OnWidgetClick,
|
||||
g => g.Map.EdgeHeight.ToString(),
|
||||
(g, v) => g.Map.SetEdgeLevel( Int32.Parse( v ) ) ),
|
||||
|
||||
MakeBack( false, titleFont,
|
||||
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
|
||||
null,
|
||||
null,
|
||||
};
|
||||
buttons[7].Metadata = typeof(Weather);
|
||||
defaultIndex = buttons.Length - 2;
|
||||
okayIndex = buttons.Length - 1;
|
||||
|
||||
defaultValues = new [] {
|
||||
Map.DefaultCloudsColour.ToRGBHexString(),
|
||||
Map.DefaultSkyColour.ToRGBHexString(),
|
||||
Map.DefaultFogColour.ToRGBHexString(),
|
||||
(1).ToString(),
|
||||
(game.Map.Height + 2).ToString(),
|
||||
|
||||
Map.DefaultSunlight.ToRGBHexString(),
|
||||
Map.DefaultShadowlight.ToRGBHexString(),
|
||||
Weather.Sunny.ToString(),
|
||||
(game.Map.Height / 2).ToString(),
|
||||
};
|
||||
|
||||
validators = new MenuInputValidator[] {
|
||||
new HexColourValidator(),
|
||||
@ -61,21 +79,39 @@ namespace ClassicalSharp {
|
||||
new HexColourValidator(),
|
||||
new RealValidator( 0, 1000 ),
|
||||
new IntegerValidator( -10000, 10000 ),
|
||||
|
||||
new HexColourValidator(),
|
||||
new HexColourValidator(),
|
||||
new EnumValidator(),
|
||||
new IntegerValidator( -2048, 2048 ),
|
||||
};
|
||||
okayIndex = buttons.Length - 1;
|
||||
}
|
||||
|
||||
ButtonWidget Make( int x, int y, string text, Anchor vDocking, Action<Game, Widget> onClick,
|
||||
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, vDocking, titleFont, onClick );
|
||||
ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre,
|
||||
Anchor.Centre, titleFont, onClick );
|
||||
widget.GetValue = getter;
|
||||
widget.SetValue = setter;
|
||||
return widget;
|
||||
}
|
||||
|
||||
protected override void InputClosed() {
|
||||
if( buttons[defaultIndex] != null )
|
||||
buttons[defaultIndex].Dispose();
|
||||
buttons[defaultIndex] = null;
|
||||
}
|
||||
|
||||
protected override void InputOpened() {
|
||||
buttons[defaultIndex] = ButtonWidget.Create(
|
||||
game, 0, 200, 180, 35, "Default value", Anchor.Centre,
|
||||
Anchor.Centre, titleFont, DefaultButtonClick );
|
||||
}
|
||||
|
||||
void DefaultButtonClick( Game game, Widget widget ) {
|
||||
int index = Array.IndexOf<ButtonWidget>( buttons, targetWidget );
|
||||
string defValue = defaultValues[index];
|
||||
inputWidget.SetText( defValue );
|
||||
}
|
||||
}
|
||||
}
|
@ -71,7 +71,7 @@ namespace ClassicalSharp {
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
ButtonWidget selectedWidget, targetWidget;
|
||||
protected ButtonWidget selectedWidget, targetWidget;
|
||||
protected override void WidgetSelected( Widget widget ) {
|
||||
ButtonWidget button = (ButtonWidget)widget;
|
||||
if( selectedWidget == button || button == null ||
|
||||
@ -127,6 +127,7 @@ namespace ClassicalSharp {
|
||||
Anchor.Centre, regularFont, titleFont, validator );
|
||||
buttons[okayIndex] = ButtonWidget.Create( game, 240, 150, 30, 30, "OK",
|
||||
Anchor.Centre, Anchor.Centre, titleFont, OnWidgetClick );
|
||||
InputOpened();
|
||||
UpdateDescription( targetWidget );
|
||||
}
|
||||
|
||||
@ -138,8 +139,14 @@ namespace ClassicalSharp {
|
||||
inputWidget = null;
|
||||
UpdateDescription( targetWidget );
|
||||
targetWidget = null;
|
||||
|
||||
buttons[okayIndex].Dispose();
|
||||
buttons[okayIndex] = null;
|
||||
InputClosed();
|
||||
}
|
||||
|
||||
protected virtual void InputOpened() { }
|
||||
|
||||
protected virtual void InputClosed() { }
|
||||
}
|
||||
}
|
@ -54,6 +54,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public void SetText( string value ) {
|
||||
chatInputText.Clear();
|
||||
chatInputText.Append( 0, value );
|
||||
DrawTextArgs args = new DrawTextArgs( value, font, false );
|
||||
Size textSize = game.Drawer2D.MeasureSize( ref args );
|
||||
|
@ -35,7 +35,6 @@
|
||||
<DefineConstants>DEBUG;TRACE;</DefineConstants>
|
||||
<StartAction>Project</StartAction>
|
||||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
|
||||
<StartArguments>wwwf ff 127.0.0.1 25565</StartArguments>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<OutputPath>..\output\release\</OutputPath>
|
||||
|
Loading…
x
Reference in New Issue
Block a user