重写标题按钮,拉伸标题按钮
This commit is contained in:
parent
8ad4476076
commit
3046e559f6
|
|
@ -507,18 +507,43 @@ class titleButton extends Yosin_BaseButton {
|
||||||
|
|
||||||
|
|
||||||
// 拉伸标题按钮
|
// 拉伸标题按钮
|
||||||
class Yosin_StretchTitleButton extends Yosin_SplicingButton {
|
class Yosin_StretchTitleButton extends Yosin_CommonUi {
|
||||||
|
|
||||||
index = null;
|
index = null;
|
||||||
select = false;
|
//按钮状态
|
||||||
cacheSelect = false;
|
State = 0;
|
||||||
LBDownOnClick = null;
|
//ui的当前状态
|
||||||
|
uiState = 0;
|
||||||
|
|
||||||
|
cecheY = null;
|
||||||
|
|
||||||
titleText = null;
|
titleText = null;
|
||||||
|
|
||||||
constructor(X, Y, W, H, Path, Idx, title,) {
|
SpriteList = null;
|
||||||
base.constructor(X, Y, W, H, Path, Idx, true, false)
|
|
||||||
|
|
||||||
|
// 鼠标左键按下时的回调
|
||||||
|
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, {
|
titleText = FontAssetManager.GenerateNormal( title , true, {
|
||||||
color = sq_RGBA(130, 114, 84, 255)
|
color = sq_RGBA(130, 114, 84, 255)
|
||||||
});
|
});
|
||||||
|
|
@ -532,30 +557,58 @@ class Yosin_StretchTitleButton extends Yosin_SplicingButton {
|
||||||
cacheSelect = select;
|
cacheSelect = select;
|
||||||
})
|
})
|
||||||
|
|
||||||
titleText.SetPosition(9, 2);
|
titleText.SetPosition(W / 2 - titleText.GetSize().w/ 2, 2);
|
||||||
Addchild(titleText);
|
Addchild(titleText);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Proc(Dt) {
|
// 设置为选中状态
|
||||||
if (select) return;
|
function SetSelect(select) {
|
||||||
|
if (select){
|
||||||
if (State != 3 && isLBDown) {
|
|
||||||
State = 2;
|
State = 2;
|
||||||
select = true;
|
ChangeFrame();
|
||||||
if (LBDownOnClick != null) {
|
}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);
|
LBDownOnClick(this);
|
||||||
}
|
}
|
||||||
|
State = 2;
|
||||||
}
|
}
|
||||||
if (State == 2) {
|
//悬停
|
||||||
Y -= 1;
|
else if (isInRect) {
|
||||||
SyncPos(X, Y);
|
State = 1;
|
||||||
} else if (SpriteState == 2) {
|
|
||||||
Y += 1;
|
|
||||||
SyncPos(X, Y);
|
|
||||||
}
|
}
|
||||||
|
//普通
|
||||||
base.Proc(Dt);
|
else {
|
||||||
|
State = 0;
|
||||||
|
}
|
||||||
|
ChangeFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -568,13 +621,13 @@ class Yosin_RowMoreTitleBtn extends Yosin_CommonUi {
|
||||||
btns = [];
|
btns = [];
|
||||||
tests = [];
|
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;
|
this.tests = titles;
|
||||||
local btnX = 0;
|
local btnX = 0;
|
||||||
for(local i = 0; i < titles.len(); i++) {
|
for(local i = 0; i < titles.len(); i++) {
|
||||||
|
|
||||||
local textW = FontAssetManager.GenerateNormal(titles[i], true).GetSize().w + 20;
|
local textW = FontAssetManager.GenerateNormal(titles[i], true).GetSize().w + 10;
|
||||||
local btnW = baseWidth + 20;
|
local btnW = baseWidth + 10;
|
||||||
btnW = textW > btnW ? textW : btnW ;
|
btnW = textW > btnW ? textW : btnW ;
|
||||||
|
|
||||||
local titleBtn = Yosin_StretchTitleButton(btnX, 1, btnW, 19, path, idx, titles[i]);
|
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);
|
btn.Parent.LBDownOnClick(this, btn.index);
|
||||||
|
|
||||||
for (local i = 0; i < btn.Parent.btns.len(); i++) {
|
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.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));
|
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]);
|
AddUIChild(btns[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btns[0].SetSelect(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue