Page 1 of 2

How to create 2 manialink pages in one xml file

Posted: 02 Jan 2016, 16:43
by adamkooo2
hi, :)

how to make 2 switchable pages of manialink in one xml file?
using maniascript in ml :mrgreen:


Thanks. :thx:

Re: How to create 2 manialink pages in one xml file

Posted: 02 Jan 2016, 19:09
by Nerpson
What do you mean by switchable pages ?

Re: How to create 2 manialink pages in one xml file

Posted: 02 Jan 2016, 19:11
by reaby
I would use 2 or more frames to hold the pages. as it's possible to say:
frame.hide() --> which will hide also all items inside the frame.

So,
Place 2 frames with same coordinates on top of eachother. Hide the second one at page load.
Make buttons outside the frame to toggle the hidden/shown status of the frame.

Done.

Re: How to create 2 manialink pages in one xml file

Posted: 02 Jan 2016, 20:53
by adamkooo2
reaby wrote:I would use 2 or more frames to hold the pages. as it's possible to say:
frame.hide() --> which will hide also all items inside the frame.

So,
Place 2 frames with same coordinates on top of eachother. Hide the second one at page load.
Make buttons outside the frame to toggle the hidden/shown status of the frame.

Done.
thanks, but this I know, but I don't have the script :/

Re: How to create 2 manialink pages in one xml file

Posted: 02 Jan 2016, 22:31
by zocka
Basically you would just do something like

Code: Select all

foreach (Event in PendingEvents) {
	if (Event.Type ==  CMlEvent::Type::MouseClick && Event.Control.HasClass("menuButton")) {
		Page.GetFirstChild(Event.Control.DataAttributeGet("page")).Show();
		// assuming the button has the attribute   data-page="frameId"
	} 
}
The thing you need to do as well is to hide the current frame. Either you have a variable pointing at the current frame, which you hide if needed and then override (least amount of variable read accesses I guess) or you have a very general approach if you have multiple/a lot of frames with something like that:

Code: Select all

if (Event.Type ==  CMlEvent::Type::MouseClick && Event.Control.HasClass("menuButton")) {
	Page.GetClassChildren("page-container", Page.MainFrame, False);
	// assuming all "pages" have the class "page-container" and are directly within <manialink>
	foreach (_Page in Page.GetClassChildren_Result) {
		if (_Page.ControlId == Event.Control.DataAttributeGet("page"))
			_Page.Show();
		else
			_Page.Hide();
			// Even hidden pages get hidden, but I don't know if checking Visibility first is any more performant
	}
}

Re: How to create 2 manialink pages in one xml file

Posted: 03 Jan 2016, 11:28
by adamkooo2
zocka wrote:Basically you would just do something like

Code: Select all

foreach (Event in PendingEvents) {
	if (Event.Type ==  CMlEvent::Type::MouseClick && Event.Control.HasClass("menuButton")) {
		Page.GetFirstChild(Event.Control.DataAttributeGet("page")).Show();
		// assuming the button has the attribute   data-page="frameId"
	} 
}
The thing you need to do as well is to hide the current frame. Either you have a variable pointing at the current frame, which you hide if needed and then override (least amount of variable read accesses I guess) or you have a very general approach if you have multiple/a lot of frames with something like that:

Code: Select all

if (Event.Type ==  CMlEvent::Type::MouseClick && Event.Control.HasClass("menuButton")) {
	Page.GetClassChildren("page-container", Page.MainFrame, False);
	// assuming all "pages" have the class "page-container" and are directly within <manialink>
	foreach (_Page in Page.GetClassChildren_Result) {
		if (_Page.ControlId == Event.Control.DataAttributeGet("page"))
			_Page.Show();
		else
			_Page.Hide();
			// Even hidden pages get hidden, but I don't know if checking Visibility first is any more performant
	}
}
thank you very much, but the manialink doesn´t switch the pages :/
here it is:

Code: Select all

