Advertisement
LiTTleDRAgo

[RGSS/2] Message Log

Aug 26th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.68 KB | None | 0 0
  1. #==============================================================================
  2. # ** Drago - Message Log
  3. # Version : 1.2
  4. # Contact : littledrago.blogspot.com / forum.chaos-project.com
  5. #==============================================================================
  6. #
  7. # Instruction :
  8. #
  9. #    $scene = Scene_MessageLog.new
  10. #
  11. #==============================================================================
  12.  
  13. module MESSAGE_LOG
  14.  
  15.   MESSAGE_LOG_TEXT = "MESSAGE LOG"
  16.   MESSAGE_LOG_FONT = "Arial"
  17.   MESSAGE_LOG_SIZE = 30
  18.  
  19.   FRAME_OPACITY = 180
  20.   FRAME_COLOR   = Color.new(180,180,180)
  21.  
  22.   OFFSET_X = 100
  23.   OFFSET_Y = 10
  24.  
  25.   EDGE_XY  = [20,10]
  26.  
  27. end
  28.  
  29. #==============================================================================
  30. # ** Script Check
  31. #==============================================================================
  32. ($imported ||= {})[:drg_message_log] = 1.2
  33.  
  34. core_engine   = "This script needs Drago - Core Engine ver 1.52 or above"
  35. multi_message = "This script isn't compatible with Multi Message Windows"
  36. ($imported[:drg_core_engine] || 0) >= 1.52 || raise(core_engine)
  37. ($multiple_message_windows) && raise(multi_message)
  38. #==============================================================================
  39. # ** Scene_MessageLog
  40. #------------------------------------------------------------------------------
  41. #  This class performs message log processing.
  42. #==============================================================================
  43.  
  44. class Scene_MessageLog
  45.   #--------------------------------------------------------------------------
  46.   # * Include
  47.   #--------------------------------------------------------------------------
  48.   include MESSAGE_LOG
  49.   #--------------------------------------------------------------------------
  50.   # * Public Instance Variables
  51.   #--------------------------------------------------------------------------
  52.   attr_sec_reader :scene_update, '[Graphics,Input,self]'
  53.   #--------------------------------------------------------------------------
  54.   # * Main Processing
  55.   #--------------------------------------------------------------------------
  56.   def main
  57.     @spriteset = Spriteset_Map.new
  58.     init_message_log    
  59.     Graphics.transition
  60.     scene_update.update while $scene == self
  61.     Graphics.freeze
  62.     all_variable_dispose
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # * init_message_log
  66.   #--------------------------------------------------------------------------
  67.   def init_message_log
  68.     @message_log_frame = Sprite.new
  69.     @message_log_text = Sprite.new
  70.     edge = [Graphics.width - EDGE_XY[0]*2, Graphics.height - EDGE_XY[1]*2]
  71.     @message_log_frame.bitmap = Bitmap.new(*edge)
  72.     @message_log_text.bitmap = @message_log_frame.bitmap.dup
  73.     @message_log_text.opacity = 255
  74.     @message_log_text.z = @message_log_frame.z + 10
  75.     @message_log_text.x, @message_log_text.y = EDGE_XY[0], EDGE_XY[1]
  76.     @message_log_frame.x, @message_log_frame.y = EDGE_XY[0], EDGE_XY[1]
  77.     @message_log_frame.opacity = FRAME_OPACITY  
  78.     @index = 0
  79.     refresh
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # * Refresh
  83.   #--------------------------------------------------------------------------
  84.   def refresh
  85.     [(mess = @message_log_frame.bitmap).clear,@message_log_text.bitmap.clear]
  86.     @message_log_height = 0
  87.     cls = [Color.new(0,0,0,0), Color.new(255,255,255,255)]
  88.     mess.fill_rect( mess.rect,FRAME_COLOR)
  89.     $game_temp.message_log.reverse.each_with_index do |i,s|
  90.       next if (@index ||= 0) > s
  91.       @message_log_height += (i.height+20)
  92.       v = mess.height - @message_log_height
  93.       @message_log_text.bitmap.blt(20 ,v ,i, i.rect)
  94.       mess.fill_rect( Rect.new(30,v-15,mess.width-60,2),cls[0])
  95.     end
  96.     @message_log_text.fill_rect( Rect.new(0,0,mess.width,50),cls[0])
  97.     mess.fill_rect( Rect.new(10,40, mess.width-20,2), cls[1])
  98.     mess.font.name = MESSAGE_LOG_FONT
  99.     mess.font.size = [MESSAGE_LOG_SIZE, 12].max
  100.     mess.draw_text(10,0, mess.width,  45,MESSAGE_LOG_TEXT)
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # * Frame Update
  104.   #--------------------------------------------------------------------------
  105.   def update
  106.     if cancel_mesage_log
  107.       $game_system.se_play($data_system.cancel_se)
  108.       return $scene = Scene_Map.new
  109.     end
  110.     scroll = mouse_scroll
  111.     if (el = elmessage_log(scroll)) || (er = ermessage_log(scroll))
  112.       s = @index
  113.       el && @index = [@index + 1, $game_temp.message_log.size-1].min
  114.       er && @index = [@index - 1, 0].max
  115.       $game_system.se_play($data_system.cursor_se) if s != @index
  116.       return refresh
  117.     end
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # * Cancel Message Log
  121.   #--------------------------------------------------------------------------
  122.   def cancel_mesage_log
  123.     return true if Input.trigger?(Input::F8)
  124.     return true if Input.trigger?(Input::B)
  125.     if $mouse_controller || $BlizzABS
  126.       return true if Input.trigger?(Input::Key['Mouse Right'])
  127.     elsif (($imported ||= {})[:drg_custom_input] || 0) >= 2.00
  128.       return true if Mouse.press?(Mouse::SECONDARY)
  129.     end
  130.     return false
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * elmessage_log
  134.   #--------------------------------------------------------------------------
  135.   def elmessage_log(sc = 0)
  136.     return true if Input.trigger?(Input::L)
  137.     return true if Input.repeat?(Input::UP)
  138.     return true if sc > 0
  139.     return false
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # * ermessage_log
  143.   #--------------------------------------------------------------------------
  144.   def ermessage_log(sc = 0)
  145.     return true if Input.trigger?(Input::R)
  146.     return true if Input.repeat?(Input::DOWN)
  147.     return true if sc < 0
  148.     return false
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # * mouse_scroll
  152.   #--------------------------------------------------------------------------
  153.   def mouse_scroll
  154.     @scroll_count = (@scroll_count || 0) + 1
  155.     return (@scroll_count = 0) if @scroll_count < 5
  156.     if $mouse_controller && Input.respond_to?(:scroll?)
  157.       return 1 if Input.scroll_up?
  158.       return -1 if Input.scroll_down?
  159.     elsif (($imported ||= {})[:drg_custom_input] || 0) >= 2.00
  160.       return 1  if Mouse.scroll_up?
  161.       return -1 if Mouse.scroll_down?
  162.     end
  163.     return 0
  164.   end
  165. end
  166. #==============================================================================
  167. # ** Game_Temp
  168. #------------------------------------------------------------------------------
  169. #  This class handles temporary data that is not included with save data.
  170. #  Refer to "$game_temp" for the instance of this class.
  171. #==============================================================================
  172.  
  173. class Game_Temp
  174.   #--------------------------------------------------------------------------
  175.   # * Public Instance Variables
  176.   #--------------------------------------------------------------------------
  177.   attr_sec_reader :message_log, 'Array.new'
  178. end
  179.  
  180. #==============================================================================
  181. # ** Window_Base
  182. #------------------------------------------------------------------------------
  183. #  This class is for all in-game windows.
  184. #==============================================================================
  185. class Window_Base
  186.   #--------------------------------------------------------------------------
  187.   # * record_message
  188.   #--------------------------------------------------------------------------
  189.   def record_message
  190.     xy = MESSAGE_LOG::OFFSET_X, MESSAGE_LOG::OFFSET_Y
  191.     edge = MESSAGE_LOG::EDGE_XY
  192.     saved_bitmap = Bitmap.new(Graphics.width-edge[0]*2,self.contents.height+10)
  193.     saved_bitmap.blt(xy[0],xy[1],self.contents,self.contents.rect)
  194.     save_message_bitmap(saved_bitmap)
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # * save_message_bitmap
  198.   #--------------------------------------------------------------------------
  199.   def save_message_bitmap(saved_bitmap)
  200.     d =  $game_temp.message_log
  201.     ($game_temp.message_log.push(saved_bitmap))
  202.     ($game_temp.message_log.shift).dispose if d.size + 1 > 20
  203.   end
  204. end
  205.  
  206. #==============================================================================
  207. # ** Window_InputNumber
  208. #------------------------------------------------------------------------------
  209. #  This window is for inputting numbers, and is used within the
  210. #  message window.
  211. #==============================================================================
  212. class Window_InputNumber
  213.   #--------------------------------------------------------------------------
  214.   # * Dispose
  215.   #--------------------------------------------------------------------------
  216.   define_pre_alias(:dispose) { record_message }
  217. end
  218.  
  219. #==============================================================================
  220. # ** Window_Message
  221. #------------------------------------------------------------------------------
  222. #  This message window is used to display text.
  223. #==============================================================================
  224. class Window_Message
  225.   #--------------------------------------------------------------------------
  226.   # * Terminate Message
  227.   #--------------------------------------------------------------------------
  228.   define_pre_alias(:terminate_message) do
  229.     if @contents_showing
  230.       if (record_input = $game_temp.num_input_variable_id != 0)
  231.         record_input = $game_temp.message_log.pop
  232.       end
  233.       record_message
  234.       record_input && $game_temp.message_log << record_input
  235.     end
  236.   end
  237. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement