TheoAllen

Window Variable

Apr 13th, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.26 KB | None | 0 0
  1. # ============================================================================
  2. if true # <-- set true buat nge-enable. false buat disable
  3. # ============================================================================
  4. module THEO
  5.  
  6.   # Nampilin variable antara = <start>..<akhir>
  7.   VARIABLE_ID = 3..6
  8.  
  9.   # Maksimal nilai value ~
  10.   # misalnya u tulis 1 => 100 maka ntar di window bakal ditampilin
  11.   # nilai_variable[1] / 100
  12.   MAX_VALUE   = {
  13.     1 => 100,
  14.     2 => 100,
  15.     # tambahin sendiri ~
  16.   }
  17.  
  18.   # Kalo ga dispesifikasi sendiri di atas. Disini defaultnya :v
  19.   DEFAULT_MAX = 100
  20.  
  21.   # Warna buat gaugenya
  22.   # misalnya 1 => 0,0 >> berarti warnanya putih
  23.   # formatnya [index variablenya] =>[warna pertama, warna kedua],
  24.   # warna bisa dipilih dari 0 - 31
  25.   BAR_COLOR   = {
  26.     1 => [3,20],
  27.     2 => [1,25],
  28.     3 => [1,1],
  29.     4 => [1,1],
  30.     5 => [1,1],
  31.     6 => [1,1],
  32.     # tambahin sendiri
  33.   }
  34.  
  35.   # Variable icon ~
  36.   # index variable => index iconnya
  37.   VARIABLE_ICON = {
  38.     1 => 20,
  39.     2 => 30,
  40.     3 => 30,
  41.     4 => 30,
  42.     5 => 30,
  43.     # tambahin sendiri
  44.   }
  45.  
  46.   # Lebar gaugenya ~
  47.   BAR_WIDTH = "contents.width" # <-- pake string
  48.   # contents.width >> sama kek lebar window
  49.  
  50.   # ====== Settingan window ===== #
  51.   WINDOW_X      = 0    # Posisi X
  52.   WINDOW_Y      = 0    # Posisi Y
  53.   WINDOW_W      = Graphics.width    # Lebar
  54.   WINDOW_H      = Graphics.height   # Tinggi
  55.   FONT_SIZE     = 24  # gede kecilnya font. default 24
  56.   OPACITY       = 255 # transparansi default 255
  57.   SHOW_VALUE    = false # Kalo true, berarti ntar nampilin 1/100 (misalnya)
  58.  
  59.   # Untuk ngambil lebar layar game, tulis >> Graphics.width
  60.   # Untuk ngambil tinggi layar game, tulis >> Graphics.height
  61.  
  62. end
  63.  
  64. class Window_Variable < Window_Base
  65.  
  66.   def initialize(x,y,width,height)
  67.     super(x,y,width,height)
  68.     contents.font.size = THEO::FONT_SIZE
  69.     self.opacity = THEO::OPACITY
  70.     refresh
  71.   end
  72.  
  73.   def refresh
  74.     contents.clear
  75.     i = 1
  76.     for index in THEO::VARIABLE_ID
  77.       draw_variables(index,i)
  78.       i += 1
  79.     end
  80.   end
  81.  
  82.   def draw_variables(index,i)
  83.     current_value = $game_variables[index].to_f
  84.     max_value = (THEO::MAX_VALUE.include?(index) ? THEO::MAX_VALUE[index] : THEO::DEFAULT_MAX)
  85.     rate = current_value / max_value
  86.     y_pos = THEO::FONT_SIZE
  87.     icon_index = (THEO::VARIABLE_ICON.include?(index) ? THEO::VARIABLE_ICON[index] : 0)
  88.     color1 = text_color(THEO::BAR_COLOR[index][0])
  89.     color2 = text_color(THEO::BAR_COLOR[index][1])
  90.     draw_gauge(24,(y_pos*i) - y_pos,eval(THEO::BAR_WIDTH)-24,rate,color1,color2)
  91.     draw_icon(icon_index,0,(y_pos*i) - y_pos)
  92.     draw_current_and_max_values(0,(y_pos*i) - y_pos,contents.width,current_value.to_i,max_value,
  93.       text_color(0),text_color(0)) if THEO::SHOW_VALUE
  94.   end
  95.  
  96. end
  97.  
  98. class Scene_Map < Scene_Base
  99.  
  100.   alias scene_start start
  101.   def start
  102.     scene_start
  103.     create_variable_window
  104.   end
  105.  
  106.   def create_variable_window
  107.     wx = THEO::WINDOW_X
  108.     wy = THEO::WINDOW_Y
  109.     ww = THEO::WINDOW_W
  110.     wh = THEO::WINDOW_H
  111.     @window_variable = Window_Variable.new(wx,wy,ww,wh)
  112.     @window_variable.viewport = @viewport
  113.   end
  114.  
  115.   alias scene_update update
  116.   def update
  117.     scene_update
  118.     @window_variable.refresh
  119.   end
  120.  
  121. end
  122.  
  123. end
Advertisement
Add Comment
Please, Sign In to add comment