Advertisement
mikb89

[VX] Visible Debug v1.2

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