Advertisement
LiTTleDRAgo

[RGSS] SMS - Scrolling Message System

Jun 26th, 2013
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 36.72 KB | None | 0 0
  1. #==============================================================
  2. # ** Scrolling Message System EX
  3. #------------------------------------------------------------------------------
  4. # Slipknot (http://www.creationasylum.net/)
  5. # Version 1.2x (edited by LiTTleDRAgo)
  6. # May 13, 2007
  7. #==============================================================
  8. $scrolling_message_system = true
  9.  
  10. module Message
  11.   #--------------------------------------------------------------------------
  12.   # * Settings
  13.   #--------------------------------------------------------------------------
  14.   # ~ Font
  15.   FontName = Font.default_name
  16.   FontSize = Font.default_size
  17.   # ~ Size
  18.   Width = 520
  19.   Height = 32
  20.   # ~ Delay
  21.   TextDelay = 2
  22.   Scroll = 30
  23.   Autoclose = 16
  24.   #--------------------------------------------------------------------------
  25.   # * Font
  26.   #--------------------------------------------------------------------------
  27.   def self.font
  28.     Font.new(FontName, FontSize)
  29.   end
  30. end
  31.  
  32. if $scrolling_message_system
  33.  
  34. class Game_Temp
  35.   #--------------------------------------------------------------------------
  36.   # * Public Instance Variables
  37.   #--------------------------------------------------------------------------
  38.   attr_accessor :input_type
  39. end
  40.  
  41.  
  42.  
  43. class Interpreter
  44.   #--------------------------------------------------------------------------
  45.   # * Alias Listing
  46.   #--------------------------------------------------------------------------
  47.   alias slipknot_sms_command_101 command_101
  48.   alias slipknot_sms_command_102 command_102
  49.   alias slipknot_sms_command_103 command_103
  50.   #--------------------------------------------------------------------------
  51.   # * Show Text
  52.   #--------------------------------------------------------------------------
  53.   def command_101
  54.     if false
  55.       return slipknot_sms_command_101
  56.     end
  57.     return false if (temp = $game_temp).message_text
  58.     @message_waiting = true
  59.     temp.message_proc = Proc.new { @message_waiting = false }
  60.     temp.message_text = @list.at(@index).parameters.at(0) + "\n"
  61.     loop do
  62.       com = @list.at(@index + 1)
  63.       if com.code == 401 || com.code == 101
  64.         temp.message_text += com.parameters.at(0) + "\n"
  65.       else
  66.         if com.code == 102
  67.           temp.message_text += "\n\n"
  68.           slipknot_sms_set_choice(com.parameters)
  69.           current_indent = com.indent
  70.           temp.choice_proc = Proc.new { |n| @branch[current_indent] = n }
  71.           @index += 1
  72.         elsif com.code == 103
  73.           @index += 1
  74.           temp.message_text += "\n"
  75.           slipknot_sms_set_inputnumber(com.parameters)
  76.         end
  77.         return true
  78.       end
  79.       @index += 1
  80.     end
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # * slipknot_sms_set_choice
  84.   #--------------------------------------------------------------------------
  85.   def slipknot_sms_set_choice(parameters)
  86.     if !$choice.nil? && $choice.is_a?(Array)
  87.       parameters[0] = $choice
  88.     end
  89.     $game_temp.choice_max = parameters.at(0).size
  90.     $game_temp.instance_variable_set(:@mes_choices, parameters.at(0))
  91.     $game_temp.choice_cancel_type = parameters.at(1)
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # * slipknot_sms_set_inputnumber
  95.   #--------------------------------------------------------------------------
  96.   def slipknot_sms_set_inputnumber(parameters)
  97.     $game_temp.num_input_variable_id = parameters.at(0)
  98.     $game_temp.num_input_digits_max = parameters.at(1)
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # * Show Choices
  102.   #--------------------------------------------------------------------------
  103.   def command_102()  end
  104.   #--------------------------------------------------------------------------
  105.   # * Input Number
  106.   #--------------------------------------------------------------------------
  107.   def command_103()  end
  108. end
  109.  
  110.  
  111. class Window_Message < Window_Selectable
  112.   #--------------------------------------------------------------------------
  113.   # * Alias Listing
  114.   #--------------------------------------------------------------------------
  115.   alias slipknot_sms_init initialize
  116.   alias slipknot_sms_refresh refresh
  117.   alias slipknot_sms_update update
  118.   #--------------------------------------------------------------------------
  119.   # * Initialize
  120.   #--------------------------------------------------------------------------
  121.   def initialize
  122.     slipknot_sms_init
  123.     @original_height = self.height
  124.     @row_max = 4
  125.     self.height = Message::Height * @row_max + 32
  126.     self.back_opacity = 160
  127.     self.windowskin = windowskin.clone
  128.     self.windowskin.fill_rect(144, 16, 32, 32, Color.new(0, 0, 0, 0))
  129.     @ey = 1.0
  130.     @y = 0
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * Opacity
  134.   #--------------------------------------------------------------------------
  135.   def opacity=(val)
  136.     super
  137.     @choices.opacity = val if @choices
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # * Refresh
  141.   #--------------------------------------------------------------------------
  142.   def refresh
  143.     contents.clear
  144.     contents.font = Message.font
  145.     self.height = Message::Height * @row_max + 32
  146.     @x = @y = @ex = @ey = 0
  147.     return if ! (@text = (temp = $game_temp).message_text)
  148.     replace_code
  149.     gold_win |= @text.gsub!(/\\[Gg]/, '')
  150.     if fit |= @text[/\\[Pp]/]
  151.       if @text.sub!(/\\[Pp]\[([-1,-2,-3,-4,0-9]+)\]/, '')
  152.         @event = $1.to_i
  153.         self.height = Message::Height * 2 + 32
  154.       elsif @text.gsub!(/\\[Pp]/, '')
  155.         @event = ev_ac
  156.         self.height = Message::Height * 2 + 32
  157.       end
  158.     end
  159.     lines_size = [0]
  160.     save, @lines = @text.clone, 0
  161.     while @c = @text.slice!(/./m)
  162.       if @c == "\n"
  163.         @lines += 1
  164.         lines_size << 0
  165.         next
  166.       end
  167.       lines_size[@lines] += eval_text(self.contents, true)
  168.     end
  169.     if temp.choice_max > 0
  170.       @c_data = [Bitmap.new(640 - Message::Width/4, Message::Height *
  171.         temp.choice_max), Array.new(temp.choice_max, 0)]
  172.       @c_data.at(0).font = Message.font
  173.       mes_choices = temp.instance_variable_get(:@mes_choices)||['']
  174.       @cond = mes_choices.collect {|s| s.is_a?(Array) ? s[1] : nil }
  175.       @text = mes_choices.collect {|s| s.is_a?(Array) ? s[0] : s }
  176.       @text.each_with_index {|s,i|
  177.         if !@cond.nil? && !@cond[i].nil? && !@cond[i] &&
  178.           mes_choices[i].is_a?(Array) && mes_choices[i][2]
  179.           @text[i] = mes_choices[i][2]
  180.         end}
  181.       @text = @text.join("\n")
  182.       replace_basic_code
  183.       @y = 0
  184.       while @c = @text.slice!(/./m)
  185.         @c_data.at(0).font.color.alpha=!@cond[@y].nil?&&!@cond[@y] ? 100 : 255
  186.         @c_data.at(1)[@y] += eval_text(@c_data.at(0))
  187.       end
  188.       @c_data[1] = @c_data.at(1).max + 8
  189.       @x = @y = 0
  190.     end
  191.     @text = save
  192.     twidth = temp.choice_max > 0 ? @c_data.at(1) + 32 : 0
  193.     #self.width = fit ? lines_size.max + 40 + @ex : Message::Width - twidth
  194.     self.width = [lines_size.max,twidth].max + 40 + @ex if @event
  195.     self.width = Message::Width if !@event
  196.     twidth += self.width
  197.     self.contents = Bitmap.new(self.width - 32, @lines * Message::Height)
  198.     contents.font = Message.font
  199.     if !@event #|| in_battle?
  200.       h2 = self.height / 2
  201.       self.y = in_battle? ? 96 - h2 :
  202.         case $game_system.message_position
  203.         when 0 then 96 - h2
  204.         when 1 then 240 - h2
  205.         when 2 then 384 - h2
  206.         end
  207.       self.x = 320 - self.width / 2
  208.     else
  209.       if in_battle?
  210.         if @event > 0
  211.           spr = spriteset.instance_variable_get(:@enemy_sprites)[@event-1]
  212.         elsif @event < 0
  213.           spr = spriteset.instance_variable_get(:actor_sprites)[(-@event)-1]
  214.         end
  215.         return terminate_message if spr == nil
  216.         sprite = spr
  217.         char_height = sprite.height
  218.         char_width = sprite.width
  219.         fx = sprite.x
  220.         fy = sprite.y - char_height/2
  221.       else
  222.         c = @event > 0 ? $game_map.events[@event] : $game_player
  223.         sprite = RPG::Cache.character(c.character_name,0)
  224.         mx, my = 636 - twidth, 476 - self.height
  225.         ch = [sprite.height / 4 + 4, 48].max
  226.         fx = [[c.screen_x - self.width / 2, 4].max, mx].min
  227.         fy = [[c.screen_y - (ch + self.height), 4].max, my].min
  228.       end
  229.       self.x, self.y = fx, fy
  230.       self.x = [[fx,0].max,640-self.width].min
  231.       self.y = [[fy,0].max,480-self.height].min
  232.     end
  233.     self.opacity = $game_system.message_frame == 0 ? 255 : 0
  234.     if gold_win
  235.       @gold_window = Window_Gold.new
  236.       @gold_window.x = 560 - @gold_window.width
  237.       @gold_window.z = self.z
  238.       if in_battle?
  239.         @gold_window.y = 192
  240.       else
  241.         @gold_window.y = self.y >= 128 ? 32 : 384
  242.       end
  243.       @gold_window.opacity = self.opacity
  244.     end
  245.     if temp.choice_max > 0
  246.       row_max = ((self.height - 32) / Message::Height) - 1
  247.       ch = [row_max - 2,0].max
  248.       x = self.x
  249.       y = self.y + Message::Height * ch + 32
  250.       y = self.y + Message::Height if @lines == 3
  251.       y = self.y if @event
  252.       size = 2
  253.       size = 3 if @lines == 3
  254.       @choices = Window_MesChoices.new(x, y, @c_data,size)
  255.       #@choices.x = self.width/2 - @choices.width/2
  256.       @choices.z = self.z
  257.       @choices.back_opacity = 0
  258.       @choices.opacity = 0
  259.       @choices.visible = false
  260.     end
  261.     return
  262.     if temp.choice_max > 0
  263.       @choices = Window_MesChoices.new(self.x + self.width, self.y, @c_data)
  264.       @choices.z = self.z
  265.       @choices.back_opacity = self.back_opacity
  266.     end
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # * In Battle?
  270.   #--------------------------------------------------------------------------
  271.   def in_battle?
  272.     return false if $scene.is_a?(Scene_Map)
  273.     return true if $scene.is_a?(Scene_Battle)
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # * Replace Code
  277.   #--------------------------------------------------------------------------
  278.   def replace_code
  279.     replace_basic_code
  280.     @text.gsub!('\!') { "\003" }
  281.     @text.gsub!('\.') { "\004" }
  282.     @text.gsub!(/\\\%\[(\d+)\]/) { "\011[#$1]" }
  283.     @text.gsub!('\%') { "\011" }
  284.     @text.gsub!("\\#\n") { "" }
  285.   end
  286.   def replace_basic_code
  287.     @text.gsub!(/\\\\/) { "\000" }
  288.     @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  289.     @text.gsub!('\$') { $game_party.gold.to_s }
  290.     @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  291.        $game_actors[$1.to_i] ? $game_actors[$1.to_i].name : ''
  292.     end
  293.     @text.gsub!(/\\[Cc]\[([0-9]+?)\]/) { "\001[#$1]" }
  294.   end
  295.   #--------------------------------------------------------------------------
  296.   # * Evaluate Text
  297.   #--------------------------------------------------------------------------
  298.   def eval_text(bitmap, read = false)
  299.     case @c
  300.     when "\000"
  301.       @c = '\\'
  302.     when "\001"
  303.       @text.sub!(/\[(\d+)\]/, '')
  304.       return 0 if read
  305.       bitmap.font.color = text_color($1.to_i)
  306.       return 0
  307.     when "\002"
  308.       @text.sub!(/\[(.*?)\]/, '')
  309.       return 24 if read
  310.       y = Message::Height * @y
  311.       bitmap.blt(@ex + @x + 4, y, RPG::Cache.icon($1.to_s),Rect.new(0,0,24,24))
  312.       @x += 24
  313.       return 0
  314.     when "\003"
  315.       return 0 if read
  316.       @stop = true
  317.       return 0
  318.     when "\004"
  319.       return 0 if read
  320.       @wait_count += 10
  321.       return 0
  322.     when "\011"
  323.       @text.sub!(/\[(\d+)\]/, '')
  324.       return 0 if read || $game_temp.num_input_variable_id > 0 ||
  325.                   $game_temp.choice_max > 0
  326.       @autoclose = $1 ? $1.to_i : Message::Autoclose
  327.       return 0
  328.     end
  329.     eval_extra(bitmap)
  330.     return 0 if @c == '' || @c == nil
  331.     if @c == "\n"
  332.       @y += 1
  333.       @x = 0
  334.       return 0
  335.     end
  336.     w = bitmap.text_size(@c).width
  337.     unless read
  338.       y1 = Message::Height
  339.       bitmap.draw_text(@ex + @x + 4, y1 * @y, w, Message::Height, @c)
  340.       @x += w
  341.     end
  342.     return w
  343.   end
  344.   def eval_extra(bitmap)  end
  345.   #--------------------------------------------------------------------------
  346.   # * Variables
  347.   #--------------------------------------------------------------------------
  348.   def ev_ac()  interpreter.instance_variable_get(:@event_id)  end
  349.   def spriteset()  $scene.instance_variable_get(:@spriteset) end
  350.   def interpreter()
  351.     return $game_system.map_interpreter    if !in_battle?
  352.     return $game_system.battle_interpreter if in_battle?
  353.   end
  354.   #--------------------------------------------------------------------------
  355.   # * Frame Update
  356.   #--------------------------------------------------------------------------
  357.   def update
  358.     if @contents_showing
  359.       super
  360.       y1 = ((self.height - 32) / Message::Height) - 1
  361.       scroll = self.oy < (@y - y1) * Message::Height && @y < @lines
  362.       if scroll
  363.         @ey += Message::Height / Message::Scroll.to_f
  364.         ey = @ey - @ey.floor
  365.         self.oy += @ey.floor
  366.         @ey = ey
  367.       end
  368.       if @text
  369.         if Input.trigger?(Input::C) && @stop
  370.           self.pause = @stop = false
  371.           return
  372.         elsif @stop
  373.           return
  374.         elsif @wait_count > 0
  375.           @wait_count -= 1
  376.           return
  377.         end
  378.         @wait_count = 0
  379.         return if scroll
  380.         if (@c = @text.slice!(/./m))
  381.           eval_text(contents)
  382.           if @stop
  383.             self.pause = true
  384.             return
  385.           end
  386.           @wait_count += Input.press?(Input::C) ? 0 : Message::TextDelay
  387.           @wait_count = 0 if Input.press?(Input::CTRL)
  388.         else
  389.           @text = nil
  390.         end
  391.         return if @text || @autoclose != -1
  392.         if $game_temp.num_input_variable_id > 0
  393.           digits_max = $game_temp.num_input_digits_max
  394.           ch = [y1 - 1,0].max
  395.           x = self.x
  396.           y = self.y + Message::Height * ch + 32
  397.           y = self.y + Message::Height * (@lines-2) + 32 if @lines == 3
  398.           if self.height == Message::Height * 2 + 32 || @lines == 2
  399.             y = self.y + Message::Height * 1
  400.           end
  401.           @input_number_window = Window_InputNumber.new(digits_max)
  402.           @input_number_window.number =
  403.              $game_variables[$game_temp.num_input_variable_id]
  404.           @input_number_window.x = x
  405.           @input_number_window.y = y
  406.           @input_number_window.z = self.z + 10
  407.           @y -= 1
  408.           @ey -= 1.0
  409.         end
  410.         @choices.index, @choices.active,@choices.visible = 0,true,true if @choices
  411.         return
  412.       else
  413.         if @autoclose > 0
  414.           @autoclose -= 1
  415.           return
  416.         elsif @autoclose == 0
  417.           terminate_message
  418.           @autoclose = -1
  419.           return
  420.         end
  421.       end
  422.       if @input_number_window
  423.         @input_number_window.update
  424.         if Input.trigger?(Input::C)
  425.           $game_system.se_play($data_system.decision_se)
  426.           $game_variables[$game_temp.num_input_variable_id] =
  427.                        @input_number_window.number
  428.           $game_map.need_refresh = true
  429.           @input_number_window.dispose
  430.           @input_number_window = nil
  431.           terminate_message
  432.         end
  433.         return
  434.       elsif @choices
  435.         @choices.update
  436.       end
  437.       self.pause = true
  438.       if Input.trigger?(Input::B)
  439.         if $game_temp.choice_max > 0 && $game_temp.choice_cancel_type > 0
  440.           result = $game_temp.choice_cancel_type - 1
  441.           if !@cond.nil? && !@cond[result].nil? && !@cond[result]
  442.             $game_system.se_play($data_system.buzzer_se)
  443.             return
  444.           end
  445.           $game_system.se_play($data_system.cancel_se)
  446.           @choices.visible = false
  447.           if !$choice.nil?
  448.             $choice_result = result
  449.             $choice = nil
  450.           end
  451.           $game_temp.choice_proc.call(result)
  452.           terminate_message
  453.         end
  454.       end
  455.       if Input.trigger?(Input::C)
  456.         if $game_temp.choice_max > 0
  457.           result = @choices.index
  458.           if !@cond.nil? && !@cond[result].nil? && !@cond[result]
  459.             $game_system.se_play($data_system.buzzer_se)
  460.             return
  461.           end
  462.           $game_system.se_play($data_system.decision_se)
  463.           @choices.visible = false
  464.           if !$choice.nil?
  465.             $choice_result = result
  466.             $choice = nil
  467.           end
  468.           $game_temp.choice_proc.call(result)
  469.         end
  470.         terminate_message
  471.       end
  472.       return
  473.     end
  474.     if ! @fade_out && $game_temp.message_text
  475.       @contents_showing = $game_temp.message_window_showing = true
  476.       if @choices
  477.         @choices.visible = false
  478.         @choices.dispose
  479.         @choices = nil
  480.       end
  481.       self.oy = 0
  482.       @stop = false
  483.       @autoclose = -1
  484.       refresh
  485.       @wait_count, self.visible = 0.0, true
  486.       return
  487.     end
  488.     return if ! visible
  489.     @fade_out = true
  490.     self.opacity -= 48
  491.     if self.opacity == 0
  492.       self.visible = @fade_out = false
  493.       if @choices
  494.         @choices.visible = false
  495.         @choices.dispose
  496.         @choices = nil
  497.       end
  498.       $game_temp.message_window_showing = false
  499.     end
  500.   end
  501. end
  502.  
  503.  
  504. class Window_MesChoices < Window_Selectable
  505.   #--------------------------------------------------------------------------
  506.   # * Initialize
  507.   #--------------------------------------------------------------------------
  508.   def initialize(x, y, data,size = 2)
  509.     super(x, y, data.at(1) + 32, size * (h = Message::Height) + 32)
  510.     self.back_opacity = 0
  511.     self.opacity = 0
  512.     @size = size
  513.     self.index, self.active, @item_max = -1, false, $game_temp.choice_max
  514.     self.contents = Bitmap.new(data.at(1), @item_max * h)
  515.     contents.blt(0, 0, data.at(0), Rect.new(0, 0, data.at(1), h * @item_max))
  516.   end
  517.   #--------------------------------------------------------------------------
  518.   # * Update Cursor
  519.   #--------------------------------------------------------------------------
  520.   def update_cursor_rect
  521.     if @index < 0
  522.       self.cursor_rect.empty
  523.       return
  524.     end
  525.     self.oy = [[@index, @item_max].min - (@size-1), 0].max * Message::Height
  526.     y = @index * Message::Height - self.oy
  527.     cursor_rect.set(0, y, width - 32, Message::Height)
  528.   end
  529. end
  530.  
  531.  
  532. class Window_InputNumber < Window_Base
  533.   #--------------------------------------------------------------------------
  534.   # * Initialize
  535.   #--------------------------------------------------------------------------
  536.   def initialize(digits_max)
  537.     case $game_temp.input_type
  538.     when nil,"default"
  539.       @character_array = ["0","1","2","3","4","5","6","7","8","9"]
  540.     when "binary"
  541.       @character_array = ["0","1"]
  542.     when "hexa"
  543.       @character_array = ["0","1","2","3","4","5","6","7","8","9",
  544.                           "A","B","C","D","E","F"]
  545.     when "upcase_letters"
  546.       @character_array = ["A","B","C","D","E","F","G","H","I",
  547.                           "J","K","L","M","N","O","P","Q","R","S",
  548.                           "T","U","V","W","X","Y","Z"," "]
  549.     when "lowercase_letters"
  550.       @character_array = ["a","b","c","d","e","f","g","h","i",
  551.                           "j","k","l","m","n","o","p","q","r","s",
  552.                           "t","u","v","w","x","y","z"," "]
  553.     when "all_letters"
  554.       @character_array = ["A","B","C","D","E","F","G","H","I",
  555.                           "J","K","L","M","N","O","P","Q","R","S",
  556.                           "T","U","V","W","X","Y","Z","a","b","c",
  557.                           "d","e","f","g","h","i","j","k","l","m",
  558.                           "n","o","p","q","r","s","t","u","v","w",
  559.                           "x","y","z"," "]
  560.     when "all_characters"
  561.       @character_array = ["A","B","C","D","E","F","G","H","I",
  562.                           "J","K","L","M","N","O","P","Q","R","S",
  563.                           "T","U","V","W","X","Y","Z","a","b","c",
  564.                           "d","e","f","g","h","i","j","k","l","m",
  565.                           "n","o","p","q","r","s","t","u","v","w",
  566.                           "x","y","z","0","1","2","3","4","5","6",
  567.                           "7","8","9","+","-","*","/","!","#","$",
  568.                           "%","&","@",".",",","-"," "]
  569.     # when...
  570.     end
  571.     @digits_max = digits_max
  572.     @type = $game_temp.input_type || "default"
  573.     $game_temp.input_type = @type
  574.     @letter_array = []
  575.     @digits_max.times{@letter_array.push(0)}
  576.     dummy_bitmap = Bitmap.new(32, 32)
  577.    
  578.     @cursor_width = 8
  579.     for i in 0...@character_array.size
  580.       letter_size = dummy_bitmap.text_size(@character_array[i]).width + 8
  581.       @cursor_width = [@cursor_width, letter_size].max
  582.     end
  583.     dummy_bitmap.dispose
  584.     super(0, 0, @cursor_width * @digits_max + 32+ 4, Message::Height+32)
  585.     self.contents = Bitmap.new(width - 32, height - 32)
  586.     self.z += 9999
  587.     self.opacity = 0
  588.     @index = 0
  589.     refresh
  590.     update_cursor_rect
  591.   end
  592.  
  593.   def letter(index)
  594.     return @character_array[@letter_array[index]]
  595.   end
  596.  
  597.   def increase_letter_array(index)
  598.     if @letter_array[index] == (@character_array.size-1)
  599.       @letter_array[index] = 0
  600.     else
  601.       @letter_array[index] += 1
  602.     end
  603.   end
  604.  
  605.   def decrease_letter_array(index)
  606.     if @letter_array[index] == 0
  607.       @letter_array[index] = (@character_array.size-1)
  608.     else
  609.       @letter_array[index] -= 1
  610.     end
  611.   end
  612.  
  613.   def update_cursor_rect
  614.     cursor_rect.set(@index * @cursor_width+2, 0, @cursor_width, Message::Height)
  615.   end
  616.  
  617.   def update
  618.     super
  619.     if Input.repeat?(Input::UP)
  620.       $game_system.se_play($data_system.cursor_se)
  621.       increase_letter_array(@index)
  622.       refresh
  623.     end
  624.     if Input.repeat?(Input::DOWN)
  625.       $game_system.se_play($data_system.cursor_se)
  626.       decrease_letter_array(@index)
  627.       refresh
  628.     end
  629.     if Input.repeat?(Input::RIGHT)
  630.       if @digits_max >= 2
  631.         $game_system.se_play($data_system.cursor_se)
  632.         @index = (@index + 1) % @digits_max
  633.       end
  634.     end
  635.     if Input.repeat?(Input::LEFT)
  636.       if @digits_max >= 2
  637.         $game_system.se_play($data_system.cursor_se)
  638.         @index = (@index + @digits_max - 1) % @digits_max
  639.       end
  640.     end
  641.     if Input.trigger?(Input::B)
  642.       @letter_array[@index] = 0
  643.       refresh
  644.     end
  645.     update_cursor_rect
  646.   end
  647.  
  648.   def refresh
  649.     contents.clear
  650.     contents.font.color = normal_color
  651.     (0...@digits_max).each {|i|
  652.       s = i * @cursor_width + 4
  653.       contents.draw_text(s,0,@cursor_width,Message::Height,letter(i),1) }
  654.   end
  655.  
  656.   def number
  657.     string  = (0...@digits_max).collect {|i| letter(i)}.join
  658.     integer = string.to_i
  659.     @number = sprintf('%0*d',@digits_max,integer) == string ? integer : string
  660.   end
  661.  
  662.   def number=(number)
  663.     if number != 0
  664.       num = number.to_s
  665.       @array = num.scan(/./)
  666.       if @array.size != @digits_max
  667.         begin
  668.           @array.unshift(@character_array[0])
  669.         end until @array.size == @digits_max
  670.       end
  671.       (0...@digits_max).each {|i|
  672.         (0..@character_array.size).each {|j|
  673.            @letter_array[i] = j if @array[i] == @character_array[j]
  674.          }}
  675.     end
  676.     refresh
  677.   end
  678. end
  679.  
  680. #==============================================================
  681. # ** Scrolling Message System / Name Box
  682. #------------------------------------------------------------------------------
  683. # Slipknot (http://www.creationasylum.net/)
  684. # Version 1.1
  685. # March 13, 2007
  686. #==============================================================
  687. class Window_Message < Window_Selectable
  688.   #--------------------------------------------------------------------------
  689.   # * Alias Listing
  690.   #--------------------------------------------------------------------------
  691.   alias slipknot_sms_nb_refresh refresh
  692.   alias slipknot_sms_nb_repcod replace_code
  693.   alias slipknot_sms_nb_termmes terminate_message
  694.   #--------------------------------------------------------------------------
  695.   # * Terminate Message
  696.   #--------------------------------------------------------------------------
  697.   def terminate_message
  698.     slipknot_sms_nb_termmes
  699.     if @name_box
  700.       @name_box.dispose
  701.       @name_box = nil
  702.     end
  703.   end
  704.   #--------------------------------------------------------------------------
  705.   # * Refresh
  706.   #--------------------------------------------------------------------------
  707.   def refresh
  708.     slipknot_sms_nb_refresh
  709.     if @name_text
  710.       @name_box = Window_MessageNameBox.new(x, y - 16, @name_text)
  711.       @name_box.back.opacity = 0 if $game_system.message_frame == 1
  712.       @name_box.z = self.z
  713.       @name_text = nil
  714.     end
  715.   end
  716.   #--------------------------------------------------------------------------
  717.   # * Replace Code
  718.   #--------------------------------------------------------------------------
  719.   def replace_code
  720.     slipknot_sms_nb_repcod
  721.     @text.gsub!(/\\[Nn]ame\[(.*?)\]/) { @name_text = $1; '' }
  722.   end
  723. end
  724.  
  725. class Window_MessageNameBox < Window_Base
  726.   #--------------------------------------------------------------------------
  727.   # * Public Instance Variables
  728.   #--------------------------------------------------------------------------
  729.   attr_reader :back
  730.   #--------------------------------------------------------------------------
  731.   # * Object Initialization
  732.   #--------------------------------------------------------------------------
  733.   def initialize(x, y, text)
  734.     dumb = Bitmap.new(160, 32)
  735.     dumb.font = Message.font
  736.     color = nil
  737.     text.sub!(/\\[Cc](\d)/) { color = text_color($1.to_i); '' }
  738.     size = dumb.text_size(text).width
  739.     dumb.dispose
  740.     @back = Window_Base.new(x, y, size + 12, 32)
  741.     @back.z = 9998
  742.     super(x - 10, y - 11, size + 32, 54)
  743.     self.z = 9999
  744.     self.opacity = 0
  745.     self.contents = Bitmap.new(size, 22)
  746.     contents.font = Message.font
  747.     contents.font.color = color if color
  748.     contents.draw_text(0, 0, size, 22, text)
  749.   end
  750.   #--------------------------------------------------------------------------
  751.   # * Dispose
  752.   #--------------------------------------------------------------------------
  753.   def dispose
  754.     @back.dispose
  755.     @back = nil
  756.     super
  757.   end
  758. end
  759. #==============================================================
  760. # ** Scrolling Message System / Face
  761. #------------------------------------------------------------------------------
  762. # Slipknot (http://www.creationasylum.net/)
  763. # Version 1.0
  764. # May 13, 2007
  765. #==============================================================
  766.  
  767. class Window_Message < Window_Selectable
  768.   #--------------------------------------------------------------------------
  769.   # * Alias Listing
  770.   #--------------------------------------------------------------------------
  771.   alias slipknot_sms_f_refresh refresh
  772.   alias slipknot_sms_f_repcod replace_code
  773.   alias slipknot_sms_f_termmes terminate_message
  774.   #--------------------------------------------------------------------------
  775.   # * Refresh
  776.   #--------------------------------------------------------------------------
  777.   def terminate_message
  778.     slipknot_sms_f_termmes
  779.     if @face
  780.       @face.dispose
  781.       @face = nil
  782.     end
  783.   end
  784.   #--------------------------------------------------------------------------
  785.   # * Refresh
  786.   #--------------------------------------------------------------------------
  787.   def refresh
  788.     slipknot_sms_f_refresh
  789.     if @face_name
  790.       @face = Sprite.new
  791.       @face.x = self.x + 16
  792.       @face.y = self.y + 16
  793.       @face.z = self.z + 1
  794.       if @face_name.to_i > 0
  795.         actor = $game_actors[@face_name.to_i]
  796.         return @face_name = nil if actor.nil?
  797.         bitmap = RPG::Cache.windowskin("Actor#{actor.id}_HFace") rescue
  798.                 RPG::Cache.windowskin("#{actor.name}_HFace") rescue
  799.                 RPG::Cache.picture("Actor#{actor.id}_HFace") rescue
  800.                 RPG::Cache.picture("#{actor.name}_HFace")
  801.         size = [bitmap.width,bitmap.height].min
  802.         rect = Rect.new(0,0,size,size)
  803.       else
  804.         bitmap = RPG::Cache.picture(@face_name)
  805.         rect = Rect.new(0,0,bitmap.width,bitmap.height)
  806.       end
  807.       @face.bitmap = Bitmap.new(60,60)
  808.       x = 30 - rect.width / 2
  809.       y = 30 - rect.height / 2
  810.       x, y = 0,0 if false
  811.       @face.bitmap.blt(x, y, bitmap, rect)
  812.       @face_name = nil
  813.     end
  814.   end
  815.   #--------------------------------------------------------------------------
  816.   # * Replace Code
  817.   #--------------------------------------------------------------------------
  818.   def replace_code
  819.     slipknot_sms_f_repcod
  820.     @text.sub!(/\\[Ff]ace\[(.*?)\]/) do
  821.       @face_name = $1
  822.       @ex += Message::Height * 2 + 4
  823.       ''
  824.     end
  825.   end
  826. end
  827. #==============================================================
  828. # ** Scrolling Message System / Bold & Italic
  829. #------------------------------------------------------------------------------
  830. # Slipknot (http://www.creationasylum.net/)
  831. # Version 1.0
  832. # May 13, 2007
  833. #==============================================================
  834.  
  835. class Window_Message < Window_Selectable
  836.   #--------------------------------------------------------------------------
  837.   # * Alias Listing
  838.   #--------------------------------------------------------------------------
  839.   alias slipknot_sms_bi_evalextra eval_extra
  840.   alias slipknot_sms_bi_repbcod replace_basic_code
  841.   #--------------------------------------------------------------------------
  842.   # * Eval Extra
  843.   #--------------------------------------------------------------------------
  844.   def eval_extra(bitmap)
  845.     slipknot_sms_bi_evalextra(bitmap)
  846.     if @c == "\005"
  847.       bitmap.font.bold = !bitmap.font.bold
  848.       @c = ''
  849.     end
  850.     if @c == "\006"
  851.       bitmap.font.italic = !bitmap.font.italic
  852.       @c = ''
  853.     end
  854.   end
  855.   #--------------------------------------------------------------------------
  856.   # * Replace Basic Code
  857.   #--------------------------------------------------------------------------
  858.   def replace_basic_code
  859.     slipknot_sms_bi_repbcod
  860.     @text.gsub!('\\b', "\005")
  861.     @text.gsub!('\\i', "\006")
  862.   end
  863. end
  864.  
  865. #==============================================================
  866. # ** Scrolling Message System / Furigana
  867. #------------------------------------------------------------------------------
  868. # LiTTleDRAgo (http://littledrago.blogspot.com/)
  869. # Version 1.0
  870. # June 27, 2013
  871. #==============================================================
  872.  
  873. class Window_Message < Window_Selectable
  874.   #--------------------------------------------------------------------------
  875.   # * Alias Listing
  876.   #--------------------------------------------------------------------------
  877.   alias drg3x4dkc2dx_evalextra eval_extra
  878.   alias drg3x4dkc2dx_evaltext eval_text
  879.   alias drg3x4dkc2dx_repbcod replace_basic_code
  880.   #--------------------------------------------------------------------------
  881.   # * Eval Extra
  882.   #--------------------------------------------------------------------------
  883.   def eval_extra(bitmap)
  884.     drg3x4dkc2dx_evalextra(bitmap)
  885.     if @c == "\031"
  886.       @text.sub!(/\[(.*?),(.*?)\]/, '')
  887.       text = [$1,$2,bitmap.font.size]
  888.       bitmap.font.size -= 6
  889.       text << bitmap.text_size(text[1])
  890.       @furigana = Bitmap.new(text[3].width,text[3].height)
  891.       @furigana.font = bitmap.font.dup
  892.       @furigana.draw_text(0,0,text[3].width,text[3].height,text[1])
  893.       bitmap.font.size = text[2]
  894.       text << bitmap.text_size(text[0])
  895.       x1 = [@ex + @x + (text[4].width/2 - text[3].width/2),0].max
  896.       y1 = Message::Height
  897.       x2 = [x1,self.width-text[3].width].min
  898.       y2 = y1 * @y - y1/10
  899.       @furigana_position = [x2,y2]
  900.       @c = text[0]
  901.     end
  902.   end
  903.   #--------------------------------------------------------------------------
  904.   # * Eval Extra
  905.   #--------------------------------------------------------------------------
  906.   def eval_text(*args)
  907.     result = drg3x4dkc2dx_evaltext(*args)
  908.     if @furigana && !@furigana.disposed?
  909.       x,y = @furigana_position
  910.       args[0].blt(x, y,@furigana,@furigana.rect) if !args[1]
  911.       @furigana.dispose
  912.     end
  913.     return result
  914.   end
  915.   #--------------------------------------------------------------------------
  916.   # * Replace Basic Code
  917.   #--------------------------------------------------------------------------
  918.   def replace_basic_code
  919.     drg3x4dkc2dx_repbcod
  920.     @text.gsub!(/\\[Rr]\[(.*?),(.*?)\]/) { "\031[#$1,#$2]" }
  921.   end
  922. end
  923.  
  924. #==============================================================
  925. # ** Scrolling Message System / Condition Text
  926. #------------------------------------------------------------------------------
  927. # LiTTleDRAgo (http://littledrago.blogspot.com/)
  928. # Version 1.0
  929. # June 27, 2013
  930. #==============================================================
  931.  
  932. class Window_Message < Window_Selectable
  933.   #--------------------------------------------------------------------------
  934.   # * Alias Listing
  935.   #--------------------------------------------------------------------------
  936.   alias drg3x4dkc2dy_repbcod replace_basic_code
  937.   #--------------------------------------------------------------------------
  938.   # * Replace Basic Code
  939.   #--------------------------------------------------------------------------
  940.   def replace_basic_code
  941.     drg3x4dkc2dy_repbcod
  942.     @text.gsub!(/\\[Ii][Ff]\[(.*?),(.*?)\]/) {
  943.           interpreter.send(:eval,"#$1") ? "#$2" : ""}
  944.     @text.gsub!(/\\[Uu][Nn][Ll][Ee][Ss][Ss]\[(.*?),(.*?)\]/) {
  945.           interpreter.send(:eval,"#$1") ? "" : "#$2"}
  946.   end
  947. end
  948.  
  949.  
  950. #==============================================================
  951. # ** Scrolling Message System / Font Name & Size
  952. #------------------------------------------------------------------------------
  953. # LiTTleDRAgo (http://littledrago.blogspot.com/)
  954. # Version 1.0
  955. # July 04, 2013
  956. #==============================================================
  957.  
  958. class Window_Message < Window_Selectable
  959.   #--------------------------------------------------------------------------
  960.   # * Alias Listing
  961.   #--------------------------------------------------------------------------
  962.   alias drg3x4dkc2dz_evalextra eval_extra
  963.   alias drg3x4dkc2dz_repbcod replace_basic_code
  964.   #--------------------------------------------------------------------------
  965.   # * Eval Extra
  966.   #--------------------------------------------------------------------------
  967.   def eval_extra(bitmap)
  968.     drg3x4dkc2dz_evalextra(bitmap)
  969.     if @c == "\023"
  970.       @text.sub!(/\[(.*?)\]/,  '')
  971.       font = $1
  972.       if font.to_i <= 0
  973.         bitmap.font.name = font
  974.       else
  975.         bitmap.font.size = font.to_i
  976.       end
  977.       @c = ''
  978.     end
  979.   end
  980.   #--------------------------------------------------------------------------
  981.   # * Replace Basic Code
  982.   #--------------------------------------------------------------------------
  983.   def replace_basic_code
  984.     drg3x4dkc2dz_repbcod
  985.     @text.gsub!(/\\[Ff][Oo][Nn][Tt]\[(.*?),([0-9]+)\]/) { "\\font[#$1]\\font[#$2]" }
  986.     @text.gsub!(/\\[Ff][Oo][Nn][Tt]\[(.*?)\]/) { "\023[#$1]" }
  987.   end
  988. end
  989.  
  990.  
  991. #==============================================================
  992. # ** Scrolling Message System / Game Related
  993. #------------------------------------------------------------------------------
  994. # LiTTleDRAgo (http://littledrago.blogspot.com/)
  995. # Version 1.0
  996. # July 04, 2013
  997. #==============================================================
  998.  
  999. class Window_Message < Window_Selectable
  1000.   #--------------------------------------------------------------------------
  1001.   # * Alias Listing
  1002.   #--------------------------------------------------------------------------
  1003.   alias drg3x4dkc2ea_repbcod replace_basic_code
  1004.   #--------------------------------------------------------------------------
  1005.   # * Replace Basic Code
  1006.   #--------------------------------------------------------------------------
  1007.   def replace_basic_code
  1008.     @text.gsub!(/\\[Ii]&[Nn]\[([EeIiWwAaSsPp])([0-9]+)\]/) {
  1009.        entity = "#$1#$2"
  1010.        "\\i[#{entity}] \\n[#{entity}]"}
  1011.     @text.gsub!(/\\[Ii]\[([EeIiWwAaSsPp])([0-9]+)\]/) {
  1012.         entity = case $1.downcase
  1013.           when 'i' then $data_items[$2.to_i]
  1014.           when 'w' then $data_weapons[$2.to_i]
  1015.           when 'a' then $data_armors[$2.to_i]
  1016.           when 's' then $data_skills[$2.to_i]
  1017.           end
  1018.         entity != nil ? "\002[#{entity.icon_name}]" : '' }
  1019.     @text.gsub!(/\\[Ii]\[(.*?)\]/) { "\002[#$1]" }
  1020.     @text.gsub!(/\\[Nn]\[([EeIiWwAaSsPp])([0-9]+)\]/) {
  1021.       entity = case $1.downcase
  1022.         when 'e' then $data_enemies[$2.to_i]
  1023.         when 'i' then $data_items[$2.to_i]
  1024.         when 'w' then $data_weapons[$2.to_i]
  1025.         when 'a' then $data_armors[$2.to_i]
  1026.         when 's' then $data_skills[$2.to_i]
  1027.         when 'p' then $game_map.events[$2.to_i]
  1028.       end
  1029.       entity != nil ? entity.name : ''   }
  1030.     @text.gsub!(/\\[$]\[([EeIiWwAaSsPp])([0-9]+)\]/) {
  1031.         e = case $1.downcase
  1032.           when 'i' then $data_items[$2.to_i]
  1033.           when 'w' then $data_weapons[$2.to_i]
  1034.           when 'a' then $data_armors[$2.to_i]
  1035.           when 's' then $data_skills[$2.to_i]
  1036.           end
  1037.         e != nil ? e.is_a?(RPG::Skill) ? e.sp_cost : e.price : '' }
  1038.     @text.gsub!(/\\[Mm][Aa][Pp]/) {
  1039.         load_data('Data/MapInfos.rxdata')[$game_map.map_id].name }
  1040.     drg3x4dkc2ea_repbcod
  1041.   end
  1042. end
  1043. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement