How to create 2 manialink pages in one xml file

Talk about ManiaLink development in this forum

Moderator: NADEO

User avatar
Rots
Translator
Translator
Posts: 1101
Joined: 01 Sep 2010, 14:39
Location: España, Barcelona

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

Post by Rots »

I found an old thing that does the thing, I know it might be dirty but it still works :D

I used it for menu switching/navigation in an old manialink. If someone can/wants to clear this up or make it easier, feel free, this way I could learn too ^^ I remember I made it from 0 maniascript knowledge

Code: Select all

<script><!--
 #Include "TextLib" as TextLib
	
	main(){
		declare CMlFrame mainpage <=> (Page.GetFirstChild("mainpage") as CMlFrame);
		declare CMlFrame home <=> (Page.GetFirstChild("home") as CMlFrame);
		declare CMlFrame skins <=> (Page.GetFirstChild("skins") as CMlFrame);
		declare CMlFrame avatars <=> (Page.GetFirstChild("avatars") as CMlFrame);
		declare CMlFrame horns <=> (Page.GetFirstChild("horns") as CMlFrame);
		
		
		while(True){
			foreach(Event in PendingEvents){
				switch(Event.Type) {
					case CMlEvent::Type::MouseClick: { 
						if(Event.ControlId=="menuhome"){
							if(skins.Visible)skins.Hide();
							if(avatars.Visible)avatars.Hide();
							if(horns.Visible)horns.Hide();
							home.Show();
						}
 						if(Event.ControlId=="menuskins"){
							if(home.Visible)home.Hide();
							if(avatars.Visible)avatars.Hide();
							if(horns.Visible)horns.Hide();
							skins.Show();
						}
						if(Event.ControlId=="menuavatars"){
							if(home.Visible)home.Hide();
							if(skins.Visible)skins.Hide();
							if(horns.Visible)horns.Hide();
							avatars.Show();
						}
						if(Event.ControlId=="menuhorns"){
							if(home.Visible)home.Hide();
							if(skins.Visible)skins.Hide();
							if(avatars.Visible)avatars.Hide();
							horns.Show();
						}
					}
				}
			}
		yield;
		}
	}
--></script>
Image
Image
Image
TrackMania Original brought me here... Here I am since 2006
User avatar
Nerpson
Translator
Translator
Posts: 1554
Joined: 27 Sep 2013, 18:02
Location: France
Contact:

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

Post by Nerpson »

You can do more with less!

Code: Select all

YourMLControl.Visible = !YourMLControl.Visible;
If YourMLControl is visible, then it will be hidden, else, it will be shown. :thumbsup:
(The '!' reverses a boolean, True => False, False => True)
ImageImageImageImage
zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

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

Post by zocka »

Rots wrote:I found an old thing that does the thing, I know it might be dirty but it still works :D

I used it for menu switching/navigation in an old manialink. If someone can/wants to clear this up or make it easier, feel free, this way I could learn too ^^ I remember I made it from 0 maniascript knowledge

Code: Select all

<script><!--
 #Include "TextLib" as TextLib
	
	main(){
		declare CMlFrame mainpage <=> (Page.GetFirstChild("mainpage") as CMlFrame);
		declare CMlFrame home <=> (Page.GetFirstChild("home") as CMlFrame);
		declare CMlFrame skins <=> (Page.GetFirstChild("skins") as CMlFrame);
		declare CMlFrame avatars <=> (Page.GetFirstChild("avatars") as CMlFrame);
		declare CMlFrame horns <=> (Page.GetFirstChild("horns") as CMlFrame);
		
		
		while(True){
			foreach(Event in PendingEvents){
				switch(Event.Type) {
					case CMlEvent::Type::MouseClick: { 
						if(Event.ControlId=="menuhome"){
							if(skins.Visible)skins.Hide();
							if(avatars.Visible)avatars.Hide();
							if(horns.Visible)horns.Hide();
							home.Show();
						}
 						if(Event.ControlId=="menuskins"){
							if(home.Visible)home.Hide();
							if(avatars.Visible)avatars.Hide();
							if(horns.Visible)horns.Hide();
							skins.Show();
						}
						if(Event.ControlId=="menuavatars"){
							if(home.Visible)home.Hide();
							if(skins.Visible)skins.Hide();
							if(horns.Visible)horns.Hide();
							avatars.Show();
						}
						if(Event.ControlId=="menuhorns"){
							if(home.Visible)home.Hide();
							if(skins.Visible)skins.Hide();
							if(avatars.Visible)avatars.Hide();
							horns.Show();
						}
					}
				}
			}
		yield;
		}
	}
--></script>
As I mentioned somewhere else in this topic, you will have to add quite some ManiaScript if you add pages. Since we now have the possibility with classes and data-attributes, I'd suggest something like this:

Code: Select all

<label text="page 1" class="menuButton" scriptevents="1" data-page="page1" />
<label text="page 2" class="menuButton" scriptevents="1" data-page="page2" />
...
<frame id="page1">..</frame>
<frame id="page2" hidden="1">..</frame>
...
<script><![CDATA[
main(){
    declare CMlControl CurrentPage = Page.GetFirstChild("page1");
    while (True) {
        foreach (Event in PendingEvents) {
            if (Event.Type == CMlEvent::Type::MouseClick &&
                Event.Control.HasClass("menuButton")) {
                CurrentPage.Hide();
                CurrentPage = Page.GetFirstChild(Event.Control.DataAttributeGet("page"));
                CurrentPage.Show();
            }
        }
        yield;
    }
}
]]></script>
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka
reaby
Posts: 956
Joined: 29 Dec 2010, 23:26
Location: Eastern Finland
Contact:

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

Post by reaby »

...and the pages contents is very easy to create/edit in interface designer, you could also paste the maniascript there for preview, so you really see what you get :)
Post Reply

Return to “ManiaLink”

Who is online

Users browsing this forum: No registered users and 2 guests