DOF/sqr/User/Controller/Controller.nut

91 lines
2.4 KiB
Plaintext
Raw Normal View History

2024-12-25 11:35:29 +08:00
/*
文件名:Controller.nut
路径:User/Controller/Controller.nut
创建日期:2024-12-21 07:31
文件用途:控制器类
*/
class _GameController_ extends _Input_ {
//最新键码输入
2025-01-11 23:58:10 +08:00
2024-12-25 11:35:29 +08:00
KeyCode = null;
GameKeyCode = null;
GameKeyCodeCallback = null;
constructor() {
base.constructor();
GameKeyCodeCallback = {};
//建立键码表 按下flag全部为false
this.KeyCode = {};
foreach(value in getconsttable().KeyCode) {
this.KeyCode.rawset(value, false);
}
//建立游戏键码表
this.GameKeyCode = {};
foreach(Key, Value in getconsttable().CONTROLLER) {
this.GameKeyCode.rawset(Key, Value);
}
2025-02-20 13:53:36 +08:00
//注册Esc按钮对所有游戏窗口的操作
RegisterGameKeyCode(CONTROLLER.OPTION_HOTKEY_MENU_SYSTEM__CLOSE_ALL_WINDOW, function(Flag) {
//按下的时候
if (Flag == 1) {
//遍历窗口队列 如果可见则调用Show
for (local i = 0; i< _SYS_WINDOW_LIST_.len(); i++) {
local Window = _SYS_WINDOW_LIST_[i];
if (typeof Window == "Game_Window") {
Window.OnEsc();
}
}
}
});
2024-12-25 11:35:29 +08:00
}
//系统对游戏的输入
function SystemInput(Code, Type) {
SetKeyCode(Code, Type);
}
//设定键码状态
function SetKeyCode(Code, Status) {
this.KeyCode[Code] = Status;
//只遍历有回调的键码
2025-01-11 23:58:10 +08:00
foreach(RCode, Callback in GameKeyCodeCallback) {
if (RCode == Code) {
Callback(Status);
2024-12-25 11:35:29 +08:00
}
}
}
//获取键码状态
function GetKeyCode(Code) {
return this.KeyCode[Code];
}
//获取游戏键码状态
function GetGameKeyCode(Code) {
if (!(GameKeyCode.rawin(Code))) return false;
return GetKeyCode(GameKeyCode[Code]);
}
//注册游戏键码回调函数
function RegisterGameKeyCode(Code, Callback) {
GameKeyCodeCallback[Code] <- Callback;
}
//Proc逻辑
function Proc(Dt, GameLister) {
// //只遍历有回调的键码
// foreach(Code, Callback in GameKeyCodeCallback) {
// //是否按下传递不同指令
// if (GetGameKeyCode(Code)) {
// Callback(true);
// } else {
// Callback(false);
// }
// }
}
}