Zero Sievertv1.2.59-1.112026年12月4日 更新

ConfigLib

为其他模组提供设置的定义、显示、读取与保存功能;本身不添加独立游戏内容。需要 Zero Sievert 1.2.59+、GMLoader 和 UiPatchLib。

简介

ConfigLib 为其他模组提供显示和编辑设置的功能,本身不独立发挥作用,仅供其他模组使用。也可在 ConfigLib 的模组设置中查看游戏文件夹或调整模组列表顺序。

前置要求

  • Zero Sievert 1.2.59 或更高版本
  • GMLoader
  • UiPatchLib

安装

  1. 将 ZIP 文件解压到 SteamLibrary\steamapps\common\ZERO Sievert。
  2. 运行 GMLoader。

文档

此库允许用户通过界面访问模组设置。所有设置都会立即保存到 INI 文件中;模组设置为全局设置,不对应特定存档。

推荐用法:

  • 使用 configlib_define_setting() 定义设置,例如在 gml_Object_obj_logo_screen_Create_0 中定义一次。
  • 使用 configlib_save_settings() 保存所有设置及其值。
  • 在模组其他部分需要时,通过 configlib_get() 获取值。
  • 需要时通过 configlib_set() 设置值。
  • 用户可以前往“主菜单/模组设置/我的模组”调整设置。
  • 目前用户无法编辑 string 类型设置。
  • INI 文件可能位于游戏安装目录下的 ...SteamLibrary\steamapps\common\ZERO Sievert\mods\config,也可能位于 %localappdata%\ZERO Sievert(例如 C:\Users\<User Name>\AppData\Local\ZERO Sievert\mods\config)。
  • language 当前未使用;bool 和 string 类型不使用 minvalue、maxvalue。

可选依赖检查

在自己的模组中,可用以下方式检查 ConfigLib 是否存在:

if (!variable_global_exists("configlib")) {
    show_message("My mod needs ConfigLib mod!");
}

可用函数

configlib_define_setting()

定义供后续使用和保存的设置。

参数:

  • modname:模组名称,也会用作 INI 文件名。
  • section:设置分区名称,默认为 "General"。
  • key:设置键名。
  • datatype:数据类型,可为:
    • "bool":逻辑值 true 或 false。
    • "int":整数。
    • "real":浮点数。
    • "string":字符串值(用户目前无法编辑)。
    • "key_code":范围为 0–255 的整数,表示按键的 Ord() 值,并通过滑块设置;目前不支持键盘/手柄扫描或键盘修饰键。
  • minvalue、maxvalue:int 和 real 类型的最小值、最大值。
  • default_value:首次加载时的初始值。
  • description:显示给用户的单行说明,建议短于 40–60 个字符。
  • tooltip:设置值说明,以工具提示形式显示。
  • language:未使用;用于标示模组名称、分区、说明和工具提示的语言。
configlib_define_setting(modname, section = "General", key, datatype = "bool", minvalue = undefined, maxvalue = undefined, default_value = undefined, description = undefined, tooltip = undefined, language = undefined);

示例:

configlib_define_setting("HP and Stamina Bar in Inventory Screen", "General", "show_hp", "bool", false, true, true, "Show HP in Inventory", "My tootlip for showing HP!", "en");

configlib_get_key_definition()

获取此前通过 configlib_define_setting() 定义的设置结构体。参数为模组名称、分区名称和设置键名。返回结构体包含 modname、section、key、datatype、minvalue、maxvalue、default_value、description、tooltip、language 和 value。

configlib_get_key_definition(modname, section, key);

示例:

var show_hp_configdef = configlib_get_key_definition("HP and Stamina Bar in Inventory Screen", "General", "show_hp");
scr_draw_text_with_box(show_hp_configdef.description); // 显示 "show_hp" 设置的说明

configlib_get()

获取设置值。参数为模组名称、分区名称(默认为 "General")和设置键名;返回包含设置定义及值的结构体。

configlib_get(modname, section = "General", key);

示例:

var show_hp = configlib_get("HP and Stamina Bar in Inventory Screen", "General", "show_hp");

configlib_save_settings()

将已定义的所有设置及其值保存到 INI 文件。

configlib_save_settings(modname);

示例:

configlib_save_settings("HP and Stamina Bar in Inventory Screen");

configlib_set()

设置某项的值,并保存到 INI 文件。参数为模组名称、分区名称(默认为 "General")、设置键名和值。

configlib_set(modname, section = "General", key, value);

示例:

configlib_set("HP and Stamina Bar in Inventory Screen", "General", "show_hp", my_show_hp_value);

configlib_reset_value()

将设置重置为 default_value 并保存到 INI 文件。