<quad posn="-161 8 0" sizen="66 12" bgcolor="FFFA" style="Bgs1" substyle="BgTitle3_2"/>
<label posn="-128 2 0" sizen="60 5" text="Editor Keyboard Tips " halign="center" valign="center" style="TextRaceMessageBig" textsize="4"/>
<frame id="Frame_Global">
<quad posn="-159 -2 0" sizen="62 74" bgcolor="FFFA" style="UIConstruction_Buttons" id="move" substyle="BgTools"/>
<label posn="-156 -3 0" sizen="69 65" text="$sEnter$s	test track mode
$sF1	$sterrain
$sF2$s	blocks
$sF3$s	skins
$sF4$s	items
$sF5$s	macroblocks
$sspace$s	place block
$sdelete$s	delete block
$sP$s	plugins
$sCtrl$s	select block
$sC$s	copy, paste, delete blocks
$sU$s	one step back
$sR$s	one step next
$s-,+$s	rotate block
$sAlt+mousewheel$s	zoom
$sAlt+rightmousebutton$s	rotate view
$snumbers$s	change view
$sZ$s	show underground
" textsize="2"/>
<quad posn="-90 -2 0" sizen="9 8" bgcolor="FFFA" scriptevents="1" style="Icons128x128_1" substyle="BackFocusable" modulatecolor="00FF07FF" id="menuButton" rot="180"/>
</frame>



<frame id="Frame_Global2" hidden="1">
<quad posn="-159 -2 0" sizen="62 74" bgcolor="FFFA" style="UIConstruction_Buttons" id="move" substyle="BgTools"/>
<label posn="-156 -3 0" sizen="69 65" text="$sEnter$s	test track mode
$sH	$sshow help
$sM$s show/hide raster


" textsize="2"/>
<quad posn="-90 -2 0" sizen="9 8" bgcolor="FFFA" scriptevents="1" style="Icons128x128_1" substyle="BackFocusable" modulatecolor="00FF07FF" id="menuButton2" rot="180"/>
</frame>

<script><!--
foreach (Event in PendingEvents) {
   if (Event.Type ==  CMlEvent::Type::MouseClick && Event.Control.HasClass("menuButton")) {
      Page.GetFirstChild(Event.Control.DataAttributeGet("Frame_Global2")).Show();
      Page.GetFirstChild(Event.Control.DataAttributeGet("Frame_Global")).Hide();
// assuming the button has the attribute   data-page="frameId"
   } 
}
foreach (Event in PendingEvents) {
   if (Event.Type ==  CMlEvent::Type::MouseClick && Event.Control.HasClass("menuButton2")) {
      Page.GetFirstChild(Event.Control.DataAttributeGet("Frame_Global")).Show();
	  Page.GetFirstChild(Event.Control.DataAttributeGet("Frame_Global2")).Hide();
	// assuming the button has the attribute   data-page="frameId"
   } 
}

--></script>

Re: How to create 2 manialink pages in one xml file

Posted: 03 Jan 2016, 12:57
by zocka
1) Your script is looking for a class (Event.Control.HasClass("menuButton")) while your markup has the value you are looking for set as id (<quad posn="-90 -2 0" ... id="menuButton" />).
Check for Event.ControlId instead.

2) If you use constant names throughout your script, you can use Page.GetFirstChild("Frame_Global2").Show(); instead of Page.GetFirstChild(Event.Control.DataAttributeGet("Frame_Global2")).Show();.
DataAttributeGet("something") looks for the value of the attribute 'data-something="..."' in your markup.
I recommended that approach so you don't have to cover each different button in case you have a lot of different frames to switch (as you have more than one frame to check for hiding etc. and have to update your maniascript every time you update the xml ;) )

3) I think you are missing the overall main(){while(True){yield; ... }} stuff around your event handling, but I'm not sure about that in editor plugins

4) You should condense your loop and maybe the if-clauses, but I think you are going to refactor afterwards.

Re: How to create 2 manialink pages in one xml file

Posted: 03 Jan 2016, 18:48
by adamkooo2
zocka wrote:1) Your script is looking for a class (Event.Control.HasClass("menuButton")) while your markup has the value you are looking for set as id (<quad posn="-90 -2 0" ... id="menuButton" />).
Check for Event.ControlId instead.

2) If you use constant names throughout your script, you can use Page.GetFirstChild("Frame_Global2").Show(); instead of Page.GetFirstChild(Event.Control.DataAttributeGet("Frame_Global2")).Show();.
DataAttributeGet("something") looks for the value of the attribute 'data-something="..."' in your markup.
I recommended that approach so you don't have to cover each different button in case you have a lot of different frames to switch (as you have more than one frame to check for hiding etc. and have to update your maniascript every time you update the xml ;) )

3) I think you are missing the overall main(){while(True){yield; ... }} stuff around your event handling, but I'm not sure about that in editor plugins

4) You should condense your loop and maybe the if-clauses, but I think you are going to refactor afterwards.
1) done.
2) I did.
3) I will show you the full version now (I showed only manialink)
4) I don´t understand completely :/

