Advertisement
roninator2

Item Name Text Scroll - Status Screen

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