FrameworkModule = { name: "Inventory Editor", key: :invedit, order: 50, menu: :NONE } #-------------------------------------------------------------------------- # Menu Commands #-------------------------------------------------------------------------- MenuFramework::MENU.register_command( type: :scene, key: :items, label: "modules/invedit:commands/items", name: "CheatMenuItems", order: 20 ) MenuFramework::MENU.register_command( type: :scene, key: :weapons, label: "modules/invedit:commands/weapons", name: "CheatMenuItems", order: 21 ) MenuFramework::MENU.register_command( type: :scene, key: :armors, label: "modules/invedit:commands/armors", name: "CheatMenuItems", order: 22 ) MenuFramework::MENU.register_command( type: :scene, key: :status, label: "modules/invedit:commands/status", name: "CheatMenuStatus", order: 30 ) # LonaCraft catalog (separate from the existing complete Items/Weapons/Armors). # Only register if the mod is available; all results come from the runtime DB. if $mod_manager.mods["LonaCraft"] && $mod_manager.mods["LonaCraft"].enabled MenuFramework::MENU.register_command( type: :scene, key: :lc_catalog, label: "modules/invedit:commands/lonacraft", name: "CheatMenuLonaCraftCatalog", dict: :LONACRAFT, order: 25 ) [ [:lc_materials, "modules/invedit:commands/lc_materials", 10], [:lc_furniture, "modules/invedit:commands/lc_furniture", 20], [:lc_weapons, "modules/invedit:commands/lc_weapons", 30], [:lc_tier_weapons, "modules/invedit:commands/lc_tier_weapons", 40], [:lc_tier_armors, "modules/invedit:commands/lc_tier_armors", 50] ].each do |catalog_type, text_key, priority| MenuFramework::SUBMENU.register_command( type: :scene, group: :LONACRAFT, key: catalog_type, label: text_key, name: "CheatMenuItems", order: priority ) end end MenuFramework::SUBMENU.register_command( type: :action, group: :MISC, key: "Bank Anywhere", label: "modules/invedit:commands/bank", hotkey: {key: "F2"}, order: 100, action: -> { SceneManager.goto(Scene_BankStorage) SceneManager.scene.prepare(System_Settings::STORAGE_BANK) }) #-------------------------------------------------------------------------- # Cache Item/weapon/armor/status Lists #-------------------------------------------------------------------------- # Pre-filtered once instead of re-scanning the raw data every time. module MenuFramework module InvEditCache extend self attr_reader :items, :weapons, :armors, :statuses attr_reader :lc_materials, :lc_furniture, :lc_weapons, :lc_tier_weapons, :lc_tier_armors def signature [$data_items, $data_weapons, $data_armors].map do |group| group ? [group.object_id, group.size] : [nil, 0] end end # Later mods (notably LonaCraft) wrap load_mod_database and append items # AFTER CheatFramework's database hook has finished. Recheck on menu open. def ensure_fresh build if @items.nil? || @built_signature != signature end def build @items = build_group($data_items, "I%03d:") @weapons = build_group($data_weapons, "W%03d:") @armors = build_group($data_armors, "A%03d:") @lc_materials = @items.select do |_label, item| item.item_name.to_s.start_with?("ItemLonaCraft") && !item.item_name.to_s.start_with?("ItemLonaCraftFurniture") end @lc_furniture = @items.select do |_label, item| item.item_name.to_s.start_with?("ItemLonaCraftFurniture") end @lc_weapons = @weapons.select do |_label, item| item.item_name.to_s.start_with?("ItemLonaCraft") end # LonaCraft crafts quality-tier equipment as _LC2 ... _LC5 variants. @lc_tier_weapons = @weapons.select do |_label, item| item.item_name.to_s =~ /_LC[2-5]\z/ end @lc_tier_armors = @armors.select do |_label, item| item.item_name.to_s =~ /_LC[2-5]\z/ end @statuses = ($data_StateName || {}).each_pair.reject do |k, v| v.nil? || k.nil? || v.name == "" || v.name == "nil" || v.name == "DataState:nil/name" || v.description == "" || v.description == "nil" || v.description == "DataState:nil/description" end.to_a @built_signature = signature end def build_group(group, fmt) return [] unless group (1...group.size).each_with_object([]) do |i, list| item = group[i] next if item.nil? || item.item_name.nil? || item.item_name == "" || item.description == "" list << [sprintf(fmt, i), item] end end end end class << DataManager alias_method :cf_invedit_load_mod_database, :load_mod_database def load_mod_database cf_invedit_load_mod_database MenuFramework::InvEditCache.build end end #-------------------------------------------------------------------------- # Menu Loading Fix #-------------------------------------------------------------------------- # Only draws the current page of rows instead of the whole list module MenuFramework module VirtualScrollWindow def contents_height page_row_max * item_height end def top_row @virtual_top_row || 0 end def top_row=(row) row = 0 if row < 0 row = row_max - 1 if row > row_max - 1 changed = row != top_row @virtual_top_row = row self.oy = 0 # bitmap only ever holds one page - never pan it refresh_visible_rows if changed end def draw_all_items first = top_row last = [top_row + page_row_max, item_max].min - 1 (first..last).each { |i| draw_item(i) } if last >= first end def item_rect(index) rect = Rect.new rect.width = item_width rect.height = item_height rect.x = index % col_max * (item_width + spacing) rect.y = (index / col_max - top_row) * item_height rect end def refresh @virtual_top_row = 0 self.oy = 0 super end def refresh_visible_rows contents.clear draw_all_items end end end #-------------------------------------------------------------------------- # Window_CheatMenuItems #-------------------------------------------------------------------------- class Window_CheatMenuItems < Window_Command include Action_Window_Defaults include MenuFramework::VirtualScrollWindow def initialize super symbol = SceneManager.scene.instance_variable_get(:@menu_symbol) set_type(symbol) end def set_type(type) @type = type refresh select(0) end def make_command_list MenuFramework::InvEditCache.ensure_fresh cache = case @type when :items then MenuFramework::InvEditCache.items when :weapons then MenuFramework::InvEditCache.weapons when :armors then MenuFramework::InvEditCache.armors when :lc_materials then MenuFramework::InvEditCache.lc_materials when :lc_furniture then MenuFramework::InvEditCache.lc_furniture when :lc_weapons then MenuFramework::InvEditCache.lc_weapons when :lc_tier_weapons then MenuFramework::InvEditCache.lc_tier_weapons when :lc_tier_armors then MenuFramework::InvEditCache.lc_tier_armors else [] end cache.each { |text, item| add_command(text, :item, true, item) } end def draw_item(index) MenuFramework.force_font(contents) if contents contents.clear_rect(item_rect_for_text(index)) rect = item_rect_for_text(index) item = @list[index][:ext] name = item.name change_color(normal_color, $game_party.item_number(item) > 0) change_color(knockout_color) if $game_party.item_number(item) > 0 && item.name == "" draw_text(rect, command_name(index)) rect.x += text_size(command_name(index)).width rect.width -= text_size(command_name(index)).width draw_icon(item.icon_index, rect.x, rect.y, $game_party.item_number(item) > 0) rect.x += 24 rect.width -= 24 draw_text(rect, $game_text[name]) text = sprintf("x%s", $game_party.item_number(item)) draw_text(rect, text, 2) end def load_initial return if @list.empty? text = prep_desc($game_text[@list[0][:ext].description]) override_help_window_text(text) end def refresh_help_window return if @list.empty? entry = @list[@index] return unless entry && entry[:ext] && entry[:ext] desc_key = entry[:ext].description text = prep_desc($game_text[desc_key]) override_help_window_text(text) end def prep_desc(desc) return "" if desc.nil? return "" if desc.end_with?("/description") return "" if desc.end_with?("nil/nil") return desc end def cursor_right(wrap = false) SndLib.play_cursor $game_party.gain_item(current_ext, Input.press?(Input::KEYMAP[:SHIFT]) ? 10 : 1) $game_party.gain_item(current_ext, Input.press?(Input::KEYMAP[:CTRL]) ? 99 : 0) draw_item(index) end def cursor_left(wrap = false) SndLib.play_cursor $game_party.lose_item(current_ext, Input.press?(Input::KEYMAP[:SHIFT]) ? 10 : 1) $game_party.lose_item(current_ext, Input.press?(Input::KEYMAP[:CTRL]) ? 99 : 0) draw_item(index) end end # Window_CheatMenuItems #-------------------------------------------------------------------------- # Window_CheatMenuStatus #-------------------------------------------------------------------------- class Window_CheatMenuStatus < Window_Command include Action_Window_Defaults include MenuFramework::VirtualScrollWindow def make_command_list $data_StateName.each_pair do |k, v| if v != nil and k != nil add_command("", :drawStat, true, [k, v]) if !(v.name == "" or v.name == "nil" or v.name == "DataState:nil/name" or v.description == "" or v.description == "nil" or v.description == "DataState:nil/description") end end end def drawStat end def draw_item(index) MenuFramework.force_font(contents) if contents contents.clear_rect(item_rect_for_text(index)) rect = item_rect_for_text(index) item = @list[index][:ext][1] name = @list[index][:ext][0] stack = $game_player.actor.state_stack(name) change_color(normal_color, stack) draw_icon(item.icon_index, rect.x, rect.y, stack) rect.x += 24 rect.width -= 24 if item.name.empty? draw_text(rect, name) else draw_text(rect, $game_text[item.name]) end text = sprintf("%s/%s", stack, item.max_stacks) draw_text(rect, text, 2) end def cursor_right(wrap = false) SndLib.play_cursor $game_player.actor.add_state(current_ext[0]) draw_item(index) end def cursor_left(wrap = false) SndLib.play_cursor $game_player.actor.remove_one_state(current_ext[0]) $game_player.actor.update_state_portrait_stat(current_ext[0]) draw_item(index) end def refresh_help_window return if @list.empty? entry = @list[@index] return unless entry && entry[:ext] && entry[:ext][1] desc_key = entry[:ext][1].description text = prep_desc($game_text[desc_key]) override_help_window_text(text) end def prep_desc(desc) return "" if desc.nil? return "" if desc.end_with?("/description") return "" if desc.end_with?("nil/nil") begin text = desc.dup text.sub!(/^\\}\\n\f\\}/, "\\}") # Remove leading \n\f\} text.sub!(/^\\}\\}/, "\\}") # Remove double \} text.sub!(/^\\}\\n/, "\\}") # Remove leading \n text.gsub!("\\n", " ") # Replace \n with space text.strip # Remove leading/trailing spaces rescue => e p "Got #{e.message}" "" end end end class Game_Actor def remove_one_state(state_id) state_id = $data_StateName[state_id].id if state_id.is_a?(String) return prp "erase_state #{state_id} not found", 1 if !state_id @states.delete_at(@states.index(state_id) || @states.length) # Removes only one stacked instance. return if state?(state_id) # Still stacked - stop here to avoid a bugged stack. # @state_turns.delete(state_id) @state_steps.delete(state_id) end end