mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 01:55:19 -04:00
Reduce model vertices size, reduce complexity of TextInputWidget significantly, add basis for a save level screen.
This commit is contained in:
parent
a12ffa3730
commit
e81bbc13ae
@ -151,6 +151,7 @@ namespace ClassicalSharp {
|
|||||||
game.CursorVisible = true;
|
game.CursorVisible = true;
|
||||||
suppressNextPress = true;
|
suppressNextPress = true;
|
||||||
HandlesAllInput = true;
|
HandlesAllInput = true;
|
||||||
|
game.Keyboard.KeyRepeat = true;
|
||||||
textInput.chatInputText.Clear();
|
textInput.chatInputText.Clear();
|
||||||
textInput.chatInputText.Append( 0, initialText );
|
textInput.chatInputText.Append( 0, initialText );
|
||||||
textInput.Init();
|
textInput.Init();
|
||||||
@ -165,6 +166,7 @@ namespace ClassicalSharp {
|
|||||||
if( game.CursorVisible )
|
if( game.CursorVisible )
|
||||||
game.CursorVisible = false;
|
game.CursorVisible = false;
|
||||||
game.Camera.RegrabMouse();
|
game.Camera.RegrabMouse();
|
||||||
|
game.Keyboard.KeyRepeat = false;
|
||||||
|
|
||||||
if( key == game.Keys[KeyMapping.PauseOrExit] )
|
if( key == game.Keys[KeyMapping.PauseOrExit] )
|
||||||
textInput.chatInputText.Clear();
|
textInput.chatInputText.Clear();
|
||||||
|
@ -10,9 +10,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
base.Init();
|
||||||
regularFont = new Font( "Arial", 16, FontStyle.Regular );
|
|
||||||
hintFont = new Font( "Arial", 14, FontStyle.Italic );
|
|
||||||
|
|
||||||
buttons = new ButtonWidget[] {
|
buttons = new ButtonWidget[] {
|
||||||
Make( -140, -150, "Clouds colour", Docking.Centre, OnWidgetClick,
|
Make( -140, -150, "Clouds colour", Docking.Centre, OnWidgetClick,
|
||||||
|
@ -26,6 +26,13 @@ namespace ClassicalSharp {
|
|||||||
graphicsApi.Texturing = false;
|
graphicsApi.Texturing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Init() {
|
||||||
|
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||||
|
regularFont = new Font( "Arial", 16, FontStyle.Regular );
|
||||||
|
hintFont = new Font( "Arial", 14, FontStyle.Italic );
|
||||||
|
game.Keyboard.KeyRepeat = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool HandlesKeyPress( char key ) {
|
public override bool HandlesKeyPress( char key ) {
|
||||||
if( inputWidget == null ) return true;
|
if( inputWidget == null ) return true;
|
||||||
return inputWidget.HandlesKeyPress( key );
|
return inputWidget.HandlesKeyPress( key );
|
||||||
@ -59,6 +66,7 @@ namespace ClassicalSharp {
|
|||||||
if( inputWidget != null )
|
if( inputWidget != null )
|
||||||
inputWidget.Dispose();
|
inputWidget.Dispose();
|
||||||
hintFont.Dispose();
|
hintFont.Dispose();
|
||||||
|
game.Keyboard.KeyRepeat = false;
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,9 +10,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
base.Init();
|
||||||
regularFont = new Font( "Arial", 16, FontStyle.Regular );
|
|
||||||
hintFont = new Font( "Arial", 14, FontStyle.Italic );
|
|
||||||
INetworkProcessor network = game.Network;
|
INetworkProcessor network = game.Network;
|
||||||
|
|
||||||
buttons = new ButtonWidget[] {
|
buttons = new ButtonWidget[] {
|
||||||
|
@ -22,7 +22,7 @@ namespace ClassicalSharp {
|
|||||||
Make( 0, -100, "Options", Docking.Centre, (g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ),
|
Make( 0, -100, "Options", Docking.Centre, (g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ),
|
||||||
Make( 0, -50, "Environment settings", Docking.Centre, (g, w) => g.SetNewScreen( new EnvSettingsScreen( g ) ) ),
|
Make( 0, -50, "Environment settings", Docking.Centre, (g, w) => g.SetNewScreen( new EnvSettingsScreen( g ) ) ),
|
||||||
Make( 0, 0, "Key mappings", Docking.Centre, (g, w) => g.SetNewScreen( new KeyMappingsScreen( g ) ) ),
|
Make( 0, 0, "Key mappings", Docking.Centre, (g, w) => g.SetNewScreen( new KeyMappingsScreen( g ) ) ),
|
||||||
//Make( 0, 50, "Load/Save/Gen level", Docking.Centre, (g, w) => { } ),
|
Make( 0, 50, "Load/Save/Gen level", Docking.Centre, (g, w) => g.SetNewScreen( new SaveLevelScreen( g ) ) ),
|
||||||
Make( 0, 55, "Back to game", Docking.BottomOrRight, (g, w) => g.SetNewScreen( new NormalScreen( g ) ) ),
|
Make( 0, 55, "Back to game", Docking.BottomOrRight, (g, w) => g.SetNewScreen( new NormalScreen( g ) ) ),
|
||||||
Make( 0, 5, "Quit game", Docking.BottomOrRight, (g, w) => g.Exit() ),
|
Make( 0, 5, "Quit game", Docking.BottomOrRight, (g, w) => g.Exit() ),
|
||||||
};
|
};
|
||||||
|
77
ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs
Normal file
77
ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
|
public sealed class SaveLevelScreen : MenuScreen {
|
||||||
|
|
||||||
|
public SaveLevelScreen( Game game ) : base( game ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuInputWidget inputWidget;
|
||||||
|
Font hintFont;
|
||||||
|
|
||||||
|
public override void Render( double delta ) {
|
||||||
|
RenderMenuBounds();
|
||||||
|
graphicsApi.Texturing = true;
|
||||||
|
RenderMenuButtons( delta );
|
||||||
|
inputWidget.Render( delta );
|
||||||
|
graphicsApi.Texturing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandlesKeyPress( char key ) {
|
||||||
|
return inputWidget.HandlesKeyPress( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandlesKeyDown( Key key ) {
|
||||||
|
if( key == Key.Escape ) {
|
||||||
|
game.SetNewScreen( new NormalScreen( game ) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return inputWidget.HandlesKeyDown( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandlesKeyUp( Key key ) {
|
||||||
|
return inputWidget.HandlesKeyUp( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Init() {
|
||||||
|
game.Keyboard.KeyRepeat = true;
|
||||||
|
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||||
|
regularFont = new Font( "Arial", 16, FontStyle.Regular );
|
||||||
|
hintFont = new Font( "Arial", 14, FontStyle.Italic );
|
||||||
|
|
||||||
|
inputWidget = MenuInputWidget.Create(
|
||||||
|
game, 0, 50, 400, 25, "", Docking.Centre, Docking.Centre,
|
||||||
|
regularFont, titleFont, hintFont, new PathValidator() );
|
||||||
|
buttons = new [] {
|
||||||
|
ButtonWidget.Create( game, 240, 50, 30, 30, "OK", Docking.Centre,
|
||||||
|
Docking.Centre, titleFont, OkButtonClick ),
|
||||||
|
ButtonWidget.Create( game, 0, 5, 240, 35, "Back to menu", Docking.Centre, Docking.BottomOrRight,
|
||||||
|
titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||||
|
inputWidget.OnResize( oldWidth, oldHeight, width, height );
|
||||||
|
base.OnResize( oldWidth, oldHeight, width, height );
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Dispose() {
|
||||||
|
game.Keyboard.KeyRepeat = false;
|
||||||
|
inputWidget.Dispose();
|
||||||
|
hintFont.Dispose();
|
||||||
|
base.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OkButtonClick( Game game, ButtonWidget widget ) {
|
||||||
|
string text = inputWidget.GetText();
|
||||||
|
|
||||||
|
if( inputWidget.Validator.IsValidValue( text ) )
|
||||||
|
game.AddChat( "okay path" );
|
||||||
|
game.SetNewScreen( new PauseScreen( game ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -92,6 +92,25 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class PathValidator : MenuInputValidator {
|
||||||
|
|
||||||
|
public PathValidator() {
|
||||||
|
Range = "&7(Enter filename)";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsValidChar( char c ) {
|
||||||
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsValidString( string s ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsValidValue( string s ) {
|
||||||
|
return s.Length > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public sealed class BooleanValidator : MenuInputValidator {
|
public sealed class BooleanValidator : MenuInputValidator {
|
||||||
|
|
||||||
public BooleanValidator() {
|
public BooleanValidator() {
|
||||||
|
@ -10,12 +10,6 @@ namespace ClassicalSharp {
|
|||||||
public TextInputWidget( Game game, Font font, Font boldFont ) : base( game ) {
|
public TextInputWidget( Game game, Font font, Font boldFont ) : base( game ) {
|
||||||
HorizontalDocking = Docking.LeftOrTop;
|
HorizontalDocking = Docking.LeftOrTop;
|
||||||
VerticalDocking = Docking.BottomOrRight;
|
VerticalDocking = Docking.BottomOrRight;
|
||||||
handlers[0] = new InputHandler( BackspaceKey, Key.BackSpace, 10 );
|
|
||||||
handlers[1] = new InputHandler( DeleteKey, Key.Delete, 10 );
|
|
||||||
handlers[2] = new InputHandler( LeftKey, Key.Left, 10 );
|
|
||||||
handlers[3] = new InputHandler( RightKey, Key.Right, 10 );
|
|
||||||
handlers[4] = new InputHandler( UpKey, Key.Up, 5 );
|
|
||||||
handlers[5] = new InputHandler( DownKey, Key.Down, 5 );
|
|
||||||
typingLogPos = game.ChatInputLog.Count; // Index of newest entry + 1.
|
typingLogPos = game.ChatInputLog.Count; // Index of newest entry + 1.
|
||||||
this.font = font;
|
this.font = font;
|
||||||
this.boldFont = boldFont;
|
this.boldFont = boldFont;
|
||||||
@ -33,7 +27,6 @@ namespace ClassicalSharp {
|
|||||||
public override void Render( double delta ) {
|
public override void Render( double delta ) {
|
||||||
chatInputTexture.Render( graphicsApi );
|
chatInputTexture.Render( graphicsApi );
|
||||||
chatCaretTexture.Render( graphicsApi );
|
chatCaretTexture.Render( graphicsApi );
|
||||||
TickInput( delta );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
@ -109,53 +102,6 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region Input handling
|
#region Input handling
|
||||||
InputHandler[] handlers = new InputHandler[6];
|
|
||||||
|
|
||||||
class InputHandler {
|
|
||||||
public Action KeyFunction;
|
|
||||||
public DateTime LastDown;
|
|
||||||
public Key AssociatedKey;
|
|
||||||
public double accumulator, period;
|
|
||||||
|
|
||||||
public InputHandler( Action func, Key key, int frequency ) {
|
|
||||||
KeyFunction = func;
|
|
||||||
AssociatedKey = key;
|
|
||||||
LastDown = DateTime.MinValue;
|
|
||||||
period = 1.0 / frequency;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HandlesKeyDown( Key key ) {
|
|
||||||
if( key != AssociatedKey ) return false;
|
|
||||||
LastDown = DateTime.UtcNow;
|
|
||||||
KeyFunction();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void KeyTick( Game game ) {
|
|
||||||
if( LastDown == DateTime.MinValue ) return;
|
|
||||||
if( game.IsKeyDown( AssociatedKey ) &&
|
|
||||||
(DateTime.UtcNow - LastDown).TotalSeconds >= period ) {
|
|
||||||
KeyFunction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HandlesKeyUp( Key key ) {
|
|
||||||
if( key != AssociatedKey ) return false;
|
|
||||||
LastDown = DateTime.MinValue;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TickInput( double delta ) {
|
|
||||||
for( int i = 0; i < handlers.Length; i++ ) {
|
|
||||||
InputHandler handler = handlers[i];
|
|
||||||
handler.accumulator += delta;
|
|
||||||
while( handler.accumulator > handler.period ) {
|
|
||||||
handler.KeyTick( game );
|
|
||||||
handler.accumulator -= handler.period;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool HandlesKeyPress( char key ) {
|
public override bool HandlesKeyPress( char key ) {
|
||||||
if( chatInputText.Length < 64 && !IsInvalidChar( key ) ) {
|
if( chatInputText.Length < 64 && !IsInvalidChar( key ) ) {
|
||||||
@ -172,6 +118,18 @@ namespace ClassicalSharp {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool HandlesKeyDown( Key key ) {
|
||||||
|
if( key == Key.Down ) DownKey();
|
||||||
|
else if( key == Key.Up ) UpKey();
|
||||||
|
else if( key == Key.Left ) LeftKey();
|
||||||
|
else if( key == Key.Right ) RightKey();
|
||||||
|
else if( key == Key.BackSpace ) BackspaceKey();
|
||||||
|
else if( key == Key.Delete ) DeleteKey();
|
||||||
|
else if( !OtherKey( key ) ) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void BackspaceKey() {
|
void BackspaceKey() {
|
||||||
if( !chatInputText.Empty && caretPos != 0 ) {
|
if( !chatInputText.Empty && caretPos != 0 ) {
|
||||||
if( caretPos == -1 ) {
|
if( caretPos == -1 ) {
|
||||||
@ -240,10 +198,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesKeyDown( Key key ) {
|
bool OtherKey( Key key ) {
|
||||||
for( int i = 0; i < handlers.Length; i++ ) {
|
|
||||||
if( handlers[i].HandlesKeyDown( key ) ) return true;
|
|
||||||
}
|
|
||||||
bool controlDown = game.IsKeyDown( Key.ControlLeft ) || game.IsKeyDown( Key.ControlRight );
|
bool controlDown = game.IsKeyDown( Key.ControlLeft ) || game.IsKeyDown( Key.ControlRight );
|
||||||
if( key == Key.V && controlDown && chatInputText.Length < 64 ) {
|
if( key == Key.V && controlDown && chatInputText.Length < 64 ) {
|
||||||
string text = Clipboard.GetText();
|
string text = Clipboard.GetText();
|
||||||
@ -277,14 +232,6 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesKeyUp( Key key ) {
|
|
||||||
for( int i = 0; i < handlers.Length; i++ ) {
|
|
||||||
if( handlers[i].HandlesKeyUp( key ) ) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -77,6 +77,7 @@
|
|||||||
<Compile Include="2D\Screens\Menu\MenuScreen.cs" />
|
<Compile Include="2D\Screens\Menu\MenuScreen.cs" />
|
||||||
<Compile Include="2D\Screens\Menu\PauseScreen.cs" />
|
<Compile Include="2D\Screens\Menu\PauseScreen.cs" />
|
||||||
<Compile Include="2D\Screens\Menu\OptionsScreen.cs" />
|
<Compile Include="2D\Screens\Menu\OptionsScreen.cs" />
|
||||||
|
<Compile Include="2D\Screens\Menu\SaveLevelScreen.cs" />
|
||||||
<Compile Include="2D\Screens\NormalScreen.cs" />
|
<Compile Include="2D\Screens\NormalScreen.cs" />
|
||||||
<Compile Include="2D\Screens\Screen.cs" />
|
<Compile Include="2D\Screens\Screen.cs" />
|
||||||
<Compile Include="2D\Texture.cs" />
|
<Compile Include="2D\Texture.cs" />
|
||||||
|
@ -7,7 +7,7 @@ namespace ClassicalSharp.Model {
|
|||||||
public class ChickenModel : IModel {
|
public class ChickenModel : IModel {
|
||||||
|
|
||||||
public ChickenModel( Game window ) : base( window ) {
|
public ChickenModel( Game window ) : base( window ) {
|
||||||
vertices = new VertexPos3fTex2fCol4b[partVertices * 6 + planeVertices * 2 * 2];
|
vertices = new ModelVertex[partVertices * 6 + planeVertices * 2 * 2];
|
||||||
Head = MakeHead();
|
Head = MakeHead();
|
||||||
Head2 = MakeHead2(); // TODO: Find a more appropriate name.
|
Head2 = MakeHead2(); // TODO: Find a more appropriate name.
|
||||||
Head3 = MakeHead3();
|
Head3 = MakeHead3();
|
||||||
|
@ -7,7 +7,7 @@ namespace ClassicalSharp.Model {
|
|||||||
public class CreeperModel : IModel {
|
public class CreeperModel : IModel {
|
||||||
|
|
||||||
public CreeperModel( Game window ) : base( window ) {
|
public CreeperModel( Game window ) : base( window ) {
|
||||||
vertices = new VertexPos3fTex2fCol4b[partVertices * 6];
|
vertices = new ModelVertex[partVertices * 6];
|
||||||
Head = MakeHead();
|
Head = MakeHead();
|
||||||
Torso = MakeTorso();
|
Torso = MakeTorso();
|
||||||
LeftLegFront = MakeLeg( -4/16f, 0, -6/16f, -2/16f );
|
LeftLegFront = MakeLeg( -4/16f, 0, -6/16f, -2/16f );
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using ClassicalSharp.GraphicsAPI;
|
using ClassicalSharp.GraphicsAPI;
|
||||||
using ClassicalSharp.Renderers;
|
using ClassicalSharp.Renderers;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
@ -48,7 +49,7 @@ namespace ClassicalSharp.Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected FastColour col;
|
protected FastColour col;
|
||||||
protected VertexPos3fTex2fCol4b[] vertices;
|
protected ModelVertex[] vertices;
|
||||||
protected int index;
|
protected int index;
|
||||||
|
|
||||||
protected ModelPart MakePart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH,
|
protected ModelPart MakePart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH,
|
||||||
@ -59,7 +60,7 @@ namespace ClassicalSharp.Model {
|
|||||||
ZPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, y1, y2, z2, _64x64 ); // back
|
ZPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, y1, y2, z2, _64x64 ); // back
|
||||||
XPlane( x, y + endsH, sidesW, sidesH, z2, z1, y1, y2, x2, _64x64 ); // left
|
XPlane( x, y + endsH, sidesW, sidesH, z2, z1, y1, y2, x2, _64x64 ); // left
|
||||||
XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, z1, z2, y1, y2, x1, _64x64 ); // right
|
XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, z1, z2, y1, y2, x1, _64x64 ); // right
|
||||||
return new ModelPart( index - 6 * 4, 6 * 4 );
|
return new ModelPart( index - 6 * 4, 6 * 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ModelPart MakeRotatedPart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH,
|
protected ModelPart MakeRotatedPart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH,
|
||||||
@ -72,52 +73,50 @@ namespace ClassicalSharp.Model {
|
|||||||
XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, y1, y2, z2, z1, x1, _64x64 ); // right
|
XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, y1, y2, z2, z1, x1, _64x64 ); // right
|
||||||
// rotate left and right 90 degrees
|
// rotate left and right 90 degrees
|
||||||
for( int i = index - 8; i < index; i++ ) {
|
for( int i = index - 8; i < index; i++ ) {
|
||||||
VertexPos3fTex2fCol4b vertex = vertices[i];
|
ModelVertex vertex = vertices[i];
|
||||||
float z = vertex.Z;
|
float z = vertex.Z;
|
||||||
vertex.Z = vertex.Y;
|
vertex.Z = vertex.Y;
|
||||||
vertex.Y = z;
|
vertex.Y = z;
|
||||||
vertices[i] = vertex;
|
vertices[i] = vertex;
|
||||||
}
|
}
|
||||||
return new ModelPart( index - 6 * 4, 6 * 4 );
|
return new ModelPart( index - 6 * 4, 6 * 4 );
|
||||||
}
|
|
||||||
|
|
||||||
protected static TextureRectangle SkinTexCoords( int x, int y, int width, int height, float skinWidth, float skinHeight ) {
|
|
||||||
return new TextureRectangle( x / skinWidth, y / skinHeight, width / skinWidth, height / skinHeight );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void XPlane( int texX, int texY, int texWidth, int texHeight,
|
protected void XPlane( int texX, int texY, int texWidth, int texHeight,
|
||||||
float z1, float z2, float y1, float y2, float x, bool _64x64 ) {
|
float z1, float z2, float y1, float y2, float x, bool _64x64 ) {
|
||||||
TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 );
|
vertices[index++] = new ModelVertex( x, y1, z1, texX, texY + texHeight );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z1, rec.U1, rec.V2, FastColour.White );
|
vertices[index++] = new ModelVertex( x, y2, z1, texX, texY );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z1, rec.U1, rec.V1, FastColour.White );
|
vertices[index++] = new ModelVertex( x, y2, z2, texX + texWidth, texY );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z2, rec.U2, rec.V1, FastColour.White );
|
vertices[index++] = new ModelVertex( x, y1, z2, texX + texWidth, texY + texHeight );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z2, rec.U2, rec.V2, FastColour.White );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void YPlane( int texX, int texY, int texWidth, int texHeight,
|
protected void YPlane( int texX, int texY, int texWidth, int texHeight,
|
||||||
float x1, float x2, float z1, float z2, float y, bool _64x64 ) {
|
float x1, float x2, float z1, float z2, float y, bool _64x64 ) {
|
||||||
TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 );
|
vertices[index++] = new ModelVertex( x1, y, z1, texX, texY );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z1, rec.U1, rec.V1, FastColour.White );
|
vertices[index++] = new ModelVertex( x2, y, z1, texX + texWidth, texY );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z1, rec.U2, rec.V1, FastColour.White );
|
vertices[index++] = new ModelVertex( x2, y, z2, texX + texWidth, texY + texHeight );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z2, rec.U2, rec.V2, FastColour.White );
|
vertices[index++] = new ModelVertex( x1, y, z2, texX, texY + texHeight );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z2, rec.U1, rec.V2, FastColour.White );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ZPlane( int texX, int texY, int texWidth, int texHeight,
|
protected void ZPlane( int texX, int texY, int texWidth, int texHeight,
|
||||||
float x1, float x2, float y1, float y2, float z, bool _64x64 ) {
|
float x1, float x2, float y1, float y2, float z, bool _64x64 ) {
|
||||||
TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 );
|
vertices[index++] = new ModelVertex( x1, y1, z, texX, texY + texHeight );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y1, z, rec.U1, rec.V2, FastColour.White );
|
vertices[index++] = new ModelVertex( x2, y1, z, texX + texWidth, texY + texHeight );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y1, z, rec.U2, rec.V2, FastColour.White );
|
vertices[index++] = new ModelVertex( x2, y2, z, texX + texWidth, texY );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x2, y2, z, rec.U2, rec.V1, FastColour.White );
|
vertices[index++] = new ModelVertex( x1, y2, z, texX, texY );
|
||||||
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y2, z, rec.U1, rec.V1, FastColour.White );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected bool _64x64 = false;
|
||||||
protected void DrawPart( ModelPart part ) {
|
protected void DrawPart( ModelPart part ) {
|
||||||
|
float vScale = _64x64 ? 64f : 32f;
|
||||||
for( int i = 0; i < part.Count; i++ ) {
|
for( int i = 0; i < part.Count; i++ ) {
|
||||||
VertexPos3fTex2fCol4b vertex = vertices[part.Offset + i];
|
ModelVertex model = vertices[part.Offset + i];
|
||||||
Vector3 newPos = Utils.RotateY( vertex.X, vertex.Y, vertex.Z, cosA, sinA ) + pos;
|
Vector3 newPos = Utils.RotateY( model.X, model.Y, model.Z, cosA, sinA ) + pos;
|
||||||
|
|
||||||
|
VertexPos3fTex2fCol4b vertex = default( VertexPos3fTex2fCol4b );
|
||||||
vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z;
|
vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z;
|
||||||
vertex.R = col.R; vertex.G = col.G; vertex.B = col.B;
|
vertex.R = col.R; vertex.G = col.G; vertex.B = col.B; vertex.A = 255;
|
||||||
|
vertex.U = model.U / 64f; vertex.V = model.V / vScale;
|
||||||
cache.vertices[index++] = vertex;
|
cache.vertices[index++] = vertex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,19 +125,33 @@ namespace ClassicalSharp.Model {
|
|||||||
float cosX = (float)Math.Cos( -angleX ), sinX = (float)Math.Sin( -angleX );
|
float cosX = (float)Math.Cos( -angleX ), sinX = (float)Math.Sin( -angleX );
|
||||||
float cosY = (float)Math.Cos( -angleY ), sinY = (float)Math.Sin( -angleY );
|
float cosY = (float)Math.Cos( -angleY ), sinY = (float)Math.Sin( -angleY );
|
||||||
float cosZ = (float)Math.Cos( -angleZ ), sinZ = (float)Math.Sin( -angleZ );
|
float cosZ = (float)Math.Cos( -angleZ ), sinZ = (float)Math.Sin( -angleZ );
|
||||||
|
float vScale = _64x64 ? 64f : 32f;
|
||||||
|
|
||||||
for( int i = 0; i < part.Count; i++ ) {
|
for( int i = 0; i < part.Count; i++ ) {
|
||||||
VertexPos3fTex2fCol4b vertex = vertices[part.Offset + i];
|
ModelVertex model = vertices[part.Offset + i];
|
||||||
Vector3 loc = new Vector3( vertex.X - x, vertex.Y - y, vertex.Z - z );
|
Vector3 loc = new Vector3( model.X - x, model.Y - y, model.Z - z );
|
||||||
loc = Utils.RotateZ( loc.X, loc.Y, loc.Z, cosZ, sinZ );
|
loc = Utils.RotateZ( loc.X, loc.Y, loc.Z, cosZ, sinZ );
|
||||||
loc = Utils.RotateY( loc.X, loc.Y, loc.Z, cosY, sinY );
|
loc = Utils.RotateY( loc.X, loc.Y, loc.Z, cosY, sinY );
|
||||||
loc = Utils.RotateX( loc.X, loc.Y, loc.Z, cosX, sinX );
|
loc = Utils.RotateX( loc.X, loc.Y, loc.Z, cosX, sinX );
|
||||||
|
|
||||||
|
VertexPos3fTex2fCol4b vertex = default( VertexPos3fTex2fCol4b );
|
||||||
Vector3 newPos = Utils.RotateY( loc.X + x, loc.Y + y, loc.Z + z, cosA, sinA ) + pos;
|
Vector3 newPos = Utils.RotateY( loc.X + x, loc.Y + y, loc.Z + z, cosA, sinA ) + pos;
|
||||||
vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z;
|
vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z;
|
||||||
vertex.R = col.R; vertex.G = col.G; vertex.B = col.B;
|
vertex.R = col.R; vertex.G = col.G; vertex.B = col.B; vertex.A = 255;
|
||||||
|
vertex.U = model.U / 64f; vertex.V = model.V / vScale;
|
||||||
cache.vertices[index++] = vertex;
|
cache.vertices[index++] = vertex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||||
|
protected struct ModelVertex {
|
||||||
|
public float X, Y, Z;
|
||||||
|
public ushort U, V;
|
||||||
|
|
||||||
|
public ModelVertex( float x, float y, float z, int u, int v ) {
|
||||||
|
X = x; Y = y; Z = z;
|
||||||
|
U = (ushort)u; V = (ushort)v;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ namespace ClassicalSharp.Model {
|
|||||||
public class PigModel : IModel {
|
public class PigModel : IModel {
|
||||||
|
|
||||||
public PigModel( Game window ) : base( window ) {
|
public PigModel( Game window ) : base( window ) {
|
||||||
vertices = new VertexPos3fTex2fCol4b[partVertices * 6];
|
vertices = new ModelVertex[partVertices * 6];
|
||||||
Head = MakeHead();
|
Head = MakeHead();
|
||||||
Torso = MakeTorso();
|
Torso = MakeTorso();
|
||||||
LeftLegFront = MakeLeg( -5/16f, -1/16f, -7/16f, -3/16f );
|
LeftLegFront = MakeLeg( -5/16f, -1/16f, -7/16f, -3/16f );
|
||||||
|
@ -7,35 +7,26 @@ namespace ClassicalSharp.Model {
|
|||||||
|
|
||||||
public class PlayerModel : IModel {
|
public class PlayerModel : IModel {
|
||||||
|
|
||||||
ModelSet Set64x32, Set64x64, Set64x64Slim;
|
ModelSet Set, SetSlim;
|
||||||
public PlayerModel( Game window ) : base( window ) {
|
public PlayerModel( Game window ) : base( window ) {
|
||||||
vertices = new VertexPos3fTex2fCol4b[partVertices * ( 7 * 2 + 2 )];
|
vertices = new ModelVertex[partVertices * ( 7 + 2 )];
|
||||||
Set64x32 = new ModelSet();
|
Set = new ModelSet();
|
||||||
Set64x32.Head = MakeHead( false );
|
Set.Head = MakeHead( false );
|
||||||
Set64x32.Torso = MakeTorso( false );
|
Set.Torso = MakeTorso( false );
|
||||||
Set64x32.LeftLeg = MakeLeftLeg( 0, 16, 4/16f, 0f, false );
|
Set.LeftLeg = MakeLeftLeg( 0, 16, 4/16f, 0f, false );
|
||||||
Set64x32.RightLeg = MakeRightLeg( 0, 16, 0, 4/16f, false );
|
Set.RightLeg = MakeRightLeg( 0, 16, 0, 4/16f, false );
|
||||||
Set64x32.LeftArm = MakeLeftArm( 40, 16, 8/16f, 4/16f, 4, false );
|
Set.LeftArm = MakeLeftArm( 40, 16, 8/16f, 4/16f, 4, false );
|
||||||
Set64x32.RightArm = MakeRightArm( 40, 16, 4/16f, 8/16f, 4, false );
|
Set.RightArm = MakeRightArm( 40, 16, 4/16f, 8/16f, 4, false );
|
||||||
Set64x32.Hat = MakeHat( false );
|
Set.Hat = MakeHat( false );
|
||||||
|
|
||||||
Set64x64 = new ModelSet();
|
SetSlim = new ModelSet();
|
||||||
Set64x64.Head = MakeHead( true );
|
SetSlim.Head = Set.Head;
|
||||||
Set64x64.Torso = MakeTorso( true );
|
SetSlim.Torso = Set.Torso;
|
||||||
Set64x64.LeftLeg = MakeLeftLeg( 16, 48, 0, 4/16f, true );
|
SetSlim.LeftLeg = Set.LeftLeg;
|
||||||
Set64x64.RightLeg = MakeRightLeg( 0, 16, 0, 4/16f, true );
|
SetSlim.RightLeg = Set.RightLeg;
|
||||||
Set64x64.LeftArm = MakeLeftArm( 32, 48, 4/16f, 8/16f, 4, true );
|
SetSlim.LeftArm = MakeLeftArm( 32, 48, 4/16f, 7/16f, 3, true );
|
||||||
Set64x64.RightArm = MakeRightArm( 40, 16, 4/16f, 8/16f, 4, true );
|
SetSlim.RightArm = MakeRightArm( 40, 16, 4/16f, 7/16f, 3, true );
|
||||||
Set64x64.Hat = MakeHat( true );
|
SetSlim.Hat = Set.Hat;
|
||||||
|
|
||||||
Set64x64Slim = new ModelSet();
|
|
||||||
Set64x64Slim.Head = Set64x64.Head;
|
|
||||||
Set64x64Slim.Torso = Set64x64.Torso;
|
|
||||||
Set64x64Slim.LeftLeg = Set64x64.LeftLeg;
|
|
||||||
Set64x64Slim.RightLeg = Set64x64.RightLeg;
|
|
||||||
Set64x64Slim.LeftArm = MakeLeftArm( 32, 48, 4/16f, 7/16f, 3, true );
|
|
||||||
Set64x64Slim.RightArm = MakeRightArm( 40, 16, 4/16f, 7/16f, 3, true );
|
|
||||||
Set64x64Slim.Hat = Set64x64.Hat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelPart MakeLeftArm( int x, int y, float x1, float x2, int width, bool _64x64 ) {
|
ModelPart MakeLeftArm( int x, int y, float x1, float x2, int width, bool _64x64 ) {
|
||||||
@ -89,9 +80,8 @@ namespace ClassicalSharp.Model {
|
|||||||
graphics.BindTexture( texId );
|
graphics.BindTexture( texId );
|
||||||
|
|
||||||
SkinType skinType = p.SkinType;
|
SkinType skinType = p.SkinType;
|
||||||
model = Set64x32;
|
_64x64 = skinType != SkinType.Type64x32;
|
||||||
if( skinType == SkinType.Type64x64 ) model = Set64x64;
|
model = skinType == SkinType.Type64x64Slim ? SetSlim : Set;
|
||||||
else if( skinType == SkinType.Type64x64Slim ) model = Set64x64Slim;
|
|
||||||
|
|
||||||
DrawRotate( 0, 24/16f, 0, -p.PitchRadians, 0, 0, model.Head );
|
DrawRotate( 0, 24/16f, 0, -p.PitchRadians, 0, 0, model.Head );
|
||||||
DrawPart( model.Torso );
|
DrawPart( model.Torso );
|
||||||
|
@ -10,7 +10,7 @@ namespace ClassicalSharp.Model {
|
|||||||
public bool Fur = true;
|
public bool Fur = true;
|
||||||
|
|
||||||
public SheepModel( Game window ) : base( window ) {
|
public SheepModel( Game window ) : base( window ) {
|
||||||
vertices = new VertexPos3fTex2fCol4b[partVertices * 6 * ( Fur ? 2 : 1 )];
|
vertices = new ModelVertex[partVertices * 6 * ( Fur ? 2 : 1 )];
|
||||||
Head = MakeHead();
|
Head = MakeHead();
|
||||||
Torso = MakeTorso();
|
Torso = MakeTorso();
|
||||||
LeftLegFront = MakeLeg( -5/16f, -1/16f, -7/16f, -3/16f );
|
LeftLegFront = MakeLeg( -5/16f, -1/16f, -7/16f, -3/16f );
|
||||||
|
@ -6,7 +6,7 @@ namespace ClassicalSharp.Model {
|
|||||||
public class SkeletonModel : IModel {
|
public class SkeletonModel : IModel {
|
||||||
|
|
||||||
public SkeletonModel( Game window ) : base( window ) {
|
public SkeletonModel( Game window ) : base( window ) {
|
||||||
vertices = new VertexPos3fTex2fCol4b[partVertices * 6];
|
vertices = new ModelVertex[partVertices * 6];
|
||||||
Head = MakeHead();
|
Head = MakeHead();
|
||||||
Torso = MakeTorso();
|
Torso = MakeTorso();
|
||||||
LeftLeg = MakeLeftLeg( 3/16f, 1/16f );
|
LeftLeg = MakeLeftLeg( 3/16f, 1/16f );
|
||||||
|
@ -6,7 +6,7 @@ namespace ClassicalSharp.Model {
|
|||||||
public class SpiderModel : IModel {
|
public class SpiderModel : IModel {
|
||||||
|
|
||||||
public SpiderModel( Game window ) : base( window ) {
|
public SpiderModel( Game window ) : base( window ) {
|
||||||
vertices = new VertexPos3fTex2fCol4b[partVertices * 5];
|
vertices = new ModelVertex[partVertices * 5];
|
||||||
Head = MakeHead();
|
Head = MakeHead();
|
||||||
Link = MakeLink();
|
Link = MakeLink();
|
||||||
End = MakeEnd();
|
End = MakeEnd();
|
||||||
|
@ -7,7 +7,7 @@ namespace ClassicalSharp.Model {
|
|||||||
public class ZombieModel : IModel {
|
public class ZombieModel : IModel {
|
||||||
|
|
||||||
public ZombieModel( Game window ) : base( window ) {
|
public ZombieModel( Game window ) : base( window ) {
|
||||||
vertices = new VertexPos3fTex2fCol4b[partVertices * 6];
|
vertices = new ModelVertex[partVertices * 6];
|
||||||
Head = MakeHead();
|
Head = MakeHead();
|
||||||
Torso = MakeTorso();
|
Torso = MakeTorso();
|
||||||
LeftLeg = MakeLeftLeg( 4/16f, 0f );
|
LeftLeg = MakeLeftLeg( 4/16f, 0f );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user