PDA

View Full Version : Windows and SubWindows



Czarisyn
July 26th, 2010, 21:22
Am I understanding this right...

<subwindow> is accessible as a variable named subwindow in the script?

is it an array (table) or is it a single entry?

example

main window = main
sub windows = sub

main.sub[1].setVisible(true)

or

window.sub[1].setVisible(true)

or am I not even close?

Foen
July 26th, 2010, 21:29
This is a torturous subject, partially explored in this old thread (https://www.fantasygrounds.com/forums/showthread.php?t=7562).

Stuart

Czarisyn
July 26th, 2010, 21:42
This is a torturous subject, partially explored in this old thread (https://www.fantasygrounds.com/forums/showthread.php?t=7562).

Stuart

Thanks for the reference.

If I was smart, for my first time programming a ruleset, I would just use what's available in the d20 ruleset. But nooooooo, I just have to be difficult. :pirate:

Czarisyn
July 27th, 2010, 21:57
okay so if subwindow is the reference of the <subwindow> tag,
does the window variable also count as a table?

I ask this because I've been trying to decipher the template_tabcontrol.lua to figure out a way to create my own interface to go to another page of the sheet. In that script, both window and subwindow are tables (or arrays).

Am I on the right track at least?

Czarisyn
July 27th, 2010, 23:26
Also, I've only gotten the <active /> subwindow to show if the subwindows are defined in the <sheetdata>

The examples from that thread does not reflect that, so am I doing it wrong on that part?

Moon Wizard
July 28th, 2010, 00:43
The subwindow and window references are actually objects. In LUA, all objects are essentially tables of methods and variables. (Technically, they are userdata variables with metadata tables, but you don't need that level of detail to use them.)

By default, subwindows are invisible by default. The <activate /> tag makes the control visible instead.

Cheers,
JPG

Czarisyn
July 28th, 2010, 01:03
for the sake of my confusion, here is basically what I got so far.
two things I am needing.

1) Does this remotely look like its on track?
2) What would the scripted commands be to have a genericcontrol (when pressed) make the other frame (combat) visible?

charsheet.xml


<includefile source="charsheet_main.xml" />
<includefile source="charsheet_combat.xml" />
<includefile source="charsheet_toplevel.xml" />


charsheet_main.xml


<windowclass name="charsheet_main">
<sheetdata>
main stuff
</sheetdata>

<script>
local parent = nil;

function registerParent(win)
parent = win;
end
</script>

</windowclass>


charsheet_combat.xml


<windowclass name="charsheet_combat">
<sheetdata>
combat stuff
</sheetdata>

<script>
local parent = nil;

function registerParent(win)
parent = win;
end
</script>

</windowclass>


charsheet_toplevel.xml


<windowclass name="charsheet">
<sheetdata>
<subwindow name="main">
<bounds>0,0,-1,-1</bounds>
<class>charsheet_main</class>
<script>
function onInstanceCreated()
subwindow.registerParent(window);
end
</script>
<activate />
</subwindow>

<subwindow name="combat">
<bounds>0,0,-1,-1</bounds>
<class>charsheet_combat</class>
<script>
function onInstanceCreated()
subwindow.registerParent(window);
end
</script>
</subwindow>
</sheetdata>
</windowclass>

Moon Wizard
July 28th, 2010, 02:14
As you were working originally, I would use the tabcontrol template as the basis for what you are trying to do.

Essentially, you need to define your genericcontrol in your "charsheet" windowclass. Then, capture the onClickDown events to the generic control to call setVisible on/off for the "main" and "combat" controls.

Cheers,
JPG

Czarisyn
July 28th, 2010, 02:20
As you were working originally, I would use the tabcontrol template as the basis for what you are trying to do.

Essentially, you need to define your genericcontrol in your "charsheet" windowclass. Then, capture the onClickDown events to the generic control to call setVisible on/off for the "main" and "combat" controls.

Cheers,
JPG

so that would be (assuming that main is the one loaded), to get to combat would be



function onClickDown(button,x,y)
window.subwindow[2].setVisible(true);

end


right?

Moon Wizard
July 28th, 2010, 20:59
It would be window.main.setVisible(true) or window.combat.setVisible(true), depending on which one you want to make visible. Also, you will need to set the visibility of any other subwindows to false in order to avoid any overlap conflicts.

JPG

Czarisyn
July 28th, 2010, 21:40
It would be window.main.setVisible(true) or window.combat.setVisible(true), depending on which one you want to make visible. Also, you will need to set the visibility of any other subwindows to false in order to avoid any overlap conflicts.

JPG



function onClickDown(button,x,y)
window.main.setVisible(false);
window.combat.setVisible(true);
end


when I click, it comes back [string "charsheet_main:<unnamed>"]:1: attempt to index field 'main' (a nil value)

Moon Wizard
July 28th, 2010, 22:31
It looks like the control you are trying to click is inside the charsheet_main class, not the charsheet class.

If your control is in the charsheet_main class, it's a bit trickier. I'm not as familiar with this interaction as some people.

But based on your scripts, you can try:
window.parent.main.setVisible(true);
or
window.subwindow.window.main.setVisible(true);

The first "window" gives you the windowinstance of "charsheet_main" containing the control you are clicking. The "subwindow" gives you the subwindow container control holding the windowinstance. The second "window" gives you the windowinstance of "charsheet" containing the subwindow control.

Cheers,
JPG

Czarisyn
July 28th, 2010, 22:55
Would it be better if I set the bounds of the subwindows to not fill the entire window and create the controls on the top level?

Czarisyn
July 29th, 2010, 01:12
finally, some progress, the frame actually switches when I press the generic control now.

I'm assuming why I can't press the other one is because of the bounds of the subwindow basically putting an invisible layer over the top, blocking the mouse click. Right?

I'm also getting a new error, [string "charsheet:combat"]:1 attempt to call field 'registerParent' (a nil value)

I'm guessing that its because, even though the sheet opened it, there are no database connections between the two.

Moon Wizard
July 29th, 2010, 01:31
Yes, in v2.6.5, the invisible controls will intercept mouse clicks, including subwindow controls. This will change in 2.7.

The script error means that registerParent is not defined for the object you are calling it on. subwindow is only a valid object within scripts of the charsheet_main and charsheet_combat windowclasses, not at the subwindow control level. You should just skip the parent registration, and use the long access (i.e. window.subwindow.window.main.setVisible(true))

I think there is a thread running somewhere on how to do the parent registration, but I'm not familiar with that code.

Cheers,
JPG