/// <summary> /// Handles the image event represented by the specified <see cref="Instruction"/>. /// </summary> /// <param name="instruction"> /// The <see cref="ImageInstruction"/> that represents the image event to handle.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="instruction"/> is a null reference.</exception> /// <remarks><para> /// <b>ShowImageEvent</b> shows the image event represented by the specified <paramref /// name="instruction"/> on the default <see cref="Session.MapView"/>. /// </para><para> /// If the <see cref="ImageInstruction.Delay"/> of the specified <paramref /// name="instruction"/> is zero or negative, <b>ShowImageEvent</b> substitutes a default /// delay of 250 msec. The specified or default delay is then adjusted by the current <see /// cref="ReplayOptions.Speed"/> setting, as follows: /// </para><list type="table"><listheader> /// <term>Speed</term><description>Delay</description> /// </listheader><item> /// <term><see cref="ReplaySpeed.Slow"/></term><description>Doubled</description> /// </item><item> /// <term><see cref="ReplaySpeed.Medium"/></term><description>Unchanged</description> /// </item><item> /// <term><see cref="ReplaySpeed.Fast"/></term><description>Halved</description> /// </item><item> /// <term><see cref="ReplaySpeed.Turbo"/></term><description>Skipped</description> /// </item></list><para> /// <b>ShowImageEvent</b> returns immediately without showing the specified <paramref /// name="instruction"/> if the current <see cref="ReplayOptions.Speed"/> setting is <see /// cref="ReplaySpeed.Turbo"/>.</para></remarks> public static void ShowImageEvent(ImageInstruction instruction) { if (instruction == null) { ThrowHelper.ThrowArgumentNullException("instruction"); } // skip image events at Turbo speed ReplaySpeed speed = ApplicationOptions.Instance.Game.Replay.Speed; if (speed == ReplaySpeed.Turbo) { return; } // get event parameters EntityClass entityClass = instruction.EntityClass; PointI[] sites = instruction.Sites.ToArray(); int delay = instruction.Delay; // default delay is 250 msec if (delay <= 0) { delay = 250; } // adjust delay for current replay speed switch (speed) { case ReplaySpeed.Slow: delay *= 2; break; case ReplaySpeed.Fast: delay /= 2; break; } // move or show image on default map view bool move = (instruction is MoveImageInstruction); Session.MapView.ShowImage(entityClass, sites, move, delay, AbortSignal); }
/// <summary> /// Handles the command event represented by the specified <see cref="Instruction"/>. /// </summary> /// <param name="instruction"> /// The <see cref="Instruction"/> that represents the command event to handle.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="instruction"/> is a null reference.</exception> /// <exception cref="PropertyValueException"> /// The current session <see cref="Session.State"/> is <see cref="SessionState.Invalid"/>. /// </exception> /// <remarks><para> /// <b>ShowCommandEvent</b> takes the following actions, depending on the exact type of the /// specified <paramref name="instruction"/>: /// </para><list type="table"><listheader> /// <term>Type</term><description>Action</description> /// </listheader><item> /// <term><see cref="SelectEntityInstruction"/></term> /// <description>Call <see cref="SelectEntityEvent"/>.</description> /// </item><item> /// <term><see cref="ImageInstruction"/></term> /// <description>Call <see cref="ShowImageEvent"/>.</description> /// </item><item> /// <term><see cref="MessageInstruction"/></term> /// <description>Call <see cref="ShowMessageEvent"/>.</description> /// </item><item> /// <term>Other</term><description>Do nothing.</description> /// </item></list></remarks> public static void ShowCommandEvent(Instruction instruction) { if (instruction == null) { ThrowHelper.ThrowArgumentNullException("instruction"); } if (Session.State == SessionState.Invalid) { ThrowHelper.ThrowPropertyValueExceptionWithFormat("Session.State", Session.State, Tektosyne.Strings.PropertyIsValue, SessionState.Invalid); } MessageInstruction message = instruction as MessageInstruction; if (message != null) { AsyncAction.Invoke(() => ShowMessageEvent(message, MainWindow.Instance.EventMessage, true)); return; } SelectEntityInstruction selectEntity = instruction as SelectEntityInstruction; if (selectEntity != null) { SelectEntityEvent(selectEntity); return; } ImageInstruction image = instruction as ImageInstruction; if (image != null) { ShowImageEvent(image); return; } }