mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Make colours in extended text widget nicer and more extensible, in preparation for CustomTextColours.
This commit is contained in:
parent
0f87b7feb5
commit
0ba33ce2a3
@ -9,7 +9,7 @@ namespace ClassicalSharp {
|
||||
|
||||
void InitData() {
|
||||
elements = new Element[] {
|
||||
new Element( "Colours", 8 * 3, 3, "&0█&1█&2█&3█&4█&5█&6█&7█&8█&9█&a█&b█&c█&d█&e█&f█" ),
|
||||
new Element( "Colours", 10, 4, GetColourString() ),
|
||||
new Element( "Math", 16, 1, "ƒ½¼αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°√ⁿ²" ),
|
||||
new Element( "Line/Box", 17, 1, "░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀■" ),
|
||||
new Element( "Letters", 17, 1, "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜáíóúñÑ" ),
|
||||
@ -17,6 +17,25 @@ namespace ClassicalSharp {
|
||||
};
|
||||
}
|
||||
|
||||
string GetColourString() {
|
||||
int count = 0;
|
||||
for( int i = 0; i < game.Drawer2D.Colours.Length; i++ ) {
|
||||
if( i >= 'A' && i <= 'F' ) continue;
|
||||
if( game.Drawer2D.Colours[i].A > 0 ) count++;
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer( count * 4 );
|
||||
int index = 0;
|
||||
for( int i = 0; i < game.Drawer2D.Colours.Length; i++ ) {
|
||||
if( i >= 'A' && i <= 'F' ) continue;
|
||||
if( game.Drawer2D.Colours[i].A == 0 ) continue;
|
||||
|
||||
buffer.Append( ref index, '&' ).Append( ref index, (char)i )
|
||||
.Append( ref index, '%' ).Append( ref index, (char)i );
|
||||
}
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
struct Element {
|
||||
public string Title;
|
||||
public Size TitleSize;
|
||||
@ -47,15 +66,14 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
unsafe Size CalculateContentSize( Element e, Size* sizes, out Size elemSize ) {
|
||||
int wrap = e.ItemsPerRow / e.CharsPerItem;
|
||||
elemSize = Size.Empty;
|
||||
for( int i = 0; i < e.Contents.Length; i += e.CharsPerItem )
|
||||
elemSize.Width = Math.Max( elemSize.Width, sizes[i / e.CharsPerItem].Width );
|
||||
|
||||
elemSize.Width += contentSpacing;
|
||||
elemSize.Height = sizes[0].Height + contentSpacing;
|
||||
int rows = Utils.CeilDiv( e.Contents.Length / e.CharsPerItem, wrap );
|
||||
return new Size( elemSize.Width * wrap, elemSize.Height * rows );
|
||||
int rows = Utils.CeilDiv( e.Contents.Length / e.CharsPerItem, e.ItemsPerRow );
|
||||
return new Size( elemSize.Width * e.ItemsPerRow, elemSize.Height * rows );
|
||||
}
|
||||
|
||||
const int titleSpacing = 10, contentSpacing = 5;
|
||||
|
@ -12,8 +12,11 @@ namespace ClassicalSharp {
|
||||
this.font = font;
|
||||
this.parent = parent;
|
||||
Active = false;
|
||||
game.Events.ColourCodesChanged += ColourCodesChanged;
|
||||
}
|
||||
|
||||
void ColourCodesChanged( object sender, EventArgs e ) { Redraw(); }
|
||||
|
||||
public Texture texture;
|
||||
readonly Font font;
|
||||
TextInputWidget parent;
|
||||
@ -66,6 +69,7 @@ namespace ClassicalSharp {
|
||||
mouseX -= X; mouseY -= Y;
|
||||
if( IntersectsHeader( mouseX, mouseY ) ) {
|
||||
Dispose();
|
||||
game.Events.ColourCodesChanged += ColourCodesChanged;
|
||||
Redraw();
|
||||
} else {
|
||||
IntersectsBody( mouseX, mouseY );
|
||||
@ -105,6 +109,7 @@ namespace ClassicalSharp {
|
||||
|
||||
public override void Dispose() {
|
||||
graphicsApi.DeleteTexture( ref texture );
|
||||
game.Events.ColourCodesChanged -= ColourCodesChanged;
|
||||
}
|
||||
}
|
||||
}
|
@ -39,6 +39,10 @@ namespace ClassicalSharp {
|
||||
public event EventHandler HackPermissionsChanged;
|
||||
internal void RaiseHackPermissionsChanged() { Raise( HackPermissionsChanged ); }
|
||||
|
||||
/// <summary> Raised when the colour codes usable by the player changes. </summary>
|
||||
public event EventHandler ColourCodesChanged;
|
||||
internal void RaiseColourCodesChanged() { Raise( ColourCodesChanged ); }
|
||||
|
||||
ChatEventArgs chatArgs = new ChatEventArgs();
|
||||
protected void Raise( EventHandler handler ) {
|
||||
if( handler != null )
|
||||
|
@ -536,6 +536,7 @@ namespace ClassicalSharp {
|
||||
if( (code >= '0' && code <= '9') || (code >= 'a' && code <= 'f')
|
||||
|| (code >= 'A' && code <= 'F') ) return; // Standard chars cannot be used.
|
||||
game.Drawer2D.Colours[code] = col;
|
||||
game.Events.RaiseColourCodesChanged();
|
||||
}
|
||||
|
||||
static SoundType[] stepSnds, breakSnds;
|
||||
|
@ -39,11 +39,10 @@ namespace ClassicalSharp.Singleplayer {
|
||||
}
|
||||
|
||||
public override void SendChat( string text, bool partial ) {
|
||||
if( !String.IsNullOrEmpty( text ) ) {
|
||||
text = text.TrimEnd();
|
||||
if( String.IsNullOrEmpty( text ) ) return;
|
||||
text = text.TrimEnd().Replace( '%', '&' );
|
||||
game.Chat.Add( text, MessageType.Normal );
|
||||
}
|
||||
}
|
||||
|
||||
public override void SendPosition( Vector3 pos, float yaw, float pitch ) {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user