UI、自定义样式与启动页面
UIStyle
默认样式来自:
go
customStyle := style.DefaultUIStyle()常用字段:
DialogueBoxColorDialogueBorderColorDialogueBorderRadiusDialoguePaddingXDialoguePaddingYTextColorTextMutedColorChoiceBgColorChoiceHoverBgColorConfigBgColorTitleTextColorToastBgColor
示例:
go
customStyle := style.DefaultUIStyle()
customStyle.DialogueBoxColor = color.RGBA{30, 20, 45, 230}
customStyle.DialogueBorderColor = color.RGBA{236, 72, 153, 180}
customStyle.ChoiceBorderRadius = 8
engine, err := galgo.NewEngine(galgo.Config{
Style: customStyle,
}, nil)对话框和气泡台词
普通对话:
go
galgo.Text("Aria", "这是一句普通台词。")气泡台词:
go
galgo.TextBubble("Aria", "这句会显示在角色附近。")气泡会尝试以当前说话角色的立绘位置作为锚点。如果没有对应立绘,则使用屏幕中上部位置。
启动页和加载等待
通过 Config 启用:
go
galgo.Config{
StartupEnabled: true,
StartupLogoText: "Galgo",
StartupSubtitle: "My Visual Novel",
StartupMinFrames: 90,
LoadingText: "Loading",
LoadingMinFrames: 45,
}启动流程:
- Splash 页面显示 Logo 和副标题。
- Loading 页面显示等待文本和进度条。
- 进入标题菜单。
玩家可用鼠标左键、空格或回车跳过 Splash,但 Loading 会等待 LoadingMinFrames。
标题页
标题页可设置背景和音乐:
go
galgo.Config{
TitleBgImagePath: "assets/title_bg.png",
TitleBgmKey: "title",
TitleBgmPath: "assets/title.ogg",
}内置标题菜单包含:START GAME、LOAD GAME、GALLERY、SETTINGS、EXIT。
标题页也支持模块化配置。可以自定义按钮、排序、点击动作和额外首页模块:
go
title := galgo.DefaultTitleMenuConfig()
title.Items = []galgo.TitleMenuItem{
{ID: "start", Label: "START GAME", Order: 10, Action: galgo.StartGame()},
{ID: "settings", Label: "SETTINGS", Order: 20, Action: galgo.ShowScreen(galgo.MenuStateConfig)},
{ID: "exit", Label: "EXIT", Order: 30, Action: galgo.Quit()},
}
title.Modules = []galgo.TitleModule{
{
ID: "news",
Order: 10,
X: 720, Y: 140, W: 420, H: 120,
Draw: func(e *galgo.Engine, screen *ebiten.Image, m galgo.TitleModule, b galgo.UIRect) bool {
e.DrawText(screen, "Custom title module", m.X+20, m.Y+24, 16, color.White)
return true
},
},
}
galgo.Config{TitleMenu: title}设置页组件
设置页可通过 Config.Settings 自定义分组、组件和排序。内置组件类型包括:
SettingsComponentSliderSettingsComponentToggleSettingsComponentOptionsSettingsComponentButtonSettingsComponentCustom
常用内置值包括 VolumeValue、TextSpeedValue、FullscreenValue、ResolutionValue、LanguageValue 和 VariableValue。
go
settings := galgo.SettingsConfig{
Title: "SETTINGS",
Sections: []galgo.SettingsSection{
{
ID: "audio",
Title: "Audio",
Order: 10,
Components: []galgo.SettingsComponent{
{ID: "voice", Label: "Voice Volume", Order: 10, Kind: galgo.SettingsComponentSlider, Value: &galgo.VolumeValue{Channel: "voice"}},
{ID: "bgm", Label: "BGM Volume", Order: 20, Kind: galgo.SettingsComponentSlider, Value: &galgo.VolumeValue{Channel: "bgm"}},
},
},
},
}
galgo.Config{Settings: settings}渲染钩子
go
galgo.Config{
Hooks: galgo.Hooks{
OnDrawBackground: func(screen *ebiten.Image, bgKey, bgPath string, alpha float64) bool {
return false
},
OnDrawSprite: func(screen *ebiten.Image, sprite *galgo.SpriteRuntimeState) bool {
return false
},
OnDrawDialogueBox: func(screen *ebiten.Image, x, y, w, h float64) bool {
return false
},
OnPostProcess: func(screen *ebiten.Image) {
// 全屏后处理
},
},
}返回 true 表示你已经完成绘制,默认绘制会被跳过。