feat(client): 客户端网络层、zh_cn 中文语言文件、NSIS 中文安装脚本、UI 渲染器与 HUD(gl 标签)
This commit is contained in:
@@ -9,6 +9,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"image"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
@@ -20,6 +21,7 @@ import (
|
||||
"mc/internal/camera"
|
||||
"mc/internal/config"
|
||||
"mc/internal/engine"
|
||||
"mc/internal/font"
|
||||
"mc/internal/game"
|
||||
"mc/internal/inventory"
|
||||
"mc/internal/item"
|
||||
@@ -28,6 +30,7 @@ import (
|
||||
"mc/internal/physics"
|
||||
"mc/internal/recipe"
|
||||
"mc/internal/render"
|
||||
"mc/internal/ui"
|
||||
"mc/internal/world"
|
||||
"mc/internal/worldgen"
|
||||
)
|
||||
@@ -40,6 +43,8 @@ type clientApp struct {
|
||||
rend *render.Renderer
|
||||
reg *block.Registry
|
||||
in *inputState
|
||||
uiR *ui.Renderer
|
||||
hud *ui.HUD
|
||||
|
||||
meshBuilder *mesh.Builder
|
||||
|
||||
@@ -101,6 +106,10 @@ func (a *clientApp) Render() {
|
||||
a.rend.BeginFrame()
|
||||
chunks := a.sess.World.ActiveChunks()
|
||||
a.rend.DrawChunks(func(i int) (int32, int32) { return chunks[i].CX, chunks[i].CZ }, len(chunks))
|
||||
// UI pass(UI与输入.md §2:3D 之后、状态隔离)
|
||||
a.uiR.Begin()
|
||||
a.hud.Draw(a.uiR)
|
||||
a.uiR.Flush()
|
||||
a.rend.EndFrame()
|
||||
}
|
||||
|
||||
@@ -152,6 +161,22 @@ func main() {
|
||||
return u0, v0, u1, v1, true
|
||||
}
|
||||
|
||||
// items 图集(HUD 热键栏图标,UI还原.md §7)
|
||||
itemKeys, err := am.ExpandAtlas("items")
|
||||
if err != nil {
|
||||
log.Warnf("items 图集展开失败: %v", err)
|
||||
}
|
||||
itemImg, itemUVs, err := atlas.Build(am.ResolveTexture, itemKeys, 16)
|
||||
if err != nil {
|
||||
log.Warnf("items 图集构建失败: %v", err)
|
||||
}
|
||||
|
||||
// 字体(UI还原.md §4:素材包位图字体)
|
||||
fontAtlas, err := font.Build(am, "default")
|
||||
if err != nil {
|
||||
log.Warnf("字体构建失败: %v", err)
|
||||
}
|
||||
|
||||
// 2) 注册表(设计.md §6.1/§6.2 数据驱动)
|
||||
reg, err := block.Load("assets/config/blocks.json")
|
||||
if err != nil {
|
||||
@@ -192,6 +217,29 @@ func main() {
|
||||
rend.SetAtlas(atlasImg)
|
||||
rend.SetCursorMode(true)
|
||||
|
||||
// UI 层(UI还原.md §3.1:427×240 基准 × 3 缩放 = 1280×720)
|
||||
guiScale := float32(3)
|
||||
uiR, err := ui.New(cfg.Client.WindowWidth, cfg.Client.WindowHeight, guiScale)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if fontAtlas != nil {
|
||||
uiR.SetFont(fontAtlas)
|
||||
}
|
||||
hud := ui.NewHUD(sess, items, 427, 240, guiScale)
|
||||
if itemImg != nil {
|
||||
itemTex := uiR.UploadImage(itemImg)
|
||||
itemUV := make(map[string][4]float32, len(itemUVs))
|
||||
for k, rect := range itemUVs {
|
||||
W, H := float32(itemImg.Bounds().Dx()), float32(itemImg.Bounds().Dy())
|
||||
itemUV[k] = [4]float32{
|
||||
float32(rect.Min.X) / W, float32(rect.Min.Y) / H,
|
||||
float32(rect.Max.X) / W, float32(rect.Max.Y) / H,
|
||||
}
|
||||
}
|
||||
hud.SetItemAtlas(itemTex, itemUV)
|
||||
}
|
||||
|
||||
// 6) 输入(鼠标捕获 + 键鼠回调)
|
||||
in := newInputState(rend.Window())
|
||||
|
||||
@@ -200,6 +248,8 @@ func main() {
|
||||
rend: rend,
|
||||
reg: reg,
|
||||
in: in,
|
||||
uiR: uiR,
|
||||
hud: hud,
|
||||
meshBuilder: mesh.NewBuilder(reg, uvFn),
|
||||
winW: cfg.Client.WindowWidth,
|
||||
winH: cfg.Client.WindowHeight,
|
||||
|
||||
Reference in New Issue
Block a user