Advertisement
dsiver144

Window Choice

Mar 11th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. class Window_Message
  2. #--------------------------------------------------------------------------
  3. # * Choice Input Processing
  4. #--------------------------------------------------------------------------
  5. def input_choice
  6. $limit_time = 0
  7. @choice_window.start
  8. Fiber.yield while @choice_window.active
  9. end
  10. end
  11.  
  12. #==============================================================================
  13. # ** Window_ChoiceList
  14. #------------------------------------------------------------------------------
  15. # This window is used for the event command [Show Choices].
  16. #==============================================================================
  17.  
  18. class Window_ChoiceList < Window_Command
  19. #--------------------------------------------------------------------------
  20. # * Object Initialization
  21. #--------------------------------------------------------------------------
  22. def initialize(message_window)
  23. @message_window = message_window
  24. super(0, 0)
  25. self.openness = 0
  26. deactivate
  27. end
  28. #--------------------------------------------------------------------------
  29. # * Start Input Processing
  30. #--------------------------------------------------------------------------
  31. def start
  32. self.opacity = 0
  33. update_placement
  34. refresh
  35. select(0)
  36. open
  37. activate
  38. end
  39.  
  40. def update
  41. super
  42. if $limit_time && $limit_time < 120
  43. $limit_time += 1
  44. elsif $limit_time
  45. p "Time up"
  46. process_ok
  47. $limit_time = nil
  48. end
  49. end
  50. #--------------------------------------------------------------------------
  51. # * Update Window Position
  52. #--------------------------------------------------------------------------
  53. def update_placement
  54. self.width = [max_choice_width + 12, 96].max + padding * 2
  55. self.width = [width, Graphics.width].min
  56. self.height = fitting_height($game_message.choices.size)
  57. self.x = Graphics.width - width
  58. if @message_window.y >= Graphics.height / 2
  59. self.y = @message_window.y - height
  60. else
  61. self.y = @message_window.y + @message_window.height
  62. end
  63. @choice_sprites ||= []
  64. @choice_sprites.each do |sprite|
  65. sprite.dispose
  66. end
  67. @choice_sprites.clear
  68. choice_bitmap = Cache.system("Choice")
  69. distance = 48
  70. start_y = ((Graphics.height - (choice_bitmap.height)*$game_message.choices.size)) * 0.5 - 40
  71. des_x = (Graphics.width - choice_bitmap.width) * 0.5
  72. $game_message.choices.size.times do |i|
  73. c_sprite = Sprite.new
  74. c_sprite.x = i % 2 == 0 ? -choice_bitmap.width : Graphics.width
  75. c_sprite.start_x = x
  76. p c_sprite.x
  77. c_sprite.y = start_y + i*distance
  78. c_sprite.bitmap = choice_bitmap
  79. @choice_sprites << c_sprite
  80. end
  81. start_time = Graphics.frame_count
  82. while (current_time = Graphics.frame_count - start_time ) < 60
  83. @choice_sprites.each do |sprite|
  84. sprite.x = easeInOutQuad(current_time, sprite.start_x, des_x - sprite.start_x, 60)
  85. Fiber.yield
  86. end
  87. Graphics.update
  88. end
  89. end
  90. #-------------------------------------------------------------------------
  91. # * new method: easeInOutQuad
  92. #-------------------------------------------------------------------------
  93. def easeInOutQuad(t, b, c, d)
  94. t = t / (d/2.0)
  95. if (t < 1)
  96. return c/2*t*t + b
  97. end
  98. t -= 1
  99. return -c/2.0 * (t*(t-2) - 1) + b
  100. end
  101. #--------------------------------------------------------------------------
  102. # * Get Maximum Width of Choices
  103. #--------------------------------------------------------------------------
  104. def max_choice_width
  105. $game_message.choices.collect {|s| text_size(s).width }.max
  106. end
  107. #--------------------------------------------------------------------------
  108. # * Calculate Height of Window Contents
  109. #--------------------------------------------------------------------------
  110. def contents_height
  111. item_max * item_height
  112. end
  113. #--------------------------------------------------------------------------
  114. # * Create Command List
  115. #--------------------------------------------------------------------------
  116. def make_command_list
  117. $game_message.choices.each do |choice|
  118. add_command(choice, :choice)
  119. end
  120. end
  121. #--------------------------------------------------------------------------
  122. # * Draw Item
  123. #--------------------------------------------------------------------------
  124. def draw_item(index)
  125. rect = item_rect_for_text(index)
  126. draw_text_ex(rect.x, rect.y, command_name(index))
  127. end
  128. #--------------------------------------------------------------------------
  129. # * Get Activation State of Cancel Processing
  130. #--------------------------------------------------------------------------
  131. def cancel_enabled?
  132. $game_message.choice_cancel_type > 0
  133. end
  134. #--------------------------------------------------------------------------
  135. # * Call OK Handler
  136. #--------------------------------------------------------------------------
  137. def call_ok_handler
  138. $game_message.choice_proc.call(index)
  139. close
  140. end
  141. #--------------------------------------------------------------------------
  142. # * Call Cancel Handler
  143. #--------------------------------------------------------------------------
  144. def call_cancel_handler
  145. $game_message.choice_proc.call($game_message.choice_cancel_type - 1)
  146. close
  147. end
  148. end
  149.  
  150. class Sprite
  151. attr_accessor :start_x
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement