Advertisement
LiTTleDRAgo

[RGSS2] Icon Window Choice

Apr 21st, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.74 KB | None | 0 0
  1. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  2. # Icon Window Choice
  3. # Version 1.10
  4. # Author: LiTTleDRAgo
  5. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  6. #
  7. # Cara Pakainya
  8. # Ketik di script call
  9. #
  10. #   IconChoice([ICON 1, ICON 2, dsb], cancel? , x, y)
  11. #
  12. #   ARRAY = semua icon choice yg dipakai
  13. #   cancel? = bisa dicancel atau ngga, default true, ga dipake juga gpp
  14. #        kalau seandainya dicancel nanti value variablenya jadi 0
  15. #   x, y = posisi dari window, ga dipake juga gpp
  16. #
  17. #   Misal
  18. #
  19. #   IconChoice([23,43,46], true, 100, 300)
  20. #
  21. #  atau seperti ini pun jadi
  22. #
  23. #   IconChoice([23,43,46])
  24. #
  25. #  Nanti valuenya bakalan masuk ke variable yg disetting di bawah
  26. #
  27. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  28. module LiTTleDRAgo
  29.  
  30.   # ID dari variable yang akan dipakai sebagai pilihan
  31.   ICON_CHOICE_VAR = 15
  32.  
  33. end
  34.  
  35. #==============================================================================
  36. # ** Game_Interpreter
  37. #------------------------------------------------------------------------------
  38. #  An interpreter for executing event commands. This class is used within the
  39. # Game_Map, Game_Troop, and Game_Event classes.
  40. #==============================================================================
  41.  
  42. class Game_Interpreter
  43.   #--------------------------------------------------------------------------
  44.   # * Public Instance Variables
  45.   #--------------------------------------------------------------------------
  46.   attr_accessor :message_waiting
  47.   #--------------------------------------------------------------------------
  48.   # * IconChoice
  49.   #--------------------------------------------------------------------------
  50.   def IconChoice(choices, cancel = true, x = nil, y = nil)
  51.     return unless $scene.is_a?(Scene_Map)
  52.     $game_map.interpreter.message_waiting = true
  53.     $game_message.choice_cancel_type = cancel
  54.     w = [Graphics.width,Graphics.height,(choices.size+1)*(24+7)]
  55.     $scene.iconchoice_window = Window_IconCommand.new(w[2], choices)
  56.     $scene.iconchoice_window.x = x ? x : (w[0]-$scene.iconchoice_window.width)/2
  57.     $scene.iconchoice_window.y = y ? y : (w[1]-$scene.iconchoice_window.height)/2
  58.   end
  59. end
  60. #==============================================================================
  61. # ** Window_IconCommand
  62. #------------------------------------------------------------------------------
  63. #  This window deals with general command choices.
  64. #==============================================================================
  65.  
  66. class Window_IconCommand < Window_Selectable
  67.   #--------------------------------------------------------------------------
  68.   # * Public Instance Variables
  69.   #--------------------------------------------------------------------------
  70.   attr_reader   :commands                 # command
  71.   #--------------------------------------------------------------------------
  72.   # * Object Initialization
  73.   #     width      : window width
  74.   #     commands   : command string array
  75.   #     column_max : digit count (if 2 or more, horizontal selection)
  76.   #     row_max    : row count (0: match command count)
  77.   #     spacing    : blank space when items are arrange horizontally
  78.   #--------------------------------------------------------------------------
  79.   def initialize(width, commands, column_max = 1, row_max = 0, spacing = 4)
  80.     column_max,row_max = commands.size, 1
  81.     super(0, 0, width, row_max * WLH + 32, spacing)
  82.     @commands, @item_max, @column_max = commands, commands.size, column_max
  83.     refresh
  84.     self.index = 0
  85.   end
  86.   #--------------------------------------------------------------------------
  87.   # * Refresh
  88.   #--------------------------------------------------------------------------
  89.   def refresh
  90.     self.contents.clear
  91.     (0...@item_max).each {|index|
  92.       rect = item_rect(index)
  93.       rect.x,rect.width = rect.x + 4, rect.width - 8
  94.       self.contents.clear_rect(rect)
  95.       draw_icon(@commands[index], (24+7)*index, rect.y)}
  96.   end
  97. end
  98. #==============================================================================
  99. # ** Scene_Map
  100. #------------------------------------------------------------------------------
  101. #  This class performs the map screen processing.
  102. #==============================================================================
  103.  
  104. class Scene_Map
  105.   #--------------------------------------------------------------------------
  106.   # * Public Instance Variables
  107.   #--------------------------------------------------------------------------
  108.   attr_accessor :iconchoice_window
  109.   #--------------------------------------------------------------------------
  110.   # * Alias Listing
  111.   #--------------------------------------------------------------------------
  112.   alias drg126_main main
  113.   alias drg126_upd update
  114.   def main
  115.     drg126_main
  116.     @iconchoice_window.dispose if @iconchoice_window
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Frame Update
  120.   #--------------------------------------------------------------------------
  121.   def update
  122.     if @iconchoice_window && @iconchoice_window.active
  123.       @iconchoice_window.update
  124.       if Input.trigger?(Input::B)
  125.         return Sound.play_buzzer unless $game_message.choice_cancel_type
  126.         Sound.play_cancel
  127.         $game_variables[LiTTleDRAgo::ICON_CHOICE_VAR] = 0
  128.         icon_terminate = true
  129.       elsif Input.trigger?(Input::C)
  130.         Sound.play_decision
  131.         $game_variables[LiTTleDRAgo::ICON_CHOICE_VAR] = @iconchoice_window.index+1
  132.         icon_terminate = true
  133.       end
  134.       if icon_terminate
  135.         $game_map.interpreter.message_waiting = false
  136.         @iconchoice_window.dispose
  137.         @iconchoice_window = nil
  138.       end
  139.     end
  140.     drg126_upd
  141.   end
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement