Advertisement
mikb89

[Ace] Visible Debug v1.2c

Jun 26th, 2012
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 29.18 KB | None | 0 0
  1. # Visible Debug v. 1.2c
  2. # VX Ace 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, tp (if enabled), atk, def, luk, 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 = :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_timer.sec)]
  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 update_call_debug() <- rewritten
  105.   def update_call_debug
  106.     SceneManager.call(Scene_ChoiceDebug) if $TEST && Input.press?(:F9)
  107.   end
  108. end
  109.  
  110. class Window_GameDebug < Window_GameEnd
  111. #class Window_GameDebug#def make_command_list()
  112.   def make_command_list
  113.     add_command(VDEBUG::CALL_CLASSIC_DEBUG_TEXT, :dbg)
  114.     add_command(VDEBUG::CALL_VDEBUG_SETTINGS_TEXT, :vd)
  115.     add_command(Vocab::cancel, :cancel)
  116.   end
  117. end
  118.  
  119. class Scene_ChoiceDebug < Scene_MenuBase
  120. #class Scene_ChoiceDebug#def start()
  121.   def start
  122.     super; @command_window = Window_GameDebug.new
  123.     @command_window.set_handler(:dbg, proc{SceneManager.goto(Scene_Debug)})
  124.     @command_window.set_handler(:vd, proc{SceneManager.goto(Scene_VisibleDebug)})
  125.     @command_window.set_handler(:cancel, method(:return_scene))
  126.   end
  127. #class Scene_ChoiceDebug#def pre_terminate()
  128.   def pre_terminate
  129.     super; @command_window.close; update until @command_window.close?
  130.   end
  131. end
  132.  
  133. # * operations to let the Visible Debug sprite work
  134.  
  135. #class Game_Event#def name()
  136. (class Game_Event; def name; @event.name; end; end) if VDEBUG::SHOW_EVENT_NAME
  137.  # why isn't the event name readable by default? WHY???
  138.  
  139. class Scene_Base
  140.   alias_method(:updateSB_b4_vdebug, :update) unless method_defined?(:updateSB_b4_vdebug)
  141. #class Scene_Base#def update() <- aliased
  142.   def update
  143.     updateSB_b4_vdebug
  144.     # update the debug sprite just everywhere!
  145.     $game_player.sdebug.update if $game_player
  146.   end
  147. end
  148.  
  149. class << SceneManager
  150.   alias_method(:run_b4_vdebug, :run) unless method_defined?(:run_b4_vdebug)
  151. #class Scene_Manager#def self.run() <- aliased
  152.   def run
  153.     run_b4_vdebug
  154.     $game_player.sdebug.dispose
  155.   end
  156.   alias_method(:snapshot_for_background_b4_vdebug, :snapshot_for_background) unless method_defined?(:snapshot_for_background_b4_vdebug)
  157. #class Scene_Manager#def self.snapshot_for_background() <- aliased
  158.   def snapshot_for_background
  159.     # we don't want the debug sprite to be captured in the snapshot
  160.     $game_player.sdebug.visible = false if $game_player
  161.     snapshot_for_background_b4_vdebug
  162.     $game_player.sdebug.visible = true if $game_player
  163.   end
  164. end
  165.  
  166. class Game_Player
  167.   # rely sprite on $game_player due to its reperibility. No, I'm not kidding :E
  168. #class Game_Player#def sdebug()
  169.   def sdebug
  170.     @sdebug ||= Sprite_Debug.new
  171.   end
  172. end
  173.  
  174. class Sprite_Debug < Sprite
  175.   attr_reader :infos
  176. #class Sprite_Debug#def initialize(i, pos)
  177.   def initialize(i = nil, pos = 0)
  178.     super()
  179.     self.infos = (i.is_a?(Array) ? i : [i]) # must be an array
  180.     self.z = 99999999 # a big value
  181.     self.opacity = 222 # little transparency
  182.     @last_values = []
  183.     @pos = pos - 1; move_around # position set
  184.   end
  185. #class Sprite_Debug#def move_around()
  186.   def move_around
  187.     @pos += 1; @pos %= 5 # increase position, modulate value
  188.     self.x = w*(@pos%2) # right/left
  189.     self.y = Graphics.height/2*(@pos/2) # up/down/out
  190.   end
  191. #class Sprite_Debug#def w()
  192.   def w # just to write a little less
  193.     Graphics.width/2
  194.   end
  195. #class Sprite_Debug#def infos=(i)
  196.   def infos=(i)
  197.     @infos = i
  198.     create_bitmap # once data change, we recreate the image
  199.   end
  200. #class Sprite_Debug#def _dump(*args)
  201.   def _dump(*args)
  202.     str = @infos[0].nil? ? "n," : ""
  203.     @infos.each {|i|
  204.       i.each {|d| str += " #{d.is_a?(Numeric) ? d : "p"}"}
  205.       str += ","
  206.     } if str == ""
  207.     str += @pos.to_s # values to save
  208.   end
  209. #class Sprite_Debug#def _load(data)
  210.   def self._load(data)
  211.     p data
  212.     data = data.split(',')
  213.     pos = data.pop.to_i || 0
  214.     i = data[0] == "n" ? nil : data.each_index {|d|
  215.           data[d] = data[d].split
  216.           data[d].each_index {|n| data[d][n] = (data[d][n] == "p" ? $game_player : data[d][n].to_i)}
  217.         }
  218.     Sprite_Debug.new(i, pos)
  219.   end
  220. #class Sprite_Debug#def create_bitmap()
  221.   def create_bitmap
  222.     self.bitmap.dispose if self.bitmap && !self.bitmap.disposed?
  223.     h = @infos.size*24
  224.     self.bitmap = Bitmap.new(w,[h,1].max) # h is 0, if there's no item
  225.     for i in 0...@infos.size
  226.       next if @infos[i] == nil || @infos[i].size < 2
  227.       draw_row(i, true)
  228.     end
  229.   end
  230. #class Sprite_Debug#def draw_row(i, new)
  231.   def draw_row(i, new = false)
  232.     self.bitmap.clear_rect(0,i*24,w,24) unless new # no need to clear if new
  233.     im = get_item(@infos[i]) # get the bitmap then blt it. This way I can get
  234.     return unless im         #  the same bitmap everywhere ^^
  235.     draw_placement(0, i*24)
  236.     self.bitmap.blt(0, i*24, im, im.rect)
  237.     im.dispose
  238.   end
  239. #class Sprite_Debug#def draw_placement(x, y)
  240.   def draw_placement(x, y)
  241.     self.bitmap.fill_rect(x+4,y+6,w-8,24-8,Color.new(0,0,0,128)) # a bLackground
  242.   end
  243. #class Sprite_Debug#def collect(v)
  244.   def collect(v) # gets the relevant value(s) for each item
  245.     case v[0]
  246.       when 0; collect_player
  247.       when 1; $game_switches[v[1]]
  248.       when 2; $game_variables[v[1]]
  249.       when 3; $game_party.item_number($data_items[v[1]])
  250.       when 4; collect_actor($game_actors[v[1]])
  251.       when 5; collect_event($game_map.events[v[1]])
  252.       when 6; collect_data(VDEBUG::useful_data[v[1]])
  253.       when 7; $game_party.item_number($data_weapons[v[1]])
  254.       when 8; $game_party.item_number($data_armors[v[1]])
  255.       when 9; collect_enemy($game_troop.members[v[1]-1])
  256.       else; nil
  257.     end
  258.   end
  259. #class Sprite_Debug#def collect_player()
  260.   def collect_player
  261.     da = []
  262.     da << $game_player.character_name
  263.     da << $game_player.character_index
  264.     da << $game_player.direction
  265.     da << $game_player.x
  266.     da << $game_player.y
  267.     da << ($game_player.through || $game_player.debug_through?)
  268.     for i in [0, 1, 2]
  269.       da << $game_map.data[$game_player.x, $game_player.y, i]
  270.     end
  271.     da
  272.   end
  273. #class Sprite_Debug#def collect_actor(actor)
  274.   def collect_actor(actor)
  275.     da = []
  276.     da << actor.character_name
  277.     da << actor.character_index
  278.     da << actor.name
  279.     da << actor.level
  280.     da << actor.hp
  281.     da << actor.mhp
  282.     da << actor.mp
  283.     da << actor.mmp
  284.     da << actor.states
  285.     da << actor.atk
  286.     da << actor.def
  287.     da << actor.luk
  288.     da << actor.agi
  289.     da
  290.   end
  291. #class Sprite_Debug#def collect_event(event)
  292.   def collect_event(event)
  293.     da = []
  294.     return da if event.nil?
  295.     da << event.character_name
  296.     da << event.character_index
  297.     da << event.direction
  298.     da << event.x
  299.     da << event.y
  300.     da << (event.through || event.debug_through?)
  301.     for ss in ['A', 'B', 'C', 'D']
  302.       da << $game_self_switches[[$game_map.map_id, event.id, ss]]
  303.     end
  304.     da
  305.   end
  306. #class Sprite_Debug#def collect_data(data)
  307.   def collect_data(data)
  308.     da = []
  309.     return da if data.nil? || !data.is_a?(Array)
  310.     data = [data] unless data[0].is_a?(Array)
  311.     return da if data.size < 1
  312.     for val in data
  313.       da << val[1]
  314.     end
  315.     da
  316.   end
  317. #class Sprite_Debug#def collect_enemy(enemy)
  318.   def collect_enemy(enemy)
  319.     da = []
  320.     return da if enemy.nil?
  321.     da << enemy.battler_name
  322.     da << enemy.battler_hue
  323.     da << enemy.name
  324.     da << enemy.hp
  325.     da << enemy.mhp
  326.     da << enemy.mp
  327.     da << enemy.mmp
  328.     da << enemy.states
  329.     da << enemy.atk
  330.     da << enemy.def
  331.     da << enemy.luk
  332.     da << enemy.agi
  333.     da
  334.   end
  335. #class Sprite_Debug#def get_item(item, width, enabled)
  336.   def get_item(item, width = w, enabled = true) # draw item in a returned bitmap
  337.     bit = Bitmap.new(width,24)
  338.     bit.font.color.alpha = blta = enabled ? 255 : 128
  339.     case item[0]
  340.     when -9; draw_container(VDEBUG::ENEMY_LIST_TEXT, item[1], bit)
  341.     when -8; draw_container(VDEBUG::ARMOR_LIST_TEXT, item[1], bit)
  342.     when -7; draw_container(VDEBUG::WEAPON_LIST_TEXT, item[1], bit)
  343.     when -6; draw_container(VDEBUG::DATA_LIST_TEXT, item[1], bit)
  344.     when -5; draw_container(VDEBUG::EVENT_LIST_TEXT, item[1], bit)
  345.     when -4; draw_container(VDEBUG::ACTOR_LIST_TEXT, item[1], bit)
  346.     when -3; draw_container(VDEBUG::ITEM_LIST_TEXT, item[1], bit)
  347.     when -2; draw_container(VDEBUG::VARIABLE_LIST_TEXT, item[1], bit)
  348.     when -1; draw_container(VDEBUG::SWITCH_LIST_TEXT, item[1], bit)
  349.     when 0; draw_player(item[1], bit, blta)
  350.     when 1; draw_switch(item[1], bit, blta)
  351.     when 2; draw_variable(item[1], bit, blta)
  352.     when 3; draw_item(item[1], bit, blta)
  353.     when 4; draw_actor(item[1], bit, blta)
  354.     when 5; draw_event(item[1], bit, blta)
  355.     when 6; draw_data(item[1], bit, blta)
  356.     when 7; draw_weapon(item[1], bit, blta)
  357.     when 8; draw_armor(item[1], bit, blta)
  358.     when 9; draw_enemy(item[1], bit, blta)
  359.     else; bit.dispose; bit = nil
  360.     end
  361.     bit
  362.   end
  363. #class Sprite_Debug#def draw_container(txt, n, bitmap)
  364.   def draw_container(txt, n, bitmap)
  365.     bitmap.draw_text(12, 0, bitmap.width-32, 24, txt)
  366.     bitmap.draw_text(0, 0, bitmap.width, 24, n > 0 ? "(#{n})" : "", 2)
  367.   end
  368. #class Sprite_Debug#def draw_player(item, bitmap, blta)
  369.   def draw_player(item, bitmap, blta)
  370.     if item != nil
  371.       bitmap.blt(0, 0, get_character_icon(item, true), Rect.new(0,0,24,24), blta)
  372.       bitmap.draw_text(24, 0, bitmap.width, 24, "(#{item.x};#{item.y})")
  373.       tile = ""
  374.       for i in [0, 1, 2]
  375.         tile += $game_map.data[item.x, item.y, i].to_s + (i != 2 ? ", " : "")
  376.       end
  377.       bitmap.draw_text(0, 0, bitmap.width-3, 24, "Tile: #{tile}", 2)
  378.       if (item.through || item.debug_through?)
  379.         bitmap.font.color = Color.new(0,0,0)
  380.         bitmap.font.out_color = Color.new(99,33,55)
  381.         bitmap.draw_text(0, 8, 23, 24, "T", 2)
  382.       end
  383.     end
  384.   end
  385. #class Sprite_Debug#def draw_switch(n, bitmap, blta)
  386.   def draw_switch(n, bitmap, blta)
  387.     if n != nil
  388.       name = $data_system.switches[n]
  389.       bitmap.blt(0, 0, get_text_icon("S"), Rect.new(0,0,24,24), blta)
  390.       bitmap.draw_text(24, 0, bitmap.width-32, 24, "[#{n}] #{name}:")
  391.       bitmap.draw_text(0, 0, bitmap.width, 24, "[O#{$game_switches[n] ? "N" : "FF"}]", 2)
  392.     end
  393.   end
  394. #class Sprite_Debug#def draw_variable(n, bitmap, blta)
  395.   def draw_variable(n, bitmap, blta)
  396.     if n != nil
  397.       name = $data_system.variables[n]
  398.       bitmap.blt(0, 0, get_text_icon("V"), Rect.new(0,0,24,24), blta)
  399.       bitmap.draw_text(24, 0, bitmap.width-32, 24, "[#{n}] #{name}:")
  400.       bitmap.draw_text(0, 0, bitmap.width-3, 24, $game_variables[n].to_s, 2)
  401.     end
  402.   end
  403. #class Sprite_Debug#def draw_item(n, bitmap, blta)
  404.   def draw_item(n, bitmap, blta)
  405.     item = $data_items[n]
  406.     if item != nil
  407.       bitmap.blt(0, 0, get_icon(item.icon_index), Rect.new(0,0,24,24), blta)
  408.       bitmap.draw_text(24, 0, bitmap.width, 24, item.name)
  409.       bitmap.draw_text(0, 0, bitmap.width-3, 24, $game_party.item_number(item), 2)
  410.     end
  411.   end
  412. #class Sprite_Debug#def draw_actor(n, bitmap, blta)
  413.   def draw_actor(n, bitmap, blta)
  414.     item = $game_actors[n]
  415.     if item != nil
  416.       iw = bitmap.width
  417.       bitmap.draw_text(24, 0, bitmap.width, 24, item.name)
  418.       wb = Window_Base.new(-(iw+32),-56,iw+32,56) # I get a Window_Base for its
  419.       wb.draw_actor_name(item, 24, 0)             #  useful draw_this, draw_that
  420.       gs = iw-w
  421.       vals = [-8, -2]
  422.       if $data_system.opt_display_tp
  423.         vals[0] -= 4; vals[1] -= 4; vals << 0
  424.         wb.draw_gauge(96, vals[2], 48+gs, item.tp_rate, wb.tp_gauge_color1, wb.tp_gauge_color2)
  425.       end
  426.       wb.draw_gauge(96, vals[0], 48+gs, item.hp_rate, wb.hp_gauge_color1, wb.hp_gauge_color2)
  427.       wb.draw_gauge(96, vals[1], 48+gs, item.mp_rate, wb.mp_gauge_color1, wb.mp_gauge_color2)
  428.       wb.draw_actor_icons(item, 154+gs, 0, 48)
  429.       wb.contents.font.size /= 2
  430.       wb.contents.font.color = Color.new(0,0,0)
  431.       wb.contents.font.out_color = wb.system_color
  432.       wb.contents.draw_text(5, 8, 12, 24, Vocab::level_a)
  433.       wb.contents.draw_text(iw-80+16, -4, 22, 24, Vocab::param(2)[0...3])
  434.       wb.contents.draw_text(iw-48+16, -4, 22, 24, Vocab::param(3)[0...3])
  435.       wb.contents.draw_text(iw-80+16, 6, 22, 24, Vocab::param(6)[0...3])
  436.       wb.contents.draw_text(iw-48+16, 6, 22, 24, Vocab::param(7)[0...3])
  437.       wb.contents.font.out_color = wb.normal_color
  438.       wb.contents.draw_text(0, 8, 23, 24, item.level, 2)
  439.       wb.contents.draw_text(iw-80+26, -4, 18, 24, item.atk, 2)
  440.       wb.contents.draw_text(iw-48+26, -4, 18, 24, item.def, 2)
  441.       wb.contents.draw_text(iw-80+26, 6, 18, 24, item.luk, 2)
  442.       wb.contents.draw_text(iw-48+26, 6, 18, 24, item.agi, 2)
  443.       bitmap.blt(0, 0, get_character_icon(item), Rect.new(0,0,24,24), blta)
  444.       bitmap.blt(0, 0, wb.contents, wb.contents.rect, blta)
  445.       wb.dispose
  446.     end
  447.   end
  448. #class Sprite_Debug#def draw_event(n, bitmap, blta)
  449.   def draw_event(n, bitmap, blta)
  450.     item = $game_map.events[n]
  451.     if item != nil
  452.       bitmap.blt(0, 0, get_character_icon(item, true), Rect.new(0,0,24,24), blta)
  453.       nm = VDEBUG::SHOW_EVENT_NAME ? item.name : ""
  454.       bitmap.draw_text(24, 0, bitmap.width-3, 24, "[#{item.id}](#{item.x};#{item.y})#{nm}")
  455.       loc = "ON:"
  456.       for ss in ['A', 'B', 'C', 'D']
  457.         loc += " " + ss + "," if $game_self_switches[[$game_map.map_id, item.id, ss]]
  458.       end
  459.       loc[-1] = "" if loc[-1] == ','
  460.       bitmap.draw_text(0, 0, bitmap.width, 24, loc, 2)
  461.       if (item.through || item.debug_through?)
  462.         bitmap.font.color = Color.new(0,0,0)
  463.         bitmap.font.out_color = Color.new(99,33,55)
  464.         bitmap.draw_text(0, 8, 23, 24, "T", 2)
  465.       end
  466.     else
  467.       bitmap.blt(0, 0, get_text_icon(n.to_s), Rect.new(0,0,24,24), blta)
  468.       bitmap.draw_text(0, 0, bitmap.width, 24, "EV#{sprintf("%03d", n)}", 1)
  469.     end
  470.   end
  471. #class Sprite_Debug#def draw_data(n, bitmap, blta)
  472.   def draw_data(n, bitmap, blta)
  473.     item = VDEBUG::useful_data[n]
  474.     if item != nil && item.is_a?(Array)
  475.       item = [item] unless item[0].is_a?(Array)
  476.       return if item.size < 1
  477.       str = ""
  478.       for val in item
  479.         str += val[0] + " #{val[1]} "
  480.       end
  481.       str[-1] = "" if str[-1] == " "
  482.       bitmap.draw_text(0, 0, bitmap.width, 24, str, 1)
  483.     end
  484.   end
  485. #class Sprite_Debug#def draw_weapon(n, bitmap, blta)
  486.   def draw_weapon(n, bitmap, blta)
  487.     item = $data_weapons[n]
  488.     if item != nil
  489.       bitmap.blt(0, 0, get_icon(item.icon_index), Rect.new(0,0,24,24), blta)
  490.       bitmap.draw_text(24, 0, bitmap.width, 24, item.name)
  491.       bitmap.draw_text(0, 0, bitmap.width-3, 24, $game_party.item_number(item), 2)
  492.     end
  493.   end
  494. #class Sprite_Debug#def draw_armor(n, bitmap, blta)
  495.   def draw_armor(n, bitmap, blta)
  496.     item = $data_armors[n]
  497.     if item != nil
  498.       bitmap.blt(0, 0, get_icon(item.icon_index), Rect.new(0,0,24,24), blta)
  499.       bitmap.draw_text(24, 0, bitmap.width, 24, item.name)
  500.       bitmap.draw_text(0, 0, bitmap.width-3, 24, $game_party.item_number(item), 2)
  501.     end
  502.   end
  503. #class Sprite_Debug#def draw_enemy(n, bitmap, blta)
  504.   def draw_enemy(n, bitmap, blta)
  505.     item = $game_troop.members[n-1]
  506.     iw = bitmap.width
  507.     if item != nil
  508.       wb = Window_Base.new(-(iw+32),-56,iw+32,56) # I get a Window_Base for its
  509.       wb.draw_actor_name(item, 24, 0)             #  useful draw_this, draw_that
  510.       gs = iw-w
  511.       vals = [-8, -2]
  512.       if $data_system.opt_display_tp
  513.         vals[0] -= 4; vals[1] -= 4; vals << 0
  514.         wb.draw_gauge(96, vals[2], 48+gs, item.tp_rate, wb.tp_gauge_color1, wb.tp_gauge_color2)
  515.       end
  516.       wb.draw_gauge(96, vals[0], 48+gs, item.hp_rate, wb.hp_gauge_color1, wb.hp_gauge_color2)
  517.       wb.draw_gauge(96, vals[1], 48+gs, item.mp_rate, wb.mp_gauge_color1, wb.mp_gauge_color2)
  518.       wb.draw_actor_icons(item, 154+gs, 0, 48)
  519.       wb.contents.font.size /= 2
  520.       wb.contents.font.color = Color.new(0,0,0)
  521.       wb.contents.font.out_color = wb.system_color
  522.       wb.contents.draw_text(iw-80+16, -4, 22, 24, Vocab::param(2)[0...3])
  523.       wb.contents.draw_text(iw-48+16, -4, 22, 24, Vocab::param(3)[0...3])
  524.       wb.contents.draw_text(iw-80+16, 6, 22, 24, Vocab::param(6)[0...3])
  525.       wb.contents.draw_text(iw-48+16, 6, 22, 24, Vocab::param(7)[0...3])
  526.       wb.contents.font.out_color = wb.normal_color
  527.       wb.contents.draw_text(0, 8, 23, 24, item.letter, 2)
  528.       wb.contents.draw_text(iw-80+26, -4, 18, 24, item.atk, 2)
  529.       wb.contents.draw_text(iw-48+26, -4, 18, 24, item.def, 2)
  530.       wb.contents.draw_text(iw-80+26, 6, 18, 24, item.luk, 2)
  531.       wb.contents.draw_text(iw-48+26, 6, 18, 24, item.agi, 2)
  532.       bitmap.blt(0, 0, get_enemy_icon(item), Rect.new(0,0,24,24), blta)
  533.       bitmap.blt(0, 0, wb.contents, wb.contents.rect, blta)
  534.       wb.dispose
  535.     else
  536.       bitmap.blt(0, 0, get_text_icon(n.to_s), Rect.new(0,0,24,24), blta)
  537.       bitmap.draw_text(0, 0, iw, 24, "...", 1)
  538.     end
  539.   end
  540. #class Sprite_Debug#def get_icon(index)
  541.   def get_icon(index) # get an icon with the Window_Base, cache it
  542.     @icache ||= {}
  543.     return @icache[index] if @icache[index]
  544.     wb = Window_Base.new(-56,-56,56,56)
  545.     wb.draw_icon(index,0,0)
  546.     bit = wb.contents.clone
  547.     wb.dispose
  548.     @icache[index] = bit
  549.     bit
  550.   end
  551. #class Sprite_Debug#def get_character_icon(chara, dir)
  552.   def get_character_icon(chara, dir = false) # get iconized character from...
  553.     @icache ||= {}
  554.     c_id = chara.character_name + "_" + chara.character_index.to_s + "_" +
  555.            (dir ? chara.direction.to_s : "2")
  556.     return @icache[c_id] if @icache[c_id]
  557.     if dir
  558.       cp = chara.clone
  559.       cp.transparent = true
  560.       sc = Sprite_Character.new(nil, cp) # ...a Sprite_Character or...
  561.       bit = Bitmap.new(24, 24)
  562.       bit.blt((24-sc.src_rect.width)/2,(24-sc.src_rect.height)/2,sc.bitmap, sc.src_rect)
  563.       sc.dispose
  564.       cp = nil
  565.     else
  566.       wb = Window_Base.new(-56,-56,56,56) # ...a Window_Base...
  567.       wb.draw_actor_graphic(chara,12,33)
  568.       bit = wb.contents.clone
  569.       wb.dispose
  570.     end
  571.     @icache[c_id] = bit # ...and cache it
  572.     bit
  573.   end
  574. #class Sprite_Debug#def get_text_icon(text)
  575.   def get_text_icon(text) # get an iconized text, like S, V or numbers
  576.     @icache ||= {}
  577.     return @icache[text] if @icache[text]
  578.     bit = Bitmap.new(24,24)
  579.     bit.font.shadow = false
  580.     bit.font.italic = true
  581.     bit.font.bold = true
  582.     bit.font.size -= 1
  583.     bit.font.color = Color.new(81,59,59, 128)
  584.     for i in -2..2; for j in -1..1 # draw black text many times around
  585.       bit.draw_text(i,j+2,24,24,text,1)
  586.     end; end
  587.     bit.blur # then blur it
  588.     bit.font.color = Color.new(255,255,255)
  589.     bit.draw_text(0,2,24,24,text,1)
  590.     @icache[text] = bit
  591.     bit
  592.   end
  593. #class Sprite_Debug#def get_enemy_icon(enemy)
  594.   def get_enemy_icon(enemy) # get an iconized enemy graphic
  595.     @icache ||= {}
  596.     id = enemy.battler_name + "_" + enemy.battler_hue.to_s
  597.     return @icache[id] if @icache[id]
  598.     bit = Bitmap.new(24,24)
  599.     sb = Sprite_Battler.new(nil, enemy) # get the bitmap from a Sprite_Battler
  600.     sb.opacity = 0 # don't wanna see the full battler
  601.     sb.update_bitmap # let the graphic be loaded
  602.     sb.dispose if sb.bitmap.nil? || sb.bitmap.disposed? # no graphic?
  603.     return bit if sb.disposed?
  604.     b2 = Bitmap.new(sb.src_rect.width, sb.src_rect.height) # I get a new bitmap
  605.     b2.blt(0, 0, sb.bitmap, sb.src_rect)                   #  within src_rect
  606.     sb.bitmap = b2 # disposing sb even its bitmap will be disposed
  607.     if b2.width <= 24 || b2.height <= 24 # if little bitmap just center it
  608.       bit.blt((24-b2.width)/2, (24-b2.height)/2, b2, b2.rect)
  609.     else # else resize
  610.       fact = (b2.width > b2.height ? b2.height : b2.width)/24.0
  611.       nw = b2.width/fact; nh = b2.height/fact
  612.       bit.stretch_blt(Rect.new((24-nw)/2, (24-nh)/2, nw, nh), b2, b2.rect)
  613.     end
  614.     sb.dispose
  615.     @icache[id] = bit
  616.     bit
  617.   end
  618. #class Sprite_Debug#def update()
  619.   def update
  620.     return if SceneManager.scene_is?(Scene_File)
  621.     move_around if Input.trigger?(VDEBUG::MOVE_AROUND_KEY)
  622.     for i in 0...@infos.compact.size
  623.       v = @infos[i]
  624.       # set every new value and redraw if needed
  625.       draw_row(i) if @last_values[i] != (@last_values[i] = collect(v))
  626.     end
  627.     super
  628.   end
  629. end
  630.  
  631. # * operation to create a Visible Debug options screen
  632.  
  633. class Window_VDList < Window_Selectable
  634.   # a silly, simple, window that handle a list
  635.   attr_reader :data
  636. #class Window_VDList#def initialize(x, y, list, ctd)
  637.   def initialize(x, y, list = [], ctd = false)
  638.     super(x, y, Graphics.width/2, Graphics.height-y)
  639.     @cantdisable = ctd
  640.     self.index = 0
  641.     set_list(list)
  642.   end
  643. #class Window_VDList#def item_max()
  644.   def item_max
  645.     @data ? @data.size : 1
  646.   end
  647. #class Window_VDList#def set_list(list)
  648.   def set_list(list)
  649.     @data = list
  650.     self.index = item_max - 1 if self.index > 0 && item_max < self.index
  651.     refresh
  652.   end
  653. #class Window_VDList#def enabled?(index)
  654.   def enabled?(index)
  655.     return true if @cantdisable
  656.     !$game_player.sdebug.infos.include?(@data[index])
  657.   end
  658. #class Window_VDList#def item()
  659.   def item
  660.     return @data[self.index]
  661.   end
  662. #class Window_VDList#def add_item(it)
  663.   def add_item(it)
  664.     @data.push(it)
  665.     set_list(@data.compact)
  666.   end
  667. #class Window_VDList#def remove_item(it)
  668.   def remove_item(it)
  669.     remove(@data.index(it))
  670.   end
  671. #class Window_VDList#def remove(index)
  672.   def remove(index)
  673.     return if index == nil
  674.     return if index < 0
  675.     return if index >= @data.size
  676.     @data.delete_at(index)
  677.     set_list(@data)
  678.   end
  679. #class Window_VDList#def refresh()
  680.   def refresh
  681.     create_contents
  682.     for i in 0...item_max
  683.       draw_item(i)
  684.     end
  685.   end
  686. #class Window_VDList#def draw_item(index)
  687.   def draw_item(index)
  688.     rect = item_rect(index)
  689.     self.contents.clear_rect(rect)
  690.     return if @data[index].nil?
  691.     im = $game_player.sdebug.get_item(@data[index], rect.width-4, enabled?(index))
  692.     self.contents.blt(rect.x, rect.y, im, im.rect) if im
  693.     im.dispose if im
  694.   end
  695. end
  696.  
  697. class Scene_VisibleDebug < Scene_Base
  698.   # a silly, simple, scene
  699. #class Scene_VisibleDebug#def start()
  700.   def start
  701.     super
  702.     @help_window = Window_Help.new(1)
  703.     @help_window.set_text(VDEBUG::HELP_TEXT)
  704.     ips = @help_window.height
  705.     # third list window parameter is the list, fourth is the cantdisable value
  706.     @mainlist_window = Window_VDList.new(0, ips, VDEBUG::collect_mainlist)
  707.     @debuglist_window = Window_VDList.new(@mainlist_window.width, ips,
  708.                                           $game_player.sdebug.infos, true)
  709.     @elementlist_window = Window_VDList.new(0, ips)
  710.     @elementlist_window.visible = false
  711.     @mainlist_window.activate
  712.     @mainlist_window.set_handler(:ok, method(:mainlist_ok))
  713.     @mainlist_window.set_handler(:cancel, method(:return_scene))
  714.     @mainlist_window.set_handler(:pageup, method(:mainlist_pag))
  715.     @mainlist_window.set_handler(:pagedown, method(:mainlist_pag))
  716.     @debuglist_window.set_handler(:ok, method(:debuglist_ok))
  717.     @debuglist_window.set_handler(:cancel, method(:return_scene))
  718.     @debuglist_window.set_handler(:pageup, method(:debuglist_pag))
  719.     @debuglist_window.set_handler(:pagedown, method(:debuglist_pag))
  720.     @elementlist_window.set_handler(:ok, method(:elementlist_ok))
  721.     @elementlist_window.set_handler(:cancel, method(:elementlist_cancel))
  722.   end
  723. #class Scene_VisibleDebug#def mainlist_ok()
  724.   def mainlist_ok
  725.     it = @mainlist_window.item
  726.     if it[0] >= 0 # if item's a item:
  727.       if @mainlist_window.enabled?(@mainlist_window.index) # add/remove
  728.         @debuglist_window.add_item(it)
  729.       else
  730.         @debuglist_window.remove_item(it)
  731.       end
  732.       $game_player.sdebug.infos = @debuglist_window.data # update
  733.       @mainlist_window.draw_item(@mainlist_window.index) # redraw
  734.       @mainlist_window.activate
  735.     else # if item's a group:
  736.       process_elementlist_open(it) # open the sub-list
  737.       @elementlist_window.activate
  738.     end
  739.   end
  740. #class Scene_VisibleDebug#def mainlist_pag()
  741.   def mainlist_pag
  742.     @debuglist_window.activate
  743.   end
  744. #class Scene_VisibleDebug#def debuglist_ok()
  745.   def debuglist_ok
  746.     @debuglist_window.remove(@debuglist_window.index) # remove the item
  747.     $game_player.sdebug.infos = @debuglist_window.data # update
  748.     @mainlist_window.refresh # redraw
  749.     @debuglist_window.activate
  750.   end
  751. #class Scene_VisibleDebug#def debuglist_pag()
  752.   def debuglist_pag
  753.     @mainlist_window.activate
  754.   end
  755. #class Scene_VisibleDebug#def elementlist_ok()
  756.   def elementlist_ok
  757.     it = @elementlist_window.item
  758.     if @elementlist_window.enabled?(@elementlist_window.index) # add/remove
  759.       @debuglist_window.add_item(it)
  760.     else
  761.       @debuglist_window.remove_item(it)
  762.     end
  763.     $game_player.sdebug.infos = @debuglist_window.data # update
  764.     @elementlist_window.draw_item(@elementlist_window.index) # redraw
  765.     @elementlist_window.activate
  766.   end
  767. #class Scene_VisibleDebug#def elementlist_cancel()
  768.   def elementlist_cancel
  769.     @mainlist_window.activate
  770.     @elementlist_window.close
  771.   end
  772. #class Scene_VisibleDebug#def process_elementlist_open(it)
  773.   def process_elementlist_open(it) # it contains the type and the size
  774.     # collect elements of the group
  775.     vals = []
  776.     for d in 1..it[1] # starting from 1, because there aren't IDs 0
  777.       vals << [it[0]*-1,d] # the type must be positive
  778.     end
  779.     # and let the window appears
  780.     @elementlist_window.set_list(vals)
  781.     @elementlist_window.index = 0
  782.     @elementlist_window.visible = true
  783.     @elementlist_window.open
  784.   end
  785. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement