add the capability to create and edit memoryrecord hotkeys

This commit is contained in:
Dark Byte 2016-08-01 21:51:50 +02:00
parent 0f04fb3bcd
commit aaf4b9d9b2
5 changed files with 126 additions and 6 deletions

View File

@ -436,6 +436,54 @@ begin
result:=1;
end;
function memoryrecord_createHotkey(L: PLua_State): integer; cdecl;
var
memoryrecord: Tmemoryrecord;
hk: TMemoryRecordHotkey;
keys: TKeyCombo;
action: TMemrecHotkeyAction;
value, description: string;
i: integer;
begin
result:=0;
memoryrecord:=luaclass_getClassObject(L);
if lua_gettop(L)=4 then
begin
if (not lua_istable(L, 1)) or (not lua_isnumber(L, 2)) then exit(0);
for i:=0 to 4 do
begin
lua_pushinteger(L, i+1);
lua_gettable(L, 1);
if lua_isnil(L, -1) then //end of the list
begin
keys[i]:=0;
lua_pop(L,1);
break;
end
else
begin
keys[i]:=lua_tointeger(L,-1);
lua_pop(L,1);
end;
end;
action:=TMemrecHotkeyAction(lua_tointeger(L, 2));
value:=Lua_ToString(L, 3);
description:=Lua_ToString(L, 4);
hk:=memoryrecord.Addhotkey(keys, action, value, description);
result:=1;
luaclass_newClass(L, hk);
end;
end;
function memoryrecord_getHotkeyCount(L: PLua_State): integer; cdecl;
var
memoryrecord: Tmemoryrecord;
@ -739,6 +787,9 @@ begin
luaclass_addClassFunctionToTable(L, metatable, userdata, 'getHotkey', memoryrecord_getHotkey);
luaclass_addClassFunctionToTable(L, metatable, userdata, 'getHotkeyByID', memoryrecord_getHotkeyByID);
luaclass_addClassFunctionToTable(L, metatable, userdata, 'createHotkey', memoryrecord_createHotkey);
luaclass_addPropertyToTable(L, metatable, userdata, 'Description', memoryrecord_getDescription, memoryrecord_setDescription);
luaclass_addPropertyToTable(L, metatable, userdata, 'Address', memoryrecord_getAddress, memoryrecord_setAddress);
@ -749,7 +800,7 @@ begin
luaclass_addPropertyToTable(L, metatable, userdata, 'Active', memoryrecord_getActive, memoryrecord_setActive);
luaclass_addPropertyToTable(L, metatable, userdata, 'Selected', memoryrecord_isSelected, nil);
luaclass_addPropertyToTable(L, metatable, userdata, 'HotkeyCount', memoryrecord_getHotkeyCount, nil);
luaclass_addArrayPropertyToTable(L, metatable, userdata, 'Hotkey', memoryrecord_getHotkey, nil);
luaclass_addArrayPropertyToTable(L, metatable, userdata, 'Hotkey', memoryrecord_getHotkey);
@ -761,6 +812,7 @@ begin
recordEntries:=Trecordentries.create;
recordEntry.name:='Size';

View File

@ -33,6 +33,48 @@ begin
result:=1;
end;
function memoryrecordhotkey_getKeys(L: PLua_State): integer; cdecl;
var
memoryrecordhotkey: TMemoryRecordHotkey;
t, i: integer;
begin
memoryrecordhotkey:=luaclass_getClassObject(L);
lua_newtable(L);
result:=1;
t:=lua_gettop(L); //1
for i:=0 to 4 do
begin
if memoryrecordhotkey.keys[i]=0 then break;
lua_pushinteger(L, i+1);
lua_pushinteger(L, memoryrecordhotkey.keys[i]);
lua_settable(L, t);
end;
end;
function memoryrecordhotkey_setKeys(L: PLua_State): integer; cdecl;
var
memoryrecordhotkey: TMemoryRecordHotkey;
i: integer;
begin
result:=0;
memoryrecordhotkey:=luaclass_getClassObject(L);
if lua_istable(L,1) then
begin
i:=0;
for i:=0 to 4 do
begin
lua_pushinteger(L, i+1);
lua_gettable(L, 1);
memoryrecordhotkey.keys[i]:=lua_tointeger(L, -1);
if memoryrecordhotkey.keys[i]=0 then exit;
end;
end;
end;
function memoryrecordhotkey_getID(L: PLua_State): integer; cdecl;
var
memoryrecordhotkey: TMemoryRecordHotkey;
@ -96,6 +138,9 @@ begin
object_addMetaData(L, metatable, userdata);
luaclass_addClassFunctionToTable(L, metatable, userdata, 'doHotkey', memoryrecordhotkey_doHotkey);
luaclass_addPropertyToTable(L, metatable, userdata, 'HotkeyString', memoryrecordhotkey_getHotkeyString, nil);
luaclass_addPropertyToTable(L, metatable, userdata, 'Keys', memoryrecordhotkey_getKeys, memoryrecordhotkey_setKeys);
end;
procedure initializeMemoryRecordHotkey;

