Advertisement
roninator2

Item Name Text Scroll - Item Scene

Dec 16th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.04 KB | None | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Item Window Name Scroll Text           ║  Version: 1.03     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║ Scroll the text when too long to fit          ║    17 Sep 2023     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires:                                                          ║
  11. # ║                                                                    ║
  12. # ║   TsukiHime Instance Items                                         ║
  13. # ║   Intended to assist with Item Affixes                             ║
  14. # ║                                                                    ║
  15. # ╚════════════════════════════════════════════════════════════════════╝
  16. # ╔════════════════════════════════════════════════════════════════════╗
  17. # ║ Brief Description:                                                 ║
  18. # ║       Scroll names in item window                                  ║
  19. # ╚════════════════════════════════════════════════════════════════════╝
  20. # ╔════════════════════════════════════════════════════════════════════╗
  21. # ║ Instructions:                                                      ║
  22. # ║                                                                    ║
  23. # ║  Plug and play                                                     ║
  24. # ║  Change the speed number if you like                               ║
  25. # ║                                                                    ║
  26. # ║  Designed for the default system and settings                      ║
  27. # ║  Modifications may need to be done if not using defaults           ║
  28. # ║                                                                    ║
  29. # ╚════════════════════════════════════════════════════════════════════╝
  30. # ╔════════════════════════════════════════════════════════════════════╗
  31. # ║ Updates:                                                           ║
  32. # ║ 1.03 - 17 Sep 2023 - Script finished                               ║
  33. # ║                                                                    ║
  34. # ╚════════════════════════════════════════════════════════════════════╝
  35. # ╔════════════════════════════════════════════════════════════════════╗
  36. # ║ Credit:                                                            ║
  37. # ║   RPG Maker Source                                                 ║
  38. # ║   Roninator2                                                       ║
  39. # ╚════════════════════════════════════════════════════════════════════╝
  40. # ╔════════════════════════════════════════════════════════════════════╗
  41. # ║ Terms of use:                                                      ║
  42. # ║  Follow the original Authors terms of use where applicable         ║
  43. # ║    - When not made by me (Roninator2)                              ║
  44. # ║  Free for all uses in RPG Maker except nudity                      ║
  45. # ║  Anyone using this script in their project before these terms      ║
  46. # ║  were changed are allowed to use this script even if it conflicts  ║
  47. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  48. # ║  No part of this code can be used with AI programs or tools        ║
  49. # ║  Credit must be given                                              ║
  50. # ╚════════════════════════════════════════════════════════════════════╝
  51.  
  52. module R2_Item_Scroll_Name
  53.   Item_Speed = 0.8 # anything from 0.4 to 1.2 is ok
  54.   Item_length = 16
  55. end
  56.  
  57. # ╔════════════════════════════════════════════════════════════════════╗
  58. # ║                      End of editable region                        ║
  59. # ╚════════════════════════════════════════════════════════════════════╝
  60.  
  61. #==============================================================================
  62. # ** Window_ItemList
  63. #==============================================================================
  64.  
  65. class Window_ItemList < Window_Selectable
  66.  
  67.   #--------------------------------------------------------------------------
  68.   # * Object Initialization
  69.   #--------------------------------------------------------------------------
  70.   alias r2_text_list_scroll_init   initialize
  71.   def initialize(x, y, width, height)
  72.     @r2_scrolling_text_line ||= {}
  73.     r2_text_list_scroll_init(x, y, width, height)
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # * Draw Item Name
  77.   #     enabled : Enabled flag. When false, draw semi-transparently.
  78.   #--------------------------------------------------------------------------
  79.   def draw_item_name(item, x, y, enabled = true, width = 200)
  80.     return unless item
  81.     draw_icon(item.icon_index, x, y, enabled)
  82.     change_color(normal_color, enabled)
  83.     cw = contents.text_size(item.name).width
  84.     if cw < width
  85.       draw_text(x + 24, y, width, line_height, item.name)
  86.     else
  87.       set_text(item.id, x, y, item.name, width, cw)
  88.     end
  89.   end
  90. #=============================================================================
  91.   #--------------------------------------------------------------------------
  92.   # * Update.                                                           [MOD]
  93.   #--------------------------------------------------------------------------
  94.   alias r2_update_text_scroll   update
  95.   def update
  96.     # Original method.
  97.     r2_update_text_scroll
  98.     # data -> key = id -> 0 = text, 1 = speed, 2 = width, 3 = bitmap,
  99.     # 4 - position {x,y}, 5 - text width, 6 - placement, 7 - direction <- ->
  100.     # 8 - viewport, 9 - type
  101.     refresh if @r2_scrolling_text_line == {} && self.active
  102.     return if @r2_scrolling_text_line == {}
  103.     dispose_list if !self.active
  104.     return if !self.active
  105.     return if (@index >= (@data.size - 1)) && SceneManager.scene_is?(Scene_Equip)
  106.     return if (@index < 0) || (@index >= @data.size)
  107.     scrollitem = @data[@index].nil? ? -1 : @data[@index].id
  108.     @r2_scrolling_text_line.each do |id, data|
  109.       next if scrollitem != id
  110.       if data[3].nil?
  111.         refresh
  112.         return
  113.       end
  114.       data[3].visible = visible
  115.       # Advance the image position
  116.       if (data[7] == 0)
  117.         # Change the offset X to scroll.
  118.         data[6] += (1.0 * data[1]).to_f
  119.         data[3].ox = data[6] - data[4][0]
  120.       elsif (data[7] == 1)
  121.         data[6] -= (1.0 * data[1]).to_f
  122.         data[3].ox = data[6] - data[4][0]
  123.       end
  124.       if (data[6] >= (data[5] - (data[2] / 5 * 4))) && (data[4][0] == 0)
  125.         data[7] = 1
  126.       elsif ((data[6] + data[4][0] - (data[2] / 5 * 3))) >= (data[5] + data[4][0]) && (data[4][0] != 0)
  127.         data[7] = 1
  128.       elsif (data[6] <= 0) && (data[4][0] == 0)
  129.         data[7] = 0
  130.       elsif (data[6]) <= (data[4][0]) && (data[4][0] != 0)
  131.         data[7] = 0
  132.       end
  133.     end
  134.   end
  135.   #--------------------------------------------------------------------------
  136.   # * Set Text.                                                         [REP]
  137.   #--------------------------------------------------------------------------
  138.   def set_text(id, x, y, text, width, cw)
  139.     # New text?
  140.     # data -> key = id -> 0 = text, 1 = speed, 2 = width, 3 = bitmap,
  141.     # 4 - position, 5 - text width, 6 - placement, 7 - direction,
  142.     # 8 - viewport
  143.     @r2_scrolling_text_line ||= {}
  144.     if @r2_scrolling_text_line.empty? || @r2_scrolling_text_line[id].nil? ||
  145.         text != @r2_scrolling_text_line[id][1]
  146.       # Dispose the Scrolling Help objects if needed.
  147.       r2_scrolling_text_dispose(id) if @r2_scrolling_text_line[id] != nil
  148.       speed = R2_Item_Scroll_Name::Item_Speed
  149.       if cw > width
  150.         # draw the line as a scrolling line.
  151.         @r2_scrolling_text_line[id] = [text, speed, width, nil, [x, y], cw,
  152.           x, 0, nil]
  153.         r2_scrolling_text_create(id, x, y, text, width)
  154.       end
  155.     end
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # * Scrolling Help Create.                                            [NEW]
  159.   #--------------------------------------------------------------------------
  160.   def r2_scrolling_text_create(id, x, y, text, width)
  161.     # draw normal text if not at index position
  162.     if SceneManager.scene_is?(Scene_Equip)
  163.       if (@index < 0) || (@index >= (@data.size - 1))
  164.         scrollitem = -1
  165.       else
  166.         scrollitem = @data[@index].id
  167.       end
  168.     else
  169.       if (@index < 0) || (@index >= @data.size)
  170.         scrollitem = -1
  171.       else
  172.         scrollitem = @data[@index].id
  173.       end
  174.     end
  175.     if scrollitem != id
  176.       text = text[0..(R2_Item_Scroll_Name::Item_length - 1)] + "..."
  177.       draw_text(x + 24, y, width, line_height, text)
  178.       return
  179.     end
  180.     # Create a Bitmap instance to draw the text into it.
  181.     line_bitmap = Bitmap.new(@r2_scrolling_text_line[id][5] + 24, calc_line_height(text))
  182.     # Save current Window's Bitmap.
  183.     original_contents = contents
  184.     # Set the recently created Bitmap as the Window's Bitmap.
  185.     self.contents = line_bitmap
  186.     # Use the default method to draw the text into it.
  187.     draw_text_ex(24, 0, text)
  188.     # Reset back the Window's Bitmap to the original one.
  189.     self.contents = original_contents
  190.     # Viewport for the Scrolling Line.
  191.     @r2_scrolling_text_line[id][8] = Viewport.new(
  192.       x + standard_padding + 24,
  193.       self.y + (@index / col_max - self.top_row) * 24 + standard_padding,
  194.       width,
  195.       line_bitmap.height
  196.     )
  197.     # Put the recently created Viewport on top of this Window.
  198.     @r2_scrolling_text_line[id][8].z = viewport ? viewport.z + 1 : z + 1
  199.     # Create a Plane instance for the scrolling effect.
  200.     @r2_scrolling_text_line[id][3] = Plane.new(@r2_scrolling_text_line[id][8])
  201.     # Assign the recently created Bitmap (where the line is drawn) to it.
  202.     @r2_scrolling_text_line[id][3].bitmap = line_bitmap
  203.   end
  204.   #--------------------------------------------------------------------------
  205.   # * Scrolling Help Dispose.                                           [NEW]
  206.   #--------------------------------------------------------------------------
  207.   def r2_scrolling_text_dispose(id)
  208.     # Disposes Bitmap, Plane and Viewport.
  209.     if !@r2_scrolling_text_line[id][3].nil?
  210.       @r2_scrolling_text_line[id][3].bitmap.dispose
  211.       @r2_scrolling_text_line[id][3].dispose
  212.     end
  213.     # Prevents executing this method when the Plane (or Viewport) is disposed.
  214.     @r2_scrolling_text_line[id][3] = nil
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # * Dispose All values.                                               [NEW]
  218.   #--------------------------------------------------------------------------
  219.   def dispose_list
  220.     if @r2_scrolling_text_line != {}
  221.       @r2_scrolling_text_line.each do |key, entry|
  222.         r2_scrolling_text_dispose(key)
  223.       end
  224.     end
  225.     @r2_scrolling_text_line = {}
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Dispose.                                                          [MOD]
  229.   #--------------------------------------------------------------------------
  230.   def dispose
  231.     # Dispose Scrolling Help objects if needed.
  232.     if @r2_scrolling_text_line != {}
  233.       dispose_list
  234.     end
  235.     @r2_scrolling_text_line = {}
  236.     # Original method.
  237.     super
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # * Refresh
  241.   #--------------------------------------------------------------------------
  242.   alias r2_refresh_dispose_scroll_text  refresh
  243.   def refresh
  244.     if @r2_scrolling_text_line != {}
  245.       dispose_list
  246.     end
  247.     @r2_scrolling_text_line = {}
  248.     r2_refresh_dispose_scroll_text
  249.   end
  250.   #--------------------------------------------------------------------------
  251.   # * Cursor Movement Processing
  252.   #--------------------------------------------------------------------------
  253.   alias r2_cursor_index_move_refresh_draw process_cursor_move
  254.   def process_cursor_move
  255.     last_index = @index
  256.     r2_cursor_index_move_refresh_draw
  257.     refresh if @index != last_index
  258.   end
  259. end
  260.  
  261. class Scene_Item < Scene_ItemBase
  262.   #--------------------------------------------------------------------------
  263.   # * Item [Cancel]
  264.   #--------------------------------------------------------------------------
  265.   alias r2_item_scroll_name_refresh_on_cancel   on_item_cancel
  266.   def on_item_cancel
  267.     r2_item_scroll_name_refresh_on_cancel
  268.     @item_window.refresh
  269.   end
  270. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement