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

Commit

Permalink
support control overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
jxpxxzj committed Oct 9, 2015
1 parent 2b6b2c0 commit 306bc20
Show file tree
Hide file tree
Showing 22 changed files with 416 additions and 271 deletions.
12 changes: 6 additions & 6 deletions WarshipGirl/Controls/MapPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace WarshipGirl.Controls
{
class MapPanel : Control
{
public Sprite MapSprite { get; set; }
public Control MapSprite { get; set; }

public Map Map { get; private set; }
Label SeaTitle;
Expand Down Expand Up @@ -86,7 +86,7 @@ public override void Initialize()
Top = 50,
};
float scale = (float)1.0 * 85 / 298;
MapSprite = new Sprite()
MapSprite = new Control()
{
Texture=Sprite.CreateTextureFromFile(Map.PreviewImagePath),
Width = (int)(530 * scale),
Expand All @@ -96,10 +96,10 @@ public override void Initialize()
Color = Color.White,
};

ChildSprites.Add(SeaTitle);
ChildSprites.Add(CreatorInfo);
ChildSprites.Add(MapTitle);
ChildSprites.Add(MapSprite);
Controls.Add(SeaTitle);
Controls.Add(CreatorInfo);
Controls.Add(MapTitle);
Controls.Add(MapSprite);
base.Initialize();
SeaTitle.Text = Map.MapName;
CreatorInfo.Text = Map.Creator;
Expand Down
8 changes: 4 additions & 4 deletions WarshipGirl/Controls/ResourceLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ResourceLabel : Control
public int Value { get; set; }
public ResourceType Type { get; set; }

Sprite TypeSprite;
Control TypeSprite;
Label LabelText;
public bool isBeginning { get; set; }
public override void Initialize()
Expand All @@ -38,7 +38,7 @@ public override void Initialize()
this.Width = 134;
this.Height = 34;
this.Color = Color.White;
TypeSprite = new Sprite()
TypeSprite = new Control()
{
Texture=restexture,
Color=Color.White,
Expand All @@ -59,8 +59,8 @@ public override void Initialize()
};
Value = 61616;
LabelText.Text = Value.ToString();
ChildSprites.Add(TypeSprite);
ChildSprites.Add(LabelText);
Controls.Add(TypeSprite);
Controls.Add(LabelText);
base.Initialize();
}
public override void Draw(GameTime gameTime)
Expand Down
9 changes: 5 additions & 4 deletions WarshipGirl/Game1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ public override void Initialize()
{
Texture = Sprite.CreateTextureFromFile(@"Content\factbg.png"),
};

this.KeyDown += Game1_KeyDown;
select = new MapSelect();
FpsCounter.KeyDown += counter_KeyDown;
Scenes.Add("Harbor", harbor);
Scenes.Add("Factory", factory);
Scenes.Add("Select", select);
Expand All @@ -80,7 +79,8 @@ public override void Initialize()
Scenes.Navigate("Harbor");

}
void counter_KeyDown(object sender, KeyEventArgs e)

private void Game1_KeyDown(object sender, KeyEventArgs e)
{
if (e.State.IsKeyDown(Keys.F1))
{
Expand All @@ -98,10 +98,11 @@ void counter_KeyDown(object sender, KeyEventArgs e)
else
ShowMessage("Fps counter are now hidden.", new TimeSpan(0, 0, 1));
}

}

