AASK.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using Microsoft.Xna.Framework;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// Opens a field message window and lets player choose a single line. AASK saves the chosen line index (first option is always 0) into a temp variable which you can retrieve with PSHI_L 0.
  6. /// </summary>
  7. /// <see cref="http://wiki.ffrtt.ru/index.php?title=FF8/Field/Script/Opcodes/06F_AASK"/>
  8. public sealed class AASK : JsmInstruction
  9. {
  10. #region Fields
  11. /// <summary>
  12. /// Line of default option
  13. /// </summary>
  14. private readonly IJsmExpression _beginLine;
  15. /// <summary>
  16. /// Line of cancel option
  17. /// </summary>
  18. private readonly IJsmExpression _cancelLine;
  19. /// <summary>
  20. /// Message Channel
  21. /// </summary>
  22. private readonly IJsmExpression _channel;
  23. /// <summary>
  24. /// Line of first option
  25. /// </summary>
  26. private readonly IJsmExpression _firstLine;
  27. /// <summary>
  28. /// Line of last option
  29. /// </summary>
  30. private readonly IJsmExpression _lastLine;
  31. /// <summary>
  32. /// Field message ID
  33. /// </summary>
  34. private readonly IJsmExpression _messageId;
  35. /// <summary>
  36. /// position of window
  37. /// </summary>
  38. private readonly Point _pos;
  39. #endregion Fields
  40. #region Constructors
  41. public AASK(IJsmExpression channel, IJsmExpression messageId, IJsmExpression firstLine, IJsmExpression lastLine, IJsmExpression beginLine, IJsmExpression cancelLine, int posX, int posY)
  42. {
  43. _channel = channel;
  44. _messageId = messageId;
  45. _firstLine = firstLine;
  46. _lastLine = lastLine;
  47. _beginLine = beginLine;
  48. _cancelLine = cancelLine;
  49. (_pos.X, _pos.Y) = (posX, posY);
  50. }
  51. public AASK(int parameter, IStack<IJsmExpression> stack)
  52. : this(
  53. posY: ((Jsm.Expression.PSHN_L)stack.Pop()).Int32(),
  54. posX: ((Jsm.Expression.PSHN_L)stack.Pop()).Int32(),
  55. cancelLine: stack.Pop(),
  56. beginLine: stack.Pop(),
  57. lastLine: stack.Pop(),
  58. firstLine: stack.Pop(),
  59. messageId: stack.Pop(),
  60. channel: stack.Pop())
  61. {
  62. }
  63. #endregion Constructors
  64. #region Methods
  65. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  66. {
  67. if (_messageId is IConstExpression message)
  68. FormatHelper.FormatAnswers(sw, formatterContext.GetMessage(message.Int32()), _firstLine, _lastLine, _beginLine, _cancelLine);
  69. sw.Format(formatterContext, services)
  70. .Await()
  71. .StaticType(nameof(IMessageService))
  72. .Method(nameof(IMessageService.ShowDialog))
  73. .Argument("channel", _channel)
  74. .Argument("messageId", _messageId)
  75. .Argument("firstLine", _firstLine)
  76. .Argument("lastLine", _lastLine)
  77. .Argument("beginLine", _beginLine)
  78. .Argument("cancelLine", _cancelLine)
  79. .Argument("posX", _pos.X)
  80. .Argument("posY", _pos.Y)
  81. .Comment(nameof(AASK));
  82. }
  83. public override IAwaitable TestExecute(IServices services) => ServiceId.Message[services].ShowQuestion(
  84. _channel.Int32(services),
  85. _messageId.Int32(services),
  86. _firstLine.Int32(services),
  87. _lastLine.Int32(services),
  88. _beginLine.Int32(services),
  89. _cancelLine.Int32(services),
  90. _pos.X,//do we need to use the services code for these? they don't do it in AMES
  91. _pos.Y);
  92. public override string ToString() => $"{nameof(AASK)}({nameof(_channel)}: {_channel}, {nameof(_messageId)}: {_messageId}, {nameof(_firstLine)}: {_firstLine}, {nameof(_lastLine)}: {_lastLine}, {nameof(_beginLine)}: {_beginLine}, {nameof(_cancelLine)}: {_cancelLine}, {nameof(_pos)}: {_pos})";
  93. #endregion Methods
  94. }
  95. }