configlib_reset_value(modname, section = "General", key);

示例:

configlib_reset_value("HP and Stamina Bar in Inventory Screen", "General", "show_hp");

configlib_set_event()

为设置变更指定回调函数。目前仅支持 "onChange" 事件。回调函数接收模组名称、分区名称、设置键名和新值作为参数。

configlib_set_event(modname, section = "General", key, event, fun = undefined);

示例:

configlib_set_event("VSync, AntiAliasing", "General", "vsync_enabled", "onChange",
function(mymodname, mysection, mykey, mynewvalue) {
    // 以下三种方式效果相同:
    // display_reset(0, configlib_get("VSync, AntiAliasing", "General", "vsync_enabled"));
    // display_reset(0, configlib_get(mymodname, mysection, mykey));
    display_reset(0, mynewvalue);
});

UiConfigLibGetValue()

在 UI 脚本中获取设置值。参数为模组名称、分区名称(默认为 "General")和设置键名。

UiConfigLibGetValue(modname, section = "General", key);

示例:

UiConfigLibGetValue("HP and Stamina Bar in Inventory Screen", "General", "show_hp");

示例模组

此示例依赖 UiPatchLib。

创建模组文件 ZS_vanilla\mods\config\code_patch\HP and Stamina Bar in Inventory Screen.yaml,内容如下:

gml_Object_obj_logo_screen_Create_0:
- type: append
code: |-
  {
      // 在本地完成所有操作
      var modname = "HP and Stamina Bar in Inventory Screen";
      var modsection = "General";

      // 创建全局可用的设置结构体,以便提高性能
      // 不要直接修改这些值,否则不会保存到 INI;请改用 configlib_set()
      global.HP_and_Stamina_Bar_in_Inventory_Screen_mod = {
          show_hp: true,
          show_stamina: true
      };

      if (variable_global_exists("configlib")) {
          configlib_define_setting(modname, modsection, "show_hp", "bool", false, true, true, "Show HP", undefined);
          configlib_define_setting(modname, modsection, "show_stamina", "bool", false, true, true, "Show Stamina", undefined);

          // 用户更改设置时调用 onChange 函数;可直接使用新值
          configlib_set_event(modname, modsection, "show_hp", "onChange", function(modname, section, key, newvalue) {
              global.HP_and_Stamina_Bar_in_Inventory_Screen_mod.show_hp = newvalue;
          });

          // 也可手动获取新值并执行其他操作
          configlib_set_event(modname, modsection, "show_stamina", "onChange", function(modname, section, key, newvalue) {
              global.HP_and_Stamina_Bar_in_Inventory_Screen_mod.show_stamina = configlib_get(modname, section, key);
          });

          // 如有需要,可读取变量值
          // var show_hp = configlib_get(modname, modsection, "show_hp");
          // var show_stamina = configlib_get(modname, modsection, "show_stamina");

          // 如有需要,可设置值
          // configlib_set(modname, modsection, "show_hp", show_hp);
          // configlib_set(modname, modsection, "show_stamina", show_stamina);

          // 更新 INI 文件
          configlib_save_settings(modname);

          // 准备动态 UI 仪表
          var ui_add_str =
              "if (UiConfigLibGetValue(\"" + modname + "\", \"" + modsection + "\", \"show_hp\")) {\r\n" +
              "  build UiPDAHpBar {\r\n" +
              "    xy = [\"45%\", \"66%\"]\r\n" +
              "    mode = \"health\"\r\n" +
              "  }\r\n" +
              "}\r\n" +
              "if (UiConfigLibGetValue(\"" + modname + "\", \"" + modsection + "\", \"show_stamina\")) {\r\n" +
              "  build UiPDAHpBar {\r\n" +
              "    xy = [\"62%\", \"66%\"]\r\n" +
              "    mode = \"stamina\"\r\n" +
              "  }\r\n" +
              "}\r\n";

          // 将玩家库存 UI 注入到指定位置
          ui_patch_add_replace_all_verbose(
              "ZS_vanilla/ui/inventory_exec_player_gear.ui",
              "//Weapon 1",
              ui_add_str + "//Weapon 1",
              modname
          );
      } else {
          show_message(modname + " requires ConfigLib!");
      }
  }

来源与文件

  • 原作者:kofolamaster
  • 原项目:ConfigLib
  • 文件:ConfigLib(ID:1635)

来源列出的依赖与关系

  • 作者列出的前置:GMLoader
  • 作者列出的前置:UiPatchLib

前往 N 网打开所选文件。安装与下载要求以原作者及平台说明为准。

<!-- aoe-mods-source:nexusmods:zerosievert:174 -->

下载模块

共 1 个来源
立即下载推荐来源
前往下载