From 1edf3151f514257bff70911065282ff8fc8bc0e4 Mon Sep 17 00:00:00 2001 From: WONIU Date: Sat, 4 Jan 2025 20:03:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E6=A0=87=E9=A2=98=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=8C=E6=8B=89=E4=BC=B8=E6=A0=87=E9=A2=98=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqr/Core/UI_Class/UI_Widget.nut | 129 +++++++++++++++++++++----------- 1 file changed, 87 insertions(+), 42 deletions(-) diff --git a/sqr/Core/UI_Class/UI_Widget.nut b/sqr/Core/UI_Class/UI_Widget.nut index 434bbaf..d572e02 100644 --- a/sqr/Core/UI_Class/UI_Widget.nut +++ b/sqr/Core/UI_Class/UI_Widget.nut @@ -163,30 +163,19 @@ class Yosin_EmeStretch extends Yosin_CommonUi { if (Direction) { local ScaleW = (W - SpriteList[0].GetSize().w - SpriteList[2].GetSize().w); local ScaleRate = ScaleW / SpriteList[1].GetSize().w; - local ScaleRateH = H / SpriteList[1].GetSize().h; - SpriteList[1].SetPosition(SpriteList[0].GetSize().w, -30); - - SpriteList[1].SetScale(ScaleRate, ScaleRateH); - SpriteList[2].SetPosition(SpriteList[0].GetSize().w + ScaleW, 0); - if (H != SpriteList[1].GetSize().h) { - SpriteList[0].SetScale(1, ScaleRateH); - SpriteList[2].SetScale(1, ScaleRateH); - } + SpriteList[1].SetPosition(SpriteList[0].GetSize().w, 0.0); + SpriteList[1].SetScale(ScaleRate, 1.0); + SpriteList[2].SetPosition(SpriteList[0].GetSize().w + ScaleW, 0.0); } //纵向 else { local ScaleH = (H - SpriteList[0].GetSize().h - SpriteList[2].GetSize().h); local ScaleRate = ScaleH / SpriteList[1].GetSize().h; - local ScaleRateW = H / SpriteList[1].GetSize().w; SpriteList[1].SetPosition(0, SpriteList[0].GetSize().h); - SpriteList[1].SetScale(ScaleRateW, ScaleRate); + SpriteList[1].SetScale(1.0, ScaleRate); SpriteList[2].SetPosition(0, SpriteList[0].GetSize().h + ScaleH); - if (W != SpriteList[1].GetSize().w) { - SpriteList[0].SetScale(ScaleRateW, ScaleRateH); - SpriteList[2].SetScale(ScaleRateW, ScaleRateH); - } } foreach(Child in SpriteList) { @@ -391,6 +380,7 @@ class Yosin_TopTitle extends Yosin_CommonUi { local BackgroundBright = CL_SpriteObject("sprite/interface/lenheartwindowcommon.img", 483); local scaleW = (W / BackgroundBright.GetSize().w).tofloat(); BackgroundBright.SetScale( scaleW , 1); + BackgroundBright.SetPosition(0, 1); Addchild(BackgroundBright); @@ -507,18 +497,43 @@ class titleButton extends Yosin_BaseButton { // 拉伸标题按钮 -class Yosin_StretchTitleButton extends Yosin_SplicingButton { +class Yosin_StretchTitleButton extends Yosin_CommonUi { index = null; - select = false; - cacheSelect = false; - LBDownOnClick = null; + //按钮状态 + State = 0; + //ui的当前状态 + uiState = 0; + + cecheY = null; titleText = null; - constructor(X, Y, W, H, Path, Idx, title,) { - base.constructor(X, Y, W, H, Path, Idx, true, false) + SpriteList = null; + // 鼠标左键按下时的回调 + LBDownOnClick = null; + + constructor(X, Y, W, H, Path, Idx, title) { + base.constructor(X, Y, W, H) + + cecheY = Y; + SpriteList = array(3); + + //普通态 + SpriteList[0] = Yosin_EmeStretch(0, 0, W, H, Path, Idx); + AddUIChild(SpriteList[0]); + + //悬停态 + SpriteList[1] = Yosin_EmeStretch(0, 0, W, H, Path, Idx + 3); + SpriteList[1].SetVisible(false) + AddUIChild(SpriteList[1]); + //按下态 + SpriteList[2] = Yosin_EmeStretch(0, 0, W, H, Path, Idx + 6); + SpriteList[2].SetVisible(false) + AddUIChild(SpriteList[2]); + + // 文字 titleText = FontAssetManager.GenerateNormal( title , true, { color = sq_RGBA(130, 114, 84, 255) }); @@ -532,30 +547,58 @@ class Yosin_StretchTitleButton extends Yosin_SplicingButton { cacheSelect = select; }) - titleText.SetPosition(9, 2); + titleText.SetPosition(W / 2 - titleText.GetSize().w/ 2, 2); Addchild(titleText); } - function Proc(Dt) { - if (select) return; - - if (State != 3 && isLBDown) { + // 设置为选中状态 + function SetSelect(select) { + if (select){ State = 2; - select = true; - if (LBDownOnClick != null) { - LBDownOnClick(this); + ChangeFrame(); + }else{ + State = 0; + ChangeFrame(); + } + } + + + function ChangeFrame() { + //状态更改 刷新精灵帧 + if (State != uiState) { + if (State == 2) { + SyncPos(X, cecheY - 1); + }else{ + SyncPos(X, cecheY); + } + uiState = State; + + for (local i = 0; i < SpriteList.len(); i++) { + SpriteList[i].SetVisible(i == uiState); } } - if (State == 2) { - Y -= 1; - SyncPos(X, Y); - } else if (SpriteState == 2) { - Y += 1; - SyncPos(X, Y); - } + } - base.Proc(Dt); + function Proc(Dt) { + if (State == 2) return; + + //按下 + if (isLBDown) { + if (LBDownOnClick!= null) { + LBDownOnClick(this); + } + State = 2; + } + //悬停 + else if (isInRect) { + State = 1; + } + //普通 + else { + State = 0; + } + ChangeFrame(); } } @@ -568,13 +611,13 @@ class Yosin_RowMoreTitleBtn extends Yosin_CommonUi { btns = []; tests = []; - constructor(X, Y, titles, baseWidth = 44, path = "sprite/interface/lenheartwindowcommon.img", idx = 160) { + constructor(X, Y, titles, selectIndex = 0, baseWidth = 34, path = "sprite/interface/lenheartwindowcommon.img", idx = 160) { this.tests = titles; local btnX = 0; for(local i = 0; i < titles.len(); i++) { - local textW = FontAssetManager.GenerateNormal(titles[i], true).GetSize().w + 20; - local btnW = baseWidth + 20; + local textW = FontAssetManager.GenerateNormal(titles[i], true).GetSize().w + 10; + local btnW = baseWidth + 10; btnW = textW > btnW ? textW : btnW ; local titleBtn = Yosin_StretchTitleButton(btnX, 1, btnW, 19, path, idx, titles[i]); @@ -584,11 +627,11 @@ class Yosin_RowMoreTitleBtn extends Yosin_CommonUi { btn.Parent.LBDownOnClick(this, btn.index); for (local i = 0; i < btn.Parent.btns.len(); i++) { - btn.Parent.btns[i].select = false; + btn.Parent.btns[i].SetSelect(false); btn.Parent.btns[i].titleText.SetFillColor(sq_RGBA(130,114,84, 255)); } - btn.select = true; + btn.SetSelect(true); btn.Parent.btns[btn.index].titleText.SetFillColor(sq_RGBA(187,176,149, 255)); }; @@ -603,6 +646,8 @@ class Yosin_RowMoreTitleBtn extends Yosin_CommonUi { AddUIChild(btns[i]); } + btns[0].SetSelect(true); + } }