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

Thanks.

Moderator: NADEO
thanks, but this I know, but I don't have the script :/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.
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"
}
}
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 :/zocka wrote:Basically you would just do something likeThe 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
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" } }
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 } }
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>
1) done.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.
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;
}
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>
Users browsing this forum: No registered users and 1 guest