Advertisement
mikb89

[XP] Visible Debug v1.2

Jun 26th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 34.85 KB | None | 0 0
  1. # Visible Debug v. 1.2
  2. # XP version
  3. # by mikb89
  4.  
  5. # Details:
  6. #  Sometimes something goes wrong with events switches and variables. You don't
  7. #   know what is happening, you just know they don't work.
  8. #  With this script you can set in game a list of parameters to take under
  9. #   control and they'll be shown and updated in real time.
  10. #  This list includes:
  11. #   - switches and variables, events' self switches;
  12. #   - events, player, actors, battlers character's graphic;
  13. #   - events and player Through state and position;
  14. #   - tile id of current player position;
  15. #   - items, weapons, armors possession number;
  16. #   - battlers' hp, sp, atk, pdef, str, dex, int, agi, state;
  17. #   - actors' name & level (enemies don't have that);
  18. #   - others useful datas you can check here in configurations and can add your
  19. #     own.
  20.  
  21. # Configurations:
  22. module VDEBUG
  23.   # Here's a list of terms you can change as you want:
  24.   HELP_TEXT = "Enter: add/remove; Pag: change list." # Help yourself!
  25.   # These are what appears on F9 press:
  26.     CALL_CLASSIC_DEBUG_TEXT = "Debug call"
  27.     CALL_VDEBUG_SETTINGS_TEXT = "Visible Debug data"
  28.   # These are lists names:
  29.     SWITCH_LIST_TEXT = "Switches"
  30.     VARIABLE_LIST_TEXT = "Variables"
  31.     ITEM_LIST_TEXT = "Items"
  32.     ACTOR_LIST_TEXT = "Actors"
  33.     EVENT_LIST_TEXT = "Events"
  34.     DATA_LIST_TEXT = "Infos"
  35.     WEAPON_LIST_TEXT = "Weapons"
  36.     ARMOR_LIST_TEXT = "Armors"
  37.     ENEMY_LIST_TEXT = "Enemies"
  38.  
  39.   SHOW_EVENT_NAME = true # Show the event name. Set false for compatibility.
  40.   MOVE_AROUND_KEY = Input::ALT
  41.    # Pressing this key many times the debug sprite will move in the four angles
  42.    #  of the screen and then hide.
  43.   TIME_TO_LOSE = 1
  44.    # Suggest to leave it as it is (1). It's the time to wait before data update.
  45.    # Don't set 0 or less or script will stop.
  46.  
  47.   # The available data:
  48.   def self.collect_mainlist
  49.     poss = [] # You can change the order as you want, but can add nothing.
  50.     poss << [-1, $data_system.switches.size-1]
  51.     poss << [-2, $data_system.variables.size-1]
  52.     poss << [-3, $data_items.size-1]
  53.     poss << [-4, $data_actors.size-1]
  54.     poss << [0, $game_player]
  55.     poss << [-5, $game_map.events.size] # No need of -1 because it's a Hash. D:
  56.     poss << [-6, self.useful_data.size-1]
  57.     poss << [-7, $data_weapons.size-1]
  58.     poss << [-8, $data_armors.size-1]
  59.     poss << [-9, [$game_troop.enemies.size, 8].max]
  60.     poss # Unless you know what you're doing, of course.
  61.   end
  62.   def self.useful_data
  63.     da = [nil] # First value must be nil.
  64.     da << [["Party:", $game_party.actors.size], # Open an array, add the item.
  65.            ["G:", $game_party.gold], # First value is a string shown...
  66.            ["S:", $game_party.steps], # ...second value is the variable to show.
  67.            ["T:", self.adjust_time(Graphics.frame_count)], # Remember the ,
  68.            ["Sav:", $game_system.save_count]] # Close the data array.
  69.            # Will show: "Party: 3 G: 333 S: 33 T: 3:33 Sav: 3" with something
  70.            #  instead of 3.
  71.     da << ["Timer:", self.adjust_time($game_system.timer)]
  72.            # Even a single item can be added. And variable can also be a def.
  73.     da << [["Map id:", $game_map.map_id],
  74.            ["Size:", $game_map.width], ["x", $game_map.height]]
  75.            # You can, as an exercise, add for example the map name. :)
  76.    
  77.      # Add here your own! We want YOU for items adding.
  78.      
  79.     da # Here just returns the datas.
  80.   end
  81.   def self.adjust_time(value) # Example of a function. Returns formatted time.
  82.     value /= Graphics.frame_rate # Graphics.frame_rate = 1 second.
  83.     sec = value % 60 # Get the seconds.
  84.     value -= sec # Subtract them.
  85.     "#{value/60}:#{sprintf("%02d",sec)}" # Return min:sec formatted time string.
  86.   end
  87. end
  88.  
  89. #Codename: vdebug
  90.    
  91. ($imported ||= {})[:mikb89_vdebug] = true
  92.  
  93. # License:
  94. # - You can ask me to include support for other scripts as long as these scripts
  95. #   use the $imported[script] = true;
  96. # - You can modify and even repost my scripts, after having received a response
  97. #   by me. For reposting it, anyway, you must have done heavy edit or porting,
  98. #   you can't do a post with the script as is;
  99. # - You can use my scripts for whatever you want, from free to open to
  100. #   commercial games. I'd appreciate by the way if you let me know about what
  101. #   you're doing;
  102. # - You must credit me, if you use this script or part of it.
  103.  
  104. # * operations to let the Visible Debug configuration be available
  105.  
  106. class Scene_Map
  107. #class Scene_Map#def call_debug() <- rewritten
  108.   def call_debug
  109.     # Clear debug call flag
  110.     $game_temp.debug_calling = false
  111.     # Play decision SE
  112.     $game_system.se_play($data_system.decision_se)
  113.     # Straighten player position
  114.     $game_player.straighten
  115.     # Switch to debug screen
  116.     $scene = Scene_ChoiceDebug.new
  117.   end
  118. end
  119.  
  120. class Scene_ChoiceDebug
  121. #class Scene_ChoiceDebug#def main()
  122.   def main
  123.     # Make command window
  124.     s1 = VDEBUG::CALL_CLASSIC_DEBUG_TEXT
  125.     s2 = VDEBUG::CALL_VDEBUG_SETTINGS_TEXT
  126.     s3 = "Cancel"
  127.     @command_window = Window_Command.new(320, [s1, s2, s3])
  128.     @command_window.x = 320 - @command_window.width / 2
  129.     @command_window.y = 240 - @command_window.height / 2
  130.     # Execute transition
  131.     Graphics.transition
  132.     # Main loop
  133.     loop do
  134.       # Update game screen
  135.       Graphics.update
  136.       # Update input information
  137.       Input.update
  138.       # Frame Update
  139.       @command_window.update
  140.       if Input.trigger?(Input::B)
  141.         $game_system.se_play($data_system.cancel_se)
  142.         $scene = Scene_Map.new
  143.       elsif Input.trigger?(Input::C)
  144.         $game_system.se_play($data_system.decision_se)
  145.         $scene = case @command_window.index
  146.          when 0; Scene_Debug.new
  147.          when 1; Scene_VisibleDebug.new
  148.          when 2; Scene_Map.new
  149.         else; self; end
  150.       end
  151.       # Abort loop if screen is changed
  152.       if $scene != self
  153.         break
  154.       end
  155.     end
  156.     # Prepare for transition
  157.     Graphics.freeze
  158.     # Dispose of window
  159.     @command_window.dispose
  160.   end
  161. end
  162.  
  163. # * operations to let the Visible Debug sprite work
  164.  
  165. #class Game_Event#def name()
  166. (class Game_Event; def name; @event.name; end; end) if VDEBUG::SHOW_EVENT_NAME
  167.  # why isn't the event name readable by default? WHY???
  168.  
  169. class Scene_End
  170.   alias_method(:mainSE_b4_vdebug, :main) unless method_defined?(:mainSE_b4_vdebug)
  171. #class Scene_End#def main() <- aliased
  172.   def main
  173.     mainSE_b4_vdebug
  174.     # dispose the sprite on Shutdown and To title commands
  175.     $game_player.sdebug.dispose if !$scene || $scene.is_a?(Scene_Title)
  176.   end
  177. end
  178.  
  179. Thread.new{
  180. wait = VDEBUG::TIME_TO_LOSE
  181. loop do
  182.   wait -= 1
  183.   ($game_player.sdebug.update rescue nil) if $game_player && $scene && wait == 0
  184.   wait = VDEBUG::TIME_TO_LOSE if wait == 0
  185. end
  186. }
  187.  # USARE QUESTO SOTTO PER DEBUG DATO CHE IL THREAD NON DA MESSAGGI DI ERRORE!!!#
  188. #class Scene_Battle#Map
  189. #  alias upd update unless method_defined?(:upd)
  190. #  def update
  191. #    #($game_player.sdebug.update) if $game_player
  192. #    upd
  193. #  end
  194. #end
  195.  #DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG#
  196.  
  197. class Game_Player < Game_Character
  198.   # rely sprite on $game_player due to its reperibility. No, I'm not kidding :E
  199. #class Game_Player#def sdebug()
  200.   def sdebug
  201.     @sdebug ||= Sprite_Debug.new
  202.   end
  203. end
  204.  
  205. class Sprite_Debug < Sprite
  206.   attr_reader :infos
  207. #class Sprite_Debug#def initialize(i, pos, vp)
  208.   def initialize(i = nil, pos = 0, vp = nil)
  209.     if vp == nil; super(); else; super(vp); end # viewport?
  210.     self.infos = (i.is_a?(Array) ? i : [i]) # must be an array
  211.     self.z = 99999999 # a big value
  212.     self.opacity = 222 # little transparency
  213.     @last_values = []
  214.     @pos = pos - 1; move_around # position set
  215.   end
  216. #class Sprite_Debug#def move_around()
  217.   def move_around
  218.     @pos += 1; @pos %= 5 # increase position, modulate value
  219.     self.x = 320*(@pos%2) # right/left
  220.     self.y = 240*(@pos/2) # up/down/out
  221.   end
  222. #class Sprite_Debug#def infos=(i)
  223.   def infos=(i)
  224.     @infos = i
  225.     create_bitmap # once data change, we recreate the image
  226.   end
  227. #class Sprite_Debug#def marshal_dump()
  228.   def marshal_dump
  229.     [@infos, @pos, self.viewport] # values to save
  230.   end
  231. #class Sprite_Debug#def marshal_load(data)
  232.   def marshal_load(data)
  233.     initialize(data[0] || nil, data[1] || 0, data[2] || nil)
  234.   end
  235. #class Sprite_Debug#def create_bitmap()
  236.   def create_bitmap
  237.     self.bitmap.dispose if self.bitmap && !self.bitmap.disposed?
  238.     h = @infos.size*24
  239.     self.bitmap = Bitmap.new(320,[h,1].max) # h is 0, if there's no item
  240.     for i in 0...@infos.size
  241.       next if @infos[i] == nil || @infos[i].size < 2
  242.       draw_row(i, true) rescue nil
  243.     end
  244.   end
  245. #class Sprite_Debug#def draw_row(i, new)
  246.   def draw_row(i, new = false)
  247.     self.bitmap.fill_rect(0,i*24,320,24,Color.new(0,0,0,0)) unless new # no need
  248.                                                             # to clear if new
  249.     im = get_item(@infos[i]) # get the bitmap then blt it. This way I can get
  250.     return unless im         #  the same bitmap everywhere ^^
  251.     draw_placement(0, i*24)
  252.     self.bitmap.blt(0, i*24, im, im.rect)
  253.     im.dispose
  254.   end
  255. #class Sprite_Debug#def draw_placement(x, y)
  256.   def draw_placement(x, y)
  257.     self.bitmap.fill_rect(x+4,y+6,320-8,24-8,Color.new(0,0,0,128)) # bLackground
  258.   end
  259. #class Sprite_Debug#def collect(v)
  260.   def collect(v) # gets the relevant value(s) for each item
  261.     case v[0]
  262.       when 0; collect_player
  263.       when 1; $game_switches[v[1]]
  264.       when 2; $game_variables[v[1]]
  265.       when 3; $game_party.item_number(v[1])
  266.       when 4; collect_actor($game_actors[v[1]])
  267.       when 5; collect_event($game_map.events[v[1]])
  268.       when 6; collect_data(VDEBUG::useful_data[v[1]])
  269.       when 7; $game_party.weapon_number(v[1])
  270.       when 8; $game_party.armor_number(v[1])
  271.       when 9; collect_enemy($game_troop.enemies[v[1]-1])
  272.     else; nil; end
  273.   end
  274. #class Sprite_Debug#def collect_player()
  275.   def collect_player
  276.     da = []
  277.     da << $game_player.character_name
  278.     da << $game_player.character_hue
  279.     da << $game_player.direction
  280.     da << $game_player.x
  281.     da << $game_player.y
  282.     da << ($game_player.through || ($DEBUG && Input.press?(Input::CTRL)))
  283.     for i in [0, 1, 2]
  284.       da << $game_map.data[$game_player.x, $game_player.y, i]
  285.     end
  286.     da
  287.   end
  288. #class Sprite_Debug#def collect_actor(actor)
  289.   def collect_actor(actor)
  290.     da = []
  291.     da << actor.character_name
  292.     da << actor.character_hue
  293.     da << actor.name
  294.     da << actor.level
  295.     da << actor.hp
  296.     da << actor.maxhp
  297.     da << actor.sp
  298.     da << actor.maxsp
  299.     da << actor.states
  300.     da << actor.atk
  301.     da << actor.pdef
  302.     da << actor.str
  303.     da << actor.dex
  304.     da << actor.int
  305.     da << actor.agi
  306.     da
  307.   end
  308. #class Sprite_Debug#def collect_event(event)
  309.   def collect_event(event)
  310.     da = []
  311.     return da if event.nil?
  312.     da << event.character_name
  313.     da << event.character_hue
  314.     da << event.direction
  315.     da << event.x
  316.     da << event.y
  317.     da << event.through
  318.     for ss in ['A', 'B', 'C', 'D']
  319.       da << $game_self_switches[[$game_map.map_id, event.id, ss]]
  320.     end
  321.     da
  322.   end
  323. #class Sprite_Debug#def collect_data(data)
  324.   def collect_data(data)
  325.     da = []
  326.     return da if data.nil? || !data.is_a?(Array)
  327.     data = [data] unless data[0].is_a?(Array)
  328.     return da if data.size < 1
  329.     for val in data
  330.       da << val[1]
  331.     end
  332.     da
  333.   end
  334. #class Sprite_Debug#def collect_enemy(enemy)
  335.   def collect_enemy(enemy)
  336.     da = []
  337.     return da if enemy.nil?
  338.     da << enemy.battler_name
  339.     da << enemy.battler_hue
  340.     da << enemy.name
  341.     da << enemy.hp
  342.     da << enemy.maxhp
  343.     da << enemy.sp
  344.     da << enemy.maxsp
  345.     da << enemy.states
  346.     da << enemy.atk
  347.     da << enemy.pdef
  348.     da << enemy.str
  349.     da << enemy.dex
  350.     da << enemy.int
  351.     da << enemy.agi
  352.     da
  353.   end
  354. #class Sprite_Debug#def get_item(item, width, enabled)
  355.   def get_item(item, width = 320, enabled = true) # draw item in a bitmap
  356.     bit = Bitmap.new(width,24)
  357.     bit.font.color.alpha = blta = enabled ? 255 : 128
  358.     case item[0]
  359.     when -9; draw_container(VDEBUG::ENEMY_LIST_TEXT, item[1], bit)
  360.     when -8; draw_container(VDEBUG::ARMOR_LIST_TEXT, item[1], bit)
  361.     when -7; draw_container(VDEBUG::WEAPON_LIST_TEXT, item[1], bit)
  362.     when -6; draw_container(VDEBUG::DATA_LIST_TEXT, item[1], bit)
  363.     when -5; draw_container(VDEBUG::EVENT_LIST_TEXT, item[1], bit)
  364.     when -4; draw_container(VDEBUG::ACTOR_LIST_TEXT, item[1], bit)
  365.     when -3; draw_container(VDEBUG::ITEM_LIST_TEXT, item[1], bit)
  366.     when -2; draw_container(VDEBUG::VARIABLE_LIST_TEXT, item[1], bit)
  367.     when -1; draw_container(VDEBUG::SWITCH_LIST_TEXT, item[1], bit)
  368.     when 0; draw_player(item[1], bit, blta)
  369.     when 1; draw_switch(item[1], bit, blta)
  370.     when 2; draw_variable(item[1], bit, blta)
  371.     when 3; draw_item(item[1], bit, blta)
  372.     when 4; draw_actor(item[1], bit, blta)
  373.     when 5; draw_event(item[1], bit, blta)
  374.     when 6; draw_data(item[1], bit, blta)
  375.     when 7; draw_weapon(item[1], bit, blta)
  376.     when 8; draw_armor(item[1], bit, blta)
  377.     when 9; draw_enemy(item[1], bit, blta)
  378.     else; bit.dispose; bit = nil
  379.     end
  380.     bit
  381.   end
  382. #class Sprite_Debug#def draw_container(txt, n, bitmap)
  383.   def draw_container(txt, n, bitmap)
  384.     bitmap.draw_text(12, 0, bitmap.width-32, 24, txt)
  385.     bitmap.draw_text(0, 0, bitmap.width, 24, n > 0 ? "(#{n})" : "", 2)
  386.   end
  387. #class Sprite_Debug#def draw_player(item, bitmap, blta)
  388.   def draw_player(item, bitmap, blta)
  389.     if item != nil
  390.       bitmap.blt(0, 0, get_character_icon(item, true), Rect.new(0,0,24,24), blta)
  391.       bitmap.draw_text(24, 0, bitmap.width, 24, "(#{item.x};#{item.y})")
  392.       tile = ""
  393.       for i in [0, 1, 2]
  394.         tile += $game_map.data[item.x, item.y, i].to_s + (i != 2 ? ", " : "")
  395.       end
  396.       bitmap.draw_text(0, 0, bitmap.width-3, 24, "Tile: #{tile}", 2)
  397.       if (item.through || ($DEBUG && Input.press?(Input::CTRL)))
  398.         bitmap.font.size /= 2
  399.         bitmap.font.shadow = false if bitmap.font.respond_to?(:shadow)
  400.         col = false
  401.         for i in -1..2; for j in -1..1 # I could avoid all this, but...
  402.           next if i == j && i == 0
  403.           if i == 2
  404.             next if j != 0
  405.             col = true
  406.             i = 0
  407.           end
  408.           bitmap.font.color = col ? Color.new(0,0,0) : Color.new(99,33,55)
  409.           bitmap.draw_text(i, j+8, 23, 24, "T", 2)
  410.           break if i == j && j == 0
  411.         end; end
  412.       end
  413.     end
  414.   end
  415. #class Sprite_Debug#def draw_switch(n, bitmap, blta)
  416.   def draw_switch(n, bitmap, blta)
  417.     if n != nil
  418.       name = $data_system.switches[n]
  419.       bitmap.blt(0, 0, get_text_icon("S"), Rect.new(0,0,24,24), blta)
  420.       bitmap.draw_text(24, 0, bitmap.width-32, 24, "[#{n}] #{name}:")
  421.       bitmap.draw_text(0, 0, bitmap.width, 24, "[O#{$game_switches[n] ? "N" : "FF"}]", 2)
  422.     end
  423.   end
  424. #class Sprite_Debug#def draw_variable(n, bitmap, blta)
  425.   def draw_variable(n, bitmap, blta)
  426.     if n != nil
  427.       name = $data_system.variables[n]
  428.       bitmap.blt(0, 0, get_text_icon("V"), Rect.new(0,0,24,24), blta)
  429.       bitmap.draw_text(24, 0, bitmap.width-32, 24, "[#{n}] #{name}:")
  430.       bitmap.draw_text(0, 0, bitmap.width-3, 24, $game_variables[n].to_s, 2)
  431.     end
  432.   end
  433. #class Sprite_Debug#def draw_item(n, bitmap, blta)
  434.   def draw_item(n, bitmap, blta)
  435.     item = $data_items[n]
  436.     if item != nil
  437.       bitmap.blt(0, 0, get_icon(item.icon_name), Rect.new(0,0,24,24), blta)
  438.       bitmap.draw_text(24, 0, bitmap.width, 24, item.name)
  439.       bitmap.draw_text(0, 0, bitmap.width-3, 24, $game_party.item_number(n).to_s, 2)
  440.     end
  441.   end
  442. #class Sprite_Debug#def draw_actor(n, bitmap, blta)
  443.   def draw_actor(n, bitmap, blta)
  444.     item = $game_actors[n]
  445.     if item != nil
  446.       iw = bitmap.width
  447.       #bitmap.draw_text(24, 0, bitmap.width, 24, item.name) # draw name twice?
  448.       wb = Window_Base.new(-(iw+32),-56,iw+32,56) # I get a Window_Base for its
  449.       wb.contents = Bitmap.new(iw+32, 56)
  450.       wb.draw_actor_name(item, 24, -4)            #  useful draw_this, draw_that
  451.       gs = iw-320
  452.       vals = [0, 10]
  453.       #vals[0] -= 4; vals[1] -= 4; vals << 0
  454.       wb.draw_actor_state(item, 160+gs, -4, 56)
  455.       wb.contents.font.size /= 2
  456.       wb.contents.font.shadow = false if wb.contents.font.respond_to?(:shadow)
  457.       col = false
  458.       for i in -1..2; for j in -1..1
  459.         next if i == j && i == 0
  460.         if i == 2
  461.           next if j != 0
  462.           col = true
  463.           i = 0
  464.         end
  465.         wb.contents.font.color = col ? Color.new(0,0,0) : wb.system_color
  466.         wb.contents.draw_text(i+106, j+vals[0], 16, 16, $data_system.words.hp)
  467.         wb.contents.draw_text(i+106, j+vals[1], 16, 16, $data_system.words.sp)
  468.         wb.contents.draw_text(i+6-1, j+8, 12, 24, "Lv")
  469.         wb.contents.draw_text(i+iw-112+16, j-4, 22, 24, $data_system.words.atk[0...3])
  470.         wb.contents.draw_text(i+iw-48+16, j-4, 22, 24, $data_system.words.pdef[0...3])
  471.         wb.contents.draw_text(i+iw-80+16, j-4, 22, 24, $data_system.words.str[0...3])
  472.         wb.contents.draw_text(i+iw-80+16, j+6, 22, 24, $data_system.words.dex[0...3])
  473.         wb.contents.draw_text(i+iw-112+16, j+6, 22, 24, $data_system.words.int[0...3])
  474.         wb.contents.draw_text(i+iw-48+16, j+6, 22, 24, $data_system.words.agi[0...3])
  475.         wb.contents.font.color = col ? Color.new(0,0,0) : wb.normal_color
  476.         wb.contents.draw_text(i, j+8, 23, 24, item.level.to_s, 2)
  477.         wb.contents.draw_text(i+iw-112+26, j-4, 18, 24, item.atk.to_s, 2)
  478.         wb.contents.draw_text(i+iw-48+26, j-4, 18, 24, item.pdef.to_s, 2)
  479.         wb.contents.draw_text(i+iw-80+26, j-4, 18, 24, item.str.to_s, 2)
  480.         wb.contents.draw_text(i+iw-80+26, j+6, 18, 24, item.dex.to_s, 2)
  481.         wb.contents.draw_text(i+iw-112+26, j+6, 18, 24, item.int.to_s, 2)
  482.         wb.contents.draw_text(i+iw-48+26, j+6, 18, 24, item.agi.to_s, 2)
  483.         wb.contents.draw_text(i+96+16+24, j+vals[0], 6, 16, "/", 1)
  484.         wb.contents.draw_text(i+96+16+24, j+vals[1], 6, 16, "/", 1)
  485.         wb.contents.draw_text(i+96+16+30, j+vals[0], 24, 16, item.maxhp.to_s)
  486.         wb.contents.draw_text(i+96+16+30, j+vals[1], 24, 16, item.maxsp.to_s)
  487.         unless col
  488.           wb.contents.font.color = wb.knockout_color if item.hp == 0
  489.           wb.contents.font.color = wb.crisis_color if item.hp <= item.maxhp / 4
  490.         end
  491.         wb.contents.draw_text(i+96+16, j+vals[0], 24, 16, item.hp.to_s, 2)
  492.         unless col
  493.           wb.contents.font.color = wb.knockout_color if item.sp == 0
  494.           wb.contents.font.color = wb.crisis_color if item.sp <= item.maxsp / 4
  495.         end
  496.         wb.contents.draw_text(i+96+16, j+vals[1], 24, 16, item.sp.to_s, 2)
  497.         break if i == j && j == 0
  498.       end; end
  499.       bitmap.blt(0, 0, get_character_icon(item), Rect.new(0,0,24,24), blta)
  500.       bitmap.blt(0, 0, wb.contents, wb.contents.rect, blta)
  501.       wb.dispose
  502.     end
  503.   end
  504. #class Sprite_Debug#def draw_event(n, bitmap, blta)
  505.   def draw_event(n, bitmap, blta)
  506.     item = $game_map.events[n]
  507.     if item != nil
  508.       bitmap.blt(0, 0, get_character_icon(item, true), Rect.new(0,0,24,24), blta)
  509.       nm = VDEBUG::SHOW_EVENT_NAME ? item.name : ""
  510.       bitmap.draw_text(24, 0, bitmap.width-3, 24, "[#{item.id}](#{item.x};#{item.y})#{nm}")
  511.       loc = "ON:"
  512.       for ss in ['A', 'B', 'C', 'D']
  513.         loc += " " + ss + "," if $game_self_switches[[$game_map.map_id, item.id, ss]]
  514.       end
  515.       loc[-1] = "" if loc[-1].chr == ','
  516.       bitmap.draw_text(0, 0, bitmap.width, 24, loc, 2)
  517.       if item.through
  518.         bitmap.font.size /= 2
  519.         bitmap.font.shadow = false if bitmap.font.respond_to?(:shadow)
  520.         col = false
  521.         for i in -1..2; for j in -1..1
  522.           next if i == j && i == 0
  523.           if i == 2
  524.             next if j != 0
  525.             col = true
  526.             i = 0
  527.           end
  528.           bitmap.font.color = col ? Color.new(0,0,0) : Color.new(99,33,55)
  529.           bitmap.draw_text(i, j+8, 23, 24, "T", 2) if item.through
  530.           break if i == j && j == 0
  531.         end; end
  532.       end
  533.     else
  534.       bitmap.blt(0, 0, get_text_icon(n.to_s), Rect.new(0,0,24,24), blta)
  535.       bitmap.draw_text(0, 0, bitmap.width, 24, "EV#{sprintf("%03d", n)}", 1)
  536.     end
  537.   end
  538. #class Sprite_Debug#def draw_data(n, bitmap, blta)
  539.   def draw_data(n, bitmap, blta)
  540.     item = VDEBUG::useful_data[n]
  541.     if item != nil && item.is_a?(Array)
  542.       item = [item] unless item[0].is_a?(Array)
  543.       return if item.size < 1
  544.       str = ""
  545.       for val in item
  546.         str += val[0] + " #{val[1]} "
  547.       end
  548.       str[-1] = "" if str[-1].chr == " "
  549.       bitmap.draw_text(0, 0, bitmap.width, 24, str, 1)
  550.     end
  551.   end
  552. #class Sprite_Debug#def draw_weapon(n, bitmap, blta)
  553.   def draw_weapon(n, bitmap, blta)
  554.     item = $data_weapons[n]
  555.     if item != nil
  556.       bitmap.blt(0, 0, get_icon(item.icon_name), Rect.new(0,0,24,24), blta)
  557.       bitmap.draw_text(24, 0, bitmap.width, 24, item.name)
  558.       bitmap.draw_text(0, 0, bitmap.width-3, 24, $game_party.weapon_number(n).to_s, 2)
  559.     end
  560.   end
  561. #class Sprite_Debug#def draw_armor(n, bitmap, blta)
  562.   def draw_armor(n, bitmap, blta)
  563.     item = $data_armors[n]
  564.     if item != nil
  565.       bitmap.blt(0, 0, get_icon(item.icon_name), Rect.new(0,0,24,24), blta)
  566.       bitmap.draw_text(24, 0, bitmap.width, 24, item.name)
  567.       bitmap.draw_text(0, 0, bitmap.width-3, 24, $game_party.armor_number(n).to_s, 2)
  568.     end
  569.   end
  570. #class Sprite_Debug#def draw_enemy(n, bitmap, blta)
  571.   def draw_enemy(n, bitmap, blta)
  572.     item = $game_troop.enemies[n-1]
  573.     iw = bitmap.width
  574.     if item != nil
  575.       wb = Window_Base.new(-(iw+32),-56,iw+32,56) # I get a Window_Base for its
  576.       wb.contents = Bitmap.new(iw+32, 56)
  577.       wb.draw_actor_name(item, 24, -4)            #  useful draw_this, draw_that
  578.       gs = iw-320
  579.       vals = [0, 10]
  580.       #vals[0] -= 4; vals[1] -= 4; vals << 0
  581.       wb.draw_actor_state(item, 160+gs, -4, 56)
  582.       wb.contents.font.size /= 2
  583.       wb.contents.font.shadow = false if wb.contents.respond_to?(:shadow)
  584.       col = false
  585.       for i in -1..2; for j in -1..1
  586.         next if i == j && i == 0
  587.         if i == 2
  588.           next if j != 0
  589.           col = true
  590.           i = 0
  591.         end
  592.         wb.contents.font.color = col ? Color.new(0,0,0) : wb.system_color
  593.         wb.contents.draw_text(i+106, j+vals[0], 16, 16, $data_system.words.hp)
  594.         wb.contents.draw_text(i+106, j+vals[1], 16, 16, $data_system.words.sp)
  595.         wb.contents.draw_text(i+iw-112+16, j-4, 22, 24, $data_system.words.atk[0...3])
  596.         wb.contents.draw_text(i+iw-48+16, j-4, 22, 24, $data_system.words.pdef[0...3])
  597.         wb.contents.draw_text(i+iw-80+16, j-4, 22, 24, $data_system.words.str[0...3])
  598.         wb.contents.draw_text(i+iw-80+16, j+6, 22, 24, $data_system.words.dex[0...3])
  599.         wb.contents.draw_text(i+iw-112+16, j+6, 22, 24, $data_system.words.int[0...3])
  600.         wb.contents.draw_text(i+iw-48+16, j+6, 22, 24, $data_system.words.agi[0...3])
  601.         wb.contents.font.color = col ? Color.new(0,0,0) : wb.normal_color
  602.         #wb.contents.draw_text(i, j+8, 23, 24, item.letter, 2)
  603.         wb.contents.draw_text(i+iw-112+26, j-4, 18, 24, item.atk.to_s, 2)
  604.         wb.contents.draw_text(i+iw-48+26, j-4, 18, 24, item.pdef.to_s, 2)
  605.         wb.contents.draw_text(i+iw-80+26, j-4, 18, 24, item.str.to_s, 2)
  606.         wb.contents.draw_text(i+iw-80+26, j+6, 18, 24, item.dex.to_s, 2)
  607.         wb.contents.draw_text(i+iw-112+26, j+6, 18, 24, item.int.to_s, 2)
  608.         wb.contents.draw_text(i+iw-48+26, j+6, 18, 24, item.agi.to_s, 2)
  609.         wb.contents.draw_text(i+96+16+24, j+vals[0], 6, 16, "/", 1)
  610.         wb.contents.draw_text(i+96+16+24, j+vals[1], 6, 16, "/", 1)
  611.         wb.contents.draw_text(i+96+16+30, j+vals[0], 24, 16, item.maxhp.to_s)
  612.         wb.contents.draw_text(i+96+16+30, j+vals[1], 24, 16, item.maxsp.to_s)
  613.         unless col
  614.           wb.contents.font.color = wb.knockout_color if item.hp == 0
  615.           wb.contents.font.color = wb.crisis_color if item.hp <= item.maxhp / 4
  616.         end
  617.         wb.contents.draw_text(i+96+16, j+vals[0], 24, 16, item.hp.to_s, 2)
  618.         unless col
  619.           wb.contents.font.color = wb.knockout_color if item.sp == 0
  620.           wb.contents.font.color = wb.crisis_color if item.sp <= item.maxsp / 4
  621.         end
  622.         wb.contents.draw_text(i+96+16, j+vals[1], 24, 16, item.sp.to_s, 2)
  623.         break if i == j && j == 0
  624.       end; end
  625.       bitmap.blt(0, 0, get_enemy_icon(item), Rect.new(0,0,24,24), blta)
  626.       bitmap.blt(0, 0, wb.contents, wb.contents.rect, blta)
  627.       wb.dispose
  628.     else
  629.       bitmap.blt(0, 0, get_text_icon(n.to_s), Rect.new(0,0,24,24), blta)
  630.       bitmap.draw_text(0, 0, iw, 24, "...", 1)
  631.     end
  632.   end
  633. #class Sprite_Debug#def get_icon(index)
  634.   def get_icon(index) # get an icon from cache, recache it
  635.     @icache ||= {}
  636.     return @icache[index] if @icache[index]
  637.     bit = RPG::Cache.icon(index).clone
  638.     @icache[index] = bit
  639.     bit
  640.   end
  641. #class Sprite_Debug#def get_character_icon(chara, dir)
  642.   def get_character_icon(chara, dir = false) # get iconized character from...
  643.     #if [characters_have_icon] && !dir # actors here have icons ^^
  644.     #  # REQUIRE Something
  645.     #    return get_icon(chara.battler_icon)
  646.     #  # END REQUIRE
  647.     #end
  648.     @icache ||= {}
  649.     c_id = chara.character_name + "_" + chara.character_hue.to_s + "_" +
  650.            (dir ? chara.direction.to_s : "2")
  651.     return @icache[c_id] if @icache[c_id]
  652.     if dir
  653.       cp = chara.clone
  654.       cp.transparent = true
  655.       return Bitmap.new(24, 24) if !cp.tile_id
  656.       sc = Sprite_Character.new(nil, cp) # ...a Sprite_Character or...
  657.       bit = Bitmap.new(24, 24)
  658.       bit.blt((24-sc.src_rect.width)/2,(24-sc.src_rect.height)/2,sc.bitmap, sc.src_rect)
  659.       sc.dispose
  660.       cp = nil
  661.     else
  662.       wb = Window_Base.new(-56,-56,56,56) # ...a Window_Base...
  663.       wb.contents = Bitmap.new(56, 56)
  664.       wb.draw_actor_graphic(chara,12,33)
  665.       bit = wb.contents.clone
  666.       wb.dispose
  667.     end
  668.     @icache[c_id] = bit # ...and cache it
  669.     bit
  670.   end
  671. #class Sprite_Debug#def get_text_icon(text)
  672.   def get_text_icon(text) # get an iconized text, like S, V or numbers
  673.     @icache ||= {}
  674.     return @icache[text] if @icache[text]
  675.     bit = Bitmap.new(24,24)
  676.     bit.font.shadow = false if bit.font.respond_to?(:shadow)
  677.     bit.font.italic = true
  678.     bit.font.bold = true
  679.     bit.font.size -= 1
  680.     bit.font.color = Color.new(81,59,59, 128)
  681.     for i in -2..2; for j in -1..1 # draw black text many times around
  682.       bit.draw_text(i,j+2,24,24,text,1)
  683.     end; end
  684.     bit.font.color = Color.new(255,255,255)
  685.     bit.draw_text(0,2,24,24,text,1)
  686.     @icache[text] = bit
  687.     bit
  688.   end
  689. #class Sprite_Debug#def get_enemy_icon(enemy)
  690.   def get_enemy_icon(enemy) # get an iconized enemy graphic
  691.     @icache ||= {}
  692.     #if [characters_have_icon] # battlers here already have an icon ^^
  693.     #  # REQUIRE Something
  694.     #    ih = enemy.icon_hue
  695.     #    id = enemy.battler_icon.to_s + "_" + ih.to_s
  696.     #    return @icache[id] if @icache[id]
  697.     #    bit = get_icon(enemy.battler_icon).clone
  698.     #    bit.hue_change(ih) if ih != 0
  699.     #  # END REQUIRE
  700.     #else
  701.       id = enemy.battler_name + "_" + enemy.battler_hue.to_s
  702.       return @icache[id] if @icache[id]
  703.       bit = Bitmap.new(24,24)
  704.       sb = Sprite_Battler.new(nil, enemy) # get the bitmap from a Sprite_Battler
  705.       sb.opacity = 0 # don't wanna see the full battler
  706.       sb.update # let the graphic be loaded
  707.       #RPG::Cache.battler(@battler_name, @battler_hue) # if something goes wrong
  708.       sb.dispose if sb.bitmap.nil? || sb.bitmap.disposed? # no graphic?
  709.       return bit if sb.disposed?
  710.       b2 = Bitmap.new(sb.src_rect.width, sb.src_rect.height) # I get a new bitmap
  711.       b2.blt(0, 0, sb.bitmap, sb.src_rect)                   #  within src_rect
  712.       sb.bitmap = b2 # disposing sb even its bitmap will be disposed
  713.       if b2.width <= 24 || b2.height <= 24 # if little bitmap just center it
  714.         bit.blt((24-b2.width)/2, (24-b2.height)/2, b2, b2.rect)
  715.       else # else resize
  716.         fact = (b2.width > b2.height ? b2.height : b2.width)/24.0
  717.         nw = b2.width/fact; nh = b2.height/fact
  718.         bit.stretch_blt(Rect.new((24-nw)/2, (24-nh)/2, nw, nh), b2, b2.rect)
  719.       end
  720.       sb.dispose
  721.     #end
  722.     @icache[id] = bit
  723.     bit
  724.   end
  725. #class Sprite_Debug#def update()
  726.   def update
  727.     move_around if Input.trigger?(VDEBUG::MOVE_AROUND_KEY)
  728.     for i in 0...@infos.compact.size
  729.       v = @infos[i]
  730.       # set every new value and redraw if needed
  731.       draw_row(i) if @last_values[i] != (@last_values[i] = collect(v))
  732.     end
  733.     super
  734.   end
  735. end
  736.  
  737. # * operation to create a Visible Debug options screen
  738.  
  739. class Window_VDList < Window_Selectable
  740.   # a silly, simple, window that handle a list
  741.   attr_reader :data
  742. #class Window_VDList#def initialize(x, y, list, ctd)
  743.   def initialize(x, y, list = [], ctd = false)
  744.     super(x, y, 320, 480-y)
  745.     @column_max = 1
  746.     @cantdisable = ctd
  747.     self.index = 0
  748.     set_list(list)
  749.   end
  750. #class Window_VDList#def set_list(list)
  751.   def set_list(list)
  752.     @data = list
  753.     @item_max = @data.size
  754.     self.index = @item_max - 1 if self.index > 0 && @item_max < self.index
  755.     self.contents.dispose if self.contents && !self.contents.disposed?
  756.     self.contents = Bitmap.new(width - 32, [@item_max, 1].max * 32)
  757.     refresh
  758.   end
  759. #class Window_VDList#def enabled?(index)
  760.   def enabled?(index)
  761.     return true if @cantdisable
  762.     !$game_player.sdebug.infos.include?(@data[index])
  763.   end
  764. #class Window_VDList#def item()
  765.   def item
  766.     return @data[self.index]
  767.   end
  768. #class Window_VDList#def add_item(it)
  769.   def add_item(it)
  770.     @data.push(it)
  771.     set_list(@data.compact)
  772.   end
  773. #class Window_VDList#def remove_item(it)
  774.   def remove_item(it)
  775.     remove(@data.index(it))
  776.   end
  777. #class Window_VDList#def remove(index)
  778.   def remove(index)
  779.     return if index == nil
  780.     return if index < 0
  781.     return if index >= @data.size
  782.     @data.delete_at(index)
  783.     set_list(@data)
  784.   end
  785. #class Window_VDList#def refresh()
  786.   def refresh
  787.     self.contents.clear
  788.     for i in 0...@item_max
  789.       draw_item(i)
  790.     end
  791.   end
  792. #class Window_VDList#def draw_item(index)
  793.   def draw_item(index)
  794.     rect = Rect.new(0, 4 + index * 32, width - 32, 24)
  795.     self.contents.fill_rect(rect, Color.new(0,0,0,0))
  796.     return if @data[index].nil?
  797.     im = $game_player.sdebug.get_item(@data[index], rect.width-4, enabled?(index))
  798.     self.contents.blt(rect.x, rect.y, im, im.rect) if im
  799.     im.dispose if im
  800.   end
  801. end
  802.  
  803. class Scene_VisibleDebug
  804.   # a silly, simple, scene
  805. #class Scene_VisibleDebug#def main()
  806.   def main
  807.     @help_window = Window_Help.new
  808.     @help_window.set_text(VDEBUG::HELP_TEXT)
  809.     ips = @help_window.height
  810.     # third list window parameter is the list, fourth is the cantdisable value
  811.     @mainlist_window = Window_VDList.new(0, ips, VDEBUG::collect_mainlist)
  812.     @debuglist_window = Window_VDList.new(@mainlist_window.width, ips,
  813.                                           $game_player.sdebug.infos, true)
  814.     @elementlist_window = Window_VDList.new(0, ips)
  815.     @elementlist_window.visible = false
  816.     @elementlist_window.active = false
  817.     @debuglist_window.active = false
  818.    
  819.     # Execute transition
  820.     Graphics.transition
  821.     # Main loop
  822.     loop do
  823.       # Update game screen
  824.       Graphics.update
  825.       # Update input information
  826.       Input.update
  827.       # Frame Update
  828.       update
  829.       # Abort loop if screen is changed
  830.       if $scene != self
  831.         break
  832.       end
  833.     end
  834.     # Refresh map
  835.     $game_map.refresh
  836.     # Prepare for transition
  837.     Graphics.freeze
  838.    
  839.     @help_window.dispose
  840.     @mainlist_window.dispose
  841.     @debuglist_window.dispose
  842.     @elementlist_window.dispose
  843.   end
  844. #class Scene_VisibleDebug#def update()
  845.   def update
  846.     @help_window.update
  847.     @mainlist_window.update
  848.     @debuglist_window.update
  849.     @elementlist_window.update
  850.     if @mainlist_window.active
  851.       update_mainlist
  852.     elsif @debuglist_window.active
  853.       update_debuglist
  854.     elsif @elementlist_window.active
  855.       update_elementlist
  856.     end
  857.   end
  858. #class Scene_VisibleDebug#def update_mainlist()
  859.   def update_mainlist
  860.     if Input.trigger?(Input::B)
  861.       $game_system.se_play($data_system.cancel_se)
  862.       $scene = Scene_Map.new
  863.       return
  864.     elsif Input.trigger?(Input::C)
  865.       $game_system.se_play($data_system.decision_se)
  866.       it = @mainlist_window.item
  867.       if it[0] >= 0 # if item's a item:
  868.         if @mainlist_window.enabled?(@mainlist_window.index) # add/remove
  869.           @debuglist_window.add_item(it)
  870.         else
  871.           @debuglist_window.remove_item(it)
  872.         end
  873.         $game_player.sdebug.infos = @debuglist_window.data # update
  874.         @mainlist_window.draw_item(@mainlist_window.index) # redraw
  875.       else # if item's a group:
  876.         process_elementlist_open(it) # open the sub-list
  877.         @mainlist_window.active = false
  878.         @elementlist_window.active = true
  879.       end
  880.     elsif Input.trigger?(Input::R) || Input.trigger?(Input::L)
  881.       $game_system.se_play($data_system.cursor_se)
  882.       @mainlist_window.active = false
  883.       @debuglist_window.active = true
  884.     end
  885.   end
  886. #class Scene_VisibleDebug#def update_debuglist()
  887.   def update_debuglist
  888.     if Input.trigger?(Input::B)
  889.       $game_system.se_play($data_system.cancel_se)
  890.       $scene = Scene_Map.new
  891.       return
  892.     elsif Input.trigger?(Input::C)
  893.       $game_system.se_play($data_system.decision_se)
  894.       @debuglist_window.remove(@debuglist_window.index) # remove the item
  895.       $game_player.sdebug.infos = @debuglist_window.data # update
  896.       @mainlist_window.refresh # redraw
  897.     elsif Input.trigger?(Input::R) || Input.trigger?(Input::L)
  898.       $game_system.se_play($data_system.cursor_se)
  899.       @mainlist_window.active = true
  900.       @debuglist_window.active = false
  901.     end
  902.   end
  903. #class Scene_VisibleDebug#def update_elementlist()
  904.   def update_elementlist
  905.     if Input.trigger?(Input::B)
  906.       $game_system.se_play($data_system.cancel_se)
  907.       @elementlist_window.active = false
  908.       @mainlist_window.active = true
  909.       @mainlist_window.visible = true
  910.       @elementlist_window.visible = false
  911.     elsif Input.trigger?(Input::C)
  912.       $game_system.se_play($data_system.decision_se)
  913.       it = @elementlist_window.item
  914.       if @elementlist_window.enabled?(@elementlist_window.index) # add/remove
  915.         @debuglist_window.add_item(it)
  916.       else
  917.         @debuglist_window.remove_item(it)
  918.       end
  919.       $game_player.sdebug.infos = @debuglist_window.data # update
  920.       @elementlist_window.draw_item(@elementlist_window.index) # redraw
  921.     end
  922.   end
  923. #class Scene_VisibleDebug#def process_elementlist_open(it)
  924.   def process_elementlist_open(it) # it contains the type and the size
  925.     # collect elements of the group
  926.     vals = []
  927.     for d in 1..it[1] # starting from 1, because there aren't IDs 0
  928.       vals << [it[0]*-1,d] # the type must be positive
  929.     end
  930.     # and let the window appears
  931.     @elementlist_window.set_list(vals)
  932.     @elementlist_window.index = 0
  933.     @mainlist_window.visible = false
  934.     @elementlist_window.visible = true
  935.   end
  936. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement