UI新增滚动条 成就系统完成分离
This commit is contained in:
@@ -736,6 +736,7 @@ class LenheartNewUI_CommonUi extends LenheartNewUI_BaseWindow {
|
||||
TopCallBackFunc = null;
|
||||
|
||||
Data = null;
|
||||
DeBugMode = false;
|
||||
|
||||
constructor(x, y, width, height) {
|
||||
this.Localtion_X = x;
|
||||
@@ -792,7 +793,13 @@ class LenheartNewUI_CommonUi extends LenheartNewUI_BaseWindow {
|
||||
|
||||
function TopShow(obj) {
|
||||
if (TopCallBackFunc) TopCallBackFunc(obj, this);
|
||||
if (DeBugMode) DeBug(obj);
|
||||
}
|
||||
|
||||
function DeBug(obj) {
|
||||
sq_DrawBox(X, Y, Width, Height, 0xffffffff);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class LenheartNewUI_BaseButton extends LenheartNewUI_CommonUi {
|
||||
@@ -1195,4 +1202,211 @@ class LenheartNewUI_TabbarsText extends LenheartNewUI_Tabbars {
|
||||
if (State == 0 || State == 8)
|
||||
L_sq_DrawCode(TextStr, X + TextXoffset, SY + 2, Color, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Yosin_DragButton extends LenheartNewUI_CommonUi {
|
||||
State = 0;
|
||||
DHeight = null; // 改为高度
|
||||
Path = "interface/lenheartwindowcommon.img";
|
||||
Idx = 172;
|
||||
FillHeight = 2; // 改为填充高度
|
||||
FirstHeight = 7; // 改为首节高度
|
||||
Width = 9; // 固定宽度,垂直按钮宽度通常是固定的
|
||||
Visible = true;
|
||||
DeBugMode = false;
|
||||
|
||||
BasePos = null;
|
||||
MoveFlag = false;
|
||||
//鼠标相对位置
|
||||
M_Xpos = null;
|
||||
M_Ypos = null;
|
||||
B_X = null;
|
||||
B_Y = null;
|
||||
Move_Value = 0;
|
||||
Max_Move_Value = 0;
|
||||
|
||||
CurrentMovePosY = 0;
|
||||
|
||||
//当前滚动值
|
||||
CurrentScrollValue = 0.0;
|
||||
|
||||
OnChange = null;
|
||||
|
||||
constructor(X, Y, H) {
|
||||
this.DHeight = H;
|
||||
LenheartNewUI_CommonUi.constructor(X, Y, Width, H + 7 * 2); // 宽度固定,高度动态
|
||||
|
||||
BasePos = {
|
||||
x = X,
|
||||
y = Y
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function SetFrame(gPath, gIdx) {
|
||||
if (gPath) Path = gPath;
|
||||
Idx = gIdx;
|
||||
}
|
||||
|
||||
function Show(obj) {
|
||||
//不可用
|
||||
if (State == 8) {
|
||||
L_sq_Draw3Image_Vertical(X + 1, Y, this.DHeight, Path, Idx + 9, FillHeight, FirstHeight);
|
||||
} else {
|
||||
//按下
|
||||
if (isLBDown) {
|
||||
L_sq_Draw3Image_Vertical(X, Y + 1, this.DHeight, Path, Idx + 3, FillHeight, FirstHeight);
|
||||
}
|
||||
//悬停
|
||||
else if (isInRect) {
|
||||
L_sq_Draw3Image_Vertical(X, Y, this.DHeight, Path, Idx + 3, FillHeight, FirstHeight);
|
||||
}
|
||||
//普通
|
||||
else {
|
||||
L_sq_Draw3Image_Vertical(X, Y, this.DHeight, Path, Idx, FillHeight, FirstHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//鼠标左键按下回调
|
||||
function OnMouseLbDown(MousePos_X, MousePos_Y) {
|
||||
LenheartNewUI_CommonUi.OnMouseLbDown(MousePos_X, MousePos_Y);
|
||||
|
||||
if (isInRect) {
|
||||
MoveFlag = true;
|
||||
M_Xpos = MousePos_X; //原始鼠标位置数据
|
||||
M_Ypos = MousePos_Y;
|
||||
B_X = X; //原始窗口位置
|
||||
B_Y = Y;
|
||||
}
|
||||
}
|
||||
|
||||
//鼠标事件回调
|
||||
function OnMouseProc(Flag, MousePos_X, MousePos_Y) {
|
||||
LenheartNewUI_CommonUi.OnMouseProc(Flag, MousePos_X, MousePos_Y);
|
||||
|
||||
//移动
|
||||
if (MoveFlag) {
|
||||
Move_Value = MousePos_Y - M_Ypos + CurrentMovePosY;
|
||||
if (Move_Value > 0 && Move_Value <= Max_Move_Value) {
|
||||
Y = (Move_Value);
|
||||
Localtion_Y = (BasePos.y + Move_Value);
|
||||
if (OnChange) {
|
||||
local Rate = Move_Value.tofloat() / Max_Move_Value.tofloat();
|
||||
CurrentScrollValue = format("%.2f", Rate).tofloat();
|
||||
OnChange(CurrentScrollValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//鼠标左键弹起回调
|
||||
function OnMouseLbUp(MousePos_X, MousePos_Y) {
|
||||
LenheartNewUI_CommonUi.OnMouseLbUp(MousePos_X, MousePos_Y);
|
||||
MoveFlag = false;
|
||||
if (Move_Value< 0) Move_Value = 0;
|
||||
if (Move_Value > Max_Move_Value) Move_Value = Max_Move_Value;
|
||||
CurrentMovePosY = Move_Value; //记录当前移动位置
|
||||
}
|
||||
|
||||
//设置最大移动值
|
||||
function SetMaxMoveValue(Value) {
|
||||
Max_Move_Value = Value;
|
||||
}
|
||||
|
||||
//设置滚动回调函数
|
||||
function SetOnChange(OnChange) {
|
||||
this.OnChange = OnChange;
|
||||
}
|
||||
|
||||
//设置滚动步进
|
||||
function SetStep(Step) {
|
||||
// 计算新的移动值
|
||||
local newValue = CurrentMovePosY + (Step * Max_Move_Value).tointeger();
|
||||
|
||||
// 边界检查
|
||||
if (newValue< 0) newValue = 0;
|
||||
if (newValue > Max_Move_Value) newValue = Max_Move_Value;
|
||||
|
||||
// 更新位置
|
||||
Move_Value = newValue;
|
||||
CurrentMovePosY = newValue;
|
||||
Localtion_Y = BasePos.y + newValue;
|
||||
// 更新并回调滚动值
|
||||
if (OnChange) {
|
||||
local Rate = Move_Value.tofloat() / Max_Move_Value.tofloat();
|
||||
CurrentScrollValue = format("%.2f", Rate).tofloat();
|
||||
OnChange(CurrentScrollValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Yosin_ScrollBar {
|
||||
|
||||
//上按钮
|
||||
UpButton = null;
|
||||
//下按钮
|
||||
DownButton = null;
|
||||
//滑动按钮
|
||||
ScrollButton = null;
|
||||
//点击时步进的Y轴值
|
||||
Step = 0.0;
|
||||
|
||||
Parent = null;
|
||||
|
||||
constructor(X, Y, H, Sbtn_H) {
|
||||
|
||||
|
||||
ScrollButton = Yosin_DragButton(X, Y + 13, Sbtn_H);
|
||||
ScrollButton.SetFrame("interface/lenheartwindowcommon.img", 184);
|
||||
//减去按钮高度 加滚动条长度加滚动条上下拼接长度15 加滚动条最大高度
|
||||
ScrollButton.SetMaxMoveValue(H - 26 - ScrollButton.Height);
|
||||
|
||||
UpButton = LenheartNewUI_BaseButton(X, Y, 9, 13, "interface/lenheartwindowcommon.img", 16);
|
||||
UpButton.OnClick = function() {
|
||||
DoStep(-1);
|
||||
}.bindenv(this);
|
||||
|
||||
DownButton = LenheartNewUI_BaseButton(X, Y + H - 13, 9, 13, "interface/lenheartwindowcommon.img", 22);
|
||||
DownButton.OnClick = function() {
|
||||
DoStep(1);
|
||||
}.bindenv(this);
|
||||
}
|
||||
|
||||
function DoStep(Flag) {
|
||||
ScrollButton.SetStep(Step * Flag);
|
||||
}
|
||||
|
||||
function SetParent(Ui) {
|
||||
Parent = Ui;
|
||||
Ui.AddChild(UpButton);
|
||||
Ui.AddChild(ScrollButton);
|
||||
Ui.AddChild(DownButton);
|
||||
}
|
||||
|
||||
function RemoveSelf() {
|
||||
for (local i = 0; i< Parent.Childrens.len(); i++) {
|
||||
local obj = Parent.Childrens[i];
|
||||
if (obj == UpButton || obj == ScrollButton || obj == DownButton) {
|
||||
Parent.Childrens.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function SetDebugModel(Flag) {
|
||||
UpButton.DeBugMode = Flag;
|
||||
ScrollButton.DeBugMode = Flag;
|
||||
DownButton.DeBugMode = Flag;
|
||||
}
|
||||
|
||||
function SetOnChange(Func) {
|
||||
ScrollButton.SetOnChange(Func);
|
||||
}
|
||||
|
||||
function SetStep(value) {
|
||||
Step = value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user