SparrohUILib
Shared UI library for Sparroh Mycopunk mods. Provides themed widgets, HUD builders, windows, and resolution-aware layout.
模組介紹 作者原文
SparrohUILib
Shared UI library for Sparroh Mycopunk mods. One theme, one set of widgets, resolution-aware layout.
Features
- Theme system — Mycopunk-inspired teal/slate surfaces with bioluminescent accents
- Resolution scaling — Reference 1920×1080; scales cleanly across aspect ratios via CanvasScaler + UITheme.Scale
- HUD builder — Single- and multi-line HUD text under the player reticle (normalized anchors); respects vanilla Hide HUD
- HUD reposition — Soft-dependency helpers for ModSettingsMenu drag-reposition (HudAnchors, HudRepositionClient, HudHandle.EnableReposition)
- Gear action bar — Shared top toolbar on the gear/menu canvas for cross-mod action buttons
- Widgets — Text, Button, Toggle, InputField, Panel, ScrollView, Separator, Dropdown, Slider, ProgressBar, Tabs, Tooltip, DragList
- Windows & dialogs — Overlay windows (per-window canvas), confirm/alert dialogs
- Rich text helpers — Label: value unit formatting with colored values
- Config colors — Bind hex color config entries with cached Color values
Install
r2modman: install Sparroh-SparrohUILib as a dependency of your mod.
Manual: place SparrohUILib.dll in BepInEx/plugins.
Consumer setup
csproj..\SparrohUILib\bin\Release\netstandard2.1\SparrohUILib.dll
Plugin
[BepInDependency("sparroh.uilibrary")]
[BepInPlugin(...)]
public class MyPlugin: BaseUnityPlugin { }.toml
[package.dependencies]
BepInEx-BepInExPack_Mycopunk = "5.4.2403"
Sparroh-SparrohUILib = "1.2.0"
Quick examples
using Sparroh.UI;
// HUD anchors (config) + rebuild when the handle dies after quit-to-menu
var anchors = HudAnchors.Bind(Config, "Altimeter", 0.15f, 0.84f);
if (!HudHandle.IsValid(hud))
{
hud = HudBuilder.Create("AltimeterHUD").ParentToReticle().Anchor(anchors.XValue, anchors.YValue).Size(300, 25).AddText("AltitudeText").Build();
// Soft-dep ModSettingsMenu: drag in F9 mode, SettingChanged → SetAnchor, auto-unregister on destroy
if (HudHandle.IsValid(hud))
hud.EnableReposition("my.mod.guid", "Altimeter", anchors);
}
if (HudHandle.IsValid(hud))
hud.Primary.SetRich("Altitude", 12.3f, UIColors.Shamrock, "m");
// Multi-line HUD
var meter = HudBuilder.Create("Carnometer").ParentToReticle().Anchor(0.15f, 0.95f).Size(320, 100).AddLines(4).Build();
meter.Lines[0].SetRichWithRate("Total Damage", total, dps, UIColors.Rose);
// Overlay window
var window = UIWindow.Create("Settings", new Vector2(800, 600), "Mod Settings", scrollable: true);
UIWindow.CreateSectionHeader(window.Content, "General");
UIToggle.Create(window.Content, "Enable HUD", true, on => { /... / });
UISlider.Create(window.Content, "Opacity", 0f, 1f, 0.8f, v => { /... / });
UIButton.Create(window.Content, "Save", () => { /... / }, UIButtonStyle.Primary);
// Dialogs
UIDialog.Confirm("Scrap upgrades?", "This cannot be undone.", onConfirm: DoScrap);
UIDialog.Alert("Done", "Upgrades scrapped.");
// Tooltip
UITooltip.Attach(someButton.GameObject, "Does the thing");
// Gear menu action bar (library hosts/ticks the bar)
GearActionBar.Register("mymod.scrap", "Scrap", GearActionBar.OrderScrapMarked, DoScrap, UIButtonStyle.Danger);
Theme & scaling
| API | Purpose |
|-----|---------|
| UIColors.* | Palette (Sky, Rose, Shamrock, PanelBg, ButtonPrimary, …) |
| UIColors.TryParseHex / ParseHex | Parse RRGGBB / #RRGGBB / RRGGBBAA / #RRGGBBAA |
| UIColors.ToHex / WithAlpha | Convert Color ↔ hex; adjust alpha |
| ConfigColor.Bind(...) | Bind a hex color config entry with cached Color |
| UITheme.S(px) / UITheme.Scale | Scale reference pixels to current resolution |
| UITheme.ScaledSize(w, h) | Scaled Vector2 |
| UITheme.ClampToScreen(size) | Keep windows on-screen |
| RichText.Labeled(...) | Colored label/value strings |
Configurable HUD colors
// In your mod constructor:
valueColor = ConfigColor.Bind(Config, "Colors", "ValueColor", UIColors.Sky,
"Rich-text value color (hex RRGGBB or #RRGGBB).");
// When drawing:
hud.Primary.SetRich("Speed", speed, valueColor.Value, "m/s");
安裝與使用 安裝:按包內說明操作
- 解壓本站下載的壓縮包,先讀包內的 readme / 說明檔案。
- 多數模組依賴遊戲的模組載入器:常見做法是用社群模組管理器(如 r2modman)選中本遊戲安裝,由管理器自動處理載入器與依賴。
- 手動安裝時,把模組檔案放進遊戲目錄下對應的 Mod / plugins 資料夾。
- 啟動遊戲確認載入成功;帶「前置依賴」的模組需要把依賴一併安裝。
不同模組的安裝位置差異較大,包內說明是最可靠的依據。
下面這些內容需要先安裝,否則該模組不會生效: