Advertisement
DrDhoom

[RGSS3] DYK Marquee

Oct 8th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.95 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # • Dhoom DYK Marquee v1.0
  4. # -- Last Updated: 2014.10.09
  5. # -- Level: Easy
  6. # -- Requires: None
  7. #
  8. #==============================================================================
  9.  
  10. module Dhoom
  11.   module DYKMarquee
  12.     TEXTS = [
  13.     #Put additional "\" before escape character
  14.     "\\I[5] this is confusion icon",
  15.     "\\N[1] is the \\C[2]first actor\\C[0] in database",
  16.     ]
  17.    
  18.     #Text scroll direction, 0 = Right to Left, 1 = Left to Right
  19.     DIRECTION = 0
  20.     #Scroll speed
  21.     SPEED = 1
  22.     #0 = Normal Window, 1 = Dim Background, 2 = Transparent, 3 = Custom Image
  23.     BACKGROUND = 0
  24.     #Custom image filename, put it in Graphics/System folder
  25.     IMAGE_FILENAME = "Window"
  26.     #Dim background colors
  27.     DIM_COLOR = [[0,0,0],[0,0,0,160]]
  28.     #Window position [X,Y]
  29.     POSITION = [0,0]
  30.     #Window size [width, height]
  31.     SIZE = [544,48]
  32.     #Text font
  33.     TEXT_FONT = "Comic Sans MS"
  34.     #Text size
  35.     TEXT_SIZE = 28
  36.   end
  37. end
  38.  
  39. $imported = {} if $imported.nil?
  40. $imported["DHDYKMarquee"] = true
  41.  
  42. class Window_Marquee < Window_Base
  43.   include Dhoom::DYKMarquee
  44.   attr_accessor :background
  45.   def initialize(x, y, width, height)
  46.     super(x, y, width, height)
  47.     @background = BACKGROUND
  48.     self.arrows_visible = false
  49.     self.opacity = 0 if @background != 0
  50.     refresh
  51.   end
  52.  
  53.   def refresh
  54.     create_back_bitmap
  55.     create_back_sprite
  56.     draw_dyk_text
  57.   end
  58.  
  59.   def create_back_bitmap
  60.     if @background == 3
  61.       @back_bitmap = Cache.system(IMAGE_FILENAME)
  62.     else
  63.       @back_bitmap = Bitmap.new(width, height)
  64.       rect1 = Rect.new(0, 0, width, 12)
  65.       rect2 = Rect.new(0, 12, width, height - 24)
  66.       rect3 = Rect.new(0, height - 12, width, 12)    
  67.       back_color1 = Color.new(DIM_COLOR[0][0],DIM_COLOR[0][1],DIM_COLOR[0][2],!DIM_COLOR[0][3].nil? ? DIM_COLOR[0][3] : 255)
  68.       back_color2 = Color.new(DIM_COLOR[1][0],DIM_COLOR[1][1],DIM_COLOR[1][2],!DIM_COLOR[1][3].nil? ? DIM_COLOR[1][3] : 255)
  69.       @back_bitmap.gradient_fill_rect(rect1, back_color2, back_color1, true)
  70.       @back_bitmap.fill_rect(rect2, back_color1)
  71.       @back_bitmap.gradient_fill_rect(rect3, back_color1, back_color2, true)
  72.     end
  73.   end
  74.  
  75.   def create_back_sprite
  76.     @back_sprite = Sprite.new
  77.     @back_sprite.bitmap = @back_bitmap
  78.     update_back_sprite
  79.   end
  80.  
  81.   def draw_dyk_text
  82.     random = rand(TEXTS.size)
  83.     text = convert_escape_characters(TEXTS[random])
  84.     reset_font_settings
  85.     w = contents.text_size(text)
  86.     contents.dispose
  87.     self.contents = Bitmap.new(w.width, contents_height)
  88.     reset_font_settings
  89.     draw_text_ex(0, 0, TEXTS[random])
  90.     self.ox =  -(self.width-contents.width) if DIRECTION == 0
  91.   end
  92.  
  93.   def reset_font_settings
  94.     change_color(normal_color)
  95.     contents.font = Font.new(TEXT_FONT)
  96.     contents.font.size = TEXT_SIZE
  97.     contents.font.bold = Font.default_bold
  98.     contents.font.italic = Font.default_italic
  99.   end
  100.  
  101.   def process_draw_icon(icon_index, pos)
  102.     draw_icon(icon_index, pos[:x], pos[:y]+(contents.font.size-24)/2)
  103.     pos[:x] += 24
  104.   end
  105.  
  106.   def update
  107.     super
  108.     update_back_sprite
  109.     update_scroll
  110.   end
  111.  
  112.   def update_back_sprite
  113.     @back_sprite.visible = [1,3].include?(@background)
  114.     @back_sprite.z = z - 1
  115.     @back_sprite.x = x
  116.     @back_sprite.y = y
  117.   end
  118.  
  119.   def update_scroll
  120.     if DIRECTION == 0
  121.       self.ox += SPEED
  122.       if self.ox >= contents.width
  123.         self.ox = -self.width
  124.       end
  125.     else      
  126.       self.ox -= SPEED
  127.       if self.ox <= -self.width
  128.         self.ox = contents.width
  129.       end
  130.     end
  131.   end
  132.  
  133.   def dispose
  134.     super
  135.     @back_sprite.dispose
  136.   end
  137. end
  138.  
  139. class Scene_Title < Scene_Base
  140.   include Dhoom::DYKMarquee
  141.   alias dhoom_marquee_scntitle_start start
  142.   def start
  143.     dhoom_marquee_scntitle_start
  144.     @marquee_window = Window_Marquee.new(POSITION[0], POSITION[1], SIZE[0], SIZE[1])
  145.   end
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement