重写标题按钮,拉伸标题按钮

This commit is contained in:
WONIU 2025-01-04 20:03:17 +08:00
parent 8ad4476076
commit 3046e559f6
1 changed files with 82 additions and 27 deletions

View File

@ -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;
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);
}
}
}
function Proc(Dt) {
if (State == 2) return;
//按下
if (isLBDown) {
if (LBDownOnClick!= null) {
LBDownOnClick(this);
}
State = 2;
}
if (State == 2) {
Y -= 1;
SyncPos(X, Y);
} else if (SpriteState == 2) {
Y += 1;
SyncPos(X, Y);
//悬停
else if (isInRect) {
State = 1;
}
base.Proc(Dt);
//普通
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);
}
}