新增 只有2图的按钮

背包完善按钮
This commit is contained in:
WONIU 2025-01-08 17:37:15 +08:00
parent 72d2e37fb0
commit ed606f570f
2 changed files with 80 additions and 115 deletions

View File

@ -141,6 +141,79 @@ class Yosin_BaseButton extends Yosin_CommonUi {
}
}
// 2图按钮
class Yosin_TwoImgButton extends Yosin_CommonUi {
//按钮状态
State = 0;
Path = null;
Idx = null;
Sprite = null;
NormalSpriteFrame = null;
SlectSpriteFrame = null;
SpriteState = -1;
//按下时的模拟偏移
DownSimulateOffset = true;
constructor(X, Y, W, H, Path, Idx) {
this.Path = Path;
this.Idx = Idx;
base.constructor(X, Y, W, H);
Sprite = CL_SpriteObject();
Addchild(Sprite);
NormalSpriteFrame = CL_SpriteFrameObject(this.Path, this.Idx);
SlectSpriteFrame = CL_SpriteFrameObject(this.Path, this.Idx + 1);
}
function ChangeFrame() {
//状态更改 刷新精灵帧
if (State != SpriteState) {
//按下时模拟偏移的Flag 如果按下 调整Y坐标向下一个单位
if (DownSimulateOffset) {
if (State == 2) {
Y += 1;
SyncPos(X, Y);
} else if (SpriteState == 2) {
Y -= 1;
SyncPos(X, Y);
}
}
SpriteState = State;
Sprite.SetFrame(State != 0 ? SlectSpriteFrame : NormalSpriteFrame );
Sprite.SetPosition(0, 0);
}
}
function Proc(Dt) {
//不可用
if (State == 3) {
} else {
//按下
if (isLBDown) {
State = 2;
}
//悬停
else if (isInRect) {
State = 1;
}
//普通
else {
State = 0;
}
}
ChangeFrame();
}
}
//三分法拉伸
class Yosin_EmeStretch extends Yosin_CommonUi {
@ -297,114 +370,6 @@ function Yosin_NineBoxStretch(X, Y, width, height, path, imgId) {
return Canvas;
}
// //九宫格拉伸
// class Yosin_NineBoxStretch extends Yosin_CommonUi {
// constructor(X, Y, W, H, Path, Idx) {
// base.constructor(X, Y, W, H);
// DrawBackground(W, H, Path, Idx);
// }
// // 绘制
// function DrawBackground(width, height, path, imgId) {
// // 创建画布
// local Canvas = CL_CanvasObject();
// // 重设大小并清空
// Canvas.ResizeAndClear(width, height);
// // 开始绘制
// Canvas.BeginDraw();
// // 左上角
// // local backgroundTopLeft = CL_SpriteObject(path, imgId);
// local backgroundTopLeft = CL_SpriteObject(path, imgId);
// // 上边
// local backgroundTop = CL_SpriteObject(path, imgId + 1);
// // 右上角
// local backgroundTopRight = CL_SpriteObject(path, imgId + 2);
// // 左边
// local backgroundLeft = CL_SpriteObject(path, imgId + 3);
// // 中间
// local backgroundCenter = CL_SpriteObject(path, imgId + 4);
// // 右边
// local backgroundRight = CL_SpriteObject(path, imgId + 5);
// // 左下角
// local backgroundBottomLeft = CL_SpriteObject(path, imgId + 6);
// // 下边
// local backgroundBottom = CL_SpriteObject(path, imgId + 7);
// // 右下角
// local backgroundBottomRight = CL_SpriteObject(path, imgId + 8);
// // 左上角
// Canvas.DrawSprite(backgroundTopLeft);
// local TopLeftSize = backgroundTopLeft.GetSize();
// local TopLeftBottom = TopLeftSize.h;
// local TopLeftRight = TopLeftSize.w;
// // 中间图片大小
// local centerImgSize = backgroundCenter.GetSize();
// local centerImgWidth = centerImgSize.w;
// local centerImgHeight = centerImgSize.h;
// local centerWidth = width - backgroundTopLeft.GetSize().w - backgroundTopRight.GetSize().w;
// local centerHeight = height - backgroundTopLeft.GetSize().h - backgroundBottomLeft.GetSize().h;
// local scaleW = (centerWidth - 1).tofloat() / centerImgWidth.tofloat();
// local scaleH = (centerHeight - 1).tofloat() / centerImgHeight.tofloat();
// // 上边
// backgroundTop.SetScale(scaleW, 1);
// backgroundTop.SetPosition(TopLeftRight + 1, 0);
// Canvas.DrawSprite(backgroundTop);
// // 右上角
// backgroundTopRight.SetPosition(width - backgroundTopRight.GetSize().w, 0);
// Canvas.DrawSprite(backgroundTopRight);
// // 左边
// backgroundLeft.SetScale(1, scaleH);
// backgroundLeft.SetPosition(0, TopLeftBottom + 1);
// Canvas.DrawSprite(backgroundLeft);
// // 中间
// backgroundCenter.SetScale(scaleW, scaleH);
// // Addchild(backgroundCenter);
// backgroundCenter.SetPosition(TopLeftRight + 1, backgroundLeft.Y);
// Canvas.DrawSprite(backgroundCenter);
// // 右边
// backgroundRight.SetScale(1, scaleH);
// backgroundRight.SetPosition(width - backgroundRight.GetSize().w, backgroundCenter.Y);
// Canvas.DrawSprite(backgroundRight);
// // 左下角
// backgroundBottomLeft.SetPosition(0, height - backgroundBottomLeft.GetSize().h);
// Canvas.DrawSprite(backgroundBottomLeft);
// // 下边
// backgroundBottom.SetScale(scaleW, 1);
// backgroundBottom.SetPosition(TopLeftRight + 1, backgroundBottomLeft.Y);
// Canvas.DrawSprite(backgroundBottom);
// // 右下角
// backgroundBottomRight.SetPosition(width - backgroundBottomRight.GetSize().w, backgroundBottomLeft.Y);
// Canvas.DrawSprite(backgroundBottomRight );
// // 结束绘制
// Canvas.EndDraw();
// // 添加画布
// Addchild(Canvas);
// }
// }
//拼接按钮
class Yosin_SplicingButton extends Yosin_CommonUi {
//按钮状态

View File

@ -70,28 +70,28 @@ class Inventory_CharactersEquipment extends Yosin_CommonUi {
// 添加按钮
function AddButton() {
// 称号
local designation = Yosin_BaseButton(2, Height - 30, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 50);
local designation = Yosin_TwoImgButton(2, Height - 30, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 50);
//点击事件回调
// permutationBtn.OnClick = function(Button) {
// }.bindenv(this);
AddUIChild(designation);
// 增益强化
local intensify = Yosin_BaseButton(designation.right() +2, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 128);
local intensify = Yosin_TwoImgButton(designation.right() +2, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 128);
AddUIChild(intensify);
// 皮肤仓库
local skin = Yosin_BaseButton(intensify.right() + 2, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 134);
local skin = Yosin_TwoImgButton(intensify.right() + 2, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 134);
AddUIChild(skin);
// 穿戴中的装备
local wear = Yosin_BaseButton(Width - 29, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 172);
local wear = Yosin_TwoImgButton(Width - 29, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 172);
AddUIChild(wear);
// 装备特性
local peculiarity = Yosin_BaseButton(wear.X - 21, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 203);
local peculiarity = Yosin_TwoImgButton(wear.X - 21, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 203);
AddUIChild(peculiarity);
// 未央环境装备
// local permutationBtn = Yosin_BaseButton(peculiarity.X - 21, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory.img", 128);
// AddUIChild(permutationBtn);
local weiyangBtn = Yosin_TwoImgButton(peculiarity.X - 21, designation.Y, 18, 20 "sprite/interface/newstyle/windows/inventory/inventory_cn.img", 26);
AddUIChild(weiyangBtn);
}