Skip to content
This repository was archived by the owner on Mar 1, 2018. It is now read-only.

Commit

Permalink
Add Controls, New FpsCounter, Text Drawing Inprove
Browse files Browse the repository at this point in the history
  • Loading branch information
jxpxxzj committed Aug 17, 2015
1 parent 525fb1a commit f98e71a
Show file tree
Hide file tree
Showing 15 changed files with 1,472 additions and 348 deletions.
486 changes: 243 additions & 243 deletions LICENSE

Large diffs are not rendered by default.

47 changes: 0 additions & 47 deletions WarshipGirl/Controls/FpsCounter.cs

This file was deleted.

4 changes: 2 additions & 2 deletions WarshipGirl/Controls/ResourceLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public override void LoadContent()
Color = Color.White,
GraphicsDevice = this.GraphicsDevice,
SpriteBatch = this.SpriteBatch,
X = this.RenderX + this.Width / 3,
Y = this.RenderY + this.Height / 2 - 2,
X = this.Width / 3,
Y = this.Height / 2 - 2,
OriginType = Origins.CenterLeft,
};
Value = 61616;
Expand Down
15 changes: 8 additions & 7 deletions WarshipGirl/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System;
using WarshipGirl.Controls;
using jxGameFramework.Controls;

namespace WarshipGirl
{
Expand All @@ -27,7 +28,7 @@ public Game1()
{
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 1024;
graphics.PreferredBackBufferHeight = 768;
graphics.PreferredBackBufferHeight = 600;
this.IsMouseVisible = true;

//注释这两行以关闭无限fps
Expand Down Expand Up @@ -60,8 +61,8 @@ protected override void LoadContent()
SpriteBatch = spriteBatch,
GraphicsDevice = this.GraphicsDevice,
Texture = Texture2D.FromStream(this.GraphicsDevice, harborbg),
Width = 1024,
Height = 768
Width = GraphicsDevice.Viewport.Width,
Height = GraphicsDevice.Viewport.Height
};
harbor.LoadContent();

Expand All @@ -74,8 +75,8 @@ protected override void LoadContent()
SpriteBatch = spriteBatch,
GraphicsDevice = this.GraphicsDevice,
Texture = Texture2D.FromStream(this.GraphicsDevice, factbg),
Width = 1024,
Height = 768
Width = GraphicsDevice.Viewport.Width,
Height = GraphicsDevice.Viewport.Height
};
factory.LoadContent();

Expand All @@ -84,8 +85,8 @@ protected override void LoadContent()
GraphicsDevice = this.GraphicsDevice,
SpriteBatch = spriteBatch,
Color = Color.White,
X = 1024,
Y = 768,
X = GraphicsDevice.Viewport.Width,
Y = GraphicsDevice.Viewport.Height,
OriginType = Origins.BottomRight
};
fpscounter.LoadContent();
Expand Down
8 changes: 4 additions & 4 deletions WarshipGirl/WarshipGirl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Controls\Button.cs" />
<Compile Include="Controls\FpsCounter.cs" />
<Compile Include="Controls\ResourceLabel.cs" />
<Compile Include="Controls\Ship64Img.cs" />
<Compile Include="Data\BaseEquipment.cs" />
Expand Down Expand Up @@ -85,6 +84,10 @@
<Reference Include="Broken_64">
<HintPath>..\WarshipGirl_Data\Broken_64.dll</HintPath>
</Reference>
<Reference Include="MonoGame.Framework, Version=3.4.0.456, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll</HintPath>
</Reference>
<Reference Include="Normal_1024">
<HintPath>..\WarshipGirl_Data\Normal_1024.dll</HintPath>
</Reference>
Expand All @@ -97,9 +100,6 @@
<Reference Include="OpenTK">
<HintPath>C:\Program Files (x86)\MonoGame\v3.0\Assemblies\WindowsGL\OpenTK.dll</HintPath>
</Reference>
<Reference Include="MonoGame.Framework">
<HintPath>C:\Program Files (x86)\MonoGame\v3.0\Assemblies\WindowsGL\MonoGame.Framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite">
Expand Down
27 changes: 26 additions & 1 deletion jxGameFramework/Components/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ public class Sprite : Component
public int Top { get; set; }
public int Bottom { get; set; }

public float Rotation { get; set; }
public Vector2 Origin { get; set; }

Vector2 _scale = new Vector2(1f, 1f);
public Vector2 Scale
{
get
{
return _scale;
}
set
{
_scale=value;
}
}
public SpriteEffects SpriteEffect { get; set; }

public Origins Margin { get; set; }

