From 3046e559f6cde9878f8f5f2637a2a4c79e0f8cb4 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 | 109 ++++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 27 deletions(-) diff --git a/sqr/Core/UI_Class/UI_Widget.nut b/sqr/Core/UI_Class/UI_Widget.nut index 434bbaf..91d61aa 100644 --- a/sqr/Core/UI_Class/UI_Widget.nut +++ b/sqr/Core/UI_Class/UI_Widget.nut @@ -507,18 +507,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 +557,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 +621,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 +637,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 +656,8 @@ class Yosin_RowMoreTitleBtn extends Yosin_CommonUi { AddUIChild(btns[i]); } + btns[0].SetSelect(true); + } }