// Startup public override void Startup(ContentManager content) { _UI.Startup(_G.Game, _G.GameInput); // load textures int bundleIndex = _UI.Texture.CreateBundle(); _UI.Texture.Add(bundleIndex, "Textures\\UI_Box", "box"); // load fonts _UI.Font.Add("Fonts\\", "SegoeUI"); // setup common font styles UI.FontStyle fontStyle = new UI.FontStyle("SegoeUI"); fontStyle.AddRenderPass(new UI.FontStyleRenderPass()); _UI.Store_FontStyle.Add("Default", fontStyle); UI.FontStyle fontStyleDS = new UI.FontStyle("SegoeUI"); UI.FontStyleRenderPass renderPassDS = new UI.FontStyleRenderPass(); renderPassDS.ColorOverride = Color.Black; renderPassDS.AlphaMult = 0.5f; renderPassDS.Offset = new Vector3(0.05f, -0.05f, 0.0f); renderPassDS.OffsetProportional = true; fontStyleDS.AddRenderPass(renderPassDS); fontStyleDS.AddRenderPass(new UI.FontStyleRenderPass()); _UI.Store_FontStyle.Add("Default3dDS", fontStyleDS); // setup font icons _UI.Store_FontIcon.Add("A", new UI.FontIcon(_UI.Texture.Get("null"), 0.0f, 0.0f, 1.0f, 1.0f)); _UI.Store_FontIcon.Add("B", new UI.FontIcon(_UI.Texture.Get("null"), 0.0f, 0.0f, 1.0f, 1.0f)); // add initial screens _UI.Screen.AddScreen(new UI.Screen_Background()); _UI.Screen.AddScreen(new UI.Screen_Start()); }
// Startup public override void Startup( ContentManager content ) { _UI.Startup( _G.Game, _G.GameInput ); // load textures int bundleIndex = _UI.Texture.CreateBundle(); _UI.Texture.Add( bundleIndex, "Textures\\UI_Box", "box" ); // load fonts _UI.Font.Add( "Fonts\\", "SegoeUI" ); // setup common font styles UI.FontStyle fontStyle = new UI.FontStyle( "SegoeUI" ); fontStyle.AddRenderPass( new UI.FontStyleRenderPass() ); _UI.Store_FontStyle.Add( "Default", fontStyle ); UI.FontStyle fontStyleDS = new UI.FontStyle( "SegoeUI" ); UI.FontStyleRenderPass renderPassDS = new UI.FontStyleRenderPass(); renderPassDS.ColorOverride = Color.Black; renderPassDS.AlphaMult = 0.5f; renderPassDS.Offset = new Vector3( 0.05f, -0.05f, 0.0f ); renderPassDS.OffsetProportional = true; fontStyleDS.AddRenderPass( renderPassDS ); fontStyleDS.AddRenderPass( new UI.FontStyleRenderPass() ); _UI.Store_FontStyle.Add( "Default3dDS", fontStyleDS ); // setup font icons _UI.Store_FontIcon.Add( "A", new UI.FontIcon( _UI.Texture.Get( "null" ), 0.0f, 0.0f, 1.0f, 1.0f ) ); _UI.Store_FontIcon.Add( "B", new UI.FontIcon( _UI.Texture.Get( "null" ), 0.0f, 0.0f, 1.0f, 1.0f ) ); // add initial screens _UI.Screen.AddScreen( new UI.Screen_Background() ); _UI.Screen.AddScreen( new UI.Screen_Start() ); }
// Copy public FontStyle Copy() { FontStyle o = new FontStyle(); o.Font = Font; o.RenderState = RenderState; o.TrackingPercentage = TrackingPercentage; o.HeightPercentage = HeightPercentage; for ( int i = 0; i < RenderPasses.Count; ++i ) o.AddRenderPass( RenderPasses[ i ].Copy() ); return o; }
// Startup public override void Startup( ContentManager content ) { _UI.Startup( _G.Game, _G.GameInput ); // load textures int bundleIndex = _UI.Texture.CreateBundle(); _UI.Texture.Add( bundleIndex, "Textures\\UI_Box", "box" ); for (int i = 0; i < 4; i++) { _UI.Texture.AddDynamic(bundleIndex, "bag", "Textures\\tex" + i, "BagButtonTex" + i); _UI.Texture.AddDynamic(bundleIndex, "yifu", "Textures\\tex" + i, "ClothButtonTex"+i); _UI.Texture.Add(bundleIndex,"Textures\\tex"+i,"ClothTexture"+i); } //Add Dynamic Texture for Bag Model //_UI.Texture.AddDynamic(bundleIndex, "yifu", "Textures\\tex0", "BagDisplayUnit"); // load fonts _UI.Font.Add( "Fonts\\", "SegoeUI" ); // setup common font styles UI.FontStyle fontStyle = new UI.FontStyle( "SegoeUI" ); fontStyle.AddRenderPass( new UI.FontStyleRenderPass() ); _UI.Store_FontStyle.Add( "Default", fontStyle ); UI.FontStyle fontStyleDS = new UI.FontStyle( "SegoeUI" ); UI.FontStyleRenderPass renderPassDS = new UI.FontStyleRenderPass(); renderPassDS.ColorOverride = Color.Black; renderPassDS.AlphaMult = 0.5f; renderPassDS.Offset = new Vector3( 0.05f, -0.05f, 0.0f ); renderPassDS.OffsetProportional = true; fontStyleDS.AddRenderPass( renderPassDS ); fontStyleDS.AddRenderPass( new UI.FontStyleRenderPass() ); _UI.Store_FontStyle.Add( "Default3dDS", fontStyleDS ); // setup font icons _UI.Store_FontIcon.Add( "A", new UI.FontIcon( _UI.Texture.Get( "null" ), 0.0f, 0.0f, 1.0f, 1.0f ) ); _UI.Store_FontIcon.Add( "B", new UI.FontIcon( _UI.Texture.Get( "null" ), 0.0f, 0.0f, 1.0f, 1.0f ) ); // add initial screens //_UI.Screen.AddScreen( new UI.Screen_Background() ); //_UI.Screen.AddScreen( new UI.Screen_LevelSelect() ); this.SideBars = new UI.SideBar(); _UI.Screen.AddScreen(SideBars); }
// WidgetFPS public WidgetFPS() : base() { RenderPass = 0; Layer = _UI.Sprite.TopLayer; Position = new Vector3( _UI.SXR, _UI.SYT, 0.0f ); Size = new Vector3( 30.0f ); AddTexture( "null", 0.0f, 0.0f, 1.0f, 1.0f ); FontStyle = _UI.Store_FontStyle.Get( "Default" ); StringUI = new StringUI( 8 ); FrameRate = 0; FrameCounter = 0; ElapsedTime = 0.0f; }
public TimelineEffect_FontStyleTrackingPercentage( FontStyle fontStyle, float from, float to, E_LerpType lerpType ) : base(from, to, lerpType) { FontStyle = fontStyle; }
// OnInit protected override void OnInit() { RenderState.BlendState = E_BlendState.NonPremultiplied; // handled in the FontStyle RenderSizeX = Size.X; RenderSizeY = Size.Y; if ( FontStyleName != null ) FontStyle = _UI.Store_FontStyle.Get( FontStyleName ); for ( int i = 0; i < FontEffects.Count; ++i ) FontEffects[ i ].Bind( this ); if ( Cache && ( SpriteListCache == null ) ) SpriteListCache = new FontSpriteList(); }
private unsafe Vector2 Process( ref StringProxy text, FontStyle fontStyle, float height, float wrapSizeX, E_FontProcessType processType ) { if ( text.Length == 0 ) return new Vector2(); SpriteList.Reset(); SpriteList.RenderPass = RenderPass; SpriteList.Layer = Layer; FontData fontData = fontStyle.Font.FontData; float startX = Position.X; float x = startX; float y = Position.Y; float scale = height / fontData.FontHeight; float charHeight = fontData.LineHeight * scale; float lineHeight = charHeight * fontStyle.HeightPercentage; float multY = _UI.Sprite.IsRenderPass3D( RenderPass ) ? -1.0f : 1.0f; int numLines = 1; fixed ( char* pString = text.String ) fixed ( FontSprite* pSpriteStart = &SpriteList.Sprites[ 0 ] ) fixed ( FontDataChar* pCharDataStart = &fontData.Characters[ 0 ] ) { char* s = ( pString != null ) ? pString : text.StringUI; for ( int i = 0; i < text.Length; ++i ) { char c = s[ i ]; if ( c == '\n' ) { ++numLines; y += ( lineHeight * multY ); x = startX; ( pSpriteStart + SpriteList.RenderEnd - 1 )->BreakType = E_LetterBreakType.Line; continue; } int characterIndex = fontData.GetCharacterIndex( c ); FontDataChar* pCharData = ( pCharDataStart + characterIndex ); if ( c == ' ' ) { // mark as potential wrap point unless we've already wrapped here FontSprite* pSpriteEnd = ( pSpriteStart + SpriteList.RenderEnd - 1 ); if ( ( SpriteList.RenderEnd != 0 ) && ( pSpriteEnd->BreakType != E_LetterBreakType.Line ) ) pSpriteEnd->BreakType = E_LetterBreakType.Wrap; // advance x += ( pCharData->AdvanceX * scale ); } else { // check for icons if ( ( ( i + 5 ) <= text.Length ) && ( c == '[' ) && ( s[ i + 1 ] == '[' ) ) { int j = i + 2; StringUI.Clear(); while ( ( j < text.Length ) && ( s[ j ] != ']' ) ) StringUI.Add( s[ j++ ] ); if ( ( ( j + 1 ) < text.Length ) && ( s[ j + 1 ] == ']' ) ) { // valid format int fontIconIndex = _UI.Store_FontIcon.Get( StringUI ); if ( fontIconIndex != -1 ) { // add to list FontIcon fontIcon = _UI.Store_FontIcon.Get( fontIconIndex ); FontSprite* pSprite = ( pSpriteStart + SpriteList.RenderEnd++ ); pSprite->Character = (char)0xffff; pSprite->Position.X = x; pSprite->Position.Y = y - ( ( ( charHeight * fontIcon.Scale ) - charHeight ) * 0.5f ) * multY; pSprite->Position.Z = Position.Z; float heightScaled = charHeight * fontIcon.Scale; pSprite->Size.X = heightScaled * fontIcon.AspectRatio; pSprite->Size.Y = heightScaled; fixed ( SpriteColor* pColor = &fontIcon.Color ) { pSprite->Colors.CopyA( ref Colors ); pSprite->Colors.MultA( pColor->A ); pSprite->Colors.R( pColor->R ); pSprite->Colors.G( pColor->G ); pSprite->Colors.B( pColor->B ); if ( Colors.PreMultipliedAlpha ) pSprite->Colors.ToPremultiplied(); } // set base texture pSprite->Texture.TextureIndex = fontIcon.Texture.TextureIndex; pSprite->Texture.PUV = fontIcon.Texture.PUV; pSprite->Texture.SUV = fontIcon.Texture.SUV; pSprite->BreakType = E_LetterBreakType.None; pSprite->IconIndex = fontIconIndex; // advance x += pSprite->Size.X; // advance string past the icon characters i += ( 4 + StringUI.Length - 1 ); } } } else { // add to list FontSprite* pSprite = ( pSpriteStart + SpriteList.RenderEnd++ ); pSprite->Character = c; pSprite->Position.X = x + ( pCharData->OffsetX * scale ); pSprite->Position.Y = y + ( pCharData->OffsetY * scale ) * multY; pSprite->Position.Z = Position.Z; pSprite->Size.X = pCharData->Width * scale; pSprite->Size.Y = pCharData->Height * scale; pSprite->Colors = Colors; // set base texture pSprite->Texture.TextureIndex = fontStyle.Font.TextureIndex; pSprite->Texture.PUV.X = (float)pCharData->X / fontData.TextureWidth; pSprite->Texture.PUV.Y = (float)pCharData->Y / fontData.TextureHeight; pSprite->Texture.SUV.X = (float)pCharData->Width / fontData.TextureWidth; pSprite->Texture.SUV.Y = (float)pCharData->Height / fontData.TextureHeight; // second (optional) texture is set through the FontStyle when rendering pSprite->BreakType = E_LetterBreakType.None; pSprite->IconIndex = -1; // advance x += ( pCharData->AdvanceX * scale ); // kerning if ( i != ( text.Length - 1 ) ) x += ( fontData.GetKerningAmount( c, s[ i + 1 ] ) * scale ); } } // check for wrapping if ( ( c != ' ' ) && ( wrapSizeX != 0.0f ) && ( ( x - startX ) > wrapSizeX ) ) { int iWrap = SpriteList.RenderEnd - 1; FontSprite* pSpriteWrap = ( pSpriteStart + iWrap ); // search backwards until we find a place to wrap while ( ( iWrap >= 0 ) && ( pSpriteWrap->BreakType != E_LetterBreakType.Wrap ) && ( pSpriteWrap->BreakType != E_LetterBreakType.Line ) ) pSpriteWrap = ( pSpriteStart + --iWrap ); bool wrapOnLine = false; if ( iWrap != -1 ) { if ( pSpriteWrap->BreakType == E_LetterBreakType.Line ) wrapOnLine = true; // word is longer than the wrap size else pSpriteWrap->BreakType = E_LetterBreakType.Line; } else { if ( SpriteList.RenderEnd > 1 ) wrapOnLine = true; // long first word with leading spaces, wtf } ++pSpriteWrap; float diffX = pSpriteWrap->Position.X - startX; float offsetX = x - pSpriteWrap->Position.X; // shift the characters after the break point for ( int j = ( iWrap + 1 ); j < SpriteList.RenderEnd; ++j ) { pSpriteWrap->Position.X -= diffX; if ( !wrapOnLine ) pSpriteWrap->Position.Y += ( lineHeight * multY ); ++pSpriteWrap; } ++numLines; if ( !wrapOnLine ) y += ( lineHeight * multY ); x = startX + offsetX; } // tracking x += ( height * fontStyle.TrackingPercentage ); } ( pSpriteStart + SpriteList.RenderEnd - 1 )->BreakType = E_LetterBreakType.Line; float totalHeight = ( ( numLines - 1 ) * lineHeight ) + charHeight; if ( processType == E_FontProcessType.Draw ) { // align if ( ( Align != E_Align.TopLeft ) && ( Align != E_Align.None ) ) { Vector2 offset = _UI.Sprite.GetVertexOffsetAligned( 0, Align ); if ( ( Align == E_Align.MiddleLeft ) || ( Align == E_Align.BottomLeft ) ) { // only just need to offset y FontSprite* pSpriteToOffset = pSpriteStart; for ( int i = 0; i < SpriteList.RenderEnd; ++i, ++pSpriteToOffset ) pSpriteToOffset->Position.Y -= ( totalHeight * offset.Y ) * multY; } else { // need to offset both x and y int iLineStart = 0; FontSprite* pSpriteLineEnd = pSpriteStart; for ( int i = 0; i < SpriteList.RenderEnd; ++i, ++pSpriteLineEnd ) { if ( pSpriteLineEnd->BreakType != E_LetterBreakType.Line ) continue; float lineWidth = ( pSpriteLineEnd->Position.X + pSpriteLineEnd->Size.X ) - startX; // offset every sprite on this line FontSprite* pSpriteToOffset = ( pSpriteStart + iLineStart ); for ( int j = iLineStart; j <= i; ++j, ++pSpriteToOffset ) { pSpriteToOffset->Position.X -= ( lineWidth * offset.X ); pSpriteToOffset->Position.Y -= ( totalHeight * offset.Y ) * multY; } iLineStart = i + 1; } } } // pre-render if ( FontEffects != null ) { for ( int i = 0; i < FontEffects.Count; ++i ) FontEffects[ i ].Process( SpriteList ); FontEffects = null; } // actual render fontStyle.Render( SpriteList, height ); } return new Vector2( ( numLines == 1 ) ? ( x - startX ) : wrapSizeX, totalHeight ); } }
// Process private Vector2 Process( ref StringProxy text, FontStyle fontStyle, int renderPass, int layer, ref Vector3 pos, float height, E_Align align, ref SpriteColors colors, float wrapSizeX ) { RenderPass = renderPass; Layer = layer; Position = pos; Align = align; Colors = colors; if ( ( fontStyle.RenderState.BlendState == E_BlendState.AlphaBlend ) && !Colors.PreMultipliedAlpha ) Colors.ToPremultiplied(); return Process( ref text, fontStyle, height, wrapSizeX, E_FontProcessType.Draw ); }
public Vector2 StringSize( StringUI text, FontStyle fontStyle, float height, float wrapSizeX ) { StringProxy stringProxy = new StringProxy( text ); return Process( ref stringProxy, fontStyle, height, wrapSizeX, E_FontProcessType.Size ); }
public Vector2 Draw( StringUI text, FontStyle fontStyle, int renderPass, int layer, ref Vector3 pos, float height, E_Align align, ref SpriteColors colors, float wrapSizeX ) { StringProxy stringProxy = new StringProxy( text ); return Process( ref stringProxy, fontStyle, renderPass, layer, ref pos, height, align, ref colors, wrapSizeX ); }
// Startup public override void Startup( ContentManager content ) { _UI.Startup( _G.Game, _G.GameInput ); // load textures int bundleIndex = _UI.Texture.CreateBundle(); _UI.Texture.Add( bundleIndex, "Textures\\UI_Box", "box" ); _UI.Texture.Add( bundleIndex, "Textures\\UI_Shine", "shine" ); _UI.Texture.Add( bundleIndex, "Textures\\UI_Buttons", "buttons" ); _UI.Texture.Add( bundleIndex, "Textures\\UI_FontMult", "font_mult" ); _UI.Texture.Add( bundleIndex, "Textures\\UI_DebugMenu", "debug_menu" ); _UI.Texture.Add( bundleIndex, "Textures\\tick", "tick" ); _UI.Texture.Add( bundleIndex, "Textures\\World_1", "world_1" ); _UI.Texture.Add( bundleIndex, "Textures\\World_2", "world_2" ); _UI.Texture.Add( bundleIndex, "Textures\\World_3", "world_3" ); _UI.Texture.Add( bundleIndex, "Textures\\World_4", "world_4" ); _UI.Texture.Add( bundleIndex, "Textures\\MM_NewGame", "mm_newgame" ); _UI.Texture.Add( bundleIndex, "Textures\\MM_LevelSelect", "mm_levelselect" ); _UI.Texture.Add( bundleIndex, "Textures\\MM_Options", "mm_options" ); _UI.Texture.Add( bundleIndex, "Textures\\MM_Quit", "mm_quit" ); _UI.Texture.Add( bundleIndex, "Textures\\CompanyLogo", "company_logo" ); _UI.Texture.Add( bundleIndex, "Textures\\GameLogo", "game_logo" ); // load fonts _UI.Font.Add( "Fonts\\", "Verdana" ); _UI.Font.Add( "Fonts\\", "Impact" ); // everyone has initial control _UI.PrimaryPad = -1; // setup colors _UI.Store_Color.Add( "Blue", 0xff0000ff ); _UI.Store_Color.Add( "Red", 0xffff0000 ); // setup timelines UI.Timeline timelineText = new UI.Timeline( "selected", false, 0.0f, 0.25f, UI.E_TimerType.Stop, UI.E_RestType.Start ); timelineText.AddEffect( new UI.TimelineEffect_ColorLerp( Color.Orange, UI.E_LerpType.SmoothStep ) ); _UI.Store_Timeline.Add( "text_selected_color", timelineText ); UI.Timeline timeline_StartAlpha = new UI.Timeline( "start", false, 0.0f, 0.25f, UI.E_TimerType.Stop, UI.E_RestType.Start ); timeline_StartAlpha.AddEffect( new UI.TimelineEffect_Alpha( -1.0f, 0.0f, UI.E_LerpType.SmoothStep ) ); _UI.Store_Timeline.Add( "text_start_alpha", timeline_StartAlpha ); // setup textures UI.SpriteTexture texture = new UI.SpriteTexture( "buttons", 0.0f, 0.0f, 0.5f, 1.0f ); _UI.Store_Texture.Add( "buttons_half", texture ); // setup font styles UI.FontStyle fontStyle = new UI.FontStyle( "Impact" ); fontStyle.AddRenderPass( new UI.FontStyleRenderPass() ); _UI.Store_FontStyle.Add( "Default", fontStyle ); UI.FontStyle fontStyleDS = new UI.FontStyle( "Impact" ); UI.FontStyleRenderPass renderPassDS = new UI.FontStyleRenderPass(); renderPassDS.ColorOverride = Color.Black; renderPassDS.AlphaMult = 0.5f; renderPassDS.Offset = new Vector3( 0.05f, -0.05f, 0.0f ); renderPassDS.OffsetProportional = true; fontStyleDS.AddRenderPass( renderPassDS ); fontStyleDS.AddRenderPass( new UI.FontStyleRenderPass() ); _UI.Store_FontStyle.Add( "DefaultDS", fontStyleDS ); // setup font effects UI.FontEffect fontEffect = new UI.FontEffect_Scale( 0.0625f, 0.25f, 2.0f, 1.0f, 2.0f, 1.0f, 2.0f, UI.E_LerpType.Sin ); _UI.Store_FontEffect.Add( "menu_item_scale", fontEffect ); // setup font icons _UI.Store_FontIcon.Add( "A", new UI.FontIcon( _UI.Texture.Get( "buttons" ), 0.0f, 0.0f, ( 64.0f / 820.0f ), 1.0f ) ); _UI.Store_FontIcon.Add( "B", new UI.FontIcon( _UI.Texture.Get( "buttons" ), ( 63.0f / 820.0f ), 0.0f, ( 64.0f / 820.0f ), 1.0f ) ); _UI.Store_FontIcon.Add( "X", new UI.FontIcon( _UI.Texture.Get( "buttons" ), ( 126.0f / 820.0f ), 0.0f, ( 64.0f / 820.0f ), 1.0f ) ); _UI.Store_FontIcon.Add( "Y", new UI.FontIcon( _UI.Texture.Get( "buttons" ), ( 189.0f / 820.0f ), 0.0f, ( 64.0f / 820.0f ), 1.0f ) ); // setup widgets UI.WidgetText text = new UI.WidgetText(); text.ColorBase = Color.White; text.Align = UI.E_Align.TopCentre; text.Position = new Vector3( 0.0f, 18.0f, 0.0f ); text.Size = new Vector3( 0.0f, 3.0f, 0.0f ); text.Alpha = 0.5f; text.FontStyleName = "Default"; text.AddTimeline( "text_start_alpha" ); text.RenderPass = 1; _UI.Store_Widget.Add( "font_effect_text", text ); // set initial screen PlayState = E_PlayState.TestUI; if ( PlayState == E_PlayState.GameWorld ) { _G.Game.DoLayerUpdate( E_Layer.LevelEditor, false ); _G.Game.DoLayerRender( E_Layer.LevelEditor, false ); _UI.Screen.AddScreen( new UI.HUD() ); } else if ( PlayState == E_PlayState.LevelEditor ) { _G.Game.DoLayerUpdate( E_Layer.GameWorld, false ); _G.Game.DoLayerRender( E_Layer.GameWorld, false ); _UI.Screen.AddScreen( new UI.LevelEditorHUD() ); } else if ( PlayState == E_PlayState.TestUI ) { _G.Game.DoLayerUpdate( E_Layer.GameWorld, false ); _G.Game.DoLayerRender( E_Layer.GameWorld, false ); _G.Game.DoLayerUpdate( E_Layer.LevelEditor, false ); _G.Game.DoLayerRender( E_Layer.LevelEditor, false ); _UI.Screen.AddScreen( new UI.Test() ); } }