View File

@ -24,7 +24,7 @@ resourcestring
rsP = 'P->';
rsError = 'error';
type TMemrecHotkeyAction=(mrhToggleActivation, mrhToggleActivationAllowIncrease, mrhToggleActivationAllowDecrease, mrhActivate, mrhDeactivate, mrhSetValue, mrhIncreaseValue, mrhDecreaseValue);
type TMemrecHotkeyAction=(mrhToggleActivation=0, mrhToggleActivationAllowIncrease=1, mrhToggleActivationAllowDecrease=2, mrhActivate=3, mrhDeactivate=4, mrhSetValue=5, mrhIncreaseValue=6, mrhDecreaseValue=7);
type TFreezeType=(ftFrozen, ftAllowIncrease, ftAllowDecrease);
@ -156,7 +156,7 @@ type
function getByteSize: integer;
function BinaryToString(b: pbytearray; bufsize: integer): string;
function getAddressString: string;
function getuniquehotkeyid: integer;
procedure setActive(state: boolean);
procedure setAllowDecrease(state: boolean);
procedure setAllowIncrease(state: boolean);
@ -210,6 +210,8 @@ type
//showAsHex: boolean;
function getuniquehotkeyid: integer;
//free for editing by user:
function hasSelectedParent: boolean;
function hasParent: boolean;
@ -332,7 +334,7 @@ type
published
property ActivateSound: string read factivateSound write factivateSound;
property DeactivateSound: string read fdeactivateSound write fdeactivateSound;
property Description: string read fDescription;
property Description: string read fDescription write fDescription;
property Owner: TMemoryRecord read fOwner;
property ID: integer read fID;
property OnHotkey: TNotifyEvent read fOnHotkey write fOnHotkey;

View File

@ -343,3 +343,12 @@ GW_HWNDPREV = 3
GW_HWNDOWNER = 4
GW_CHILD = 5;
GW_ENABLEDPOPUP = 6;
mrhToggleActivation=0
mrhToggleActivationAllowIncrease=1
mrhToggleActivationAllowDecrease=2
mrhActivate=3
mrhDeactivate=4
mrhSetValue=5
mrhIncreaseValue=6
mrhDecreaseValue=7

View File

@ -1613,12 +1613,23 @@ methods
MemoryRecordHotkey Class: (Inheritance: object)
The memoryrecord hotkey class is mainly readonly with the exception of the event properties to be used to automatically create trainers
Use the genreric hotkey class if you wish to create your own hotkeys
Use the generic hotkey class if you wish to create your own hotkeys
properties
Owner: MemoryRecord - The memoryrecord this hotkey belongs to (ReadOnly)
Keys: Table - Table containing the keys(combination) for this hotkey
action: integer - The action that should happen when this hotkey triggers
mrhToggleActivation(0): Toggles between active/deactive
mrhToggleActivationAllowIncrease(1): Toggles between active/deactive. Allows increase when active
mrhToggleActivationAllowDecrease(2): Toggles between active/deactive. Allows decrease when active
mrhActivate(3): Sets the state to active
mrhDeactivate(4): Sets the state to deactive
mrhSetValue(5): Sets a specific value to the value properyy (see value)
mrhIncreaseValue(6): Increases the current value with the value property (see value)
mrhDecreaseValue(7): Decreases the current value with the value property (see value)
value: string - Value used depending on what kind of hotkey is used
ID: integer - Unique id of this hotkey (ReadOnly)
Description: string - The description of this hotkey (ReadOnly)
Description: string - The description of this hotkey
HotkeyString: string - The hotkey formatted as a string (ReadOnly)
ActivateSound: string - Tablefile name of a WAV file inside the table which will get played on activate events
DeactivateSound: string - Tablefile name of a .WAV file inside the table which will get played on deactivate events
@ -1698,6 +1709,7 @@ methods
getHotkey(index): Returns the hotkey from the hotkey array
getHotkeyByID(integer): Returns the hotkey with the given id
createHotkey({keys}, action, value OPTIONAL): Returns a hotkey object
global events
function onMemRecPreExecute(memoryrecord, newstate BOOLEAN):