FG Spreadshirt Swag
Page 1 of 2 12 Last
  1. #1

    Window Controls with sub-elements.

    Is there a way to access sub-elements within a window control?

    In the toolbar template, it utilizes the toolbar_30 template which is a frame. Nested within this frame are several buttons (paint/unmask/erase) whose controls I want to access. Frames as far as the ruleset documentation states, isn't a unique kind of window control, therefore it's working off the base WindowControl. Unlike window I can't Window.getControls() to get at their sub-elements, unless I'm missing something here.

    The fact that CoreRPG is stuffing buttons inside of a frame definition tells me that it's a container of some kind, and a way to get at them, but I can't find any concrete definition to proceed here.


    For reference:
    Code:
    <toolbar_30 name="toolbar_draw">
        <anchored to="toolbar_anchor">
            <top />
            <left anchor="right" relation="relative" />
        </anchored>
        <button name="unmask_button">
            <id>unmask</id>
            <icon>tool_mask_30</icon>
            <tooltipres>image_tooltip_toolbarmask</tooltipres>
        </button>
    
    ...
    
    </toolbar_30>
    Code:
    <framedef name="toolbar_30">
    	<bitmap file="graphics/toolbar/toolbar_30.png"/>
    	<topleft rect="0,0,4,3" />
    	<top rect="4,0,32,3" />
    	<topright rect="62,0,4,3" />
    	<left rect="0,3,4,28" />
    	<middle rect="4,3,32,28" />
    	<right rect="62,3,4,28" />
    	<bottomleft rect="0,31,4,3" />
    	<bottom rect="4,31,32,3" />
    	<bottomright rect="62,31,4,3" />
    </framedef>

  2. #2
    I'm not an expert, but one thing you might be missing is that when you insert your <toolbar_30 /> control into your windowclass, you aren't referencing the <framedef> defined in on line 51 of template_toolbar.xml of the Core RPG ruleset, instead you are referencing a template with the same name defined on line 78 of the same file.

    Code:
    	<template name="toolbar_30">
    		<genericcontrol>
    			<parameters>
    				<horzmargin>2</horzmargin>
    				<vertmargin>2</vertmargin>
    				<buttonsize>30</buttonsize>
    			</parameters>
    			<frame name="toolbar_30" />
    			<button mergerule="resetandadd" />
    			<script file="common/scripts/toolbar.lua" />
    		</genericcontrol>
    	</template>
    Notice how the template include a <frame> tag. This is what invokes the framedef you cited. As I understand it, a framedef isn't a control, just a graphic that a control can use.

    As to your original question, are you trying to get a script reference to a control contained in a windowinstance? This would basically be a property of the windowinstance object, for example window.toolbar_draw.

    EDIT: As for the buttons beneath your toolbar_draw control, what you're seeing in the control definition isn't actually a sub control, it's just a set of properties of the control itself. You can access them as properties of the control, although the properties themselves are stored as tables, even if there's only one tag. For example:

    Code:
    if window.toolbar_draw.button and window.toolbar_draw.button[1] then
    	local button1 = window.toolbar_draw.button[1];
            --doStuff with button1.
    end
    Usually you'd probably want to handle this with some kind of loop, but I'm not sure if this is actually what you want. Actually these properties are processed in the onInit function of common/scripts/toolbar.lua.
    Code:
    	if button and type(button[1]) == "table" then
    		for k, v in ipairs(button) do
    			if v.id and v.icon then
    				local sID = v.id[1];
    				local sIcon = v.icon[1];
    
    				local sTooltip = "";
    				if v.tooltipres then
    					sTooltip = Interface.getString(v.tooltipres[1]);
    				elseif v.tooltip then
    					sTooltip = v.tooltip[1];
    				end
    
    				addButton(sID, sIcon, sTooltip);
    			end
    		end
    	end
    addButton in turn goes and actually creates the button controls you want to access via script
    Code:
    function addButton(sID, sIcon, sTooltip)
    	local bToggle = false;
    	if toggle then
    		bToggle = true;
    	end
    	
    	local button = window.createControl("toolbar_button", "");
    	if button then
    		local x = nButtonHorzMargin + (nButtons * (nButtonSize + nButtonHorzMargin));
    		nButtons = nButtons + 1;
    
    		local nBarWidth = x + nButtonSize + nButtonHorzMargin;
    		setAnchoredWidth(nBarWidth);
    		setAnchoredHeight(nButtonSize + (2 * nButtonVertMargin));
    		local w,h = getSize();
    
    		button.setAnchor("left", getName(), "left", "absolute", x);
    		button.setAnchor("top", getName(), "top", "absolute", nButtonVertMargin);
    		button.setAnchoredWidth(nButtonSize);
    		button.setAnchoredHeight(nButtonSize);
    
    		button.configure(self, sID, sIcon, sTooltip, bToggle);
    		
    		aButtons[sID] = button;
    
    		if isVisible() then
    			button.setVisible(true);
    		end
    	end
    end
    From a cursory reading of this script I'm not sure how you'd access these dynamically created button controls at runtime, but you can try toolbar_draw["<buttonId>"], where buttonId is a value defined in the <id> tag beneath a <button> tag, for example toolbar_draw["unmask"], or maybe toolbar_draw.unmask.

    Sorry I can't be more specific but maybe this will get you on the right track.
    Last edited by ElementalAjah; December 12th, 2017 at 02:22. Reason: Further explanation of accessing buttons in a toolbar

  3. #3
    Quote Originally Posted by ElementalAjah View Post
    As to your original question, are you trying to get a script reference to a control contained in a windowinstance? This would basically be a property of the windowinstance object, for example window.toolbar_draw.
    It would technically be window.toolbar_30.unmask_button which isn't pulling anything. I then tried to work through Window.getControls() and walking towards the ButtonControl but the inability to walk the elements inside the WindowControl of the Frame stopped that.

  4. #4
    Sorry, I did a ninja edit with more information above at about the same time you posted your response. Let me know if there's anything useful in there.

    I don't think window.toolbar_30 is going to be correct though. toolbar_30 is the name of the template your control references, but not the control instance. I do mention trying window.toolbar_draw.unmask or window.toolbar_draw["unmask"] in my edited example above, give that a try.
    Last edited by ElementalAjah; December 12th, 2017 at 02:23.

  5. #5
    That's a big edit there.

    The play off the window.toolbar_30's table entries is interesting, reminds me of java reflection hacks.

    The addButton I believe to be a dynamic option as the buttons I reference are actually built into the window definition (campaign/record_image.xml to be exact).

  6. #6
    type(window.toobar_draw["unmask_button"]) is nil which I kinda expected from a WindowControl which toolbar_draw is. It's a container with no access to its elements which is a kinda weird framework design.

  7. #7
    Okay, I just noticed something strange. The definition of toolbar_draw that I'm seeing in my version of the coreRPG ruleset looks different from what you posted above — I'd been assuming they were the same and was working off of what I had on my own machine, which may explain why it sounds like we're talking about two different things.. Mine looks like this:

    Code:
    			<toolbar_30 name="toolbar_draw">
    				<anchored to="toolbar_anchor">
    					<top />
    					<left anchor="right" relation="relative" />
    				</anchored>
    				<button>
    					<id>unmask</id>
    					<icon>tool_mask_30</icon>
    					<tooltipres>image_tooltip_toolbarmask</tooltipres>
    				</button>
    				<button>
    					<id>paint</id>
    					<icon>tool_paint_30</icon>
    					<tooltipres>image_tooltip_toolbardraw</tooltipres>
    				</button>
    				<button>
    					<id>erase</id>
    					<icon>tool_erase_30</icon>
    					<tooltipres>image_tooltip_toolbarerase</tooltipres>
    				</button>
    				[...a few more tags]
    			</toolbar_30>
    The buttons in my version don't look like full controls, compared to yours which has a "name" property. Also both of these are defined with a <button> tag, whereas a real button control is defined with <buttoncontrol>.
    Last edited by ElementalAjah; December 12th, 2017 at 02:53.

  8. #8
    It's a container with no access to its elements
    This is a good point. toolbar_draw is a control so shouldn't be able to contain other controls. I guess they're getting created somewhere else, probably the same window that contains toolbar_draw. If you're iterating window.getControls() and not seeing them show up though I'm not sure how to access them.

  9. #9
    Quote Originally Posted by ElementalAjah View Post
    The buttons in my version don't look like full controls, compared to yours which has a "name" property. Also both of these are defined with a <button> tag, whereas a real button control is defined with <buttoncontrol>.
    I added the name in a custom extension to override it so I can access it. It's a moot point if I can't even see or reach the element to manipulate it.

  10. #10
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,413
    Do a find in files in CoreRPG for toolbar_draw - you'll see the toolbar can be reached with window.toolbar.subwindow.toolbar_draw

    Now that you have button names in your extension, try window.toolbar.subwindow.toolbar_draw.unmask_butto n
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

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
  •  
5E Character Create Playlist

Log in

Log in