Advertisement
roninator2

Status Item Name Scroll Text

Nov 17th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.33 KB | Source Code | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Status Item Name Scroll Text           ║  Version: 1.01     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║   Adjust text display                         ║    17 Sep 2023     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires: TsukiHime Instance Items                                 ║
  11. # ║                                                                    ║
  12. # ╚════════════════════════════════════════════════════════════════════╝
  13. # ╔════════════════════════════════════════════════════════════════════╗
  14. # ║ Brief Description: Scroll the text when too long to fit            ║
  15. # ║       Intended to assist with Item Affixes                         ║
  16. # ╚════════════════════════════════════════════════════════════════════╝
  17. # ╔════════════════════════════════════════════════════════════════════╗
  18. # ║ Instructions:                                                      ║
  19. # ║  Plug and play                                                     ║
  20. # ║  Change the speed number if you like                               ║
  21. # ║                                                                    ║
  22. # ║  Designed for the default system and settings                      ║
  23. # ║  Modifications may need to be done if not using defaults           ║
  24. # ║                                                                    ║
  25. # ╚════════════════════════════════════════════════════════════════════╝
  26. # ╔════════════════════════════════════════════════════════════════════╗
  27. # ║ Updates:                                                           ║
  28. # ║ 1.00 - 17 Sep 2023 - Script finished                               ║
  29. # ║ 1.01 - added support for item rarity script                        ║
  30. # ║                                                                    ║
  31. # ╚════════════════════════════════════════════════════════════════════╝
  32. # ╔════════════════════════════════════════════════════════════════════╗
  33. # ║ Credits and Thanks:                                                ║
  34. # ║   Roninator2                                                       ║
  35. # ║   RPG Maker Source                                                 ║
  36. # ╚════════════════════════════════════════════════════════════════════╝
  37. # ╔════════════════════════════════════════════════════════════════════╗
  38. # ║ Terms of use:                                                      ║
  39. # ║  Follow the original Authors terms of use where applicable         ║
  40. # ║    - When not made by me (Roninator2)                              ║
  41. # ║  Free for all uses in RPG Maker except nudity                      ║
  42. # ║  Anyone using this script in their project before these terms      ║
  43. # ║  were changed are allowed to use this script even if it conflicts  ║
  44. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  45. # ║  No part of this code can be used with AI programs or tools        ║
  46. # ║  Credit must be given                                              ║
  47. # ╚════════════════════════════════════════════════════════════════════╝
  48.  
  49.  
  50. module R2_Item_Scroll_Name
  51.   Status_Speed = 0.8 # anything from 0.4 to 1.2 is ok
  52.   Status_length = 16
  53. end
  54.  
  55. #==============================================================================
  56. # ** Window_Status
  57. #==============================================================================
  58.  
  59. class Window_Status < Window_Selectable
  60.  
  61.   #--------------------------------------------------------------------------
  62.   # * Object Initialization
  63.   #--------------------------------------------------------------------------
  64.   alias r2_text_scroll_init   initialize
  65.   def initialize(actor)
  66.     @r2_scrolling_status_text_line ||= {}
  67.     r2_text_scroll_init(actor)
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # * Draw Item Name
  71.   #     enabled : Enabled flag. When false, draw semi-transparently.
  72.   #--------------------------------------------------------------------------
  73.   def draw_item_name(item, x, y, enabled = true, width = 175)
  74.     return unless item
  75.     draw_icon(item.icon_index, x, y, enabled)
  76.     if $imported[:TH_ItemRarity]
  77.       change_color(item.rarity_colour, enabled)
  78.     else
  79.       change_color(normal_color, enabled)
  80.     end
  81.     cw = contents.text_size(item.name).width
  82.     if cw < width
  83.       draw_text(x + 24, y, width, line_height, item.name)
  84.     else
  85.       set_text(item.id, x, y, item.name, width)
  86.     end
  87.   end
  88. #=============================================================================
  89.   #--------------------------------------------------------------------------
  90.   # * Update.                                                           [MOD]
  91.   #--------------------------------------------------------------------------
  92.   alias r2_update_status_text_scroll   update
  93.   def update
  94.     # Original method.
  95.     r2_update_status_text_scroll
  96.     # data -> key = id -> 0 = text, 1 = speed, 2 = width, 3 = bitmap,
  97.     # 4 - position {x,y}, 5 - text width, 6 - placement, 7 - direction <- ->
  98.     # 8 - viewport, 9 - type
  99.     return if @r2_scrolling_status_text_line.nil? || @r2_scrolling_status_text_line.empty?
  100.     @r2_scrolling_status_text_line.each do |id, data|
  101.       # Advance the image position
  102.       # Change the offset X to scroll.
  103.       if (data[7] == 0)
  104.         data[6] += (1.0 * data[1]).to_f
  105.         data[3].ox = data[6] + data[2]
  106.       elsif (data[7] == 1)
  107.         data[6] -= (1.0 * data[1]).to_f
  108.         data[3].ox = data[6] + data[2]
  109.       end
  110.       if (data[6] >= (data[5] + data[2] - (data[2] / 5 * 4) + 10))
  111.         data[7] = 1
  112.       elsif (data[6] <= (data[5] - (data[2] / 5 * 4) + 10))
  113.         data[7] = 0
  114.       end
  115.     end
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # * Set Text.                                                         [REP]
  119.   #--------------------------------------------------------------------------
  120.   def set_text(id, x, y, text, width)
  121.     # New text?
  122.     # data -> key = id -> 0 = text, 1 = speed, 2 = width, 3 = bitmap,
  123.     # 4 - position, 5 - text width, 6 - placement, 7 - direction,
  124.     # 8 - viewport
  125.     @r2_scrolling_status_text_line ||= {}
  126.     cw = contents.text_size(text).width
  127.     if @r2_scrolling_status_text_line.empty? || @r2_scrolling_status_text_line[id].nil? ||
  128.         text != @r2_scrolling_status_text_line[id][1]
  129.       # Dispose the Scrolling Help objects if needed.
  130.       r2_scrolling_text_dispose(id) if @r2_scrolling_status_text_line[id] != nil
  131.       speed = R2_Item_Scroll_Name::Status_Speed
  132.       x = x + self.x
  133.       if cw > width
  134.         # draw the line as a scrolling line.
  135.         @r2_scrolling_status_text_line[id] = [text, speed, width, nil, [x, y], cw,
  136.           x, 0, nil]
  137.         r2_scrolling_text_create(id, x, y, text, width)
  138.       end
  139.     end
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # * Scrolling Help Create.                                            [NEW]
  143.   #--------------------------------------------------------------------------
  144.   def r2_scrolling_text_create(id, x, y, text, width)
  145.     # Create a Bitmap instance to draw the text into it.
  146.     line_bitmap = Bitmap.new(@r2_scrolling_status_text_line[id][5] + 24, calc_line_height(text))
  147.     # Save current Window's Bitmap.
  148.     original_contents = contents
  149.     # Set the recently created Bitmap as the Window's Bitmap.
  150.     self.contents = line_bitmap
  151.     # Use the default method to draw the text into it.
  152.     draw_text_ex(24, 0, text)
  153.     # Reset back the Window's Bitmap to the original one.
  154.     self.contents = original_contents
  155.     # Viewport for the Scrolling Line.
  156.     @r2_scrolling_status_text_line[id][8] = Viewport.new(
  157.       x + standard_padding + 24,
  158.       self.y + y + standard_padding,
  159.       width,
  160.       line_bitmap.height
  161.     )
  162.     # Put the recently created Viewport on top of this Window.
  163.     @r2_scrolling_status_text_line[id][8].z = viewport ? viewport.z + 1 : z + 1
  164.     # Create a Plane instance for the scrolling effect.
  165.     @r2_scrolling_status_text_line[id][3] = Plane.new(@r2_scrolling_status_text_line[id][8])
  166.     # Assign the recently created Bitmap (where the line is drawn) to it.
  167.     @r2_scrolling_status_text_line[id][3].bitmap = line_bitmap
  168.   end
  169.   #--------------------------------------------------------------------------
  170.   # * Scrolling Help Dispose.                                           [NEW]
  171.   #--------------------------------------------------------------------------
  172.   def r2_scrolling_text_dispose(id)
  173.     # Disposes Bitmap, Plane and Viewport.
  174.     @r2_scrolling_status_text_line[id][3].bitmap.dispose
  175.     @r2_scrolling_status_text_line[id][3].dispose
  176.     # Prevents executing this method when the Plane (or Viewport) is disposed.
  177.     @r2_scrolling_status_text_line[id][3] = nil
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # * Dispose.                                                          [MOD]
  181.   #--------------------------------------------------------------------------
  182.   def dispose
  183.     # Dispose Scrolling Help objects if needed.
  184.     if @r2_scrolling_status_text_line != {}
  185.       @r2_scrolling_status_text_line.each do |key, entry|
  186.         r2_scrolling_text_dispose(key)
  187.       end
  188.     end
  189.     @r2_scrolling_status_text_line = {}
  190.     # Original method.
  191.     super
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * Refresh
  195.   #--------------------------------------------------------------------------
  196.   alias r2_refresh_dispose_scroll_text  refresh
  197.   def refresh
  198.     if @r2_scrolling_status_text_line != {}
  199.       @r2_scrolling_status_text_line.each do |key, entry|
  200.         r2_scrolling_text_dispose(key)
  201.       end
  202.     end
  203.     @r2_scrolling_status_text_line = {}
  204.     r2_refresh_dispose_scroll_text
  205.   end
  206. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement