FG Spreadshirt Swag
  1. #1

    How to do a lockable window

    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
    Code:
    <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

    Code:
    <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 ?
    Last edited by Tabulazero; May 23rd, 2019 at 22:33.

  2. #2
    wndrngdru's Avatar
    Join Date
    Jun 2015
    Location
    US, Central (UTC -6 or -5)
    Posts
    438
    Edit: Ugh. I really must stop posting when I'm half asleep.
    Last edited by wndrngdru; May 24th, 2019 at 20:42.

  3. #3
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,656
    Blog Entries
    1
    try something like:

    Code:
    		<script>
    			function onInit()
    				onLockChanged();
    				DB.addHandler(DB.getPath(getDatabaseNode(), "locked"), "onUpdate", onLockChanged);
    			end
    			function onClose()
    				DB.removeHandler(DB.getPath(getDatabaseNode(), "locked"), "onUpdate", onLockChanged);
    			end
    			function update()
    				local bReadOnly = WindowManager.getReadOnlyState(getDatabaseNode());
    				talent_header.setReadOnly(bReadOnly);
    				notes.setReadOnly(bReadOnly);
    			end
    		</script>

  4. #4
    It is not working I am afraid but I am not giving up. Could someone kindly point me as to the easiest way to specify the state of a button ? I have basically two states and I would like to come up with an OnInit function for the button script that would default to my button's first state.

    How can I do that ?

  5. #5
    And the answer is as follows

    Code:
    <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()
    				onLock(1);
    				if User.isHost() then
    					hardlocked.setVisible(false);
    					locked.setVisible(true);
    				else
    					hardlocked.setVisible(true);
    					locked.setVisible(false);
    				end
    			end
    
    			function onLock(lockedvalue)
    				if lockedvalue==0 then
    					talent_header.setReadOnly(false);
    					talent_notes.setReadOnly(false);
    				else
    					talent_header.setReadOnly(true);
    					talent_notes.setReadOnly(true);
    				end
    			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="talent_notesframe">
    				<bounds>30,70,-30,-15</bounds>
    			</frame_char>
    			<label_frametop>
    				<anchored to="talent_notesframe" />
    				<static text="DESCRIPTION" />
    			</label_frametop>
    			<stringu name="talent_notes">
    				<anchored to="talent_notesframe">
    					<top offset="30" />
    					<left offset="15" />
    					<right offset="-15" />
    					<bottom offset="-15" />
    				</anchored>
    				<multilinespacing>20</multilinespacing>
    				<nodrag />
    			</stringu>
    			<scrollbar_list>
    				<anchored to="talent_notes" />
    				<target>talent_notes</target>
    			</scrollbar_list>
    			<icon_record_locked />
    			<button_locked />
    			<button_close />
    		</sheetdata>
    </windowclass>
    Code:
    	<!-- CLOSE ICON -->
    	<template name="close_base" mergerule="replace">
    		<buttoncontrol>
    			<icon normal="button_close" pressed="button_close_down" hover="button_close_hover" />
    			<script>
    				function onButtonPress()
    					local sClass = window.getClass();
    					if sClass == "imagebackpanel" then
    						ImageManager.closePanel();
    					elseif sClass == "imagefullpanel" then
    						ImageManager.closePanel();
    					else
    						window.close();
    					end
    				end
    			</script>
    		</buttoncontrol>
    	</template>
    
    	<template name="close" mergerule="replace">
    		<close_base>
    			<anchored height="24" width="24">
    				<top />
    				<right />
    			</anchored>
    		</close_base>
    	</template>
    
    	<template name="button_close">
    		<close>
    			<anchored>
    				<top offset="10" />
    				<right offset="-10" />
    			</anchored>
    		</close>
    	</template>
    
    	<!-- LOCKED ICON -->
    	<template name="icon_record_locked">
    		<genericcontrol name="hardlocked">
    			<anchored to="rightanchor" width="20" height="20">
    				<top anchor="top" relation="relative" offset="40" />
    				<right anchor="left" relation="relative" offset="-12" />
    			</anchored>
    			<icon>record_readonly</icon>
    			<tooltip textres="tooltip_readonly" />
    		</genericcontrol>
    	</template>
    
    	<!-- BUTTON LOCKED -->
    	<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>
    				function onInit()
    					setValue(1);
    				end
    
    				function onButtonPress()
    					window.onLock(getValue());
    				end
    			</script>
    		</buttoncontrol>
    	</template>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in