Skip to content

Commit

Permalink
Code cleanup on all 245 files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonty800 committed Aug 6, 2013
1 parent f92a94b commit 1e947a3
Show file tree
Hide file tree
Showing 245 changed files with 18,397 additions and 19,276 deletions.
451 changes: 224 additions & 227 deletions ConfigGUI/AddWorldPopup.cs

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions ConfigGUI/ChatPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@
using System.Windows.Forms;
using fCraft.ConfigGUI.Properties;


namespace fCraft.ConfigGUI {

sealed partial class ChatPreview : UserControl {

struct ColorPair {
private struct ColorPair {

public ColorPair( int r, int g, int b, int sr, int sg, int sb ) {
Foreground = new SolidBrush( System.Drawing.Color.FromArgb( r, g, b ) );
Shadow = new SolidBrush( System.Drawing.Color.FromArgb( sr, sg, sb ) );
}

public readonly Brush Foreground, Shadow;
}

static readonly PrivateFontCollection Fonts;
static readonly Font MinecraftFont;
static readonly ColorPair[] ColorPairs;
private static readonly PrivateFontCollection Fonts;
private static readonly Font MinecraftFont;
private static readonly ColorPair[] ColorPairs;

unsafe static ChatPreview() {
Fonts = new PrivateFontCollection();
fixed( byte* fontPointer = Resources.MinecraftFont ) {
Fonts.AddMemoryFont( (IntPtr)fontPointer, Resources.MinecraftFont.Length );
fixed ( byte* fontPointer = Resources.MinecraftFont ) {
Fonts.AddMemoryFont( ( IntPtr )fontPointer, Resources.MinecraftFont.Length );
}
MinecraftFont = new Font( Fonts.Families[0], 12, FontStyle.Regular );
ColorPairs = new[]{
Expand All @@ -50,14 +52,12 @@ unsafe static ChatPreview() {
};
}


public ChatPreview() {
InitializeComponent();
DoubleBuffered = true;
}


sealed class TextSegment {
private sealed class TextSegment {
public string Text;
public ColorPair Color;
public int X, Y;
Expand All @@ -68,26 +68,28 @@ public void Draw( Graphics g ) {
}
}

static readonly Regex SplitByColorRegex = new Regex( "(&[0-9a-zA-Z])", RegexOptions.Compiled );
TextSegment[] segments;
private static readonly Regex SplitByColorRegex = new Regex( "(&[0-9a-zA-Z])", RegexOptions.Compiled );
private TextSegment[] segments;

public void SetText( string[] lines ) {
List<TextSegment> newSegments = new List<TextSegment>();
using( Bitmap b = new Bitmap( 1, 1 ) ) {
using( Graphics g = Graphics.FromImage( b ) ) { // graphics for string mesaurement
using ( Bitmap b = new Bitmap( 1, 1 ) ) {
using ( Graphics g = Graphics.FromImage( b ) ) { // graphics for string mesaurement
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;

int y = 5;
for( int i = 0; i < lines.Length; i++ ) {
if( lines[i] == null || lines[i].Length == 0 ) continue;
for ( int i = 0; i < lines.Length; i++ ) {
if ( lines[i] == null || lines[i].Length == 0 )
continue;
int x = 5;
string[] plainTextSegments = SplitByColorRegex.Split( lines[i] );

int color = Color.ParseToIndex( Color.White );

for( int j = 0; j < plainTextSegments.Length; j++ ) {
if( plainTextSegments[j].Length == 0 ) continue;
if( plainTextSegments[j][0] == '&' ) {
for ( int j = 0; j < plainTextSegments.Length; j++ ) {
if ( plainTextSegments[j].Length == 0 )
continue;
if ( plainTextSegments[j][0] == '&' ) {
color = Color.ParseToIndex( plainTextSegments[j] );
} else {
newSegments.Add( new TextSegment {
Expand All @@ -96,26 +98,24 @@ public void SetText( string[] lines ) {
X = x,
Y = y
} );
x += (int)g.MeasureString( plainTextSegments[j], MinecraftFont ).Width;
x += ( int )g.MeasureString( plainTextSegments[j], MinecraftFont ).Width;
}
}
y += 20;
}

}
}
segments = newSegments.ToArray();
Invalidate();
}


protected override void OnPaint( PaintEventArgs e ) {
e.Graphics.DrawImageUnscaledAndClipped( Resources.ChatBackground, e.ClipRectangle );

e.Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;

if( segments != null && segments.Length > 0 ) {
for( int i = 0; i < segments.Length; i++ ) {
if ( segments != null && segments.Length > 0 ) {
for ( int i = 0; i < segments.Length; i++ ) {
segments[i].Draw( e.Graphics );
}
}
Expand Down
6 changes: 3 additions & 3 deletions ConfigGUI/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
using System.Windows.Forms;

namespace fCraft.ConfigGUI {

internal sealed partial class ColorPicker : Form {
public static readonly Dictionary<int, ColorPair> ColorPairs = new Dictionary<int, ColorPair>();
public int ColorIndex;


static ColorPicker() {
ColorPairs.Add( 0, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.Black ) );
ColorPairs.Add( 8, new ColorPair( System.Drawing.Color.White, System.Drawing.Color.DimGray ) );
Expand All @@ -27,7 +27,6 @@ static ColorPicker() {
ColorPairs.Add( 15, new ColorPair( System.Drawing.Color.Black, System.Drawing.Color.White ) );
}


public ColorPicker( string title, int oldColorIndex ) {
InitializeComponent();
Text = title;
Expand All @@ -52,12 +51,13 @@ public ColorPicker( string title, int oldColorIndex ) {
bf.Click += delegate { ColorIndex = 15; DialogResult = DialogResult.OK; Close(); };
}


internal struct ColorPair {

public ColorPair( System.Drawing.Color foreground, System.Drawing.Color background ) {
Foreground = foreground;
Background = background;
}

public System.Drawing.Color Foreground;
public System.Drawing.Color Background;
}
Expand Down
8 changes: 5 additions & 3 deletions ConfigGUI/CustomPictureBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
using System.Windows.Forms;

namespace fCraft.ConfigGUI {
sealed class CustomPictureBox : PictureBox {

internal sealed class CustomPictureBox : PictureBox {

protected override void OnPaint( PaintEventArgs pe ) {
if( Image != null ) {
if ( Image != null ) {
pe.Graphics.SmoothingMode = SmoothingMode.HighQuality;
pe.Graphics.CompositingQuality = CompositingQuality.HighQuality;
if( Image.Height * 3 > Height || Image.Width * 3 > Width ) {
if ( Image.Height * 3 > Height || Image.Width * 3 > Width ) {
pe.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
} else {
pe.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
Expand Down
17 changes: 10 additions & 7 deletions ConfigGUI/DeleteRankPopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
using System.Windows.Forms;

namespace fCraft.ConfigGUI {

public sealed partial class DeleteRankPopup : Form {

internal Rank SubstituteRank { get; private set; }

public DeleteRankPopup( Rank deletedRank ) {
InitializeComponent();
foreach( Rank rank in RankManager.Ranks ) {
if( rank != deletedRank ) {
foreach ( Rank rank in RankManager.Ranks ) {
if ( rank != deletedRank ) {
cSubstitute.Items.Add( MainForm.ToComboBoxOption( rank ) );
}
}
lWarning.Text = String.Format( lWarning.Text, deletedRank.Name );
cSubstitute.SelectedIndex = cSubstitute.Items.Count - 1;
}


private void cSubstitute_SelectedIndexChanged( object sender, EventArgs e ) {
if( cSubstitute.SelectedIndex < 0 ) return;
foreach( Rank rank in RankManager.Ranks ) {
if( cSubstitute.SelectedItem.ToString() != MainForm.ToComboBoxOption( rank ) ) continue;
if ( cSubstitute.SelectedIndex < 0 )
return;
foreach ( Rank rank in RankManager.Ranks ) {
if ( cSubstitute.SelectedItem.ToString() != MainForm.ToComboBoxOption( rank ) )
continue;
SubstituteRank = rank;
bDelete.Enabled = true;
break;
}
}
}
}
}
18 changes: 10 additions & 8 deletions ConfigGUI/KeywordPicker.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Windows.Forms;

namespace fCraft.ConfigGUI {

public sealed partial class KeywordPicker : Form {
public string Result;

readonly ToolTip tips;
static readonly KeywordInfo[] Keywords = new[]{
private readonly ToolTip tips;

private static readonly KeywordInfo[] Keywords = new[]{
new KeywordInfo("{SERVER_NAME}", "Server name", "Name of your server, as specified in config." ),
new KeywordInfo("{RANK}", "Player's rank", "Player's rank, including prefix and colors (if applicable)." ),
new KeywordInfo("{PLAYER_NAME}", "Player's name", "Name of the player, including prefix and colors (if applicable)." ),
Expand All @@ -17,13 +19,13 @@ public sealed partial class KeywordPicker : Form {
new KeywordInfo("{VERSION}", "800Craft version", "Version of 800Craft that this server is running." )
};

const int ButtonWidth = 150,
private const int ButtonWidth = 150,
ButtonHeight = 28;

public KeywordPicker() {
InitializeComponent();
tips = new ToolTip();
foreach( KeywordInfo keyword in Keywords ) {
foreach ( KeywordInfo keyword in Keywords ) {
Button newButton = new Button {
Text = keyword.LongName,
Tag = keyword.Keyword,
Expand All @@ -32,26 +34,26 @@ public KeywordPicker() {
};
pFlow.Controls.Add( newButton );
newButton.Click += delegate {
Result = (string)newButton.Tag;
Result = ( string )newButton.Tag;
DialogResult = DialogResult.OK;
Close();
};
tips.SetToolTip( newButton, keyword.Description );
}
}

private struct KeywordInfo {

struct KeywordInfo {
public KeywordInfo( string keyword, string name, string description ) {
Keyword = keyword;
LongName = name;
Description = description;
}

public readonly string Keyword, LongName, Description;
}

private void pFlow_Paint ( object sender, PaintEventArgs e ) {

private void pFlow_Paint( object sender, PaintEventArgs e ) {
}
}
}
Loading

0 comments on commit 1e947a3

Please sign in to comment.