public override void Update(GameTime gameTime)
{

if (_msgwatch.ElapsedMilliseconds > _msgTime.TotalMilliseconds)
{
_globalmsg = "";
Expand Down
18 changes: 9 additions & 9 deletions WarshipGirl/Scene/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ public override void Initialize()
Type = ResourceType.Aluminium
};

ChildSprites.Add(oilres);
ChildSprites.Add(bulres);
ChildSprites.Add(irores);
ChildSprites.Add(alures);
ChildSprites.Add(building);
ChildSprites.Add(disassembly);
ChildSprites.Add(developing);
ChildSprites.Add(disintegrate);
ChildSprites.Add(toharbor);
Controls.Add(oilres);
Controls.Add(bulres);
Controls.Add(irores);
Controls.Add(alures);
Controls.Add(building);
Controls.Add(disassembly);
Controls.Add(developing);
Controls.Add(disintegrate);
Controls.Add(toharbor);

this.Show += Factory_Show;
this.Leave += Factory_Leave;
Expand Down
34 changes: 17 additions & 17 deletions WarshipGirl/Scene/Harbor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ partial class Harbor:BaseScene
Button collection;
Button settings;

Sprite hude;
Sprite expbar;
Control hude;
Control expbar;

Label level;

Expand Down Expand Up @@ -64,15 +64,15 @@ public override void Initialize()
Height = 40,
Margin = Origins.BottomLeft
};
hude = new Sprite()
hude = new Control()
{
Left =-100,
Margin = Origins.CenterLeft,
Width = 800,
Height = 800,
Texture = TextureManager.LoadShipImage(8009,TextureManager.ShipSize.Large)
};
expbar = new Sprite()
expbar = new Control()
{
Margin=Origins.TopLeft,
Width=222,
Expand Down Expand Up @@ -167,19 +167,19 @@ public override void Initialize()
// LoopMode = LoopMode.Forever,
// EasingFunction = new Power()
//};
ChildSprites.Add(hude);
ChildSprites.Add(collection);
ChildSprites.Add(settings);
ChildSprites.Add(poss);
ChildSprites.Add(dock);
ChildSprites.Add(fact);
ChildSprites.Add(trans);
ChildSprites.Add(expbar);
ChildSprites.Add(level);
ChildSprites.Add(oilres);
ChildSprites.Add(bulres);
ChildSprites.Add(irores);
ChildSprites.Add(alures);
Controls.Add(hude);
Controls.Add(collection);
Controls.Add(settings);
Controls.Add(poss);
Controls.Add(dock);
Controls.Add(fact);
Controls.Add(trans);
Controls.Add(expbar);
Controls.Add(level);
Controls.Add(oilres);
Controls.Add(bulres);
Controls.Add(irores);
Controls.Add(alures);

this.Show += Harbor_Show;
this.Leave += Harbor_Leave;
Expand Down
16 changes: 8 additions & 8 deletions WarshipGirl/Scene/MapSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,21 @@ public override void Initialize()
menu_osu = Sprite.CreateTextureFromFile(@"Content\010c0951.png");
top = Sprite.CreateTextureFromFile(@"Content\songselect-top.png");

ChildSprites.Add(spm);
ChildSprites.Add(b);
ChildSprites.Add(breturn);
ChildSprites.Add(combob);
ChildSprites.Add(groupcb);
ChildSprites.Add(sortcb);
ChildSprites.Add(tb);
Controls.Add(spm);
Controls.Add(b);
Controls.Add(breturn);
Controls.Add(tb);
Controls.Add(combob);
Controls.Add(groupcb);
Controls.Add(sortcb);


base.Initialize();

CreateMap();
p_Click((object)maps[0], null);

spm.ChildSprites.AddRange(maps.ToArray());
spm.Controls.AddRange(maps.ToArray());

spm.ScrollSpeed = 150;
b.Text = "开始颓废";
Expand Down
6 changes: 5 additions & 1 deletion jxGameFramework/Components/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ public Game Game
return Graphics.Instance.Game;
}
}
public bool Initialized { get; protected set; }

public event EventHandler<EventArgs> EnabledChanged;
public event EventHandler<EventArgs> UpdateOrderChanged;

public virtual void Dispose() { }
public virtual void Initialize() { }
public virtual void Initialize()
{
Initialized = true;
}
public virtual void Update(GameTime gameTime) { }
protected virtual void OnEnabledChanged(object sender,EventArgs e)
{
Expand Down
35 changes: 0 additions & 35 deletions jxGameFramework/Components/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public enum Origins
/// </summary>
public class Sprite : DrawableComponent
{
public Sprite()
{
ChildSprites = new SpriteCollection(this);
}
public Sprite Parent { get; set; }
public int Left { get; set; }
public int Right { get; set; }
Expand All @@ -55,8 +51,6 @@ public Sprite()
public int Height { get; set; }
public Color Color { get; set; } = Color.White;
public List<Animation> AnimList = new List<Animation>();
//TODO: suppport component
public SpriteCollection ChildSprites { get; set; }

Texture2D _texture;
Color[] _texturepixel;
Expand Down Expand Up @@ -237,22 +231,6 @@ internal Rectangle SourceRect
return new Rectangle(x, y, width, height);
}
}
public static Sprite Empty
{
get
{
var s = new Sprite()
{
Top = 0,
Left = 0,
Width = 1,
Height = 1,
Color = Color.White,
Margin = Origins.TopLeft,
};
return s;
}
}

/// <summary>
/// 从文件创建Texture
Expand Down Expand Up @@ -313,7 +291,6 @@ public override void Draw(GameTime gameTime)
{
SpriteBatch.DrawArea(Texture, new Vector2(DestX,DestY), SourceRect, new Vector2(Width, Height), Color, Rotation, Origin, SpriteEffect, LayerDepth);
}
ChildSprites.Draw(gameTime);
#if DEBUG
//
//Graphics.Instance.SpriteBatch.DrawRectangle(DestRect, Color.Black);
Expand All @@ -323,20 +300,8 @@ public override void Draw(GameTime gameTime)
#endif
}
}
public override void Initialize()
{
ChildSprites.Initialize();
}
public override void Dispose()
{
ChildSprites.Dispose();
}
public override void Update(GameTime gameTime)
{
if (Visible)
{
ChildSprites.Update(gameTime);
}
int i = 0;
while (i < AnimList.Count)
{
Expand Down
Loading

0 comments on commit 306bc20

Please sign in to comment.