MES.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. namespace OpenVIII.Fields.Scripts.Instructions
  2. {
  3. /// <summary>
  4. /// Popup a message window.
  5. /// This is usually used on lines to popup text when the player crosses a certain point on a screen.
  6. /// The size of the message window can be set with WINSIZE.
  7. /// </summary>
  8. internal sealed class MES : JsmInstruction
  9. {
  10. #region Fields
  11. private readonly int _channel;
  12. private readonly int _messageId;
  13. #endregion Fields
  14. #region Constructors
  15. public MES(int channel, int messageId)
  16. {
  17. _channel = channel;
  18. _messageId = messageId;
  19. }
  20. public MES(int parameter, IStack<IJsmExpression> stack)
  21. : this(
  22. messageId: ((Jsm.Expression.PSHN_L)stack.Pop()).Int32(),
  23. channel: ((Jsm.Expression.PSHN_L)stack.Pop()).Int32())
  24. {
  25. }
  26. #endregion Constructors
  27. #region Methods
  28. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  29. {
  30. FormatHelper.FormatMonologue(sw, formatterContext.GetMessage(_messageId));
  31. sw.Format(formatterContext, services)
  32. .StaticType(nameof(IMessageService))
  33. .Method(nameof(IMessageService.Show))
  34. .Argument("channel", _channel)
  35. .Argument("messageId", _messageId)
  36. .Comment(nameof(MES));
  37. }
  38. public override IAwaitable TestExecute(IServices services)
  39. {
  40. ServiceId.Message[services].Show(_channel, _messageId);
  41. return DummyAwaitable.Instance;
  42. }
  43. public override string ToString() => $"{nameof(MES)}({nameof(_channel)}: {_channel}, {nameof(_messageId)}: {_messageId})";
  44. #endregion Methods
  45. }
  46. }