197 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			197 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:234_HUD_FuncInter.nut
 | |
| 路径:User/UI/Window/234_HUD_FuncInter.nut
 | |
| 创建日期:2025-01-29	13:35
 | |
| 文件用途:NPC 与 玩家 功能交互
 | |
| */
 | |
| _NameSpace_FunctionInteractive <- {};
 | |
| class _NameSpace_FunctionInteractive._InteractiveButton extends Yosin_CommonUi {
 | |
|     //按钮状态
 | |
|     State = 0;
 | |
|     Sprite = null;
 | |
|     SpriteState = -1;
 | |
| 
 | |
|     Info = null;
 | |
|     FramePath = "sprite/interface2/popup_menu/popup_back.img";
 | |
|     FrameList = null;
 | |
|     RoleTextActor = null;
 | |
| 
 | |
|     Role = null;
 | |
|     RoleValue = null;
 | |
| 
 | |
| 
 | |
|     constructor(RoleName, RoleValue) {
 | |
|         this.Role = RoleName;
 | |
|         this.RoleValue = RoleValue;
 | |
|         base.constructor(0, 0, 100, 21);
 | |
|         if (AssetManager.EtcConfig.NpcRole.rawin(RoleName)) {
 | |
|             Info = AssetManager.EtcConfig.NpcRole[RoleName];
 | |
|             Init();
 | |
|         } else {
 | |
|             error("NPC 功能交互 功能错误");
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function Init() {
 | |
|         FrameList = [];
 | |
|         //基础态
 | |
|         FrameList.push(CL_SpriteFrameObject(this.FramePath, 0));
 | |
|         //悬停态
 | |
|         FrameList.push(CL_SpriteFrameObject(this.FramePath, Info.imgidx * 2 + 1));
 | |
|         //按下态
 | |
|         FrameList.push(CL_SpriteFrameObject(this.FramePath, Info.imgidx * 2 + 2));
 | |
| 
 | |
|         Sprite = CL_SpriteObject();
 | |
|         Addchild(Sprite);
 | |
| 
 | |
|         //绘制功能图标
 | |
|         local RoleIconActor = CL_SpriteObject("sprite/interface2/popup_menu/popup_icon_" + Info.iconpath + ".img", Info.iconidx);
 | |
|         RoleIconActor.SetZOrder(1);
 | |
|         Addchild(RoleIconActor);
 | |
| 
 | |
|         //功能文本
 | |
|         RoleTextActor = FontAssetManager.GenerateNormal(Info.name, true, {
 | |
|             color = Info.namecolor
 | |
|         });
 | |
|         RoleTextActor.SetPosition(18 + (82 - RoleTextActor.GetSize().w) / 2, 1);
 | |
|         RoleTextActor.SetZOrder(1);
 | |
|         Addchild(RoleTextActor);
 | |
| 
 | |
|         OnClick = function(Btn) {
 | |
|             _NameSpace_FunctionInteractive[Role](RoleValue);
 | |
|         };
 | |
|     }
 | |
| 
 | |
|     function ChangeFrame() {
 | |
|         //状态更改 刷新精灵帧
 | |
|         if (State != SpriteState) {
 | |
|             //按下时 文本下移
 | |
|             if (State == 2) {
 | |
|                 RoleTextActor.MoveBy(0, 1);
 | |
|             } else if (SpriteState == 2) {
 | |
|                 RoleTextActor.MoveBy(0, -1);
 | |
|             }
 | |
|             SpriteState = State;
 | |
|             Sprite.SetFrame(FrameList[SpriteState]);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     function Proc(Dt) {
 | |
|         //不可用
 | |
|         if (State == 3) {
 | |
| 
 | |
|         } else {
 | |
|             //按下
 | |
|             if (isLBDown) {
 | |
|                 State = 2;
 | |
|             }
 | |
|             //悬停
 | |
|             else if (isInRect) {
 | |
|                 State = 1;
 | |
|             }
 | |
|             //普通
 | |
|             else {
 | |
|                 State = 0;
 | |
|             }
 | |
|         }
 | |
|         ChangeFrame();
 | |
|     }
 | |
| }
 | |
| //窗口主类
 | |
| class _NameSpace_FunctionInteractive._FunctionInteractive extends Yosin_Window {
 | |
| 
 | |
|     NpcInfo = null;
 | |
| 
 | |
|     //顶层窗口
 | |
|     IsTop = true;
 | |
| 
 | |
|     //生成器  如果这个窗口开着就刷新一下位置  如果没有就生成一个
 | |
|     function Generator(Id, Xpos, Ypos) {
 | |
|         local RealId = "NPC交互窗口" + Id;
 | |
|         foreach(Index, WindowObj in _SYS_WINDOW_LIST_) {
 | |
|             if (WindowObj.ObjectId == RealId) {
 | |
|                 WindowObj.SetPosition(Xpos, Ypos);
 | |
|                 WindowObj.ResetFocus();
 | |
|                 return WindowObj;
 | |
|             }
 | |
|         }
 | |
|         return _NameSpace_FunctionInteractive._FunctionInteractive(Id, Xpos, Ypos);
 | |
|     }
 | |
| 
 | |
|     //构造函数
 | |
|     constructor(Id, Xpos, Ypos) {
 | |
|         //获取npc数据
 | |
|         NpcInfo = AssetManager.GetNpc(Id);
 | |
|         //获取npc功能数量
 | |
|         local NpcFuncCount = NpcInfo.role.len();
 | |
| 
 | |
|         // 默认构造数据 NpcFuncCount 要+1 因为还有他自己的头像
 | |
|         base.constructor("NPC交互窗口" + Id, Xpos, Ypos, 100, (NpcFuncCount + 1) * 21, 0);
 | |
|         ResetFocus();
 | |
|         // OpenDeBug();
 | |
| 
 | |
|         // 初始化窗口
 | |
|         InitWindow();
 | |
|     }
 | |
| 
 | |
|     // 初始化窗口
 | |
|     function InitWindow() {
 | |
|         local Header = CL_SpriteObject("sprite/interface2/popup_menu/popup_back.img", 0);
 | |
|         Addchild(Header);
 | |
| 
 | |
|         //NPC头像
 | |
|         local NpcFace = CL_SpriteObject(NpcInfo["popup_face"].img, NpcInfo["popup_face"].idx);
 | |
|         Addchild(NpcFace);
 | |
| 
 | |
|         //NPC名字
 | |
|         local NpcNameTextActor = FontAssetManager.GenerateNormal(NpcInfo.name, true, {
 | |
|             color = sq_RGBA(231, 199, 156, 250)
 | |
|         });
 | |
|         NpcNameTextActor.SetPosition(18 + (82 - NpcNameTextActor.GetSize().w) / 2, 1);
 | |
|         NpcNameTextActor.SetZOrder(1);
 | |
|         Addchild(NpcNameTextActor);
 | |
| 
 | |
| 
 | |
|         local pos = 1;
 | |
|         foreach(Role, Value in NpcInfo.role) {
 | |
|             local Buffer = _NameSpace_FunctionInteractive._InteractiveButton(Role, Value);
 | |
|             Buffer.SetPosition(0, pos * 21)
 | |
|             AddUIChild(Buffer);
 | |
|             pos++;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //override
 | |
|     //鼠标左键单击回调
 | |
|     function OnMouseLbClick(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
 | |
|         //点到自己 先执行子类Button的事件  在关闭自己
 | |
|         base.OnMouseLbClick(MousePos_X, MousePos_Y, WindowInteractiveFlag);
 | |
|         CloseWindow();
 | |
|     }
 | |
| 
 | |
|     //override
 | |
|     //鼠标左键按下回调
 | |
|     function OnMouseLbDown(MousePos_X, MousePos_Y, WindowInteractiveFlag) {
 | |
|         if (!WindowInteractiveFlag) base.OnMouseLbDown(MousePos_X, MousePos_Y, WindowInteractiveFlag);
 | |
|         else CloseWindow();
 | |
|         //没点到自己直接关闭
 | |
|         if (!Math.IsIntersectRect(MousePos_X, MousePos_Y, 1, 1, X, Y, Width, Height)) CloseWindow();
 | |
|     }
 | |
| }
 | |
| 
 | |
| //NPC商店回调
 | |
| _NameSpace_FunctionInteractive["item shop"] <- function(Value) {
 | |
|     //判断是否生成过
 | |
|     foreach(Index, WindowObj in _SYS_WINDOW_LIST_) {
 | |
|         if (WindowObj.ObjectId == "NPC商店") {
 | |
|             WindowObj.ResetFocus();
 | |
|             ClientCharacterInventory.ResetFocus();
 | |
|             return;
 | |
|         }
 | |
|     }
 | |
|     //生成窗口
 | |
|     local WindowObj = UISpace_NpcShop.Shop("NPC商店", 130, 63, 366, 486, 20);
 | |
|     WindowObj.Init(Value);
 | |
|     WindowObj.ResetFocus();
 | |
|     ClientCharacterInventory.ResetFocus();
 | |
| } |