//public int X { get; set; }
Expand Down Expand Up @@ -84,6 +101,14 @@ public void AddComponent(Component comp)
catch (Exception)
{

}
try
{
((Text)comp).Parent = this;
}
catch (Exception)
{

}
CompList.Add(comp);
}
Expand Down Expand Up @@ -212,7 +237,7 @@ private static void PreMultiplyAlphas(Texture2D ret)
public override void Draw(GameTime gameTime)
{
if(Texture != null)
SpriteBatch.Draw(Texture, new Rectangle(RenderX,RenderY , Width, Height),Color);
SpriteBatch.Draw(Texture, new Rectangle(RenderX,RenderY , (int)(Width*Scale.X), (int)(Height*Scale.Y)),null,Color,Rotation,Origin,SpriteEffect,0);
foreach (Component comp in CompList)
comp.Draw(gameTime);
}
Expand Down
41 changes: 31 additions & 10 deletions jxGameFramework/Components/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,60 @@ public string text
}
}
}
public Sprite Parent { get; set; }
public int Width { get; protected set; }
public int Height { get; protected set; }
public Color Color { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int RenderX { get; set; }
public int RenderY { get; set; }
private int ParentRenderX
{
get
{
if (Parent != null)
return Parent.RenderX;
else
return 0;
}
}
private int ParentRenderY
{
get
{
if (Parent != null)
return Parent.RenderY;
else
return 0;
}
}
public Origins OriginType { get; set; }
public Vector2 CustomOriginPoint { get; set; }
public Font Font { get; set; }
public override void Draw(GameTime gameTime)
{
switch (OriginType)
{
case Origins.TopLeft: RenderX = X; RenderY = Y;
case Origins.TopLeft: RenderX = ParentRenderX + X; RenderY = ParentRenderY + Y;
break;
case Origins.TopCenter: RenderX = X - Width - 2; RenderY = Y;
case Origins.TopCenter: RenderX = ParentRenderX + X - Width / 2; RenderY = ParentRenderY + Y;
break;
case Origins.TopRight: RenderX = X - Width; RenderY = Y;
case Origins.TopRight: RenderX = ParentRenderX + X - Width; RenderY = ParentRenderY + Y;
break;
case Origins.CenterLeft: RenderX = X; RenderY = Y - Height / 2;
case Origins.CenterLeft: RenderX = ParentRenderX + X; RenderY = ParentRenderY + Y - Height / 2;
break;
case Origins.Center: RenderX = X - Width / 2; RenderY = Y - Height / 2;
case Origins.Center: RenderX = ParentRenderX + X - Width / 2; RenderY = ParentRenderY + Y - Height / 2;
break;
case Origins.CenterRight: RenderX = X - Width; RenderY = Y - Height / 2;
case Origins.CenterRight: RenderX = ParentRenderX + X - Width; RenderY = ParentRenderY + Y - Height / 2;
break;
case Origins.BottomLeft: RenderX = X; RenderY = Y - Height;
case Origins.BottomLeft: RenderX = ParentRenderX + X; RenderY = ParentRenderY + Y - Height;
break;
case Origins.BottomCenter: RenderX = X - Width / 2; RenderY = Y - Height;
case Origins.BottomCenter: RenderX = ParentRenderX + X - Width / 2; RenderY = ParentRenderY + Y - Height;
break;
case Origins.BottomRight: RenderX = X - Width; RenderY = Y - Height;
case Origins.BottomRight: RenderX = ParentRenderX + X - Width; RenderY = ParentRenderY + Y - Height;
break;
case Origins.Custom: RenderX = X - Width * (int)CustomOriginPoint.X; RenderY = Y - Height * (int)CustomOriginPoint.Y;
case Origins.Custom: RenderX = ParentRenderX + X - Width * (int)CustomOriginPoint.X; RenderY = ParentRenderY + Y - Height * (int)CustomOriginPoint.Y;
break;
default:
break;
Expand Down
103 changes: 103 additions & 0 deletions jxGameFramework/Controls/CheckBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using jxGameFramework.Controls;
using jxGameFramework.Components;
using jxGameFramework.Data;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace jxGameFramework.Controls
{
class CheckBox : Control
{
Sprite _checkcircle;
Text _title;
Font _fnt;

Texture2D full;
Texture2D empty;

public string Text
{
get
{
return _title.text;
}
set
{
_title.text = value;
}
}
bool _checked = false;
public bool Checked
{
get
{
return _checked;
}
set
{
_checked = value;
if(_checked)
{
_checkcircle.Texture = full;
}
else
{
_checkcircle.Texture = empty;
}
}
}

public override void LoadContent()
{
GDIpInterop gdip = new GDIpInterop(18, 18, GraphicsDevice);
gdip.g.FillEllipse(System.Drawing.Brushes.White, 0, 0, 16, 16);
full = gdip.SaveTexture();
gdip.g.Clear(System.Drawing.Color.Transparent);
System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.White, 2);
gdip.g.DrawEllipse(p, 0, 0, 16, 16);
empty = gdip.SaveTexture();

_fnt = new Font(GraphicsDevice, "msyh.ttc", 15)
{
EnableShadow = true,
ShadowColor = Color.Black,
ShadowYOffset = 1,
};
_checkcircle = new Sprite()
{
Texture = empty,
Margin=Origins.CenterLeft,
Left = 2,
Color=Color.DeepPink,
};
_checkcircle.Width = _checkcircle.Texture.Width;
_checkcircle.Height = _checkcircle.Texture.Height;

_title = new Text()
{
Font = _fnt,
Color = Color.White,
OriginType = Origins.CenterLeft,
X = 22,
Y = 7,
};
AddComponent(_title);
AddComponent(_checkcircle);
this.Width = full.Width;
this.Height = full.Height;
this.Click += CheckBox_Click;
base.LoadContent();
}

void CheckBox_Click(object sender, EventArgs e)
{
this.Checked = !this.Checked;
}

}
}
Loading

0 comments on commit f98e71a

Please sign in to comment.