Advertisement
roninator2

Item Window Item Name Scroll Text

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