DOF/sqr/User/UI/Widget/IMouse.nut

141 lines
3.4 KiB
Plaintext

/*
文件名:IMouse.nut
路径:User/UI/Widget/IMouse.nut
创建日期:2024-12-18 14:03
文件用途:
*/
class _IMouse_ extends _Yosin_Cursor {
NormalC = null;
//普通状态0 //动态状态1
State = 0;
//当前帧数编号
Idx = 0;
//动态帧 当前帧数
ActiveCurrentFrame = 0;
//动态帧 总帧数
ActiveFrameCount = 0;
//动态帧 Timer
ActiveFrameTimer = 0;
//拖动的对象
DragObj = null;
//挂载的精灵
AttachObjList = null;
constructor() {
NormalC = [];
AttachObjList = {};
base.constructor();
getroottable().IMouse <- this;
//关闭系统鼠标
Sq_ShowCursor(false);
//调用父类初始化 将自己添加为UI层子对象
Init();
//初始化所有普通图标
InitSprite();
//更换为0号指针
Change(0);
//注册Proc
_Game_Logic_Func_._IMouse_Proc <- Proc.bindenv(this);
}
//初始化普通鼠标指针
function InitSprite() {
for (local i = 0; i< 254; i++) {
local Sp = CL_SpriteFrameObject("sprite/interface/newstyle/windows/cursor.img", i);
NormalC.push(Sp);
}
}
//更换普通鼠标指针
function Change(Idx) {
State = 0;
this.Idx = Idx;
local Sp = NormalC[Idx];
base.Change(Sp);
}
//更换动态鼠标指针
function ChangeActive(Idx, Count) {
State = 1;
this.Idx = Idx;
this.ActiveFrameCount = Count;
this.ActiveCurrentFrame = 0;
}
//挂载一个对象位于鼠标下
function AttachObjectBottom(KeyName, Obj) {
AttachObjList.rawset(KeyName, {
Object = Obj,
ZOrder = Obj.GetZOrder
});
Obj.SetPosition(-14, -14);
Obj.SetZOrder(-1);
Addchild(Obj);
}
//移除一个挂载的对象
function RemoveObject(KeyName) {
if (AttachObjList.rawin(KeyName)) {
local Obj = AttachObjList[KeyName].Object;
Obj.SetZOrder(AttachObjList[KeyName].ZOrder);
Removechild(Obj);
AttachObjList.rawdelete(KeyName);
}
}
//添加拖动道具
function AddDragObject(Obj) {
DragObj = Obj;
//挂载图标到鼠标下
AttachObjectBottom("Drag", DragObj.ItemIcon);
}
//移除拖动道具
function RemoveDragObject() {
if (DragObj) {
RemoveObject("Drag");
local RetObj = DragObj;
DragObj = null;
return RetObj;
}
}
function OnMouseProc(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
}
//按下
function OnMouseLbDown(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
//普通状态的点击效果
if (Idx == 0) {
Change(1);
}
}
//抬起
function OnMouseLbUp(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
//普通状态的点击效果
if (Idx == 1) {
Change(0);
}
}
function Proc(Dt, Listener) {
if (State == 1) {
ActiveFrameTimer += Dt;
if (ActiveFrameTimer >= 160) {
ActiveFrameTimer = 0;
ActiveCurrentFrame += 1;
if (ActiveCurrentFrame >= ActiveFrameCount) ActiveCurrentFrame = 0;
local Sp = NormalC[Idx + ActiveCurrentFrame];
base.Change(Sp);
}
}
}
}