Tabulazero
May 23rd, 2019, 22:28
Hi there,
I am really struggling to come up with a simple lockable window class. I have tried to look at the scripts running the items but I struggle to comprehend them. My window is very simple and consists of a tittle field called talent_header and a notes field called notes. Any help would be appreciated.
The window class
<windowclass name="talent_window" >
<frame>statbox</frame>
<placement>
<size width="300" height="400" />
</placement>
<sizelimits>
<minimum width="300" height="400" />
<dynamic />
</sizelimits>
<nodelete />
<softclose />
<playercontrol />
<script>
function onInit()
update();
end
function update()
local nodeRecord = getDatabaseNode();
local bReadOnly = WindowManager.getReadOnlyState(nodeRecord);
talent_header.setReadOnly(bReadOnly);
notes.setReadOnly(bReadOnly);
end
</script>
<sheetdata>
<genericcontrol name="leftanchor">
<anchored height="0" width="0">
<top offset="0"/>
<left offset="0"/>
</anchored>
</genericcontrol>
<genericcontrol name="rightanchor">
<anchored height="0" width="0">
<top offset="0"/>
<right offset="0"/>
</anchored>
</genericcontrol>
<string_labeled name="talent_header">
<anchored>
<top parent="leftanchor" anchor="top" relation="relative" offset="15" />
<left parent="leftanchor" anchor="left" relation="relative" offset="35" />
<right offset="-45"/>
<size height="30"/>
</anchored>
<lineoffset>10</lineoffset>
<labelres>talent</labelres>
</string_labeled>
<frame_char name="notesframe">
<bounds>30,70,-30,-15</bounds>
</frame_char>
<label_frametop>
<anchored to="notesframe" />
<static text="DESCRIPTION" />
</label_frametop>
<stringu name="notes">
<anchored to="notesframe">
<top offset="30" />
<left offset="15" />
<right offset="-15" />
<bottom offset="-15" />
</anchored>
<multilinespacing>20</multilinespacing>
<nodrag />
</stringu>
<scrollbar_list>
<anchored to="notes" />
<target>notes</target>
</scrollbar_list>
<button_locked />
<close_talent />
</sheetdata>
</windowclass>
and the button script I am using
<template name="button_locked">
<buttoncontrol name="locked">
<anchored to="rightanchor" width="20" height="20">
<top anchor="top" relation="relative" offset="40" />
<right anchor="left" relation="relative" offset="-12" />
</anchored>
<state icon="padlock_open" tooltipres="tooltip_unlock" />
<state icon="padlock_closed" tooltipres="tooltip_lock" />
<script>
local bUpdating = false;
local nodeSrc = nil;
local nDefault = 0;
function onInit()
nodeSrc = window.getDatabaseNode();
if nodeSrc and nodeSrc.getModule() then
nDefault = 1;
end
if not nodeSrc or nodeSrc.isReadOnly() then
nodeSrc = nil;
setVisible(false);
else
onUpdate();
DB.addHandler(DB.getPath(nodeSrc, "locked"), "onUpdate", onUpdate);
end
notify();
end
function onClose()
if nodeSrc then
DB.removeHandler(DB.getPath(nodeSrc, "locked"), "onUpdate", onUpdate);
end
end
function onUpdate()
if bUpdating then
return;
end
bUpdating = true;
local nValue = DB.getValue(nodeSrc, "locked", nDefault);
if nValue == 0 then
setValue(0);
else
setValue(1);
end
bUpdating = false;
end
function onValueChanged()
if not bUpdating then
bUpdating = true;
if nodeSrc then
DB.setValue(nodeSrc, "locked", "number", getValue());
end
bUpdating = false;
end
notify();
end
function notify()
if window.parentcontrol and window.parentcontrol.window.onLockChanged then
window.parentcontrol.window.onLockChanged();
elseif window.onLockChanged then
window.onLockChanged();
end
end
</script>
</buttoncontrol>
</template>
What am I doing wrong ?
I am really struggling to come up with a simple lockable window class. I have tried to look at the scripts running the items but I struggle to comprehend them. My window is very simple and consists of a tittle field called talent_header and a notes field called notes. Any help would be appreciated.
The window class
<windowclass name="talent_window" >
<frame>statbox</frame>
<placement>
<size width="300" height="400" />
</placement>
<sizelimits>
<minimum width="300" height="400" />
<dynamic />
</sizelimits>
<nodelete />
<softclose />
<playercontrol />
<script>
function onInit()
update();
end
function update()
local nodeRecord = getDatabaseNode();
local bReadOnly = WindowManager.getReadOnlyState(nodeRecord);
talent_header.setReadOnly(bReadOnly);
notes.setReadOnly(bReadOnly);
end
</script>
<sheetdata>
<genericcontrol name="leftanchor">
<anchored height="0" width="0">
<top offset="0"/>
<left offset="0"/>
</anchored>
</genericcontrol>
<genericcontrol name="rightanchor">
<anchored height="0" width="0">
<top offset="0"/>
<right offset="0"/>
</anchored>
</genericcontrol>
<string_labeled name="talent_header">
<anchored>
<top parent="leftanchor" anchor="top" relation="relative" offset="15" />
<left parent="leftanchor" anchor="left" relation="relative" offset="35" />
<right offset="-45"/>
<size height="30"/>
</anchored>
<lineoffset>10</lineoffset>
<labelres>talent</labelres>
</string_labeled>
<frame_char name="notesframe">
<bounds>30,70,-30,-15</bounds>
</frame_char>
<label_frametop>
<anchored to="notesframe" />
<static text="DESCRIPTION" />
</label_frametop>
<stringu name="notes">
<anchored to="notesframe">
<top offset="30" />
<left offset="15" />
<right offset="-15" />
<bottom offset="-15" />
</anchored>
<multilinespacing>20</multilinespacing>
<nodrag />
</stringu>
<scrollbar_list>
<anchored to="notes" />
<target>notes</target>
</scrollbar_list>
<button_locked />
<close_talent />
</sheetdata>
</windowclass>
and the button script I am using
<template name="button_locked">
<buttoncontrol name="locked">
<anchored to="rightanchor" width="20" height="20">
<top anchor="top" relation="relative" offset="40" />
<right anchor="left" relation="relative" offset="-12" />
</anchored>
<state icon="padlock_open" tooltipres="tooltip_unlock" />
<state icon="padlock_closed" tooltipres="tooltip_lock" />
<script>
local bUpdating = false;
local nodeSrc = nil;
local nDefault = 0;
function onInit()
nodeSrc = window.getDatabaseNode();
if nodeSrc and nodeSrc.getModule() then
nDefault = 1;
end
if not nodeSrc or nodeSrc.isReadOnly() then
nodeSrc = nil;
setVisible(false);
else
onUpdate();
DB.addHandler(DB.getPath(nodeSrc, "locked"), "onUpdate", onUpdate);
end
notify();
end
function onClose()
if nodeSrc then
DB.removeHandler(DB.getPath(nodeSrc, "locked"), "onUpdate", onUpdate);
end
end
function onUpdate()
if bUpdating then
return;
end
bUpdating = true;
local nValue = DB.getValue(nodeSrc, "locked", nDefault);
if nValue == 0 then
setValue(0);
else
setValue(1);
end
bUpdating = false;
end
function onValueChanged()
if not bUpdating then
bUpdating = true;
if nodeSrc then
DB.setValue(nodeSrc, "locked", "number", getValue());
end
bUpdating = false;
end
notify();
end
function notify()
if window.parentcontrol and window.parentcontrol.window.onLockChanged then
window.parentcontrol.window.onLockChanged();
elseif window.onLockChanged then
window.onLockChanged();
end
end
</script>
</buttoncontrol>
</template>
What am I doing wrong ?