Release 0.0.1.8.8.7
This commit is contained in:
1 parent
3c8a17aa78
commit
c7beab414c
16283 files changed
+768761
-2
No files matched your search
@@ -0,0 +1,514 @@
|
||||
#==============================================================================
|
||||
# CheatConfig
|
||||
#------------------------------------------------------------------------------
|
||||
# Handles config loading, saving, and tracking of hotkeys, variables,
|
||||
# and per-module enable/disable states.
|
||||
#==============================================================================
|
||||
|
||||
class FrameworkConfig
|
||||
attr_reader :mod_ini
|
||||
attr_reader :key_ini
|
||||
attr_reader :var_ini
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Legacy Global Variable Fixes
|
||||
#--------------------------------------------------------------------------
|
||||
# Fixes for stale "Global Variables" entries in globals.ini carried over from an older config.
|
||||
# Applied once at startup, before anything else reads globals.ini.
|
||||
# {type: :value, key:, from:, to:} - value "from" -> "to"
|
||||
# {type: :rename, from:, to:} - key "from" -> "to"
|
||||
# {type: :delete, key:} - drop the key
|
||||
LEGACY_GLOBAL_FIXES = [
|
||||
{type: :value, key: "Prevent Discard", from: "true", to: "1"},
|
||||
]
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Initialize and load INI files
|
||||
#--------------------------------------------------------------------------
|
||||
def initialize(config_dir)
|
||||
Dir.mkdir(config_dir) unless Dir.exist?(config_dir)
|
||||
@key_ini = load_or_create(File.join(config_dir, "hotkeys.ini"))
|
||||
@var_ini = load_or_create(File.join(config_dir, "globals.ini"))
|
||||
@mod_ini = load_or_create(File.join(config_dir, "modules.ini"))
|
||||
migrate_legacy_globals
|
||||
end
|
||||
|
||||
def migrate_legacy_globals
|
||||
section = "Global Variables"
|
||||
return unless @var_ini.has_section?(section)
|
||||
data = @var_ini[section]
|
||||
changed = false
|
||||
LEGACY_GLOBAL_FIXES.each do |fix|
|
||||
case fix[:type]
|
||||
when :value
|
||||
next unless data.key?(fix[:key]) && data[fix[:key]].to_s == fix[:from]
|
||||
data[fix[:key]] = fix[:to]
|
||||
changed = true
|
||||
when :rename
|
||||
next unless data.key?(fix[:from])
|
||||
data[fix[:to]] = data[fix[:from]] unless data.key?(fix[:to])
|
||||
data.delete(fix[:from])
|
||||
changed = true
|
||||
when :delete
|
||||
next unless data.key?(fix[:key])
|
||||
data.delete(fix[:key])
|
||||
changed = true
|
||||
end
|
||||
end
|
||||
@var_ini.write if changed
|
||||
end
|
||||
|
||||
def load_or_create(path)
|
||||
ini = IniFile.load(path)
|
||||
unless ini
|
||||
ini = IniFile.new(filename: path)
|
||||
ini.write
|
||||
end
|
||||
return ini
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Read / write helpers
|
||||
#--------------------------------------------------------------------------
|
||||
def read(section, key, default = "", ini)
|
||||
ini.read if ini.respond_to?(:read)
|
||||
if ini.has_section?(section) && ini[section].key?(key)
|
||||
ini[section][key]
|
||||
else
|
||||
default
|
||||
end
|
||||
end
|
||||
|
||||
def write(section, key, value, ini)
|
||||
ini[section] ||= {}
|
||||
ini[section][key] = value
|
||||
ini.write
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Mod override handlers
|
||||
#--------------------------------------------------------------------------
|
||||
def get_enabled(key, default = true)
|
||||
val = read("Module Load Overrides", key, default, @mod_ini).to_s.downcase
|
||||
return true if ["true", "1", "yes"].include?(val)
|
||||
return false if ["false", "0", "no"].include?(val)
|
||||
default
|
||||
end
|
||||
|
||||
def get_load_order(key, default = 999)
|
||||
val = read("Load Order Overrides", key, default, @mod_ini)
|
||||
val.to_i.nonzero? || default
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Global variables handlers
|
||||
#--------------------------------------------------------------------------
|
||||
def read_global(key, default)
|
||||
value = read("Global Variables", key, default, @var_ini)
|
||||
Object.instance_eval("$#{sanitize_key(key)} = #{format_value(value)}")
|
||||
value
|
||||
end
|
||||
|
||||
def write_global(key, value)
|
||||
write("Global Variables", key, value, @var_ini)
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Hotkey handling
|
||||
#--------------------------------------------------------------------------
|
||||
def init_hotkeys
|
||||
compare_hotkeys_to_ini
|
||||
clear_conflicting_hotkeys
|
||||
save_hotkeys_to_ini
|
||||
build_hotkey_map
|
||||
end
|
||||
|
||||
# Self-clears any of our own hotkeys sitting on a key HotkeyReserved flags.
|
||||
# The menu toggle's key never appears in hotkey_defs (see Input::SYM_KEYS[:CF_CHEAT_MENU], scripts/Menu.rb).
|
||||
def clear_conflicting_hotkeys
|
||||
$framework.hotkey_defs.each do |full_key, data|
|
||||
next unless data[:key]
|
||||
next unless HotkeyReserved.info_for_combo(data[:key])
|
||||
data[:key] = "NONE"
|
||||
end
|
||||
end
|
||||
|
||||
# Drops any "GROUP.Key" mapping whose command no longer exists (renamed, moved to a different
|
||||
# key, or removed entirely) instead of reviving it as a phantom hotkey_defs entry - safer than
|
||||
# guessing what it should remap to. $framework.commands is fully populated by init_modules,
|
||||
# which always runs before this (see __init__.rb), so it's a complete, reliable source of truth.
|
||||
def prune_orphaned_hotkeys(section)
|
||||
@key_ini[section].keys.each do |full_key|
|
||||
group, key = full_key.split('.', 2)
|
||||
# split always yields a String key, but commands can be registered with either
|
||||
# a String or Symbol key (see Controls.rb#resolve_record) - check both.
|
||||
dict = group && key && $framework.commands[group.to_sym]
|
||||
next if dict && (dict.key?(key) || dict.key?(key.to_sym))
|
||||
@key_ini[section].delete(full_key)
|
||||
end
|
||||
end
|
||||
|
||||
def compare_hotkeys_to_ini
|
||||
section = "Cheat Hotkeys"
|
||||
return unless @key_ini.has_section?(section)
|
||||
|
||||
prune_orphaned_hotkeys(section)
|
||||
|
||||
@key_ini[section].each do |full_key, value|
|
||||
next if value.nil?
|
||||
|
||||
# IniFile auto-typecasts a bare digit ("6") into an Integer on read -
|
||||
# a real possibility now that digit keys are assignable hotkeys.
|
||||
value = value.to_s.strip
|
||||
next if value.empty?
|
||||
|
||||
# Handle NONE → disable
|
||||
if value.upcase == "NONE"
|
||||
if $framework.hotkey_defs.key?(full_key)
|
||||
$framework.hotkey_defs[full_key][:key] = "NONE"
|
||||
else
|
||||
$framework.hotkey_defs[full_key] = { key: "NONE", sound: nil }
|
||||
end
|
||||
next
|
||||
end
|
||||
|
||||
# Otherwise, override or add
|
||||
if $framework.hotkey_defs.key?(full_key)
|
||||
$framework.hotkey_defs[full_key][:key] = value
|
||||
else
|
||||
$framework.hotkey_defs[full_key] = { key: value, sound: nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_hotkeys_to_ini
|
||||
section = "Cheat Hotkeys"
|
||||
@key_ini[section] ||= {}
|
||||
|
||||
$framework.hotkey_defs.each do |full_key, data|
|
||||
key_name = "#{full_key}"
|
||||
value = data[:key] || "NONE"
|
||||
@key_ini[section][key_name] = value
|
||||
end
|
||||
|
||||
@key_ini.write
|
||||
end
|
||||
|
||||
def build_hotkey_map
|
||||
$framework.hotkeys = Hash.new { |h, k| h[k] = [] }
|
||||
|
||||
$framework.hotkey_defs.each do |full_key, data|
|
||||
next if data[:key].nil? || data[:key].upcase == "NONE"
|
||||
|
||||
mods, base = parse_hotkey(data[:key])
|
||||
key_const = base
|
||||
|
||||
group, key = full_key.split('.', 2)
|
||||
$framework.hotkeys[key_const] << {
|
||||
group: group.to_sym,
|
||||
key: key,
|
||||
mods: mods,
|
||||
sound: data[:sound]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Main Menu Toggle key (portable backup)
|
||||
#--------------------------------------------------------------------------
|
||||
# Input::SYM_KEYS[:CF_CHEAT_MENU]/$LonaINI (the game's own Key Binds menu)
|
||||
def init_menu_toggle_key
|
||||
if menu_toggle_key_configured_in_game?
|
||||
Input::SYM_KEYS[:CF_CHEAT_MENU] = (0..2).map do |i|
|
||||
val = $LonaINI["Keyboard"]["CF_CHEAT_MENU_#{i}"]
|
||||
(val && val != 0 && val != "0") ? (Input::KEYMAP[val.to_s.to_sym] || 0) : 0
|
||||
end
|
||||
live = FrameworkUtils.current_menu_toggle_key
|
||||
save_menu_toggle_key(live) if live
|
||||
else
|
||||
saved_key = @key_ini["Main Menu Toggle"]["key"]
|
||||
saved_key = "F9" if saved_key.nil? || saved_key.to_s.strip.empty?
|
||||
apply_menu_toggle_key(saved_key)
|
||||
end
|
||||
end
|
||||
|
||||
def menu_toggle_key_configured_in_game?
|
||||
(0..2).any? do |i|
|
||||
val = $LonaINI["Keyboard"]["CF_CHEAT_MENU_#{i}"]
|
||||
val && val != 0 && val != "0"
|
||||
end
|
||||
end
|
||||
|
||||
def apply_menu_toggle_key(key_str)
|
||||
key_sym = HotkeySymbols.symbol_for(key_str) || key_str.to_sym
|
||||
Input::SYM_KEYS[:CF_CHEAT_MENU] = [Input::KEYMAP[key_sym] || Input::KEYMAP[:F9], 0, 0]
|
||||
save_menu_toggle_key(key_str)
|
||||
save_menu_toggle_key_to_game_ini
|
||||
end
|
||||
|
||||
# hook_vanilla_keybind_menu puts :CF_CHEAT_MENU in InputUtils.keyList, so MouseSupport's
|
||||
# frequent InputUtils.load_input_settings calls reload it from $LonaINI - write it there too
|
||||
# or our default gets overwritten back to unbound the next time the mouse toggles.
|
||||
def save_menu_toggle_key_to_game_ini
|
||||
(0..2).each do |i|
|
||||
code = Input::SYM_KEYS[:CF_CHEAT_MENU][i]
|
||||
$LonaINI["Keyboard"]["CF_CHEAT_MENU_#{i}"] = code != 0 ? InputUtils.reverse_key_map[code].to_s : "0"
|
||||
end
|
||||
$LonaINI.save
|
||||
end
|
||||
|
||||
def save_menu_toggle_key(key_str)
|
||||
@key_ini["Main Menu Toggle"]["key"] = key_str
|
||||
@key_ini.write
|
||||
end
|
||||
|
||||
# Catches rebinds made through the vanilla Key Binds menu.
|
||||
def sync_menu_toggle_key
|
||||
live = FrameworkUtils.current_menu_toggle_key
|
||||
return unless live
|
||||
return if live == @key_ini["Main Menu Toggle"]["key"]
|
||||
save_menu_toggle_key(live)
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Menu order handling
|
||||
#--------------------------------------------------------------------------
|
||||
def init_order
|
||||
compare_order_to_ini
|
||||
save_order_to_ini
|
||||
end
|
||||
|
||||
def compare_order_to_ini
|
||||
section = "Menu Order Overrides"
|
||||
return unless @mod_ini.has_section?(section)
|
||||
|
||||
@mod_ini[section].each do |full_key, value|
|
||||
next if value.nil? || value.to_s.strip.empty?
|
||||
|
||||
group_key, cmd_key = full_key.split('.', 2)
|
||||
next unless group_key && cmd_key
|
||||
|
||||
dict = $framework.commands[group_key.to_sym]
|
||||
next unless dict
|
||||
|
||||
record = dict[cmd_key] || dict[cmd_key.to_sym]
|
||||
next unless record
|
||||
|
||||
record[:order] = value.to_i
|
||||
end
|
||||
end
|
||||
|
||||
def save_order_to_ini
|
||||
section = "Menu Order Overrides"
|
||||
@mod_ini[section] ||= {}
|
||||
|
||||
$framework.commands.each do |group, dict|
|
||||
next unless dict.is_a?(Hash)
|
||||
|
||||
dict.each do |key, record|
|
||||
next unless record.is_a?(Hash) && record.key?(:order)
|
||||
@mod_ini[section]["#{group}.#{key}"] = record[:order]
|
||||
end
|
||||
end
|
||||
|
||||
@mod_ini.write
|
||||
end
|
||||
|
||||
# Wipes all custom menu ordering back to each command's registered default.
|
||||
def reset_menu_order
|
||||
$framework.commands.each do |_group, dict|
|
||||
next unless dict.is_a?(Hash)
|
||||
dict.each do |_key, record|
|
||||
next unless record.is_a?(Hash) && record.key?(:default_order)
|
||||
record[:order] = record[:default_order]
|
||||
end
|
||||
end
|
||||
|
||||
@mod_ini.delete_section("Menu Order Overrides")
|
||||
@mod_ini.write
|
||||
end
|
||||
|
||||
# In-memory session for Edit Menu Order's Save/Discard confirm flow.
|
||||
def start_menu_order_session
|
||||
snapshot = {}
|
||||
$framework.commands.each do |group, dict|
|
||||
next unless dict.is_a?(Hash)
|
||||
dict.each do |key, record|
|
||||
next unless record.is_a?(Hash) && record.key?(:order)
|
||||
snapshot["#{group}.#{key}"] = record[:order]
|
||||
end
|
||||
end
|
||||
$framework.menu_order_snapshot = snapshot
|
||||
$framework.menu_order_dirty = false
|
||||
end
|
||||
|
||||
def mark_menu_order_dirty
|
||||
$framework.menu_order_dirty = true
|
||||
end
|
||||
|
||||
def menu_order_dirty?
|
||||
!!$framework.menu_order_dirty
|
||||
end
|
||||
|
||||
def revert_menu_order_session
|
||||
return unless $framework.menu_order_snapshot
|
||||
$framework.menu_order_snapshot.each do |full_key, order|
|
||||
group_key, cmd_key = full_key.split('.', 2)
|
||||
dict = $framework.commands[group_key.to_sym]
|
||||
next unless dict
|
||||
record = dict[cmd_key] || dict[cmd_key.to_sym]
|
||||
next unless record
|
||||
record[:order] = order
|
||||
end
|
||||
clear_menu_order_session
|
||||
end
|
||||
|
||||
def clear_menu_order_session
|
||||
$framework.menu_order_snapshot = nil
|
||||
$framework.menu_order_dirty = false
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Local/Global override handling (Config > Edit Globals)
|
||||
#--------------------------------------------------------------------------
|
||||
# Unlike menu order/hotkeys, these two actively prune stale entries.
|
||||
def init_force_modes
|
||||
compare_force_modes_to_ini
|
||||
save_force_modes_to_ini
|
||||
end
|
||||
|
||||
def compare_force_modes_to_ini
|
||||
section = "Force Mode Overrides"
|
||||
return unless @mod_ini.has_section?(section)
|
||||
|
||||
@mod_ini[section].each do |full_key, value|
|
||||
next if value.nil? || value.to_s.strip.empty?
|
||||
next unless global_override_eligible?(full_key)
|
||||
|
||||
$framework.force_modes[full_key] = coerce_ini_value(value) == true
|
||||
end
|
||||
end
|
||||
|
||||
def save_force_modes_to_ini
|
||||
section = "Force Mode Overrides"
|
||||
@mod_ini.delete_section(section)
|
||||
@mod_ini[section] = {}
|
||||
|
||||
$framework.force_modes.each do |full_key, mode|
|
||||
@mod_ini[section][full_key] = mode
|
||||
end
|
||||
|
||||
@mod_ini.write
|
||||
end
|
||||
|
||||
def init_force_values
|
||||
compare_force_values_to_ini
|
||||
save_force_values_to_ini
|
||||
end
|
||||
|
||||
def compare_force_values_to_ini
|
||||
section = "Force Value Overrides"
|
||||
return unless @mod_ini.has_section?(section)
|
||||
|
||||
@mod_ini[section].each do |full_key, value|
|
||||
next if value.nil? || value.to_s.strip.empty?
|
||||
next unless global_override_eligible?(full_key)
|
||||
|
||||
$framework.force_values[full_key] = coerce_ini_value(value)
|
||||
end
|
||||
end
|
||||
|
||||
def save_force_values_to_ini
|
||||
section = "Force Value Overrides"
|
||||
@mod_ini.delete_section(section)
|
||||
@mod_ini[section] = {}
|
||||
|
||||
$framework.force_values.each do |full_key, value|
|
||||
@mod_ini[section][full_key] = value
|
||||
end
|
||||
|
||||
@mod_ini.write
|
||||
end
|
||||
|
||||
# True if "GROUP.CommandKey" still resolves to a global:-flagged command.
|
||||
def global_override_eligible?(full_key)
|
||||
group_key, cmd_key = full_key.split('.', 2)
|
||||
return false unless group_key && cmd_key
|
||||
|
||||
dict = $framework.commands[group_key.to_sym]
|
||||
return false unless dict
|
||||
|
||||
record = dict[cmd_key] || dict[cmd_key.to_sym]
|
||||
!!(record && !record[:global].nil?)
|
||||
end
|
||||
|
||||
# IniFile typecasts numbers on its own; this adds true/false.
|
||||
def coerce_ini_value(value)
|
||||
return value unless value.is_a?(String)
|
||||
return true if value.downcase == "true"
|
||||
return false if value.downcase == "false"
|
||||
value
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Full reset (Config > Reset All Settings)
|
||||
#--------------------------------------------------------------------------
|
||||
def reset_all_settings
|
||||
@mod_ini.delete_section("Module Load Overrides")
|
||||
@mod_ini.delete_section("Load Order Overrides")
|
||||
@mod_ini.write
|
||||
|
||||
@var_ini.delete_section("Global Variables")
|
||||
@var_ini.write
|
||||
end
|
||||
|
||||
def reset_hotkeys_live
|
||||
$framework.hotkey_defs = $framework.hotkey_defaults.each_with_object({}) { |(k, v), h| h[k] = v.dup }
|
||||
clear_conflicting_hotkeys
|
||||
@key_ini.delete_section("Cheat Hotkeys")
|
||||
save_hotkeys_to_ini
|
||||
build_hotkey_map
|
||||
|
||||
apply_menu_toggle_key("F9")
|
||||
end
|
||||
|
||||
def reset_force_overrides
|
||||
$framework.force_modes.clear
|
||||
$framework.force_values.clear
|
||||
@mod_ini.delete_section("Force Mode Overrides")
|
||||
@mod_ini.delete_section("Force Value Overrides")
|
||||
@mod_ini.write
|
||||
end
|
||||
|
||||
def parse_hotkey(hotkey_str)
|
||||
parts = hotkey_str.split('+').map(&:strip)
|
||||
mods = []
|
||||
base = nil
|
||||
|
||||
parts.each do |p|
|
||||
case p.downcase
|
||||
when "shift" then mods << :SHIFT
|
||||
when "ctrl", "control" then mods << :CTRL
|
||||
when "alt" then mods << :ALT
|
||||
else
|
||||
base = HotkeySymbols.symbol_for(p) || p.upcase.to_sym
|
||||
end
|
||||
end
|
||||
|
||||
[mods, base]
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Special handlers
|
||||
#--------------------------------------------------------------------------
|
||||
private
|
||||
|
||||
def sanitize_key(key)
|
||||
key.to_s.strip.gsub(/\s+/, "_").downcase
|
||||
end
|
||||
|
||||
def format_value(value)
|
||||
return "\"#{value}\"" if value.is_a?(String) && value !~ /^\d+$/
|
||||
value
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,940 @@
|
||||
#==============================================================================
|
||||
# Config screens: Edit Menu Order, View Hotkeys, Edit Globals
|
||||
#------------------------------------------------------------------------------
|
||||
# Core framework tooling, not a cheat, so it lives in scripts/ (always
|
||||
# loaded) rather than modules/. No FrameworkModule block; load order is just
|
||||
# top-to-bottom in this file. Text keys live in text/<LANG>/menu.txt.
|
||||
#==============================================================================
|
||||
|
||||
#==============================================================================
|
||||
# Shared instructional footer for all three screens below
|
||||
#==============================================================================
|
||||
class Window_CheatOrderHelp < Window_Base
|
||||
def initialize(text)
|
||||
super(0, Graphics.height - 120, Graphics.width, 120)
|
||||
set_text(text)
|
||||
end
|
||||
|
||||
def set_text(text)
|
||||
@text = text
|
||||
refresh
|
||||
end
|
||||
|
||||
def refresh
|
||||
contents.clear
|
||||
MenuFramework.force_font(contents)
|
||||
draw_text_ex(4, 0, @text)
|
||||
end
|
||||
end
|
||||
|
||||
#==============================================================================
|
||||
# Forced Save/Discard prompt for unsaved menu reordering. No :cancel handler.
|
||||
#==============================================================================
|
||||
class Window_CheatOrderConfirm < Window_Command
|
||||
def initialize
|
||||
super((Graphics.width - window_width) / 2, (Graphics.height - window_height) / 2)
|
||||
end
|
||||
|
||||
def window_width; 300; end
|
||||
def window_height; fitting_height(2); end
|
||||
|
||||
def make_command_list
|
||||
add_command("Save Changes", :save)
|
||||
add_command("Discard Changes", :discard)
|
||||
end
|
||||
|
||||
def draw_item(index)
|
||||
MenuFramework.force_font(contents)
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
#==============================================================================
|
||||
# Step 1: pick which menu (group) to reorder
|
||||
#==============================================================================
|
||||
class Window_CheatMenuOrderGroups < Window_Command
|
||||
include Window_ConfigList_Defaults
|
||||
|
||||
# :MENU hotkey plumbing
|
||||
HIDDEN_GROUPS = [:NONE, :MENU]
|
||||
|
||||
# Groups matching this prefix (SUMMON, SUMMON_HUMAN, SUMMON_WILD, ...) get
|
||||
# collapsed into a single "family" row instead of cluttering the top level.
|
||||
FAMILY_PREFIX = "SUMMON"
|
||||
|
||||
def initialize
|
||||
super(0, 0)
|
||||
@filter = SceneManager.scene.instance_variable_get(:@filter)
|
||||
refresh
|
||||
select(0)
|
||||
end
|
||||
|
||||
def make_command_list
|
||||
# Pinned first, irrespective of alphabetical order, and only at the top
|
||||
# (unfiltered) level - a reset doesn't belong scoped to one family view.
|
||||
add_command($framework.txt("menu:commands/reset_order"), :reset, true, nil) unless @filter
|
||||
|
||||
groups = $framework.commands.keys.reject { |g| HIDDEN_GROUPS.include?(g) }
|
||||
groups = groups.select { |g| $framework.commands[g].is_a?(Hash) && !$framework.commands[g].empty? }
|
||||
|
||||
if @filter
|
||||
groups.select { |g| in_family?(g, @filter) }
|
||||
.sort_by(&:to_s)
|
||||
.each { |group| add_command(group_label(group), :ok, true, group) }
|
||||
else
|
||||
family, singles = groups.partition { |g| in_family?(g, FAMILY_PREFIX) }
|
||||
singles.sort_by(&:to_s).each { |group| add_command(group_label(group), :ok, true, group) }
|
||||
unless family.empty?
|
||||
total = family.inject(0) { |sum, g| sum + $framework.commands[g].size }
|
||||
add_command("#{FAMILY_PREFIX} family (#{family.size} menus, #{total} commands)", :family, true, FAMILY_PREFIX)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def in_family?(group, prefix)
|
||||
group.to_s == prefix || group.to_s.start_with?("#{prefix}_")
|
||||
end
|
||||
|
||||
def group_label(group)
|
||||
"#{group} (#{$framework.commands[group].size})"
|
||||
end
|
||||
|
||||
def draw_item(index)
|
||||
force_content_font
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
class Scene_CheatMenuOrderGroups < Scene_MenuBase
|
||||
include Scene_ConfigList_Defaults
|
||||
|
||||
def start
|
||||
super
|
||||
# Only true top-level entry starts a session (family drill-downs and
|
||||
# returning here from a child scene reuse whatever's already running).
|
||||
$framework.ini.start_menu_order_session if @filter.nil? && $framework.menu_order_snapshot.nil?
|
||||
|
||||
@command_window = Window_CheatMenuOrderGroups.new
|
||||
@command_window.set_handler(:ok, method(:open_group))
|
||||
@command_window.set_handler(:family, method(:open_family))
|
||||
@command_window.set_handler(:reset, method(:perform_reset))
|
||||
@command_window.set_handler(:cancel, method(:on_cancel))
|
||||
@help_window = Window_CheatOrderHelp.new(
|
||||
@filter ? "Pick a #{@filter} menu to reorder.\nZ: Open X: Back" : "Pick a menu to reorder, or reset it.\nZ: Select X: Back"
|
||||
)
|
||||
restore_selection
|
||||
end
|
||||
|
||||
# Each handler reactivates @command_window first (process_ok deactivates it).
|
||||
def open_group
|
||||
@command_window.activate
|
||||
group = @command_window.current_ext
|
||||
save_selection
|
||||
SceneManager.call(Scene_CheatMenuOrderEdit)
|
||||
SceneManager.scene.instance_variable_set(:@group, group) if SceneManager.scene
|
||||
end
|
||||
|
||||
def perform_reset
|
||||
@command_window.activate
|
||||
$framework.ini.reset_menu_order
|
||||
$framework.ini.start_menu_order_session # re-baseline: nothing pending after a reset
|
||||
SndLib.sys_ok
|
||||
@command_window.refresh
|
||||
@command_window.select(0)
|
||||
end
|
||||
|
||||
# Drill into the collapsed "family" row (e.g. SUMMON) - reopens this same
|
||||
# scene class, just filtered down to that family's groups.
|
||||
def open_family
|
||||
@command_window.activate
|
||||
prefix = @command_window.current_ext
|
||||
save_selection
|
||||
SceneManager.call(Scene_CheatMenuOrderGroups)
|
||||
SceneManager.scene.instance_variable_set(:@filter, prefix) if SceneManager.scene
|
||||
end
|
||||
|
||||
# A dirty top-level exit forces a Save/Discard choice first.
|
||||
def on_cancel
|
||||
if @filter.nil? && $framework.ini.menu_order_dirty?
|
||||
show_confirm
|
||||
else
|
||||
save_selection
|
||||
return_scene
|
||||
end
|
||||
end
|
||||
|
||||
def show_confirm
|
||||
@command_window.deactivate
|
||||
@help_window.set_text("You have unsaved menu order changes.\nPick one - there's no going back without choosing.")
|
||||
@confirm_window = Window_CheatOrderConfirm.new
|
||||
@confirm_window.set_handler(:save, method(:confirm_save))
|
||||
@confirm_window.set_handler(:discard, method(:confirm_discard))
|
||||
end
|
||||
|
||||
def confirm_save
|
||||
$framework.ini.save_order_to_ini
|
||||
$framework.ini.clear_menu_order_session
|
||||
SndLib.sys_ok
|
||||
leave_after_confirm
|
||||
end
|
||||
|
||||
def confirm_discard
|
||||
$framework.ini.revert_menu_order_session
|
||||
SndLib.sys_buzzer
|
||||
leave_after_confirm
|
||||
end
|
||||
|
||||
def leave_after_confirm
|
||||
@confirm_window.dispose
|
||||
@confirm_window = nil
|
||||
save_selection
|
||||
return_scene
|
||||
end
|
||||
|
||||
# Distinct breadcrumb key for the unfiltered list vs. each family sub-view.
|
||||
def menu_key
|
||||
@filter ? :"edit_menu_order_family_#{@filter}" : :edit_menu_order
|
||||
end
|
||||
end
|
||||
FrameworkUtils.menu_scenes << Scene_CheatMenuOrderGroups
|
||||
|
||||
#==============================================================================
|
||||
# Step 2: reorder the commands within the chosen group
|
||||
#==============================================================================
|
||||
class Window_CheatMenuOrderEdit < Window_Command
|
||||
include Window_ConfigList_Defaults
|
||||
|
||||
def initialize
|
||||
super(0, 0)
|
||||
@group = SceneManager.scene.instance_variable_get(:@group)
|
||||
refresh
|
||||
select(0)
|
||||
end
|
||||
|
||||
def make_command_list
|
||||
return unless @group
|
||||
dict = $framework.commands[@group]
|
||||
return unless dict
|
||||
FrameworkUtils.sorted_commands(dict).each do |key, record|
|
||||
name = FrameworkUtils.display_name_for(record, key)
|
||||
add_command(name, :ok, true, key)
|
||||
end
|
||||
end
|
||||
|
||||
def draw_item(index)
|
||||
force_content_font
|
||||
rect = item_rect_for_text(index)
|
||||
contents.clear_rect(rect)
|
||||
change_color(normal_color, command_enabled?(index))
|
||||
draw_text(rect, command_name(index), 0)
|
||||
|
||||
key = @list[index][:ext]
|
||||
record = @group && $framework.commands[@group] ? $framework.commands[@group][key] : nil
|
||||
draw_text(rect, record[:order].to_s, 2) if record && record[:order]
|
||||
end
|
||||
|
||||
# Swaps the selected command's position and renumbers the group.
|
||||
def cursor_left(wrap = false)
|
||||
move_selected(-1)
|
||||
end
|
||||
|
||||
def cursor_right(wrap = false)
|
||||
move_selected(1)
|
||||
end
|
||||
|
||||
def move_selected(direction)
|
||||
return unless @group
|
||||
dict = $framework.commands[@group]
|
||||
return unless dict
|
||||
|
||||
ordered = FrameworkUtils.sorted_commands(dict)
|
||||
i = ordered.index { |key, _record| key == current_ext }
|
||||
return unless i
|
||||
|
||||
j = i + direction
|
||||
return if j < 0 || j >= ordered.size
|
||||
|
||||
ordered[i], ordered[j] = ordered[j], ordered[i]
|
||||
ordered.each_with_index { |(_key, record), idx| record[:order] = (idx + 1) * 10 }
|
||||
|
||||
SndLib.play_cursor
|
||||
$framework.ini.mark_menu_order_dirty # cached in memory only - written on explicit confirm
|
||||
|
||||
moved_key = current_ext
|
||||
refresh
|
||||
new_index = @list.index { |cmd| cmd[:ext] == moved_key }
|
||||
select(new_index || index)
|
||||
end
|
||||
end
|
||||
|
||||
class Scene_CheatMenuOrderEdit < Scene_MenuBase
|
||||
include Scene_ConfigList_Defaults
|
||||
|
||||
def start
|
||||
super
|
||||
@command_window = Window_CheatMenuOrderEdit.new
|
||||
@command_window.set_handler(:cancel, method(:return_to_groups))
|
||||
@help_window = Window_CheatOrderHelp.new(
|
||||
"Left/Right: Move up/down X: Back to menu list"
|
||||
)
|
||||
restore_selection
|
||||
end
|
||||
|
||||
def return_to_groups
|
||||
save_selection
|
||||
return_scene
|
||||
end
|
||||
|
||||
# Distinct breadcrumb key per group (this scene class is reused for all of them).
|
||||
def menu_key
|
||||
:"edit_menu_order_#{@group}"
|
||||
end
|
||||
end
|
||||
FrameworkUtils.menu_scenes << Scene_CheatMenuOrderEdit
|
||||
|
||||
#==============================================================================
|
||||
# View Hotkeys: every bound command and its key (clear only)
|
||||
#==============================================================================
|
||||
class Window_CheatHotkeyList < Window_Command
|
||||
include Window_ConfigList_Defaults
|
||||
|
||||
MAIN_MENU_KEY = "MENU.Main Menu"
|
||||
|
||||
# F1/F12/F10 excluded (blocked/reserved); F5/F6 excluded (RolePlay-S
|
||||
# QuickSave/QuickLoad while active). M is a free letter key, not an F-key.
|
||||
MAIN_MENU_CANDIDATES = %w[F2 F3 F4 F7 F8 F9 F11 M]
|
||||
|
||||
def initialize
|
||||
super(0, 0)
|
||||
@editing_main_menu = false
|
||||
@pending_index = 0
|
||||
end
|
||||
|
||||
def make_command_list
|
||||
# Pinned first, always. Not a plain :ok row like the rest - see
|
||||
# toggle_main_menu_edit for why changing this one is a bigger deal.
|
||||
add_command(main_menu_label, :locked, true, MAIN_MENU_KEY)
|
||||
|
||||
$framework.hotkey_defs.each do |full_key, data|
|
||||
next if data[:key].nil? || data[:key].to_s.upcase == "NONE" # nothing to show/clear anymore
|
||||
record = resolve_record(full_key)
|
||||
next unless record
|
||||
|
||||
name = FrameworkUtils.display_name_for(record, record[:key])
|
||||
add_command(name, :ok, true, full_key)
|
||||
end
|
||||
end
|
||||
|
||||
def main_menu_label
|
||||
"Main Menu (more options in Keybind menu)"
|
||||
end
|
||||
|
||||
def resolve_record(full_key)
|
||||
group_key, cmd_key = full_key.split('.', 2)
|
||||
dict = $framework.commands[group_key.to_sym]
|
||||
return nil unless dict
|
||||
dict[cmd_key] || dict[cmd_key.to_sym]
|
||||
end
|
||||
|
||||
def draw_item(index)
|
||||
force_content_font
|
||||
rect = item_rect_for_text(index)
|
||||
contents.clear_rect(rect)
|
||||
|
||||
full_key = @list[index][:ext]
|
||||
|
||||
if full_key == MAIN_MENU_KEY
|
||||
draw_main_menu_row(rect, index)
|
||||
return
|
||||
end
|
||||
|
||||
change_color(normal_color)
|
||||
draw_text(rect, command_name(index), 0)
|
||||
|
||||
data = $framework.hotkey_defs[full_key]
|
||||
key_text = (data && data[:key]) || "NONE"
|
||||
reserved = HotkeyReserved.info_for(key_text)
|
||||
if reserved
|
||||
change_color(text_color(8))
|
||||
draw_text(rect, "#{key_text} (also: #{reserved[:label]})", 2)
|
||||
else
|
||||
change_color(normal_color)
|
||||
draw_text(rect, key_text, 2)
|
||||
end
|
||||
end
|
||||
|
||||
def draw_main_menu_row(rect, index)
|
||||
current = FrameworkUtils.current_menu_toggle_key || "NONE"
|
||||
change_color(@editing_main_menu ? text_color(16) : text_color(8))
|
||||
draw_text(rect, command_name(index), 0)
|
||||
draw_text(rect, @editing_main_menu ? MAIN_MENU_CANDIDATES[@pending_index] : current, 2)
|
||||
end
|
||||
|
||||
# Rebind for the Main Menu hotkey: cycle candidates, second press confirms.
|
||||
def toggle_main_menu_edit
|
||||
if @editing_main_menu
|
||||
confirm_main_menu_edit
|
||||
else
|
||||
start_main_menu_edit
|
||||
end
|
||||
end
|
||||
|
||||
def start_main_menu_edit
|
||||
current = FrameworkUtils.current_menu_toggle_key || "F9"
|
||||
@pending_index = MAIN_MENU_CANDIDATES.index(current) || MAIN_MENU_CANDIDATES.index("F9")
|
||||
@editing_main_menu = true
|
||||
SndLib.play_cursor
|
||||
refresh
|
||||
update_warning_text
|
||||
end
|
||||
|
||||
def cancel_main_menu_edit
|
||||
@editing_main_menu = false
|
||||
SndLib.sys_cancel
|
||||
refresh
|
||||
update_warning_text
|
||||
end
|
||||
|
||||
def confirm_main_menu_edit
|
||||
new_key = MAIN_MENU_CANDIDATES[@pending_index]
|
||||
@editing_main_menu = false
|
||||
|
||||
# Single source of truth, shared with the vanilla Key Binds menu.
|
||||
$framework.ini.apply_menu_toggle_key(new_key)
|
||||
|
||||
# Wipe any cheat hotkey already sitting on the new base key (any modifier).
|
||||
wiped = false
|
||||
$framework.hotkey_defs.each do |full_key, data|
|
||||
next unless data[:key]
|
||||
next unless data[:key].to_s.split('+').last.upcase == new_key
|
||||
data[:key] = "NONE"
|
||||
wiped = true
|
||||
end
|
||||
if wiped
|
||||
$framework.ini.save_hotkeys_to_ini
|
||||
$framework.ini.build_hotkey_map
|
||||
end
|
||||
|
||||
SndLib.sys_ok
|
||||
refresh
|
||||
update_warning_text
|
||||
end
|
||||
|
||||
def update_warning_text
|
||||
return unless SceneManager.scene.respond_to?(:set_main_menu_warning)
|
||||
if @editing_main_menu
|
||||
SceneManager.scene.set_main_menu_warning(
|
||||
"WARNING: this changes which key opens this menu - pick carefully!\n" \
|
||||
"Previewing: #{MAIN_MENU_CANDIDATES[@pending_index]} " \
|
||||
"Left/Right: change Z: confirm X: cancel"
|
||||
)
|
||||
else
|
||||
SceneManager.scene.set_main_menu_warning(nil)
|
||||
end
|
||||
end
|
||||
|
||||
def cursor_up(wrap = false)
|
||||
super unless @editing_main_menu
|
||||
end
|
||||
|
||||
def cursor_down(wrap = false)
|
||||
super unless @editing_main_menu
|
||||
end
|
||||
|
||||
# Also locked while editing (reachable via L/R shoulder or mouse wheel).
|
||||
def cursor_pageup
|
||||
super unless @editing_main_menu
|
||||
end
|
||||
|
||||
def cursor_pagedown
|
||||
super unless @editing_main_menu
|
||||
end
|
||||
|
||||
def cursor_left(wrap = false)
|
||||
if @editing_main_menu
|
||||
SndLib.play_cursor
|
||||
@pending_index = (@pending_index - 1) % MAIN_MENU_CANDIDATES.size
|
||||
refresh
|
||||
update_warning_text
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def cursor_right(wrap = false)
|
||||
if @editing_main_menu
|
||||
SndLib.play_cursor
|
||||
@pending_index = (@pending_index + 1) % MAIN_MENU_CANDIDATES.size
|
||||
refresh
|
||||
update_warning_text
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def process_cancel
|
||||
if @editing_main_menu
|
||||
cancel_main_menu_edit
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Scene_CheatHotkeyList < Scene_MenuBase
|
||||
include Scene_ConfigList_Defaults
|
||||
|
||||
def menu_key; :set_hotkeys; end
|
||||
|
||||
def start
|
||||
super
|
||||
@command_window = Window_CheatHotkeyList.new
|
||||
@command_window.set_handler(:ok, method(:clear_selected))
|
||||
@command_window.set_handler(:locked, method(:on_main_menu_locked))
|
||||
@command_window.set_handler(:cancel, method(:on_cancel))
|
||||
@base_help_text = "Read-only - to assign or change one, use C in the command's own menu.\nZ: Clear X: Back"
|
||||
@help_window = Window_CheatOrderHelp.new(@base_help_text)
|
||||
restore_selection
|
||||
end
|
||||
|
||||
def set_main_menu_warning(text)
|
||||
@help_window.set_text(text || @base_help_text)
|
||||
end
|
||||
|
||||
def on_main_menu_locked
|
||||
@command_window.activate # process_ok already deactivated - reactivate before doing anything
|
||||
@command_window.toggle_main_menu_edit
|
||||
end
|
||||
|
||||
def clear_selected
|
||||
# Reactivate - process_ok deactivates before calling the handler.
|
||||
@command_window.activate
|
||||
|
||||
full_key = @command_window.current_ext
|
||||
return unless $framework.hotkey_defs[full_key]
|
||||
|
||||
$framework.hotkey_defs[full_key][:key] = "NONE"
|
||||
$framework.ini.save_hotkeys_to_ini
|
||||
$framework.ini.build_hotkey_map # live immediately - no restart needed
|
||||
SndLib.sys_cancel
|
||||
|
||||
@command_window.refresh
|
||||
clamp_selection # the cleared row just vanished from the list - keep the cursor in bounds
|
||||
end
|
||||
|
||||
def on_cancel
|
||||
save_selection
|
||||
return_scene
|
||||
end
|
||||
end
|
||||
FrameworkUtils.menu_scenes << Scene_CheatHotkeyList
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Local/Global override engine (Config > Edit Globals)
|
||||
#--------------------------------------------------------------------------
|
||||
module FrameworkUtils
|
||||
# force_modes["GROUP.CommandKey"] = true/false, is an override active.
|
||||
def self.force_mode_for(group, key)
|
||||
$framework.force_modes["#{group}.#{key}"] == true
|
||||
end
|
||||
|
||||
# Whether the command is currently, effectively behaving as Global.
|
||||
def self.currently_global?(group, key, record)
|
||||
active = force_mode_for(group, key)
|
||||
record && record[:global] == true ? !active : active
|
||||
end
|
||||
|
||||
def self.current_command_value(record)
|
||||
return nil unless record && record[:state]
|
||||
value = record[:state].call
|
||||
record[:type] == :toggle ? !!value : value
|
||||
end
|
||||
|
||||
def self.local_value_story_key(full_key)
|
||||
"CF_local_#{full_key}"
|
||||
end
|
||||
|
||||
# global: false -> force_values, modules.ini. global: true -> $story_stats.
|
||||
def self.force_value_for(group, key, record)
|
||||
full_key = "#{group}.#{key}"
|
||||
if record && record[:global] == false
|
||||
return $framework.force_values[full_key] if $framework.force_values.key?(full_key)
|
||||
seed = current_command_value(record)
|
||||
$framework.force_values[full_key] = seed
|
||||
$framework.ini.save_force_values_to_ini
|
||||
seed
|
||||
else
|
||||
story_key = local_value_story_key(full_key)
|
||||
return $story_stats[story_key] if $story_stats.data.key?(story_key)
|
||||
seed = current_command_value(record)
|
||||
$story_stats[story_key] = seed
|
||||
seed
|
||||
end
|
||||
end
|
||||
|
||||
def self.set_force_value(group, key, record, new_value)
|
||||
full_key = "#{group}.#{key}"
|
||||
if record && record[:global] == false
|
||||
$framework.force_values[full_key] = new_value
|
||||
$framework.ini.save_force_values_to_ini
|
||||
else
|
||||
$story_stats[local_value_story_key(full_key)] = new_value
|
||||
end
|
||||
end
|
||||
|
||||
def self.toggle_force_mode(group, key, record)
|
||||
full_key = "#{group}.#{key}"
|
||||
$framework.force_modes[full_key] = !force_mode_for(group, key)
|
||||
$framework.ini.save_force_modes_to_ini
|
||||
apply_force_mode(group, key, record)
|
||||
end
|
||||
|
||||
def self.toggle_force_value(group, key, record)
|
||||
set_force_value(group, key, record, !force_value_for(group, key, record))
|
||||
apply_force_mode(group, key, record)
|
||||
end
|
||||
|
||||
# Left/Right editing for a :edit_num/:edit_list-sourced Value row.
|
||||
def self.adjust_force_value(group, key, record, direction, multiplier = 1)
|
||||
current = force_value_for(group, key, record)
|
||||
new_value = case record[:type]
|
||||
when :edit_num
|
||||
min = record[:min].is_a?(Proc) ? record[:min].call : (record[:min] || 0)
|
||||
max = record[:max].is_a?(Proc) ? record[:max].call : (record[:max] || 999)
|
||||
[[current.to_i + direction * multiplier, min].max, max].min
|
||||
when :edit_list
|
||||
list = record[:list] || []
|
||||
return if list.empty?
|
||||
idx = (list.index { |i| i[:key] == current } || 0)
|
||||
list[(idx + direction) % list.size][:key]
|
||||
else
|
||||
current
|
||||
end
|
||||
set_force_value(group, key, record, new_value)
|
||||
apply_force_mode(group, key, record)
|
||||
end
|
||||
|
||||
# Applies a forced value via the command's own action: (arity-dispatched).
|
||||
def self.force_command_value(record, desired)
|
||||
return unless record && record[:state] && record[:action]
|
||||
return if current_command_value(record) == desired
|
||||
case record[:action].arity
|
||||
when 1 then record[:action].call(desired)
|
||||
when 2 then record[:action].call(record[:key], desired)
|
||||
else record[:action].call
|
||||
end
|
||||
end
|
||||
|
||||
# Assigns the variable directly via state_str, bypassing action: (which
|
||||
# would also write globals.ini for a gdef:-backed command).
|
||||
def self.quiet_set_command_value(record, desired)
|
||||
return unless record && record[:state_str]
|
||||
return if current_command_value(record) == desired
|
||||
eval("#{record[:state_str]} = #{desired.inspect}")
|
||||
end
|
||||
|
||||
# Applies one command's configured override - a no-op while inactive.
|
||||
def self.apply_force_mode(group, key, record)
|
||||
return unless record && !record[:global].nil?
|
||||
return unless force_mode_for(group, key)
|
||||
desired = force_value_for(group, key, record)
|
||||
if record[:global] == false
|
||||
force_command_value(record, desired)
|
||||
else
|
||||
quiet_set_command_value(record, desired)
|
||||
end
|
||||
end
|
||||
|
||||
def self.apply_force_modes
|
||||
$framework.commands.each do |group, dict|
|
||||
next unless dict.is_a?(Hash)
|
||||
dict.each do |key, record|
|
||||
next unless record.is_a?(Hash)
|
||||
apply_force_mode(group, key, record)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Builds $framework.commands[:GLOBAL_OVERRIDES], one entry per global:
|
||||
# true/false command, addressed by source_group/source_key.
|
||||
def self.build_global_overrides
|
||||
overrides = {}
|
||||
order = 0
|
||||
$framework.commands.each do |group, dict|
|
||||
next if group == :GLOBAL_OVERRIDES
|
||||
next unless dict.is_a?(Hash)
|
||||
dict.each do |key, record|
|
||||
next unless record.is_a?(Hash) && !record[:global].nil?
|
||||
order += 10
|
||||
overrides["#{group}.#{key}"] = {
|
||||
source_group: group,
|
||||
source_key: key,
|
||||
# Live lookup for Edit Menu Order's display.
|
||||
label: -> {
|
||||
source = $framework.commands[group] && $framework.commands[group][key]
|
||||
FrameworkUtils.display_name_for(source, key)
|
||||
},
|
||||
order: order,
|
||||
default_order: order
|
||||
}
|
||||
end
|
||||
end
|
||||
$framework.commands[:GLOBAL_OVERRIDES] = overrides
|
||||
end
|
||||
end
|
||||
|
||||
#==============================================================================
|
||||
# Edit Globals: Mode row (Local/Global) plus a derived Value row
|
||||
#==============================================================================
|
||||
class Window_CheatGlobalsList < Window_Command
|
||||
include Window_ConfigList_Defaults
|
||||
|
||||
def initialize
|
||||
super(0, 0)
|
||||
end
|
||||
|
||||
def make_command_list
|
||||
FrameworkUtils.sorted_commands(overrides_dict).each do |full_key, override|
|
||||
source = source_record(override)
|
||||
next unless source
|
||||
name = "#{FrameworkUtils.display_name_for(source, override[:source_key])} [#{override[:source_group]}]"
|
||||
add_command(name, :toggle_mode, true, full_key)
|
||||
# Indentation is applied here, not baked into the text key.
|
||||
add_command(" #{$framework.txt("menu:mode/value_row")}", :toggle_value, true, full_key)
|
||||
end
|
||||
end
|
||||
|
||||
def overrides_dict
|
||||
$framework.commands[:GLOBAL_OVERRIDES] || {}
|
||||
end
|
||||
|
||||
def override_for(full_key)
|
||||
overrides_dict[full_key]
|
||||
end
|
||||
|
||||
def source_record(override)
|
||||
dict = override && $framework.commands[override[:source_group]]
|
||||
dict && dict[override[:source_key]]
|
||||
end
|
||||
|
||||
def draw_item(index)
|
||||
force_content_font
|
||||
rect = item_rect_for_text(index)
|
||||
contents.clear_rect(rect)
|
||||
|
||||
full_key = @list[index][:ext]
|
||||
override = override_for(full_key)
|
||||
source = source_record(override)
|
||||
return unless override && source
|
||||
|
||||
group, key = override[:source_group], override[:source_key]
|
||||
active = FrameworkUtils.force_mode_for(group, key) # is an override currently applying at all
|
||||
|
||||
case @list[index][:symbol]
|
||||
when :toggle_mode
|
||||
change_color(normal_color)
|
||||
draw_text(rect, command_name(index), 0)
|
||||
showing_global = FrameworkUtils.currently_global?(group, key, source)
|
||||
draw_text(rect, showing_global ? $framework.txt("menu:mode/global") : $framework.txt("menu:mode/local"), 2)
|
||||
when :toggle_value
|
||||
change_color(active ? normal_color : text_color(8))
|
||||
draw_text(rect, command_name(index), 0)
|
||||
value = FrameworkUtils.force_value_for(group, key, source)
|
||||
draw_text(rect, format_force_value(source, value), 2)
|
||||
end
|
||||
end
|
||||
|
||||
def format_force_value(record, value)
|
||||
case record[:type]
|
||||
when :toggle
|
||||
value ? $framework.txt("menu:cheat_toggle/on") : $framework.txt("menu:cheat_toggle/off")
|
||||
when :edit_list
|
||||
item = (record[:list] || []).find { |i| i[:key] == value }
|
||||
item ? item[:label] : value.to_s
|
||||
else
|
||||
value.to_s
|
||||
end
|
||||
end
|
||||
|
||||
# Left/Right only edits an :edit_num/:edit_list Value row; falls through otherwise.
|
||||
def cursor_left(wrap = false)
|
||||
return super unless adjustable_value_row?
|
||||
adjust_value_row(-1)
|
||||
end
|
||||
|
||||
def cursor_right(wrap = false)
|
||||
return super unless adjustable_value_row?
|
||||
adjust_value_row(1)
|
||||
end
|
||||
|
||||
def adjustable_value_row?
|
||||
entry = @list[index]
|
||||
return false unless entry && entry[:symbol] == :toggle_value
|
||||
source = source_record(override_for(entry[:ext]))
|
||||
source && [:edit_num, :edit_list].include?(source[:type])
|
||||
end
|
||||
|
||||
def adjust_value_row(direction)
|
||||
full_key = current_ext
|
||||
override = override_for(full_key)
|
||||
source = source_record(override)
|
||||
return unless override && source
|
||||
SndLib.play_cursor
|
||||
FrameworkUtils.adjust_force_value(override[:source_group], override[:source_key], source, direction, edit_value_multiply)
|
||||
refresh
|
||||
end
|
||||
|
||||
def edit_value_multiply
|
||||
multi = 1
|
||||
multi *= 10 if Input.press?(Input::KEYMAP[:SHIFT])
|
||||
multi *= 100 if Input.press?(Input::KEYMAP[:CONTROL])
|
||||
multi
|
||||
end
|
||||
end
|
||||
|
||||
class Scene_CheatGlobalsList < Scene_MenuBase
|
||||
include Scene_ConfigList_Defaults
|
||||
|
||||
def menu_key; :edit_globals; end
|
||||
|
||||
def start
|
||||
super
|
||||
@command_window = Window_CheatGlobalsList.new
|
||||
@command_window.set_handler(:toggle_mode, method(:toggle_mode))
|
||||
@command_window.set_handler(:toggle_value, method(:toggle_value))
|
||||
@command_window.set_handler(:cancel, method(:on_cancel))
|
||||
@help_window = Window_CheatOrderHelp.new(
|
||||
"Z: Local/Global (top row) or toggle the forced value (bottom row - :toggle sources only,\n" \
|
||||
"Left/Right instead for a number/list)\nX: Back"
|
||||
)
|
||||
restore_selection
|
||||
end
|
||||
|
||||
def toggle_mode
|
||||
@command_window.activate # process_ok already deactivated - reactivate before doing anything
|
||||
with_addressed_source(method(:apply_toggle_mode))
|
||||
end
|
||||
|
||||
def toggle_value
|
||||
@command_window.activate
|
||||
with_addressed_source(method(:apply_toggle_value))
|
||||
end
|
||||
|
||||
def apply_toggle_mode(group, key, source)
|
||||
FrameworkUtils.toggle_force_mode(group, key, source)
|
||||
SndLib.sys_ok
|
||||
end
|
||||
|
||||
# Z only flips a :toggle source; numeric/list ones use Left/Right instead.
|
||||
def apply_toggle_value(group, key, source)
|
||||
return SndLib.sys_buzzer unless source[:type] == :toggle
|
||||
FrameworkUtils.toggle_force_value(group, key, source)
|
||||
SndLib.sys_ok
|
||||
end
|
||||
|
||||
def with_addressed_source(block)
|
||||
full_key = @command_window.current_ext
|
||||
override = @command_window.override_for(full_key)
|
||||
return unless override
|
||||
source = @command_window.source_record(override)
|
||||
return unless source
|
||||
block.call(override[:source_group], override[:source_key], source)
|
||||
@command_window.refresh
|
||||
end
|
||||
|
||||
def on_cancel
|
||||
save_selection
|
||||
return_scene
|
||||
end
|
||||
end
|
||||
FrameworkUtils.menu_scenes << Scene_CheatGlobalsList
|
||||
|
||||
#==============================================================================
|
||||
# Reset Config Settings, Yes/No gated. Hotkeys/menu order/Local-Global
|
||||
# overrides reset live; module enable/order and cheat defaults need a restart.
|
||||
#==============================================================================
|
||||
class Window_CheatResetSettings < Window_Command
|
||||
def initialize
|
||||
super((Graphics.width - window_width) / 2, (Graphics.height - window_height) / 2)
|
||||
end
|
||||
|
||||
def window_width; 340; end
|
||||
def window_height; fitting_height(2); end
|
||||
|
||||
def make_command_list
|
||||
add_command("Reset Everything", :reset)
|
||||
add_command("Cancel", :cancel)
|
||||
end
|
||||
end
|
||||
|
||||
class Scene_CheatResetSettings < Scene_MenuBase
|
||||
def start
|
||||
super
|
||||
@help_window = Window_CheatOrderHelp.new(
|
||||
"Hotkeys, menu order, and Local/Global overrides reset immediately.\n" \
|
||||
"Module enable/order and cheat variable defaults need a restart."
|
||||
)
|
||||
@command_window = Window_CheatResetSettings.new
|
||||
@command_window.set_handler(:reset, method(:perform_reset))
|
||||
@command_window.set_handler(:cancel, method(:return_scene)) # covers the Cancel row and X
|
||||
end
|
||||
|
||||
def perform_reset
|
||||
$framework.ini.reset_all_settings
|
||||
$framework.ini.reset_hotkeys_live
|
||||
$framework.ini.reset_menu_order
|
||||
$framework.ini.reset_force_overrides
|
||||
$framework.restart_needed = true
|
||||
SndLib.sys_ok
|
||||
return_scene
|
||||
end
|
||||
end
|
||||
FrameworkUtils.menu_scenes << Scene_CheatResetSettings
|
||||
|
||||
#==============================================================================
|
||||
# Register the four entry points
|
||||
#==============================================================================
|
||||
module MenuFramework
|
||||
module SUBMENU
|
||||
register_command(
|
||||
group: :CONFIG,
|
||||
type: :scene,
|
||||
key: :set_hotkeys,
|
||||
label: "menu:commands/set_hotkeys",
|
||||
help1: "menu:command_help/set_hotkeys1",
|
||||
help2: "menu:command_help/set_hotkeys2",
|
||||
name: "CheatHotkeyList",
|
||||
order: 20
|
||||
)
|
||||
register_command(
|
||||
group: :CONFIG,
|
||||
type: :scene,
|
||||
key: :edit_menu_order,
|
||||
label: "menu:commands/edit_order",
|
||||
help1: "menu:command_help/edit_order1",
|
||||
help2: "menu:command_help/edit_order2",
|
||||
name: "CheatMenuOrderGroups",
|
||||
order: 30
|
||||
)
|
||||
register_command(
|
||||
group: :CONFIG,
|
||||
type: :scene,
|
||||
key: :edit_globals,
|
||||
label: "menu:commands/edit_globals",
|
||||
help1: "menu:command_help/edit_globals1",
|
||||
help2: "menu:command_help/edit_globals2",
|
||||
name: "CheatGlobalsList",
|
||||
order: 40
|
||||
)
|
||||
register_command(
|
||||
group: :CONFIG,
|
||||
type: :scene,
|
||||
key: :reset_all_settings,
|
||||
label: "menu:commands/reset_all_settings",
|
||||
help1: "menu:command_help/reset_all_settings1",
|
||||
help2: "menu:command_help/reset_all_settings2",
|
||||
name: "CheatResetSettings",
|
||||
order: 50
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,875 @@
|
||||
#===============================================================================
|
||||
# Menu Defaults
|
||||
#------------------------------------------------------------------------------
|
||||
# Handles default commands structure and interface
|
||||
#===============================================================================
|
||||
|
||||
module MenuFramework
|
||||
module ScrollArrows
|
||||
ARROW_SRC_DOWN = Rect.new(0, 0, 19, 12)
|
||||
ARROW_WIDTH = 12
|
||||
ARROW_HEIGHT = 8
|
||||
ARROW_Z = 200
|
||||
JIGGLE_PERIOD = 60
|
||||
ARROW_UP_Y_OFFSET = 4 # nudge down to re-center against the smaller glyphs
|
||||
ARROW_DOWN_Y_OFFSET = 0
|
||||
|
||||
# Cap the cluster at 180px so it doesn't stretch to fill wide windows.
|
||||
def scroll_arrow_span
|
||||
[contents_width, 180].min
|
||||
end
|
||||
|
||||
# Override to 1 for a single centered arrow instead of a 3-wide cluster.
|
||||
def scroll_arrow_tile_count
|
||||
3
|
||||
end
|
||||
|
||||
def create_scroll_arrows
|
||||
source = Cache.system("Menu/08Items/item_arrow")
|
||||
down_glyph = Bitmap.new(ARROW_WIDTH, ARROW_HEIGHT)
|
||||
down_glyph.stretch_blt(down_glyph.rect, source, ARROW_SRC_DOWN)
|
||||
@scroll_arrow_down = build_scroll_arrow(down_glyph)
|
||||
@scroll_arrow_up = build_scroll_arrow(flip_glyph(down_glyph))
|
||||
update_scroll_arrows
|
||||
end
|
||||
|
||||
# Row-by-row reversal instead of a negative sprite zoom (zoom_y = -1
|
||||
# silently failed to render at all) - keeps up/down pixel-identical.
|
||||
def flip_glyph(glyph)
|
||||
flipped = Bitmap.new(glyph.width, glyph.height)
|
||||
glyph.height.times do |row|
|
||||
flipped.blt(0, glyph.height - 1 - row, glyph, Rect.new(0, row, glyph.width, 1))
|
||||
end
|
||||
flipped
|
||||
end
|
||||
|
||||
def build_scroll_arrow(glyph)
|
||||
span = scroll_arrow_span
|
||||
sprite = Sprite.new
|
||||
sprite.z = ARROW_Z
|
||||
sprite.bitmap = Bitmap.new(span, ARROW_HEIGHT)
|
||||
scroll_arrow_tile_positions(span).each do |dest_x|
|
||||
sprite.bitmap.blt(dest_x, 0, glyph, glyph.rect)
|
||||
end
|
||||
sprite.x = self.x + padding + (contents_width - span) / 2
|
||||
sprite.visible = false
|
||||
sprite
|
||||
end
|
||||
|
||||
def scroll_arrow_tile_positions(span)
|
||||
count = scroll_arrow_tile_count
|
||||
return [span / 2 - ARROW_WIDTH / 2] if count <= 1
|
||||
(0...count).map { |i| i * (span - ARROW_WIDTH) / (count - 1) }
|
||||
end
|
||||
|
||||
def update_scroll_arrows
|
||||
return unless @scroll_arrow_up && @scroll_arrow_down
|
||||
more_rows = page_row_max > 0 && row_max > page_row_max
|
||||
@scroll_arrow_up.visible = more_rows && top_row > 0
|
||||
@scroll_arrow_down.visible = more_rows && bottom_row < row_max - 1
|
||||
|
||||
jiggle = Graphics.frame_count % JIGGLE_PERIOD / (JIGGLE_PERIOD / 3)
|
||||
@scroll_arrow_up.y = self.y + ARROW_UP_Y_OFFSET - jiggle if @scroll_arrow_up.visible
|
||||
@scroll_arrow_down.y = self.y + height - padding_bottom + ARROW_DOWN_Y_OFFSET + jiggle if @scroll_arrow_down.visible
|
||||
end
|
||||
|
||||
def dispose_scroll_arrows
|
||||
@scroll_arrow_up.dispose if @scroll_arrow_up
|
||||
@scroll_arrow_down.dispose if @scroll_arrow_down
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
update_scroll_arrows
|
||||
end
|
||||
|
||||
def dispose
|
||||
dispose_scroll_arrows
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#==============================================================================
|
||||
# Action Window Module
|
||||
#==============================================================================
|
||||
module Action_Window_Defaults
|
||||
include MenuFramework::ScrollArrows
|
||||
attr_accessor :dictionary
|
||||
#--------------------------------------------------------------------------
|
||||
# Initialize
|
||||
#-------------------------------------------------------------------------
|
||||
def initialize
|
||||
super(160, 0)
|
||||
@dictionary = nil
|
||||
@hotkey_capture_mode = false
|
||||
clear_edit
|
||||
create_scroll_arrows
|
||||
end
|
||||
|
||||
def clear_edit
|
||||
@editing = false
|
||||
@editing_this = nil
|
||||
@editing_number = nil
|
||||
@edit_value = 0
|
||||
@edit_list = []
|
||||
@edit_index = 0
|
||||
@edit_min = 0
|
||||
@edit_max = 0
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Window Structure
|
||||
#--------------------------------------------------------------------------
|
||||
def window_width; return Graphics.width - 160; end
|
||||
def window_height; return Graphics.height - 120; end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Command Initialization
|
||||
#--------------------------------------------------------------------------
|
||||
def commands_from_group
|
||||
return unless @dictionary
|
||||
FrameworkUtils.sorted_commands(@dictionary).each do |key, record|
|
||||
next if record[:hide].is_a?(Proc) ? record[:hide].call : record[:hide]
|
||||
enable = record[:enable].is_a?(Proc) ? record[:enable].call : record[:enable]
|
||||
|
||||
add_command(
|
||||
#$framework.txt(record[:label]), added alternative proc handling for testing:
|
||||
record[:label].is_a?(Proc) ? record[:label].call : $framework.txt(record[:label]),
|
||||
:run_default_command,
|
||||
enable,
|
||||
record[:key]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Command Definition
|
||||
#--------------------------------------------------------------------------
|
||||
def run_default_command
|
||||
return if @hotkey_capture_mode # assigning a hotkey, not activating the row
|
||||
|
||||
key = current_ext
|
||||
record = @dictionary[key]
|
||||
return unless record
|
||||
|
||||
case record[:type]
|
||||
when :edit_num, :edit_list
|
||||
if @editing
|
||||
save_editing(key)
|
||||
else
|
||||
start_editing(key)
|
||||
end
|
||||
refresh
|
||||
else
|
||||
record[:action].call if record[:action]
|
||||
FrameworkUtils.mark_restart_needed(record)
|
||||
SndLib.sys_ok
|
||||
refresh
|
||||
end
|
||||
end
|
||||
|
||||
def start_editing(key)
|
||||
record = @dictionary[key]
|
||||
return unless record
|
||||
|
||||
@editing = true
|
||||
@editing_this = key
|
||||
@editing_number = record[:type] == :edit_num
|
||||
@edit_value = record[:state].call rescue 0
|
||||
|
||||
if @editing_number
|
||||
@edit_min = record[:min].is_a?(Proc) ? record[:min].call : record[:min] || 0
|
||||
@edit_max = record[:max].is_a?(Proc) ? record[:max].call : record[:max] || 999
|
||||
else
|
||||
@edit_list = record[:list] || []
|
||||
@edit_index = @edit_list.index { |i| i[:key] == record[:state].call rescue 0 } || 0
|
||||
@edit_value = @edit_list[@edit_index][:label]
|
||||
end
|
||||
end
|
||||
|
||||
def save_editing(key)
|
||||
record = @dictionary[key]
|
||||
return unless record
|
||||
|
||||
save_value =
|
||||
if record[:type] == :edit_list
|
||||
save_value = @edit_list[@edit_index][:key]
|
||||
else
|
||||
save_value = @edit_value
|
||||
end
|
||||
|
||||
if record[:action].arity == 1
|
||||
#Handle Value (v) entry.
|
||||
record[:action].call(save_value)
|
||||
elsif record[:action].arity == 2
|
||||
#Handle Key/Value pair - mostly for saving to config.
|
||||
record[:action].call(record[:key],save_value)
|
||||
else
|
||||
#Run the command as-is if nothing required.
|
||||
instance_exec(&record[:action])
|
||||
end
|
||||
FrameworkUtils.mark_restart_needed(record)
|
||||
SndLib.sys_ok
|
||||
clear_edit
|
||||
end
|
||||
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Draw Setup
|
||||
#--------------------------------------------------------------------------
|
||||
def draw_item(index)
|
||||
MenuFramework.force_font(contents) if contents
|
||||
rect = item_rect_for_text(index)
|
||||
contents.clear_rect(rect)
|
||||
|
||||
key = @list[index][:ext]
|
||||
name = command_name(index)
|
||||
enabled = command_enabled?(index)
|
||||
record = @dictionary && key ? @dictionary[key] : nil
|
||||
value = nil
|
||||
right = ""
|
||||
|
||||
# --- Determine base color ---
|
||||
color = if record && record[:color]
|
||||
c = record[:color]
|
||||
val = c.respond_to?(:call) ? c.call : c
|
||||
val.is_a?(Numeric) ? text_color(val) : val
|
||||
else
|
||||
normal_color
|
||||
end
|
||||
|
||||
# --- Determine what to display on the right side ---
|
||||
case record && record[:type]
|
||||
when :info
|
||||
right = record[:state].call rescue ""
|
||||
color = text_color(8)
|
||||
when :toggle
|
||||
value = record[:state].call rescue false
|
||||
right = value ? "[#{$framework.txt("menu:cheat_toggle/on")}]" :
|
||||
"[#{$framework.txt("menu:cheat_toggle/off")}]"
|
||||
when :edit_num
|
||||
value = record[:state].call rescue 0
|
||||
right = value.to_s
|
||||
when :edit_list
|
||||
list = record[:list] || []
|
||||
value = record[:state].call rescue 0
|
||||
item = list.find { |i| i[:key] == value }
|
||||
right = item ? item[:label] : value.to_s
|
||||
when :scene
|
||||
right = ">>>"
|
||||
end
|
||||
|
||||
# --- Adjust display name and color ---
|
||||
hotkey_tag = FrameworkUtils.hotkey_tag_for(@dictionary, key)
|
||||
# edit_list/edit_num rows cannot be assigned a hotkey, so no conflict with restart tag.
|
||||
restart_tag = hotkey_tag ? nil : (FrameworkUtils.restart_mismatch?(record) ? "[#{$framework.txt("menu:commands_status/restart_needed")}]" : nil)
|
||||
tag = hotkey_tag || restart_tag
|
||||
tagged_name = tag ? "#{name} #{tag}" : name
|
||||
display_name = enabled ? tagged_name : "#{tagged_name} (#{$framework.txt("menu:commands_status/locked")})"
|
||||
color = enabled ? color : text_color(8)
|
||||
|
||||
if @editing && key == @editing_this
|
||||
color = text_color(16)
|
||||
right = @edit_value.to_s
|
||||
end
|
||||
|
||||
if @hotkey_capture_mode && index == self.index
|
||||
color = text_color(16)
|
||||
end
|
||||
|
||||
# --- Draw ---
|
||||
change_color(color)
|
||||
draw_text(rect, display_name, 0)
|
||||
draw_text(rect, right, 2) if right && !right.to_s.empty?
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Control Overrides
|
||||
#--------------------------------------------------------------------------
|
||||
def cursor_left(wrap = false)
|
||||
if @editing
|
||||
SndLib.play_cursor
|
||||
number = @editing_number ? edit_key_multiply : 1
|
||||
modify_variable(-number)
|
||||
else
|
||||
cursor_pageup
|
||||
end
|
||||
end
|
||||
|
||||
def cursor_right(wrap = false)
|
||||
if @editing
|
||||
SndLib.play_cursor
|
||||
number = @editing_number ? edit_key_multiply : 1
|
||||
modify_variable(number)
|
||||
else
|
||||
cursor_pagedown
|
||||
end
|
||||
end
|
||||
|
||||
def cursor_up(wrap = false)
|
||||
super unless @editing
|
||||
refresh_help_window
|
||||
end
|
||||
|
||||
def cursor_down(wrap = false)
|
||||
super unless @editing
|
||||
refresh_help_window
|
||||
end
|
||||
|
||||
def refresh_help_window
|
||||
SceneManager.scene.refresh_help_window if SceneManager.scene.respond_to?(:refresh_help_window)
|
||||
end
|
||||
|
||||
def override_help_window_text(text)
|
||||
SceneManager.scene.override_help_window_text(text) if SceneManager.scene.respond_to?(:override_help_window_text)
|
||||
end
|
||||
|
||||
def process_cancel
|
||||
if @hotkey_capture_mode
|
||||
exit_hotkey_capture
|
||||
elsif @editing
|
||||
clear_edit
|
||||
refresh
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Hotkey Capture
|
||||
#--------------------------------------------------------------------------
|
||||
# LETTER_C arms the row, Shift/Ctrl/Alt+key assigns (F-key or letter/digit/
|
||||
# punctuation, see HotkeySymbols), Delete/Backspace clears, LETTER_C/Cancel
|
||||
# disarms. Any command can hold a hotkey via hotkey_defs.
|
||||
FKEY_SYMBOLS = (1..12).map { |n| :"F#{n}" }
|
||||
|
||||
# :edit_num/:edit_list actions need a value argument, which a bare keypress can't supply.
|
||||
CAPTURABLE_TYPES = [:toggle, :action, :scene]
|
||||
|
||||
def update
|
||||
super
|
||||
return unless active
|
||||
|
||||
if @hotkey_capture_mode
|
||||
update_hotkey_capture
|
||||
elsif !@editing && current_ext && Input.trigger?(:LETTER_C)
|
||||
if capturable_row?
|
||||
enter_hotkey_capture
|
||||
else
|
||||
SndLib.sys_buzzer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def capturable_row?
|
||||
return false unless @dictionary && current_ext
|
||||
record = @dictionary[current_ext]
|
||||
record && CAPTURABLE_TYPES.include?(record[:type])
|
||||
end
|
||||
|
||||
# Cursor movement is frozen on the armed row while capturing.
|
||||
def process_cursor_move
|
||||
return if @hotkey_capture_mode
|
||||
super
|
||||
end
|
||||
|
||||
def enter_hotkey_capture
|
||||
@hotkey_capture_mode = true
|
||||
$framework.hotkey_capture_active = true
|
||||
SndLib.play_cursor
|
||||
refresh_help_window
|
||||
refresh
|
||||
end
|
||||
|
||||
# Backs out without assigning anything - the only time "C to cancel" is
|
||||
# accurate, since assign/clear below leave on their own once committed.
|
||||
def exit_hotkey_capture
|
||||
SndLib.play_cursor
|
||||
leave_hotkey_capture
|
||||
end
|
||||
|
||||
def leave_hotkey_capture
|
||||
@hotkey_capture_mode = false
|
||||
$framework.hotkey_capture_active = false
|
||||
refresh_help_window
|
||||
refresh
|
||||
end
|
||||
|
||||
def update_hotkey_capture
|
||||
if Input.trigger?(:LETTER_C)
|
||||
exit_hotkey_capture
|
||||
return
|
||||
end
|
||||
|
||||
if Input.trigger?(:BACK) || Input.trigger?(:DELETE)
|
||||
clear_current_hotkey
|
||||
return
|
||||
end
|
||||
|
||||
(FKEY_SYMBOLS + HotkeySymbols.symbols).each do |key_sym|
|
||||
next unless Input.trigger?(key_sym)
|
||||
assign_current_hotkey(key_sym)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def current_hotkey_full_key
|
||||
key = current_ext
|
||||
return nil unless key
|
||||
group = FrameworkUtils.group_for_dictionary(@dictionary)
|
||||
return nil unless group
|
||||
"#{group}.#{key}"
|
||||
end
|
||||
|
||||
def assign_current_hotkey(key_sym)
|
||||
full_key = current_hotkey_full_key
|
||||
return unless full_key
|
||||
|
||||
if HotkeyReserved.info_for(key_sym.to_s)
|
||||
SndLib.sys_buzzer # reserved (Main Menu Key and F10 always, F5/F6 while RolePlay-S is active) - refuse, modifiers don't help
|
||||
return
|
||||
end
|
||||
|
||||
mods = []
|
||||
mods << "Shift" if Input.press?(:SHIFT)
|
||||
mods << "Ctrl" if Input.press?(:CTRL)
|
||||
mods << "Alt" if Input.press?(:ALT)
|
||||
key_str = (mods + [HotkeySymbols.name_for(key_sym) || key_sym.to_s]).join("+")
|
||||
|
||||
if $framework.hotkey_defs[full_key]
|
||||
$framework.hotkey_defs[full_key][:key] = key_str
|
||||
else
|
||||
$framework.hotkey_defs[full_key] = { key: key_str, sound: nil }
|
||||
end
|
||||
|
||||
$framework.ini.save_hotkeys_to_ini
|
||||
$framework.ini.build_hotkey_map # live immediately - no restart needed
|
||||
SndLib.sys_ok
|
||||
leave_hotkey_capture
|
||||
end
|
||||
|
||||
def clear_current_hotkey
|
||||
full_key = current_hotkey_full_key
|
||||
return unless full_key
|
||||
return unless $framework.hotkey_defs[full_key]
|
||||
|
||||
$framework.hotkey_defs[full_key][:key] = "NONE"
|
||||
$framework.ini.save_hotkeys_to_ini
|
||||
$framework.ini.build_hotkey_map
|
||||
SndLib.sys_cancel
|
||||
leave_hotkey_capture
|
||||
end
|
||||
|
||||
def edit_key_multiply
|
||||
multi = 1
|
||||
multi *= 10 if Input.press?(Input::KEYMAP[:SHIFT])
|
||||
multi *= 100 if Input.press?(Input::KEYMAP[:CONTROL])
|
||||
multi
|
||||
end
|
||||
|
||||
def modify_variable(change)
|
||||
if @editing_number
|
||||
@edit_value += change
|
||||
@edit_value = [[@edit_value, @edit_min].max, @edit_max].min
|
||||
else
|
||||
return unless @edit_list && @edit_list.is_a?(Array)
|
||||
@edit_index = (@edit_index + change) % @edit_list.size # cycles properly
|
||||
@edit_value = @edit_list[@edit_index][:label]
|
||||
end
|
||||
refresh
|
||||
refresh_help_window if live_help_command?
|
||||
end
|
||||
|
||||
# True if this row's help1-4 is a Proc, so it needs redrawing mid-edit.
|
||||
def live_help_command?
|
||||
record = @dictionary && @editing_this ? @dictionary[@editing_this] : nil
|
||||
record && [:help1, :help2, :help3, :help4].any? { |k| record[k].is_a?(Proc) }
|
||||
end
|
||||
end
|
||||
|
||||
#==============================================================================
|
||||
# Scene Defaults
|
||||
#==============================================================================
|
||||
module Scene_Defaults
|
||||
attr_accessor :menu_symbol
|
||||
attr_reader :action_window
|
||||
|
||||
# Online live-map under cheat UI (same host as ESC/storage).
|
||||
if defined?(MPLiveEscMenu) && defined?(MPLiveEscMenu::SpritesetHost)
|
||||
include MPLiveEscMenu::SpritesetHost
|
||||
end
|
||||
|
||||
CF_LIVE_DIM_Z = 50
|
||||
CF_LIVE_WINDOW_Z = 2100
|
||||
|
||||
def mp_cf_live_online?
|
||||
defined?(MPLiveEscMenu) && MPLiveEscMenu.respond_to?(:online?) && MPLiveEscMenu.online?
|
||||
rescue
|
||||
false
|
||||
end
|
||||
|
||||
# Soft dim ABOVE the map spriteset, BELOW cheat windows (default Window z≈100
|
||||
# would sit under SCENE_BASE_Z=2000 dim — that was the blackout bug).
|
||||
def mp_cf_create_live_dim
|
||||
@background_sprite = Sprite.new
|
||||
@background_sprite.z = CF_LIVE_DIM_Z
|
||||
w = [(Graphics.width rescue 640).to_i, 1].max
|
||||
h = [(Graphics.height rescue 360).to_i, 1].max
|
||||
bmp = Bitmap.new(w, h)
|
||||
bmp.fill_rect(0, 0, w, h, Color.new(0, 0, 0, 80))
|
||||
@background_sprite.bitmap = bmp
|
||||
@background_sprite.opacity = 255
|
||||
@mp_live_owned_bg_sprite_bitmap = true
|
||||
rescue
|
||||
@background_sprite = nil
|
||||
end
|
||||
|
||||
def create_background
|
||||
if mp_cf_live_online?
|
||||
mp_cf_create_live_dim
|
||||
return
|
||||
end
|
||||
super
|
||||
rescue
|
||||
super
|
||||
end
|
||||
|
||||
def dispose_background
|
||||
begin
|
||||
if @mp_live_owned_bg_sprite_bitmap
|
||||
if @background_sprite
|
||||
begin
|
||||
bmp = @background_sprite.bitmap
|
||||
@background_sprite.bitmap = nil
|
||||
bmp.dispose if bmp && !bmp.disposed?
|
||||
rescue
|
||||
end
|
||||
begin
|
||||
@background_sprite.dispose unless (@background_sprite.disposed? rescue true)
|
||||
rescue
|
||||
end
|
||||
end
|
||||
@background_sprite = nil
|
||||
@mp_live_owned_bg_sprite_bitmap = false
|
||||
return
|
||||
end
|
||||
rescue
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
def mp_cf_raise_window_z
|
||||
z = CF_LIVE_WINDOW_Z
|
||||
[@command_window, @help_window, @action_window].each do |win|
|
||||
next unless win
|
||||
begin
|
||||
win.z = z if win.respond_to?(:z=)
|
||||
rescue
|
||||
end
|
||||
end
|
||||
rescue
|
||||
end
|
||||
|
||||
def start
|
||||
super
|
||||
create_command_window
|
||||
create_help_window
|
||||
create_action_window
|
||||
@help_window_text1 = nil
|
||||
@help_window_text2 = nil
|
||||
@help_window_text3 = nil
|
||||
@help_window_text4 = nil
|
||||
begin
|
||||
if mp_cf_live_online? && respond_to?(:mp_live_setup_spriteset)
|
||||
mp_live_setup_spriteset
|
||||
mp_cf_raise_window_z
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
begin
|
||||
if mp_cf_live_online? && @mp_live_spriteset && respond_to?(:mp_live_tick_world)
|
||||
if respond_to?(:mp_live_tick_world_or_exit_on_transfer)
|
||||
return if mp_live_tick_world_or_exit_on_transfer
|
||||
else
|
||||
mp_live_tick_world
|
||||
end
|
||||
end
|
||||
rescue
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
def terminate
|
||||
begin
|
||||
(@mp_cf_orphan_windows || []).each do |win|
|
||||
next unless win
|
||||
win.dispose unless (win.disposed? rescue false)
|
||||
end
|
||||
rescue
|
||||
end
|
||||
@mp_cf_orphan_windows = nil
|
||||
begin
|
||||
mp_live_dispose_spriteset if respond_to?(:mp_live_dispose_spriteset)
|
||||
rescue
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
def create_action_window
|
||||
wx = @command_window.width
|
||||
ww = Graphics.width - wx
|
||||
wh = Graphics.height - @help_window.height
|
||||
@action_window = Window_Base.new(wx, 0, ww, wh)
|
||||
mp_cf_raise_window_z if mp_cf_live_online?
|
||||
end
|
||||
|
||||
def override_action_window
|
||||
@command_window.deactivate
|
||||
# Replacing @action_window without dispose leaked the blank right panel
|
||||
# onto the map after leaving CheatFramework.
|
||||
begin
|
||||
old = @action_window
|
||||
if old && !(old.disposed? rescue false)
|
||||
old.dispose
|
||||
end
|
||||
rescue
|
||||
begin
|
||||
@mp_cf_orphan_windows ||= []
|
||||
@mp_cf_orphan_windows << @action_window if @action_window
|
||||
rescue
|
||||
end
|
||||
end
|
||||
@action_window = @window.new
|
||||
@action_window.dictionary = @dictionary
|
||||
@action_window.set_handler(:cancel, method(:return_action_scene))
|
||||
@action_window.set_handler(:run_default_command, method(:default_command))
|
||||
mp_cf_raise_window_z if mp_cf_live_online?
|
||||
restore_action_window_state
|
||||
refresh_help_window
|
||||
end
|
||||
|
||||
def default_command
|
||||
@action_window.activate
|
||||
@action_window.dictionary = @dictionary
|
||||
save_action_window_state
|
||||
@action_window.run_default_command
|
||||
refresh_help_window
|
||||
end
|
||||
|
||||
def return_action_scene
|
||||
save_action_window_state
|
||||
return_scene
|
||||
end
|
||||
|
||||
def save_action_window_state
|
||||
menu = @menu_symbol
|
||||
$framework.menu_stack.push({ menu: menu, symbol: @action_window.current_ext, index: @action_window.index })
|
||||
end
|
||||
|
||||
def save_action_window_state
|
||||
menu = @menu_symbol
|
||||
symbol = @action_window.current_ext rescue nil
|
||||
index = @action_window.index rescue 0
|
||||
$framework.menu_stack.push({ menu: menu, symbol: @action_window.current_ext, index: @action_window.index })
|
||||
end
|
||||
|
||||
def restore_action_window_state
|
||||
menu = @menu_symbol
|
||||
return unless menu && $framework.menu_stack && @action_window.active
|
||||
entry = $framework.menu_stack.reverse.find { |e| e[:menu] == menu }
|
||||
if entry
|
||||
list = @action_window.instance_variable_get(:@list)
|
||||
idx = list.index { |cmd| cmd[:symbol] == entry[:symbol] } || entry[:index] || 0
|
||||
idx = [[idx, 0].max, list.size - 1].min
|
||||
@action_window.select(idx)
|
||||
end
|
||||
end
|
||||
|
||||
def menu_has_saved_state?(symbol)
|
||||
$framework.menu_stack.any? { |h| h[:symbol] == symbol }
|
||||
end
|
||||
|
||||
def create_help_window
|
||||
wx = @command_window.width
|
||||
wy = Graphics.height - 120
|
||||
ww = Graphics.width - wx
|
||||
wh = 120
|
||||
@help_window = Window_Base.new(wx, wy, ww, wh)
|
||||
end
|
||||
|
||||
def override_help_window_text(text)
|
||||
if @help_window && @help_window.contents
|
||||
c = @help_window.contents
|
||||
c.clear
|
||||
MenuFramework.force_font(c)
|
||||
@help_window.draw_text_ex(4, 0, text)
|
||||
end
|
||||
end
|
||||
|
||||
def refresh_help_window
|
||||
text = ""
|
||||
unless @command_window.active
|
||||
cmd = @action_window.current_ext
|
||||
dict = @action_window.instance_variable_get(:@dictionary) rescue nil
|
||||
record = dict ? dict[cmd] : nil
|
||||
|
||||
# Build help text
|
||||
help_lines = []
|
||||
help1 = (record[:help1] rescue nil) #command specific text
|
||||
help1 = help1.call if help1.is_a?(Proc)
|
||||
help2 = (record[:help2] rescue nil) #command specific text
|
||||
help2 = help2.call if help2.is_a?(Proc)
|
||||
help3 = (record[:help3] rescue nil) #command specific text
|
||||
help3 = help3.call if help3.is_a?(Proc)
|
||||
help4 = (record[:help4] rescue nil) #command specific text
|
||||
help4 = help4.call if help4.is_a?(Proc)
|
||||
if help1.nil? && help2.nil?
|
||||
help1 = @help_window_text1 rescue nil #scene specific text
|
||||
help2 = @help_window_text2 rescue nil #scene specific text
|
||||
if help1.nil? && help2.nil?
|
||||
help1 = "" #if neither set, leave blank
|
||||
help2 = "" #if neither set, leave blank
|
||||
end
|
||||
end
|
||||
help_lines << help1
|
||||
help_lines << help2
|
||||
|
||||
# Interface Instructions
|
||||
if help3.nil? && help4.nil?
|
||||
help3 = @help_window_text3 rescue nil #scene specific text
|
||||
help4 = @help_window_text4 rescue nil #scene specific text
|
||||
if help3.nil? && help4.nil?
|
||||
if @action_window && @action_window.instance_variable_get(:@hotkey_capture_mode)
|
||||
help3 = $framework.txt("menu:command_help/hotkey_capture1")
|
||||
help4 = $framework.txt("menu:command_help/hotkey_capture2")
|
||||
elsif @action_window && @action_window.instance_variable_get(:@editing_number)
|
||||
help3 = $framework.txt("menu:command_help/num_edit1")
|
||||
help4 = $framework.txt("menu:command_help/num_edit2")
|
||||
elsif @action_window && @action_window.instance_variable_get(:@editing)
|
||||
help3 = ""
|
||||
help4 = $framework.txt("menu:command_help/num_edit1")
|
||||
else
|
||||
type = record && record[:type]
|
||||
case type
|
||||
when :action then help3 = $framework.txt("menu:command_help/execute")
|
||||
when :scene then help3 = $framework.txt("menu:command_help/scene")
|
||||
when :toggle then help3 = $framework.txt("menu:command_help/toggle")
|
||||
when :edit_num, :edit_list then help3 = $framework.txt("menu:command_help/edit")
|
||||
else help3 = ""
|
||||
end
|
||||
# Only :action/:toggle/:scene rows can carry a hotkey (see
|
||||
# Action_Window_Defaults::CAPTURABLE_TYPES) - :edit_num/:edit_list
|
||||
# get no hint since pressing C there just buzzes.
|
||||
help4 = [:action, :scene, :toggle].include?(type) ? $framework.txt("menu:command_help/set_hotkey_hint") : ""
|
||||
end
|
||||
end
|
||||
end
|
||||
help_lines << help3
|
||||
help_lines << help4
|
||||
|
||||
text = help_lines.join("\n")
|
||||
|
||||
# Update Help Window
|
||||
if @help_window && @help_window.contents
|
||||
c = @help_window.contents
|
||||
c.clear
|
||||
MenuFramework.force_font(c)
|
||||
@help_window.draw_text_ex(4, 0, text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_command_window
|
||||
@command_window = Window_CheatMainMenu.new
|
||||
main_dict = $framework.commands[:MAIN] || {}
|
||||
|
||||
main_dict.each do |symbol, entry|
|
||||
@command_window.set_handler(:menu_command, method(:menu_command_update))
|
||||
end
|
||||
# Always restore using the first (root) menu symbol in the stack
|
||||
if $framework.menu_stack && !$framework.menu_stack.empty?
|
||||
first = $framework.menu_stack.first
|
||||
list = @command_window.instance_variable_get(:@list)
|
||||
index = list.index { |cmd| cmd[:ext] == first[:symbol] }
|
||||
@command_window.select(index || 0)
|
||||
else
|
||||
@command_window.select(0)
|
||||
end
|
||||
end
|
||||
|
||||
def save_command_window_state
|
||||
menu = :MAIN
|
||||
symbol = @command_window.current_ext rescue nil
|
||||
index = @command_window.index rescue 0
|
||||
return unless symbol
|
||||
$framework.menu_stack.clear
|
||||
$framework.menu_stack.push({ menu: :MAIN, symbol: symbol, index: index })
|
||||
end
|
||||
|
||||
def menu_command_update
|
||||
save_command_window_state
|
||||
key = @command_window.current_ext
|
||||
record = $framework.commands[:MAIN][key]
|
||||
|
||||
return unless record
|
||||
record[:action].call if record[:action]
|
||||
SndLib.sys_ok
|
||||
end
|
||||
|
||||
# Small fix to prevent crashes when opening the menu during animations.
|
||||
def hud
|
||||
self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#==============================================================================
|
||||
# Config List Defaults (Edit Menu Order / View Hotkeys / Edit Globals - the
|
||||
# full-width single-window screens in scripts/Controls.rb)
|
||||
#==============================================================================
|
||||
module Window_ConfigList_Defaults
|
||||
include MenuFramework::ScrollArrows
|
||||
def window_width; Graphics.width; end
|
||||
def window_height; Graphics.height - 120; end
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
create_scroll_arrows
|
||||
end
|
||||
|
||||
def force_content_font
|
||||
MenuFramework.force_font(contents) if contents
|
||||
end
|
||||
end
|
||||
|
||||
module Scene_ConfigList_Defaults
|
||||
# Breadcrumb save/restore/clamp, keyed by each scene's own menu_key.
|
||||
def save_selection
|
||||
$framework.menu_stack.push({
|
||||
menu: menu_key,
|
||||
symbol: @command_window.current_ext,
|
||||
index: @command_window.index
|
||||
})
|
||||
end
|
||||
|
||||
def restore_selection
|
||||
entry = $framework.menu_stack.reverse.find { |e| e[:menu] == menu_key }
|
||||
return unless entry
|
||||
list = @command_window.instance_variable_get(:@list)
|
||||
idx = list.index { |cmd| cmd[:ext] == entry[:symbol] } || entry[:index] || 0
|
||||
idx = [[idx, 0].max, list.size - 1].min
|
||||
@command_window.select(idx)
|
||||
end
|
||||
|
||||
def clamp_selection
|
||||
list = @command_window.instance_variable_get(:@list)
|
||||
return if list.empty?
|
||||
idx = [[@command_window.index, 0].max, list.size - 1].min
|
||||
@command_window.select(idx)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,142 @@
|
||||
#===============================================================================
|
||||
# FrameworkLoader
|
||||
#------------------------------------------------------------------------------
|
||||
# Handles discovery, registration, and loading of modular cheat components
|
||||
#===============================================================================
|
||||
class FrameworkLoader
|
||||
attr_reader :modules
|
||||
attr_reader :loaded
|
||||
|
||||
def initialize(root_path, ini = nil)
|
||||
@path = root_path
|
||||
@ini = ini || FrameworkConfig.new(File.join($framework.config_dir, "_system"))
|
||||
@modules = []
|
||||
@modules_by_key = {}
|
||||
@loaded = []
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Find all files in modules folder
|
||||
#--------------------------------------------------------------------------
|
||||
def discover
|
||||
unless Dir.exist?(@path)
|
||||
return
|
||||
end
|
||||
|
||||
@modules = []
|
||||
@modules_by_key = {}
|
||||
|
||||
Dir.glob(File.join(@path, "**", "*.rb")).each do |file|
|
||||
meta = read_metadata(file)
|
||||
|
||||
# If no metadata block was found, build a sane default from filename
|
||||
unless meta
|
||||
base = File.basename(file, ".rb")
|
||||
rel = file.sub(@path + File::SEPARATOR, '')
|
||||
|
||||
meta = {
|
||||
name: base,
|
||||
key: base.downcase.gsub(/[^a-z0-9]+/, '_').to_sym,
|
||||
path: rel,
|
||||
depends_on: [],
|
||||
enabled: true,
|
||||
order: 999
|
||||
}
|
||||
end
|
||||
|
||||
# normalize key -> symbol, ensure path and depends_on exist
|
||||
key = (meta[:key] || meta[:id] || File.basename(file, ".rb")).to_sym
|
||||
meta[:key] = key
|
||||
meta[:path] ||= file
|
||||
meta[:depends_on] ||= []
|
||||
|
||||
# apply INI overrides
|
||||
meta[:enabled] = @ini.get_enabled("#{key}.enabled", meta.fetch(:enabled, true))
|
||||
meta[:order] = @ini.get_load_order("#{key}.order", meta.fetch(:order, 999))
|
||||
|
||||
@modules << meta
|
||||
@modules_by_key[key] = meta
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Collects metadata from files without loading
|
||||
#--------------------------------------------------------------------------
|
||||
def read_metadata(file)
|
||||
content = File.read(file)
|
||||
if content =~ /FrameworkModule\s*=\s*(\{.*?\})/m
|
||||
begin
|
||||
# eval the hash literal only (it won't define a top-level constant)
|
||||
parsed = eval($1)
|
||||
# normalize keys to symbols if they are strings
|
||||
if parsed.is_a?(Hash)
|
||||
parsed = parsed.transform_keys { |k| k.is_a?(String) ? k.to_sym : k }
|
||||
parsed[:path] = file.sub(@path + File::SEPARATOR, '')
|
||||
parsed[:depends_on] ||= []
|
||||
return parsed
|
||||
end
|
||||
rescue => e
|
||||
return nil
|
||||
end
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Load called by init after discovery
|
||||
#--------------------------------------------------------------------------
|
||||
def load_all
|
||||
resolve_dependencies
|
||||
load_enabled_modules
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Reorder modules based on dependencies
|
||||
#--------------------------------------------------------------------------
|
||||
def resolve_dependencies
|
||||
# Simple topological sort
|
||||
sorted = []
|
||||
visited = {}
|
||||
|
||||
visit = lambda do |mod|
|
||||
return if visited[mod[:key]]
|
||||
visited[mod[:key]] = true
|
||||
|
||||
mod[:depends_on].each do |dep|
|
||||
dep_mod = @modules_by_key[dep]
|
||||
unless dep_mod
|
||||
next
|
||||
end
|
||||
visit.call(dep_mod)
|
||||
end
|
||||
sorted << mod
|
||||
end
|
||||
|
||||
@modules.each { |m| visit.call(m) }
|
||||
@modules = sorted.sort_by { |m| m[:order] }
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Load modules, filtering disabled ones
|
||||
#--------------------------------------------------------------------------
|
||||
def load_enabled_modules
|
||||
@modules.each do |mod|
|
||||
next unless mod[:enabled]
|
||||
|
||||
begin
|
||||
safe_load(mod[:path])
|
||||
@loaded << mod[:key]
|
||||
ensure
|
||||
Object.send(:remove_const, :FrameworkModule) if Object.const_defined?(:FrameworkModule)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Safe loader with error handling
|
||||
#--------------------------------------------------------------------------
|
||||
def safe_load(file)
|
||||
load_script($mod_manager.get_resource("cheatframework", "modules/#{file}"))
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,527 @@
|
||||
# Cheat Framework: Main Menu
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Hotkeys
|
||||
#---------------------------------------------------------------------------
|
||||
module FrameworkUtils
|
||||
def self.process_hotkeys
|
||||
return unless FrameworkUtils.ingame?
|
||||
return unless FrameworkUtils.cheats_allowed?
|
||||
return if FrameworkUtils.admin_overlay_open?
|
||||
|
||||
process_menu_toggle_hotkey
|
||||
|
||||
$framework.hotkeys.each do |key_const, actions|
|
||||
next unless Input.trigger?(key_const)
|
||||
|
||||
actions.each do |data|
|
||||
record = $framework.commands.dig(data[:group], data[:key])
|
||||
cmd = record && record[:action]
|
||||
next unless cmd
|
||||
# Suppress hotkeys while a submenu is mid-capture, so the target key
|
||||
# doesn't also fire whatever it's currently bound to.
|
||||
next if $framework.hotkey_capture_active
|
||||
# Don't fire cheat hotkeys while browsing the cheat menu itself.
|
||||
next if FrameworkUtils.in_menu?
|
||||
# Letter/digit/punctuation hotkeys no-op if the game's own Key Binds
|
||||
# menu claims that key; F-keys skip this check (see HotkeySymbols).
|
||||
next if HotkeySymbols.symbols.include?(key_const) && FrameworkUtils.claimed_by_game_controls?(key_const)
|
||||
next unless modifiers_match?(data[:mods])
|
||||
cmd.call
|
||||
FrameworkUtils.mark_restart_needed(record)
|
||||
SndLib.send(data[:sound]) if defined?(SndLib) && data[:sound]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Reads the Main Menu Toggle key from Input::SYM_KEYS[:CF_CHEAT_MENU] (see
|
||||
# hook_vanilla_keybind_menu), not a :MENU-group entry in $framework.hotkeys.
|
||||
def self.process_menu_toggle_hotkey
|
||||
return unless FrameworkUtils.cheats_allowed?
|
||||
return if FrameworkUtils.admin_overlay_open?
|
||||
return if $framework.hotkey_capture_active
|
||||
return unless Input.trigger?(:CF_CHEAT_MENU)
|
||||
|
||||
record = $framework.commands.dig(:MENU, "Main Menu")
|
||||
cmd = record && record[:action]
|
||||
return unless cmd
|
||||
|
||||
if FrameworkUtils.in_menu?
|
||||
# Loop since SceneManager.return only pops one level at a time.
|
||||
SceneManager.return while FrameworkUtils.in_menu?
|
||||
else
|
||||
cmd.call # not in menu → open it
|
||||
end
|
||||
end
|
||||
|
||||
def self.modifiers_match?(mods)
|
||||
# Convert symbols to input names dynamically
|
||||
pressed = {
|
||||
SHIFT: Input.press?(:SHIFT),
|
||||
CTRL: Input.press?(:CTRL),
|
||||
ALT: Input.press?(:ALT)
|
||||
}
|
||||
|
||||
mods.all? { |m| pressed[m] } &&
|
||||
(!pressed[:SHIFT] || mods.include?(:SHIFT)) &&
|
||||
(!pressed[:CTRL] || mods.include?(:CTRL)) &&
|
||||
(!pressed[:ALT] || mods.include?(:ALT))
|
||||
end
|
||||
end
|
||||
|
||||
class CheatFramework
|
||||
alias_method :hotkey_trigger_Framework, :hotkey_trigger
|
||||
def hotkey_trigger
|
||||
hotkey_trigger_Framework
|
||||
FrameworkUtils.process_hotkeys if FrameworkUtils.ingame?
|
||||
end
|
||||
end
|
||||
|
||||
#============================================================================
|
||||
# Menu Initialization
|
||||
#============================================================================
|
||||
module MenuFramework
|
||||
#==========================================================================
|
||||
# Framework-level helpers
|
||||
#==========================================================================
|
||||
def self.ensure_scene_and_window(opts)
|
||||
name = opts[:name]
|
||||
dict = opts[:dict]
|
||||
|
||||
win_name = "Window_#{name}"
|
||||
scene_name = "Scene_#{name}"
|
||||
unless Object.const_defined?(win_name)
|
||||
Object.const_set(win_name, Class.new(Window_Command) do
|
||||
include Action_Window_Defaults
|
||||
define_method(:make_command_list) do
|
||||
@dictionary = $framework.commands[dict]
|
||||
commands_from_group
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
unless Object.const_defined?(scene_name)
|
||||
new_scene = Class.new(Scene_MenuBase) do
|
||||
include Scene_Defaults
|
||||
define_method(:start) do
|
||||
super()
|
||||
@dictionary = $framework.commands[dict]
|
||||
@window = Object.const_get(win_name)
|
||||
@help_window_text1 = opts[:menu1].is_a?(Proc) ? opts[:menu1].call : (opts[:menu1] ? "#{$framework.txt(opts[:menu1])}" : nil)
|
||||
@help_window_text2 = opts[:menu2].is_a?(Proc) ? opts[:menu2].call : (opts[:menu2] ? "#{$framework.txt(opts[:menu2])}" : nil)
|
||||
@help_window_text3 = opts[:menu3].is_a?(Proc) ? opts[:menu3].call : (opts[:menu3] ? "#{$framework.txt(opts[:menu3])}" : nil)
|
||||
@help_window_text4 = opts[:menu4].is_a?(Proc) ? opts[:menu4].call : (opts[:menu4] ? "#{$framework.txt(opts[:menu4])}" : nil)
|
||||
override_action_window
|
||||
end
|
||||
end
|
||||
|
||||
Object.const_set(scene_name, new_scene)
|
||||
# Track dynamically created scene for hotkey handling
|
||||
FrameworkUtils.menu_scenes << new_scene
|
||||
end
|
||||
end
|
||||
|
||||
def self.force_font(contents)
|
||||
return unless contents
|
||||
|
||||
# RUS2 defines its own compact menu font. Use it for every
|
||||
# CheatFramework window instead of falling back to the CJK default font.
|
||||
if defined?(FONT_MOD) &&
|
||||
FONT_MOD.const_defined?(:MENU_L) &&
|
||||
FONT_MOD.const_defined?(:MENU_L_S) &&
|
||||
Font.exist?(FONT_MOD::MENU_L)
|
||||
contents.font.name = FONT_MOD::MENU_L
|
||||
contents.font.size = FONT_MOD::MENU_L_S
|
||||
contents.font.bold = true
|
||||
contents.font.shadow = false
|
||||
contents.font.outline = false
|
||||
return
|
||||
end
|
||||
|
||||
return if Font.default_name == "Noto Sans CJK TC Black"
|
||||
return unless Font.exist?("Noto Sans CJK TC Black")
|
||||
|
||||
contents.font.name = "Noto Sans CJK TC Black"
|
||||
contents.font.size = Font.default_size
|
||||
end
|
||||
|
||||
#==========================================================================
|
||||
# Main Menu Registration
|
||||
#==========================================================================
|
||||
module MENU
|
||||
|
||||
$framework.commands[:MAIN] ||= {}
|
||||
|
||||
unless singleton_class.method_defined?(:orig_register_command)
|
||||
class << self
|
||||
alias_method :orig_register_command, :register_command if method_defined?(:register_command)
|
||||
|
||||
def register_command(opts = {})
|
||||
# Automatically attach current module source if defined
|
||||
if defined?(FrameworkModule) && FrameworkModule.is_a?(Hash)
|
||||
alt_name = (FrameworkModule[:name] || (FrameworkModule[:key] || FrameworkModule[:id]).capitalize)
|
||||
opts[:name] ||= "CheatMenu#{alt_name.gsub(/\s+/, '')}"
|
||||
opts[:source] ||= (FrameworkModule[:name] || FrameworkModule[:key] || FrameworkModule[:id])
|
||||
opts[:dict] ||= FrameworkModule[:menu] || FrameworkModule[:key].to_s.upcase
|
||||
opts[:key] ||= opts[:source]
|
||||
end
|
||||
orig_register_command(opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.orig_register_command(opts = {})
|
||||
# Prepare keys and menu references
|
||||
key = opts[:key] # menu key
|
||||
name = opts[:name] # scene/window name
|
||||
dict = opts[:dict] || :NONE # submenu constant name
|
||||
|
||||
# Initialize the group in $framework.commands
|
||||
$framework.commands[dict] ||= {}
|
||||
|
||||
if name
|
||||
MenuFramework.ensure_scene_and_window(opts)
|
||||
scene = Object.const_get("Scene_#{name}")
|
||||
# Dynamically handle scene/window creation if needed
|
||||
action = -> {
|
||||
SceneManager.call(scene)
|
||||
SceneManager.scene.instance_variable_set(:@menu_symbol, key) if SceneManager.scene
|
||||
}
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
# Store in $framework.commands instead of COMMANDS
|
||||
$framework.commands[:MAIN][key] = {
|
||||
source: opts[:source],
|
||||
key: opts[:key],
|
||||
label: opts[:label],
|
||||
menu1: opts[:menu1],
|
||||
menu2: opts[:menu2],
|
||||
menu3: opts[:menu3],
|
||||
menu4: opts[:menu4],
|
||||
order: opts[:order] || 999,
|
||||
default_order: opts[:order] || 999,
|
||||
action: action
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
#==========================================================================
|
||||
# Submenu Registration
|
||||
#==========================================================================
|
||||
module SUBMENU
|
||||
# Define default submenu groups
|
||||
|
||||
unless singleton_class.method_defined?(:orig_register_command)
|
||||
class << self
|
||||
alias_method :orig_register_command, :register_command if method_defined?(:register_command)
|
||||
|
||||
def register_command(opts = {})
|
||||
if defined?(FrameworkModule) && FrameworkModule.is_a?(Hash)
|
||||
alt_name = (FrameworkModule[:name] || (FrameworkModule[:key] || FrameworkModule[:id]).capitalize)
|
||||
opts[:name] ||= "CheatMenu#{alt_name.gsub(/\s+/, '')}"
|
||||
# Use module key or menu name for source/group defaults
|
||||
opts[:source] ||= (FrameworkModule[:name] || FrameworkModule[:key] || FrameworkModule[:id])
|
||||
opts[:group] ||= (FrameworkModule[:menu] || FrameworkModule[:key].to_s.upcase)
|
||||
end
|
||||
orig_register_command(opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
# Unified command registration method
|
||||
def self.orig_register_command(opts)
|
||||
key = opts[:key]
|
||||
name = opts[:name] # scene/window name, when this command opens one
|
||||
type = opts[:type]
|
||||
group = opts[:group]
|
||||
state = opts[:state] # only :toggle/:edit_num/:edit_list/:info use this
|
||||
gdef = opts[:gdef]
|
||||
hotkey = opts[:hotkey]
|
||||
scene = opts[:scene]
|
||||
action = opts[:action]
|
||||
|
||||
#Handle group lookup/creation
|
||||
group = group.upcase.to_sym
|
||||
$framework.commands[group] ||= {}
|
||||
|
||||
if type == :toggle && !action && state
|
||||
action = -> {
|
||||
new_val = !eval(state); eval("#{state} = #{new_val}")
|
||||
$framework.ini.write_global(key, new_val)
|
||||
}
|
||||
end
|
||||
|
||||
if !opts[:gdef].nil? && state
|
||||
var_name = state[1..-1] # remove $
|
||||
default = gdef
|
||||
|
||||
# Read from INI or use default
|
||||
value = $framework.ini.read_global(key, default)
|
||||
eval("$#{var_name} = #{value.inspect}")
|
||||
|
||||
# Auto-define an action if missing
|
||||
if action.nil?
|
||||
action = lambda do |val|
|
||||
next if val.nil?
|
||||
eval("$#{var_name} = val")
|
||||
$framework.ini.write_global(key, val)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if hotkey && hotkey[:key]
|
||||
sound = hotkey[:sound] || :sys_ok
|
||||
$framework.hotkey_defs["#{group}.#{key}"] = { key: hotkey[:key], sound: sound }
|
||||
end
|
||||
|
||||
#Dynamically handles scene and window creation if needed.
|
||||
if type == :scene && name
|
||||
MenuFramework.ensure_scene_and_window(opts)
|
||||
scene = Object.const_get("Scene_#{name}")
|
||||
end
|
||||
|
||||
#Special handling to populate/standardize scene command.
|
||||
if type == :scene && scene
|
||||
action = -> {
|
||||
SceneManager.call(scene)
|
||||
SceneManager.scene.instance_variable_set(:@menu_symbol, key) if SceneManager.scene
|
||||
}
|
||||
end
|
||||
|
||||
if opts[:source]=="Edit Lona" && opts[:group]==:MISC
|
||||
#msgbox "#{opts.inspect}"
|
||||
end
|
||||
|
||||
# Snapshot at boot for restart_mismatch? to compare against: whether the
|
||||
# value equals the restart: sentinel, or (restart: true) the raw value itself.
|
||||
restart_boot_disabled =
|
||||
if state && opts[:restart].is_a?(Numeric)
|
||||
(eval(state) rescue nil) == opts[:restart]
|
||||
elsif state && opts[:restart] == true
|
||||
(eval(state) rescue nil)
|
||||
end
|
||||
|
||||
$framework.commands[group][key] = {
|
||||
source: opts[:source],
|
||||
type: opts[:type],
|
||||
key: opts[:key],
|
||||
label: opts[:label],
|
||||
action: action,
|
||||
state: opts[:state] ? -> { eval(opts[:state]) } : nil,
|
||||
# Raw string form of state:, used by the Local/Global override system.
|
||||
state_str: opts[:state],
|
||||
help1: opts[:help1].is_a?(Proc) ? opts[:help1] : (opts[:help1] ? $framework.txt(opts[:help1]) : nil),
|
||||
help2: opts[:help2].is_a?(Proc) ? opts[:help2] : (opts[:help2] ? $framework.txt(opts[:help2]) : nil),
|
||||
help3: opts[:help3].is_a?(Proc) ? opts[:help3] : (opts[:help3] ? $framework.txt(opts[:help3]) : nil),
|
||||
help4: opts[:help4].is_a?(Proc) ? opts[:help4] : (opts[:help4] ? $framework.txt(opts[:help4]) : nil),
|
||||
list: opts[:list],
|
||||
min: opts[:min],
|
||||
max: opts[:max],
|
||||
order: opts[:order] || 999,
|
||||
default_order: opts[:order] || 999,
|
||||
enable: opts.has_key?(:enable) ? opts[:enable] : true,
|
||||
hide: opts.has_key?(:hide) ? opts[:hide] : false,
|
||||
color: opts.has_key?(:color) ? opts[:color] : false,
|
||||
restart: opts.has_key?(:restart) ? opts[:restart] : false,
|
||||
restart_boot_disabled: restart_boot_disabled,
|
||||
# Local/Global override eligibility (Config > Edit Globals). nil = not
|
||||
# eligible. false = natively Local. true = natively Global.
|
||||
global: opts.has_key?(:global) ? opts[:global] : nil
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#============================================================================
|
||||
# Main Menu Window Initialization
|
||||
#============================================================================
|
||||
class Window_CheatMainMenu < Window_Command
|
||||
include MenuFramework::ScrollArrows
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Initialize
|
||||
#--------------------------------------------------------------------------
|
||||
def initialize
|
||||
super(0, 0)
|
||||
create_scroll_arrows
|
||||
end
|
||||
|
||||
def scroll_arrow_tile_count
|
||||
1
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Draw Setup
|
||||
#--------------------------------------------------------------------------
|
||||
def draw_item(index)
|
||||
MenuFramework.force_font(contents) if contents
|
||||
super
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Window Structure
|
||||
#--------------------------------------------------------------------------
|
||||
def window_width; return 160; end
|
||||
def window_height; return Graphics.height; end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Command List
|
||||
#--------------------------------------------------------------------------
|
||||
def make_command_list
|
||||
return unless $framework.commands[:MAIN]
|
||||
FrameworkUtils.sorted_commands($framework.commands[:MAIN]).each do |key, record|
|
||||
add_command(
|
||||
record[:label].is_a?(Proc) ? record[:label].call : $framework.txt(record[:label]),
|
||||
:menu_command,
|
||||
true,
|
||||
record[:key]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end # Window_CheatMainMenu
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Main Menu Scene Initialization
|
||||
#---------------------------------------------------------------------------
|
||||
# Restart-needed warning draws into @help_window (otherwise unused here),
|
||||
# overriding normal_color on that instance to animate its color.
|
||||
class Scene_CheatMainMenu < Scene_MenuBase
|
||||
include Scene_Defaults
|
||||
def create_command_window
|
||||
super
|
||||
@command_window.set_handler(:cancel, method(:return_scene))
|
||||
end
|
||||
|
||||
# Full red -> yellow -> red sweep every ~6 seconds at 60fps.
|
||||
RESTART_WARNING_STEP = 1.0 / 180
|
||||
|
||||
def start
|
||||
super
|
||||
@restart_warning_phase = 0.0 # 0.0 = red, 1.0 = yellow
|
||||
@restart_warning_rising = true
|
||||
@help_window.instance_variable_set(:@restart_warning_color, nil)
|
||||
def @help_window.normal_color
|
||||
@restart_warning_color || super
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
refresh_restart_warning
|
||||
end
|
||||
|
||||
def refresh_restart_warning
|
||||
unless $framework.restart_needed
|
||||
return unless @help_window.instance_variable_get(:@restart_warning_color)
|
||||
@help_window.instance_variable_set(:@restart_warning_color, nil)
|
||||
@help_window.contents.clear
|
||||
return
|
||||
end
|
||||
|
||||
if @restart_warning_rising
|
||||
@restart_warning_phase += RESTART_WARNING_STEP
|
||||
@restart_warning_rising = false if @restart_warning_phase >= 1.0
|
||||
else
|
||||
@restart_warning_phase -= RESTART_WARNING_STEP
|
||||
@restart_warning_rising = true if @restart_warning_phase <= 0.0
|
||||
end
|
||||
@restart_warning_phase = [[@restart_warning_phase, 0.0].max, 1.0].min
|
||||
|
||||
# Red (255,0,0) -> yellow (255,255,0): only green needs to move.
|
||||
green = (@restart_warning_phase * 255).round
|
||||
@help_window.instance_variable_set(:@restart_warning_color, Color.new(255, green, 0))
|
||||
|
||||
@help_window.contents.clear
|
||||
MenuFramework.force_font(@help_window.contents)
|
||||
@help_window.draw_text_ex(4, 0, $framework.txt("menu:warnings/restart_required"))
|
||||
end
|
||||
end
|
||||
FrameworkUtils.menu_scenes << Scene_CheatMainMenu
|
||||
|
||||
# LonaRPG Online compatibility: do not patch Menu_System's save row.
|
||||
# Entry points are F9 (solo or OWNER online) and / > Чит-меню (OWNER).
|
||||
|
||||
# Open Cheat Menu is a rebindable vanilla Key Binds entry. Its key
|
||||
# (Input::SYM_KEYS[:CF_CHEAT_MENU]) is the single source of truth, also used by View Hotkeys (Controls.rb).
|
||||
module FrameworkUtils
|
||||
def self.hook_vanilla_keybind_menu
|
||||
InputUtils.keyList << [
|
||||
:CF_CHEAT_MENU,
|
||||
"#{$framework.info.id}:menu:commands/cheat_menu_keybind",
|
||||
"Open Cheat Menu",
|
||||
[:F9]
|
||||
]
|
||||
end
|
||||
|
||||
# Resolves the live Main Menu Toggle key to a display string (e.g. "F9"
|
||||
# or "M"), for View Hotkeys' own row and HotkeyReserved's dynamic lookup.
|
||||
def self.current_menu_toggle_key
|
||||
code = Input::SYM_KEYS[:CF_CHEAT_MENU] && Input::SYM_KEYS[:CF_CHEAT_MENU].find { |c| c != 0 }
|
||||
return nil unless code
|
||||
symbol = InputUtils.reverse_key_map[code]
|
||||
return nil unless symbol
|
||||
HotkeySymbols.clean_name_for(symbol)
|
||||
end
|
||||
end
|
||||
|
||||
# Catches rebinds made through the vanilla Key Binds menu (not just View
|
||||
# Hotkeys), so the portable backup (config/hotkeys.ini) doesn't go stale.
|
||||
class CheatFramework
|
||||
alias_method :slow_trigger_VanillaKeybind, :slow_trigger
|
||||
|
||||
def slow_trigger
|
||||
slow_trigger_VanillaKeybind
|
||||
$framework.ini.sync_menu_toggle_key
|
||||
end
|
||||
end
|
||||
|
||||
FrameworkUtils.hook_vanilla_keybind_menu
|
||||
|
||||
#============================================================================
|
||||
# Default Category Initialization
|
||||
#============================================================================
|
||||
MenuFramework::MENU.register_command(
|
||||
type: :scene,
|
||||
key: :misc_menu,
|
||||
label: "menu:commands/misc",
|
||||
name: "CheatMenuMiscellaneous",
|
||||
dict: :MISC,
|
||||
order: 1
|
||||
)
|
||||
MenuFramework::MENU.register_command(
|
||||
type: :scene,
|
||||
key: :toggle_menu,
|
||||
label: "menu:commands/toggles",
|
||||
name: "CheatMenuToggles",
|
||||
dict: :TOGGLES,
|
||||
order: 2
|
||||
)
|
||||
MenuFramework::MENU.register_command(
|
||||
type: :scene,
|
||||
key: :edit_lona,
|
||||
label: "menu:commands/character",
|
||||
menu1: "menu:window_help/character1",
|
||||
name: "CheatMenuEditLona",
|
||||
dict: :LONA,
|
||||
order: 4
|
||||
)
|
||||
MenuFramework::MENU.register_command(
|
||||
type: :scene,
|
||||
key: :edit_npc,
|
||||
label: "menu:commands/npc",
|
||||
name: "CheatMenuNPCOptions",
|
||||
dict: :NPC,
|
||||
order: 6
|
||||
)
|
||||
MenuFramework::MENU.register_command(
|
||||
type: :scene,
|
||||
key: :config_menu,
|
||||
label: "menu:commands/config",
|
||||
name: "CheatMenuConfiguration",
|
||||
dict: :CONFIG,
|
||||
order: 1000
|
||||
)
|
||||
@@ -0,0 +1,364 @@
|
||||
#===============================================================================
|
||||
# Cheat Utilities
|
||||
#------------------------------------------------------------------------------
|
||||
# Provides utility functions for the Cheat Framework.
|
||||
#===============================================================================
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Table of physical F-keys claimed outside CheatFramework
|
||||
#--------------------------------------------------------------------------
|
||||
module HotkeyReserved
|
||||
TABLE = {
|
||||
"F10" => { label: "Console", active: -> { true } },
|
||||
"F5" => { label: "RolePlay-S QuickSave", active: -> { $framework.roleplay_mod? } },
|
||||
"F6" => { label: "RolePlay-S QuickLoad", active: -> { $framework.roleplay_mod? } },
|
||||
# Blocked at the OS level by 10_removeF1F12.rb, not assignable in Ruby.
|
||||
"F1" => { label: "Disabled by the game itself (F1AltEnterF12.dll)", active: -> { true } },
|
||||
"F12" => { label: "Disabled by the game itself (F1AltEnterF12.dll)", active: -> { true } },
|
||||
}
|
||||
|
||||
# Main Menu Toggle key is resolved dynamically via
|
||||
# FrameworkUtils.current_menu_toggle_key (scripts/Menu.rb) rather than a static TABLE entry.
|
||||
def self.info_for(key)
|
||||
key_str = key.to_s.upcase
|
||||
return { label: "Main Menu Toggle", active: true } if key_str == FrameworkUtils.current_menu_toggle_key
|
||||
entry = TABLE[key_str]
|
||||
return nil unless entry
|
||||
entry[:active].call ? entry : nil
|
||||
end
|
||||
|
||||
# Strips any Shift+/Ctrl+/Alt+ prefix and checks just the base F-key.
|
||||
def self.info_for_combo(key_str)
|
||||
return nil unless key_str
|
||||
info_for(key_str.to_s.split('+').last)
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Hotkey Display Names
|
||||
#--------------------------------------------------------------------------
|
||||
# Punctuation entries are leftover X11 keysym names reused for Windows VK_OEM_*
|
||||
# keys, not literal. LETTER_C is excluded - it's the hotkey-capture arm/disarm key.
|
||||
module HotkeySymbols
|
||||
DISPLAY_NAMES = {
|
||||
LETTER_A: "A", LETTER_B: "B", LETTER_D: "D", LETTER_E: "E", LETTER_F: "F",
|
||||
LETTER_G: "G", LETTER_H: "H", LETTER_I: "I", LETTER_J: "J", LETTER_K: "K",
|
||||
LETTER_L: "L", LETTER_M: "M", LETTER_N: "N", LETTER_O: "O", LETTER_P: "P",
|
||||
LETTER_Q: "Q", LETTER_R: "R", LETTER_S: "S", LETTER_T: "T", LETTER_U: "U",
|
||||
LETTER_V: "V", LETTER_W: "W", LETTER_X: "X", LETTER_Y: "Y", LETTER_Z: "Z",
|
||||
KEY_1: "1", KEY_2: "2", KEY_3: "3", KEY_4: "4", KEY_5: "5",
|
||||
KEY_6: "6", KEY_7: "7", KEY_8: "8", KEY_9: "9", N0: "0",
|
||||
masculine: ";", guillemotright: "=", onequarter: ",", onehalf: "-",
|
||||
threequarters: ".", questiondown: "/", Ucircumflex: "[", Udiaeresis: "\\",
|
||||
Yacute: "]", THORN: "'"
|
||||
}
|
||||
SYMBOLS_BY_NAME = DISPLAY_NAMES.invert
|
||||
|
||||
def self.symbols
|
||||
DISPLAY_NAMES.keys
|
||||
end
|
||||
|
||||
def self.name_for(symbol)
|
||||
DISPLAY_NAMES[symbol]
|
||||
end
|
||||
|
||||
def self.symbol_for(name)
|
||||
SYMBOLS_BY_NAME[name]
|
||||
end
|
||||
|
||||
# Unlike name_for, always returns something displayable, including symbols
|
||||
# the table excludes (like :LETTER_C) by stripping the RGSS-internal prefix directly.
|
||||
def self.clean_name_for(symbol)
|
||||
return name_for(symbol) if DISPLAY_NAMES.key?(symbol)
|
||||
str = symbol.to_s
|
||||
return "0" if str == "N0"
|
||||
return str.sub("LETTER_", "") if str.start_with?("LETTER_")
|
||||
return str.sub("KEY_", "") if str.start_with?("KEY_")
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# FrameworkUtils
|
||||
#--------------------------------------------------------------------------
|
||||
module FrameworkUtils
|
||||
class << self
|
||||
attr_accessor :menu_scenes
|
||||
end
|
||||
|
||||
# Online cheats are OWNER-only; keep original functionality in offline game.
|
||||
# This is a CLIENT UI guard, not a substitute for server permission checks.
|
||||
def self.cheats_allowed?
|
||||
return true unless defined?(WebSocket) && WebSocket.respond_to?(:connected?) && WebSocket.connected?
|
||||
WebSocket.respond_to?(:admin_owner_active?) && WebSocket.admin_owner_active?
|
||||
rescue
|
||||
false
|
||||
end
|
||||
|
||||
def self.admin_overlay_open?
|
||||
defined?(MPAdminMenu) && MPAdminMenu.respond_to?(:captures_gameplay_input?) &&
|
||||
MPAdminMenu.captures_gameplay_input?
|
||||
rescue
|
||||
false
|
||||
end
|
||||
#List of Scenes classed as being out of game
|
||||
@outgame_scenes = [
|
||||
ModManagerScene,
|
||||
Scene_MapTitle,
|
||||
Scene_AdultContentWarning,
|
||||
Scene_FirstTimeSetup,
|
||||
Scene_Title,
|
||||
Scene_TitleOptions,
|
||||
Scene_TitleOptInputMenu,
|
||||
Scene_ACHlistMenu,
|
||||
Scene_Credits,
|
||||
Scene_Menu,
|
||||
Scene_File,
|
||||
Scene_Save,
|
||||
Scene_Load_OnGameMenu,
|
||||
Scene_Load
|
||||
]
|
||||
@menu_scenes = []
|
||||
#Check if a game is loaded
|
||||
def self.ingame?
|
||||
return (!@outgame_scenes.any? {
|
||||
|outgame_scene|
|
||||
SceneManager.scene_is?(outgame_scene)
|
||||
} and $loading_screen.disposed?)
|
||||
end
|
||||
|
||||
def self.in_menu?
|
||||
@menu_scenes.any? { |scene_class| SceneManager.scene_is?(scene_class) }
|
||||
end
|
||||
|
||||
# True if this hotkey's physical key is already bound to one of the game's
|
||||
# own controls (Input::SYM_KEYS, live-updated by Key Binds). F-keys never go through this check.
|
||||
def self.claimed_by_game_controls?(key_const)
|
||||
vk_code = Input::KEYMAP[key_const]
|
||||
return false unless vk_code
|
||||
Input::SYM_KEYS.values.any? { |codes| codes.include?(vk_code) }
|
||||
end
|
||||
|
||||
def self.custom_state_edit(state, new_value)
|
||||
actor = $game_player.actor
|
||||
state_id = state
|
||||
change = new_value - (actor.stat[state_id] || 0)
|
||||
if change == 0
|
||||
return
|
||||
elsif change < 0
|
||||
change.abs.times { actor.remove_state_stack(state_id) }
|
||||
elsif change > 0
|
||||
change.times { actor.add_state(state_id) }
|
||||
end
|
||||
end
|
||||
|
||||
# Sorts a $framework.commands dict by :order, using registration order as a tiebreaker.
|
||||
def self.sorted_commands(dictionary)
|
||||
return [] unless dictionary
|
||||
dictionary.to_a.each_with_index
|
||||
.sort_by { |(_key, record), idx| [record[:order] || 999, idx] }
|
||||
.map { |pair, _idx| pair }
|
||||
end
|
||||
|
||||
# True if the live value disagrees with the boot-time snapshot: crossed the
|
||||
# restart: <number> sentinel boundary, or (restart: true) just changed at all.
|
||||
def self.restart_mismatch?(record)
|
||||
return false unless record && record[:state]
|
||||
restart = record[:restart]
|
||||
return false unless restart.is_a?(Numeric) || restart == true
|
||||
boot_disabled = record[:restart_boot_disabled]
|
||||
return false if boot_disabled.nil?
|
||||
current_val = record[:state].call rescue nil
|
||||
return false if current_val.nil?
|
||||
restart.is_a?(Numeric) ? (current_val == restart) != boot_disabled : current_val != boot_disabled
|
||||
end
|
||||
|
||||
# Flags that a restart is needed: on every change for restart: true, or only
|
||||
# when the change crosses the disabled/enabled boundary for restart: <number>.
|
||||
def self.mark_restart_needed(record)
|
||||
return unless record && record[:restart]
|
||||
if record[:restart].is_a?(Numeric)
|
||||
$framework.restart_needed = true if restart_mismatch?(record)
|
||||
else
|
||||
$framework.restart_needed = true
|
||||
end
|
||||
end
|
||||
|
||||
# Hotkey address lookup for the current row (Action_Window_Defaults).
|
||||
def self.group_for_dictionary(dict)
|
||||
return nil unless dict
|
||||
entry = $framework.commands.find { |_group, d| d.equal?(dict) }
|
||||
entry ? entry[0] : nil
|
||||
end
|
||||
|
||||
def self.hotkey_tag_for(dict, key)
|
||||
return nil unless key
|
||||
group = group_for_dictionary(dict)
|
||||
return nil unless group
|
||||
data = $framework.hotkey_defs["#{group}.#{key}"]
|
||||
return nil if data.nil? || data[:key].nil? || data[:key].to_s.upcase == "NONE"
|
||||
"[#{data[:key]}]"
|
||||
end
|
||||
|
||||
# The {key:, label:} entry currently highlighted in an in-progress edit_list edit.
|
||||
def self.current_edit_option
|
||||
scene = SceneManager.scene
|
||||
return nil unless scene.respond_to?(:action_window)
|
||||
aw = scene.action_window
|
||||
return nil unless aw && aw.instance_variable_get(:@editing)
|
||||
list = aw.instance_variable_get(:@edit_list)
|
||||
idx = aw.instance_variable_get(:@edit_index)
|
||||
list && list[idx]
|
||||
end
|
||||
|
||||
# Resolves a command's display name, falling back to `fallback` if it has no label:.
|
||||
def self.display_name_for(record, fallback)
|
||||
return fallback.to_s unless record
|
||||
label = record[:label]
|
||||
if label.is_a?(Proc)
|
||||
label.call
|
||||
elsif label
|
||||
$framework.txt(label) rescue fallback.to_s
|
||||
else
|
||||
fallback.to_s
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Overrides to remove debug massaging in SceneManager
|
||||
#--------------------------------------------------------------------------
|
||||
class Scene_Base
|
||||
def return_scene
|
||||
SceneManager.return
|
||||
end
|
||||
end
|
||||
|
||||
module SceneManager
|
||||
def self.call(scene_class)
|
||||
@stack.push(@scene)
|
||||
@scene = scene_class.new
|
||||
end
|
||||
|
||||
def self.return
|
||||
@scene = @stack.pop
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Window Base adjustment to reduce padding
|
||||
#--------------------------------------------------------------------------
|
||||
class Window_Base < Window
|
||||
def new_line_x
|
||||
standard_padding / 2
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Scene Base update override to include cheat triggers
|
||||
#--------------------------------------------------------------------------
|
||||
class Scene_Base
|
||||
alias_method :update_Framework, :update
|
||||
|
||||
def update
|
||||
update_Framework
|
||||
if FrameworkUtils.in_menu? && !FrameworkUtils.cheats_allowed?
|
||||
SceneManager.return
|
||||
elsif FrameworkUtils.ingame? && FrameworkUtils.cheats_allowed?
|
||||
$framework.hotkey_trigger
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Block the debug console (F10) while actively assigning a hotkey
|
||||
#--------------------------------------------------------------------------
|
||||
class Scene_Base
|
||||
alias_method :trigger_debug_window_entry_CheatFramework, :trigger_debug_window_entry
|
||||
|
||||
def trigger_debug_window_entry
|
||||
return if $framework.hotkey_capture_active
|
||||
trigger_debug_window_entry_CheatFramework
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Calls $framework.on_save_ready after a new game or a loaded save
|
||||
#--------------------------------------------------------------------------
|
||||
# Three hooks for full coverage: a fresh game, Scene_Load (title-screen and
|
||||
# in-game load), and Scene_CustomModeLoad (auto-saves, Doom-mode save, RolePlay-S quickload).
|
||||
module DataManager
|
||||
class << self
|
||||
alias_method :setup_new_game_CheatFramework, :setup_new_game
|
||||
|
||||
def setup_new_game(*args)
|
||||
setup_new_game_CheatFramework(*args)
|
||||
$framework.on_save_ready
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Scene_Load
|
||||
alias_method :on_load_success_CheatFramework, :on_load_success
|
||||
|
||||
def on_load_success
|
||||
on_load_success_CheatFramework
|
||||
$framework.on_save_ready
|
||||
end
|
||||
end
|
||||
|
||||
class Scene_CustomModeLoad
|
||||
alias_method :on_load_success_CheatFramework, :on_load_success
|
||||
|
||||
def on_load_success
|
||||
on_load_success_CheatFramework
|
||||
$framework.on_save_ready
|
||||
end
|
||||
end
|
||||
|
||||
# Applies every global: true/false command's configured override.
|
||||
class CheatFramework
|
||||
alias_method :on_save_ready_FORCE_MODES, :on_save_ready
|
||||
|
||||
def on_save_ready
|
||||
on_save_ready_FORCE_MODES
|
||||
FrameworkUtils.apply_force_modes
|
||||
end
|
||||
end
|
||||
|
||||
# Sets the update rate for other triggers.
|
||||
class CheatFramework
|
||||
alias_method :hotkey_trigger_TIMER, :hotkey_trigger
|
||||
|
||||
def hotkey_trigger
|
||||
hotkey_trigger_TIMER
|
||||
frame = Graphics.frame_count
|
||||
@last_normal_check ||= 0
|
||||
@last_slow_check ||= 0
|
||||
|
||||
# Every ~1 second
|
||||
if frame - @last_normal_check >= 40
|
||||
@last_normal_check = frame
|
||||
normal_trigger
|
||||
end
|
||||
|
||||
# Every ~3 seconds
|
||||
if frame - @last_slow_check >= 120
|
||||
@last_slow_check = frame
|
||||
slow_trigger
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Add extra triggerable keys to Input module
|
||||
#--------------------------------------------------------------------------
|
||||
module Input
|
||||
F1 = [KEYMAP[:F1]]
|
||||
F2 = [KEYMAP[:F2]]
|
||||
F3 = [KEYMAP[:F3]]
|
||||
F4 = [KEYMAP[:F4]]
|
||||
Agrave = [KEYMAP[:Agrave]]
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user