123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using GameEditorPlugin.Win32.Runtime;
- using CommonAI.ZoneClient;
- using System.Drawing;
- using System.Windows.Forms;
- using CommonLang;
- using CommonAIClient.Client;
- using CommonAI.Zone.ZoneEditor;
- using CommonLang.Protocol;
- using System.Drawing.Drawing2D;
- using CommonAI.Zone;
- using CommonAI.RTS;
- using CommonLang.Vector;
- using CommonAI.Zone.Helper;
- using CommonAI.Zone.Instance;
- using CommonLang.Property;
- using CommonAI.RTS.Manhattan;
- using CommonAI.ZoneClient.Agent;
- using CommonFroms.Drawing;
- namespace GameEditorPlugin.Win32.BattleClient
- {
- public class DisplayLayerWorld : DisplayManhattanTerrain
- {
- //--------------------------------------------------------------------
- [Desc("显示警戒范围", "show")]
- public bool ShowGuardRange = false;
- [Desc("显示攻击范围", "show")]
- public bool ShowAttackRange = false;
- [Desc("显示受击范围", "show")]
- public bool ShowDamageRange = false;
- [Desc("显示名字", "show")]
- public bool ShowName = false;
- [Desc("显示Flag名字", "show")]
- public bool ShowFlagName = false;
- [Desc("显示HP", "show")]
- public bool ShowHP = false;
- [Desc("显示详细日志", "show")]
- public bool ShowAllLog = false;
- //--------------------------------------------------------------------
- public static SolidBrush name_brush = new SolidBrush(Color.White);
- public static Font name_font = new Font(@"微软雅黑", 9f, FontStyle.Regular);
- public static Pen pen_write = new Pen(Color.White);
- public static Brush brush_hp = new SolidBrush(Color.FromArgb(0xff, 0, 0xff, 0));
- public static Brush brush_mp = new SolidBrush(Color.FromArgb(0xff, 0x80, 0x80, 0xff));
- public static Brush brush_black = new SolidBrush(Color.FromArgb(0xff, 0, 0, 0));
- public static Brush brush_attack = new SolidBrush(Color.FromArgb(0x80, 0xff, 0x00, 0x00));
- public readonly Random random = new Random();
- public float UpdateTimeScale = 1f;
- public bool Pause = false;
- private ZoneLayer layer;
- private AbstractBattle client;
- private HashMap<uint, DisplayLayerObject> objectes = new HashMap<uint, DisplayLayerObject>();
- private HashMap<string, DisplayGameFlag> flags = new HashMap<string, DisplayGameFlag>();
- private DisplayLayerObject selected_unit = null;
- private LocalClientStatus LocalStatus;
- private int mFPS = 0;
- public int UpdateIntervalMS { get; private set; }
- public DisplayLayerObject SelectedObject { get { return selected_unit; } }
- public ZoneLayer Layer { get { return layer; } }
- public AbstractBattle Client { get { return client; } }
- public int ObjectsCount { get { return this.Layer.ObjectsCount; } }
- //public int ServerObjectsCount { get { if (client is BattleLocal) { return (client as BattleLocal).Zone.AllObjectsCount; } return 0; } }
- public int FPS { get { return mFPS; } }
- public DisplayGameUnit DisplayActor
- {
- get
- {
- if (client.Actor != null)
- {
- return GetObject(client.Actor.ObjectID) as DisplayGameUnit;
- }
- return null;
- }
- }
- public int SpaceDIV
- {
- get
- {
- if (layer != null) return layer.SpaceDivSize;
- return 0;
- }
- }
- public override AstarManhattan PathFinder
- {
- get
- {
- if (layer != null) return layer.PathFinder;
- return null;
- }
- }
- public override int SpaceDivSize
- {
- get
- {
- if (layer != null) return layer.SpaceDivSize;
- return 0;
- }
- }
- public virtual void InitClient(AbstractBattle client)
- {
- this.layer = client.Layer;
- this.client = client;
- this.layer.LayerInit += OnLayerInit;
- this.layer.ObjectEnter += OnObjectEnter;
- this.layer.ObjectLeave += OnObjectLeave;
- this.layer.MessageReceived += OnMessageReceived;
- this.layer.ObjectMessageReceived += OnObjectMessageReceived;
- this.LocalStatus = new LocalClientStatus(this);
- }
- public override void Dispose()
- {
- this.client.Dispose();
- }
- public void SkipClientEvent()
- {
- LocalStatus.Skip();
- }
- //---------------------------------------------------
- private void OnLayerInit(ZoneLayer layer)
- {
- base.InitTerrain(layer.Terrain);
- foreach (DecorationData dt in layer.Data.Decorations)
- {
- ZoneEditorDecoration zed = layer.GetFlag<ZoneEditorDecoration>(dt.Name);
- DisplayGameDecoration gf = new DisplayGameDecoration(this, zed);
- flags.Add(dt.Name, gf);
- }
- setCameraScale(1, 1);
- setCamera(base.Terrain.TotalWidth / 2, base.Terrain.TotalHeight / 2);
- // if (client.Actor != null)
- // {
- // client.Actor.SendUnitGuard(true);
- // }
- }
- private void OnObjectEnter(ZoneLayer layer, ZoneObject obj)
- {
- if (obj is ZoneUnit)
- {
- DisplayGameUnit u = new DisplayGameUnit(this, obj as ZoneUnit);
- objectes.Add(obj.ObjectID, u);
- if (client.Actor != null && obj.ObjectID == client.Actor.ObjectID)
- {
- client.Actor.OnMoneyChanged += (ZoneUnit unit, int oldM, int newM) =>
- {
- showLog((newM - oldM).ToString(), unit.X, unit.Y, Color.Yellow);
- };
- client.Actor.OnHPChanged += (ZoneUnit unit, int oldM, int newM) =>
- {
- };
- client.Actor.OnMPChanged += (ZoneUnit unit, int oldM, int newM) =>
- {
- };
- }
- }
- if (obj is ZoneSpell)
- {
- DisplayGameSpell u = new DisplayGameSpell(this, obj as ZoneSpell);
- objectes.Add(obj.ObjectID, u);
- }
- if (obj is ZoneItem)
- {
- DisplayGameItem u = new DisplayGameItem(this, obj as ZoneItem);
- objectes.Add(obj.ObjectID, u);
- }
- }
- private void OnObjectLeave(ZoneLayer layer, ZoneObject obj)
- {
- objectes.RemoveByKey(obj.ObjectID);
- showLog("ObjectLeave: " + obj.Name, obj.X, obj.Y);
- }
- private void OnMessageReceived(ZoneLayer layer, IMessage msg)
- {
- LocalStatus.onEvent(msg);
- }
- private void OnObjectMessageReceived(ZoneLayer layer, IMessage msg, ZoneObject obj)
- {
- if (msg is UnitDoActionEvent)
- {
- showLog("UnitDoAction: " + obj.Name + " - " + (msg as UnitDoActionEvent).ActionName, obj.X, obj.Y);
- }
- else if (ShowAllLog)
- {
- showLog(msg.ToString(),
- obj.X + (float)(random.NextDouble() * obj.RadiusSize * 2),
- obj.Y + (float)(random.NextDouble() * obj.RadiusSize * 2));
- }
- }
- //---------------------------------------------------
- virtual protected void clientUpdate(int intervalMS)
- {
- client.BeginUpdate(intervalMS);
- client.Update();
- }
- override public void update(int intervalMS)
- {
- this.UpdateIntervalMS = intervalMS;
- this.LocalStatus.update(intervalMS);
- this.clientUpdate((int)(intervalMS * UpdateTimeScale));
- base.update(intervalMS);
- if (intervalMS > 0)
- {
- this.mFPS = (int)(1000 / intervalMS);
- }
- }
- //---------------------------------------------------
- #region Render
- protected readonly Pen pen_icon_border = new Pen(Color.Gray);
- protected readonly Brush brush_icon_body = new SolidBrush(Color.FromArgb(0xFF, 0x40, 0x40, 0x40));
- protected readonly Brush brush_icon_cd = new SolidBrush(Color.FromArgb(0x80, 0xFF, 0xFF, 0xFF));
- protected readonly Brush brush_text = new SolidBrush(Color.White);
- protected readonly Brush brush_text_error = new SolidBrush(Color.Red);
- protected readonly Brush brush_gauge = new SolidBrush(Color.FromArgb(0xA0, 0x20, 0xFF, 0x20));
- protected readonly Pen pen_path = new Pen(Color.White);
- override public void render(Graphics g)
- {
- base.render(g);
- LocalStatus.render(g);
- }
- protected override void renderObjects(Graphics g, RectangleF worldBounds)
- {
- drawObjectes(g, worldBounds, flags.Values);
- drawObjectes(g, worldBounds, objectes.Values);
- renderActorInMap(g, worldBounds);
- if (OnRenderLayer != null)
- {
- OnRenderLayer.Invoke(g, this);
- }
- }
- protected virtual void renderActorInMap(Graphics g, RectangleF worldBounds)
- {
- if (DisplayActor != null)
- {
- var actor = DisplayActor.Data as ZoneActor;
- if (actor != null)
- {
- var agent = actor.GetAgentByType<ActorMoveAgent>();
- if (agent != null && !agent.IsEnd)
- {
- pen_path.Width = 1f / getCameraScale();
- drawPath(g, new Vector2(actor.X, actor.Y), agent.WayPoints, pen_path, pen_path);
- }
- }
- }
- }
- protected override void renderScreen(Graphics g, RectangleF worldBounds)
- {
- renderUnitsHUD(g, flags.Values, worldBounds);
- renderUnitsHUD(g, objectes.Values, worldBounds);
- if (layer.Actor != null)
- {
- renderObjectHUD(g, 0, WindowH, AnchorStyles.Bottom | AnchorStyles.Left, layer.Actor);
- }
- if (SelectedObject is DisplayGameUnit)
- {
- renderObjectHUD(g, WindowW / 2, 0, AnchorStyles.Top | AnchorStyles.Left, (SelectedObject as DisplayGameUnit).Data);
- }
- renderHUD(g);
- if (OnRenderHUD != null)
- {
- OnRenderHUD.Invoke(g, this);
- }
- }
- private void renderUnitsHUD<T>(Graphics g, ICollection<T> list, RectangleF rect) where T : DisplayObject
- {
- foreach (var u in list)
- {
- if (CMath.intersectRect2(
- rect.X,
- rect.Y,
- rect.Width,
- rect.Height,
- u.X + u.LocalBounds.X,
- u.Y + u.LocalBounds.Y,
- u.LocalBounds.Width,
- u.LocalBounds.Height))
- {
- System.Drawing.Drawing2D.GraphicsState state = g.Save();
- g.TranslateTransform(
- worldToScreenX(u.X),
- worldToScreenY(u.Y));
- if (ShowHP)
- {
- u.renderHP(g);
- }
- if (ShowName)
- {
- u.renderName(g, font, name_brush);
- }
- g.Restore(state);
- }
- }
- }
- protected virtual void renderHUD(Graphics g)
- {
- float sw = WindowW / 2;
- float sy = 1;
- var rect_text = new TextRect();
- GraphicsState gs = g.Save();
- {
- {
- TimeSpan time = new TimeSpan(0, 0, 0, 0, (int)layer.ServerTimeMS);
- StringBuilder sb = new StringBuilder();
- sb.Append(" Time=" + time);
- sb.Append(" TimeScale=" + (this.UpdateTimeScale * 100) + "%");
- sb.Append(" Paused=" + (this.Pause));
- sb.Append(" LayerObjects=" + this.ObjectsCount);
- if ((client is BattleLocal))
- {
- sb.Append(" ZoneObjects=" + (client as BattleLocal).Zone.AllObjectsCount);
- }
- sy += rect_text.SetText(sb.ToString()).Draw(g, 1, sy, sw, 0);
- }
- {
- string mem = string.Format("SZ={0}/{1} SO={2}/{3} CZ={4}/{5} CO={6}/{7}",
- InstanceZone.ActiveZoneCount, InstanceZone.AllocZoneCount,
- InstanceZoneObject.ActiveObjectCount, InstanceZoneObject.AllocObjectCount,
- ZoneLayer.ActiveZoneLayerCount, ZoneLayer.AllocZoneLayerCount,
- ZoneObject.ActiveObjectCount, ZoneObject.AllocObjectCount);
- sy += rect_text.SetText(mem).Draw(g, 1, sy, sw, 0);
- }
- {
- string head = string.Format(" FPS={0} Mouse=({1} , {2})",
- this.FPS,
- screenToWorldX(base.MouseX).ToString("#0.0"),
- screenToWorldY(base.MouseY).ToString("#0.0"));
- sy += rect_text.SetText(head).Draw(g, 1, sy, sw, 0);
- }
- }
- if (client.IsNet)
- {
- StringBuilder sb = new StringBuilder();
- sb.Append(" Send=" + client.SendPackages);
- sb.Append(" Recv=" + client.RecvPackages);
- sb.Append(" Ping=" + client.CurrentPing);
- if (client.KickMessage != null)
- {
- sb.Append(" Kicked=" + client.KickMessage.message);
- }
- sy += rect_text.SetText(sb.ToString()).Draw(g, 1, sy, sw, 0);
- }
- if (client.Layer.ServerStatus != null)
- {
- var state = client.Layer.ServerStatus;
- List<string> sb = new List<string>();
- sb.Add("ServerStatus:");
- sb.Add(" PID=" + state.PID);
- sb.Add(" ActiveGameObjectCount=" + state.ActiveGameObjectCount);
- sb.Add(" ActiveInstanceZoneCount=" + state.ActiveInstanceZoneCount);
- sb.Add(" PrivateMemorySize=" + CUtils.ToBytesSizeString(state.PrivateMemorySize64));
- foreach (var line in sb)
- {
- sy += rect_text.SetText(line).Draw(g, 1, sy, sw, 0);
- }
- }
- {
- sy += rect_text.SetText(" 环境变量:").Draw(g, 1, sy, sw, 0);
- foreach (string evk in Layer.ListEnvironmentVars())
- {
- sy += rect_text.SetText(string.Format(" {0} = {1}", evk, Layer.GetEnvironmentVar(evk))).Draw(g, 1, sy, sw, 0);
- }
- if (Layer.Actor != null)
- {
- sy += rect_text.SetText(" 单位环境变量:").Draw(g, 1, sy, sw, 0);
- foreach (string evk in Layer.Actor.ListEnvironmentVars())
- {
- sy += rect_text.SetText(string.Format(" {0} = {1}", evk, Layer.Actor.GetEnvironmentVar(evk))).Draw(g, 1, sy, sw, 0);
- }
- }
- }
- g.Restore(gs);
- }
- protected virtual void renderObjectHUD(Graphics g, float start_x, float start_y, AnchorStyles anc, ZoneUnit unit)
- {
- float sy = start_y;
- var text_line = new TextLine() { anchor = anc };
- var gauge_line = new GaugeStrip() { anchor = anc };
- #region status
- {
- StringBuilder tl = new StringBuilder();
- using (var timelines = ListObjectPool<bool>.AllocAutoRelease())
- {
- unit.GetMultiTimeLineStatus(timelines);
- foreach (var e in timelines) { tl.Append((e ? 1 : 0)); }
- }
- string text = string.Format("OID={6} UUID={0} Force={12} HP={1}/{2} MP={3}/{4} SP={5} State={7} Speed={8} FCR={9} Level={10} TL[{11}]",
- unit.PlayerUUID,
- unit.HP, unit.MaxHP,
- unit.MP, unit.MaxMP,
- unit.SP,
- unit.ObjectID,
- unit.CurrentState,
- unit.MoveSpeedSEC / unit.Info.MoveSpeedSEC,
- unit.FastCastRate,
- unit.Level,
- tl,
- unit.Force);
- sy += text_line.SetText(text.ToString()).Draw(g, start_x, sy, 0, 0);
- }
- #endregion
- #region skills
- using (var skills = ListObjectPool<ZoneActor.SkillState>.AllocAutoRelease())
- {
- unit.GetSkillStatus(skills);
- if (skills.Count > 0)
- {
- var gauge_fan = new GaugeRectFan() { anchor = anc };
- float sw = 50;
- float sh = 50;
- float sx = start_x;
- float dy = 0;
- int i = 0;
- foreach (ZoneActor.SkillState ss in skills)
- {
- gauge_fan.text_brush = ss.IsActive ? brush_text : this.brush_text_error;
- dy = gauge_fan
- .SetText(ss.Data.Name, (ss.IsActive ? ToSkillShortKey(i) : null))
- .SetPercent(ss.CDPercent)
- .Draw(g, sx, sy, sw, sh);
- sx += sw;
- i++;
- }
- sy += dy;
- }
- }
- #endregion
- #region items
- if (unit is ZoneActor)
- {
- var actor = unit as ZoneActor;
- using (var items = ListObjectPool<ZoneActor.ItemSlot>.AllocAutoRelease())
- {
- actor.GetItemSlots(items);
- if (items.Count > 0)
- {
- var gauge_fan = new GaugeRectFan() { anchor = anc };
- float sw = 40;
- float sh = 40;
- float sx = start_x;
- float dy = 0;
- int i = 0;
- foreach (ZoneActor.ItemSlot item in items)
- {
- if (!item.IsEmpty)
- {
- string text1 = null;
- string text2 = null;
- float pct = 0;
- text1 = item.Data.Name;
- text2 = "x" + item.Count;
- var cd = actor.GetCoolDownItem(item.Data.ID);
- if (cd != null) pct = cd.Percent;
- dy = gauge_fan
- .SetText(text1, text2)
- .SetPercent(pct)
- .Draw(g, sx, sy, sw, sh);
- sx += sw;
- }
- i++;
- }
- sy += dy;
- }
- }
- }
- #endregion
- #region buffs
- using (var buffs = ListObjectPool<ZoneUnit.BuffState>.AllocAutoRelease())
- {
- unit.GetBuffStatus(buffs);
- if (buffs.Count > 0)
- {
- var gauge_fan = new GaugeRectFan() { anchor = anc };
- float sw = 20;
- float sh = 20;
- float sx = start_x;
- float dy = 0;
- int i = 0;
- foreach (ZoneActor.BuffState bs in buffs)
- {
- dy = gauge_fan
- .SetText(bs.Data.Name, null)
- .SetPercent(bs.CDPercent)
- .Draw(g, sx, sy, sw, sh);
- sx += sw;
- i++;
- }
- sy += dy;
- }
- }
- #endregion
- if (unit.ChantingSkill != null)
- {
- var ss = unit.ChantingSkill;
- float pct = (unit.ChantingSkillPassMS / (float)unit.ChantingSkillTotalMS);
- sy += gauge_line
- .SetText("吟唱:" + ss.Data.Name)
- .SetPercent(pct)
- .Draw(g, start_x + 4, sy, 200, 0);
- }
- if (unit.CurrentSkillAction != null)
- {
- var skill = unit.CurrentSkillAction;
- sy += gauge_line
- .SetText("引导:" + skill.SkillData.Name + "(" + skill.CurrentActionIndex + ")")
- .SetPercent(1 - skill.ExpirePercent)
- .Draw(g, start_x + 4, sy, 200, 0);
- }
- if (unit.PickEvent != null)
- {
- var pick = unit.PickEvent;
- sy += gauge_line
- .SetText("检取:" + pick.Tag.object_id)
- .SetPercent(pick.Percent)
- .Draw(g, start_x + 4, sy, 200, 0);
- }
- #region name
- {
- sy += text_line.SetText(unit.DisplayName).Draw(g, start_x, sy, 0, 0);
- }
- #endregion
- }
- #endregion
- //---------------------------------------------------
- public DisplayLayerObject GetObject(uint id)
- {
- return objectes.Get(id);
- }
- public DisplayGameFlag GetFlag(string name)
- {
- return flags.Get(name);
- }
- public DisplayGameUnit GetUnitByName(string name)
- {
- foreach (DisplayLayerObject u in objectes.Values)
- {
- if (u is DisplayGameUnit)
- {
- if (name.Equals((u as DisplayGameUnit).Name))
- {
- return u as DisplayGameUnit;
- }
- }
- }
- return null;
- }
- public DisplayLayerObject PickObject(float x, float y)
- {
- foreach (DisplayLayerObject u in objectes.Values)
- {
- if (u is DisplayGameSpell) continue;
- if (CMath.includeRectPoint2(
- u.X + u.LocalBounds.X,
- u.Y + u.LocalBounds.Y,
- u.LocalBounds.Width,
- u.LocalBounds.Height,
- x, y))
- {
- selected_unit = u;
- return selected_unit;
- }
- }
- selected_unit = null;
- return null;
- }
- public virtual string ToSkillShortKey(int index)
- {
- index++;
- if (index >= 1 && index <= 9) { return (index).ToString(); }
- if (index == 10) { return "0"; }
- if (index >= 11 && index <= 19) { return "num" + (index - 10).ToString(); }
- if (index == 20) { return "num0"; }
- return "";
- }
- public virtual int ToSkillIndex(Keys key)
- {
- if (key >= Keys.D1 && key <= Keys.D9)
- {
- int i = (key - Keys.D1);
- return i;
- }
- if (key == Keys.D0) { return 9; }
- if (key >= Keys.NumPad1 && key <= Keys.NumPad9)
- {
- int i = (key - Keys.NumPad1);
- return 10 + i;
- }
- if (key == Keys.NumPad0) { return 19; }
- return int.MaxValue;
- }
- public void ActorLaunchSkill(KeyEventArgs e, float mouseX, float mouseY)
- {
- ZoneActor actor = layer.Actor;
- if (actor != null)
- {
- List<ZoneActor.SkillState> status = actor.GetSkillStatus();
- int i = ToSkillIndex(e.KeyCode);
- if (i < status.Count)
- {
- ZoneActor.SkillState ss = status[i];
- actor.SendUnitLaunchSkill(ss.Data.ID, mouseX, mouseY);
- }
- }
- }
- public void ActorLaunchSkill(KeyEventArgs e, ZoneObject target)
- {
- ZoneActor actor = layer.Actor;
- if (actor != null)
- {
- List<ZoneActor.SkillState> status = actor.GetSkillStatus();
- int i = ToSkillIndex(e.KeyCode);
- if (i < status.Count)
- {
- ZoneActor.SkillState ss = status[i];
- actor.SendUnitLaunchSkill(ss.Data.ID, target.ObjectID);
- }
- }
- }
- public void ActorUseItem(KeyEventArgs e)
- {
- ZoneActor actor = layer.Actor;
- if (actor != null)
- {
- List<ZoneActor.ItemSlot> items = actor.GetItemSlots();
- int i = ToSkillIndex(e.KeyCode);
- if (i < items.Count)
- {
- ZoneActor.ItemSlot slot = items[i];
- actor.SendUnitUseItem(i);
- }
- }
- }
- //---------------------------------------------------
- class LocalClientStatus
- {
- public readonly DisplayLayerWorld Layer;
- private Vector2 mCameraPos = new Vector2();
- private bool mPause = false;
- private long mTimer;
- public LookAtEvent LookAt;
- public CameraMoveToEvent CameraMoveTo;
- public CameraFocusUnitEvent CameraFocus;
- public CameraZoomToEvent CameraZoomTo;
- public CameraRotateToEvent CameraRotateTo;
- public LocalClientStatus(DisplayLayerWorld layer)
- {
- this.Layer = layer;
- }
- public void Skip()
- {
- mPause = false;
- CameraMoveTo = null;
- CameraFocus = null;
- CameraZoomTo = null;
- CameraRotateTo = null;
- }
- internal void onEvent(IMessage evt)
- {
- if (evt is LookAtEvent)
- {
- LookAt = evt as LookAtEvent;
- }
- else if (evt is ChangeTimeScaleEvent)
- {
- ChangeTimeScaleEvent ctse = evt as ChangeTimeScaleEvent;
- Layer.UpdateTimeScale = ctse.TimeScalePct / 100f;
- }
- else if (evt is GamePauseEvent)
- {
- mPause = true;
- }
- else if (evt is GameResumeEvent)
- {
- mPause = false;
- }
- else if (evt is CameraResetEvent)
- {
- CameraMoveTo = null;
- CameraFocus = null;
- CameraZoomTo = null;
- CameraRotateTo = null;
- }
- else
- {
- if (evt is CameraMoveToEvent)
- CameraMoveTo = evt as CameraMoveToEvent;
- if (evt is CameraFocusUnitEvent)
- CameraFocus = evt as CameraFocusUnitEvent;
- if (evt is CameraZoomToEvent)
- CameraZoomTo = evt as CameraZoomToEvent;
- if (evt is CameraRotateToEvent)
- CameraRotateTo = evt as CameraRotateToEvent;
- }
- }
- internal void update(int intervalMS)
- {
- if (CameraMoveTo != null)
- {
- MathVector.moveTo(mCameraPos, CameraMoveTo.x, CameraMoveTo.y, MoveHelper.GetDistance(intervalMS, CameraMoveTo.MoveSpeedSec));
- Layer.setCamera(mCameraPos.X, mCameraPos.Y);
- }
- if (CameraFocus != null)
- {
- DisplayLayerObject obj = Layer.GetObject(CameraFocus.ObjectID);
- if (obj != null)
- {
- mCameraPos.SetX(obj.X);
- mCameraPos.SetY(obj.Y);
- Layer.setCamera(mCameraPos.X, mCameraPos.Y);
- }
- }
- if (mPause)
- {
- Layer.Pause = true;
- }
- mCameraPos.SetX(Layer.CameraX);
- mCameraPos.SetY(Layer.CameraY);
- mTimer += intervalMS;
- }
- internal void render(Graphics g)
- {
- if (LookAt != null)
- {
- float s = ((float)(Math.Abs(Math.Sin(mTimer / 100f) * 10))) + 1;
- float x = Layer.worldToScreenX(LookAt.x);
- float y = Layer.worldToScreenY(LookAt.y);
- g.DrawArc(DisplayLayerWorld.pen_write, x - s, y - s, s * 2, s * 2, 0, 360);
- }
- }
- }
- //---------------------------------------------------
- [Desc("渲染完HUD时触发")]
- public event OnRenderHUDHandler OnRenderHUD;
- public delegate void OnRenderHUDHandler(Graphics g, DisplayLayerWorld world);
- [Desc("渲染完场景时触发")]
- public event OnRenderLayerHandler OnRenderLayer;
- public delegate void OnRenderLayerHandler(Graphics g, DisplayLayerWorld world);
- }
- }
|