but my script is here:

Code: Select all

#RequireContext CEditorPlugin

Text CreateManialink()
{
	declare Integer MaxBlocksCount for ManialinkPage;
	
	//layer2
	ManialinkText = """
<quad posn="-161 8 0" sizen="66 12" bgcolor="FFFA" style="Bgs1" substyle="BgTitle3_2"/>
<label posn="-128 2 0" sizen="60 5" text="Editor Keyboard Tips " halign="center" valign="center" style="TextRaceMessageBig" textsize="4"/>
<frame id="Frame_Global">
<quad posn="-159 -2 0" sizen="62 74" bgcolor="FFFA" style="UIConstruction_Buttons" id="move" substyle="BgTools"/>
<label posn="-156 -3 0" sizen="69 65" text="$sEnter$s   test track mode
$sF1   $sterrain
$sF2$s   blocks
$sF3$s   skins
$sF4$s   items
$sF5$s   macroblocks
$sspace$s   place block
$sdelete$s   delete block
$sP$s   plugins
$sCtrl$s   select block
$sC$s   copy, paste, delete blocks
$sU$s   one step back
$sR$s   one step next
$s-,+$s   rotate block
$sAlt+mousewheel$s   zoom
$sAlt+rightmousebutton$s   rotate view
$snumbers$s   change view
$sZ$s   show underground
" textsize="2"/>
<quad posn="-90 -2 0" sizen="9 8" bgcolor="FFFA" scriptevents="1" style="Icons128x128_1" substyle="BackFocusable" modulatecolor="00FF07FF" id="menuButton" rot="180"/>
</frame>



<frame id="Frame_Global2" hidden="1">
<quad posn="-159 -2 0" sizen="62 74" bgcolor="FFFA" style="UIConstruction_Buttons" id="move" substyle="BgTools"/>
<label posn="-156 -3 0" sizen="69 65" text="$sEnter$s   test track mode
$sH   $sshow help
$sM$s show/hide raster


" textsize="2"/>
<quad posn="-90 -2 0" sizen="9 8" bgcolor="FFFA" scriptevents="1" style="Icons128x128_1" substyle="BackFocusable" modulatecolor="00FF07FF" id="menuButton2" rot="180"/>
</frame>

<script><!--
while(True){
foreach (Event in PendingEvents) {
   if (Event.Type ==  CMlEvent::Type::MouseClick && Event.ControlId("menuButton")) {
      Page.GetFirstChild("Frame_Global2").Show();
      Page.GetFirstChild("Frame_Global").Hide();
// assuming the button has the attribute   data-page="frameId"
   } 
}
foreach (Event in PendingEvents) {
   if (Event.Type ==  CMlEvent::Type::MouseClick && Event.ControlId("menuButton2")) {
	Page.GetFirstChild("Frame_Global").Show();
	Page.GetFirstChild("Frame_Global2").Hide();
   } 
}
yield;
}
--></script>
""";
	return ManialinkText;

}
////////main

main()
{
	 //Without multiples layers, maybe is something wrong here :
	ManialinkText = CreateManialink();
	
yield;

}

Re: How to create 2 manialink pages in one xml file

Posted: 03 Jan 2016, 19:51
by zocka
You know you can debug ManiaScript with strg+G in the editor as well?
There it said, that CMlControl.ControlId is not a function.

The fixed script (working for me like that) (also including the changes mentioned in 3) and 4) ) looks like this:

Code: Select all

<script><!--
main() {
    while(True){
        foreach (Event in PendingEvents) {
            if (Event.Type ==  CMlEvent::Type::MouseClick) {
                if (Event.ControlId == "menuButton") {
                    Page.GetFirstChild("Frame_Global2").Show();
                    Page.GetFirstChild("Frame_Global").Hide();
                }
                if (Event.ControlId == "menuButton2") {
                    Page.GetFirstChild("Frame_Global").Show();
                    Page.GetFirstChild("Frame_Global2").Hide();
                }
            }
        }
        yield;
    }    
}
--></script>

For the purpose you have in mind, you could consider placing as many labels as you have lines on your panel, store all the information you want to display in an array and then cycle through, as you click on 'next page' buttons and the like.
This would rid you of the need to change the whole markup and maybe even think of the logic to add new pages, if you have to add information ;)

Re: How to create 2 manialink pages in one xml file

Posted: 03 Jan 2016, 20:00
by adamkooo2
thank you :thx:
it works :roflol: