Page 2 of 2

Re: Menu example code needed

Posted: 05 Feb 2012, 19:48
by w1lla
See:

\libraries\ManiaLibDemo\Views\ManiaScript\Index.php

it gives an example of usage for maniascript.

Another example is this:


or this also can be used:

Code: Select all

function display()
	{
		$ui = new \ManiaLib\Gui\Elements\IncludeManialink();
		$ui->setUrl('manialib.xml', false);
		$ui->save();
		
		Manialink::appendScript('main() {');
		Manialink::appendScript('while(True) {
    foreach(Event in PendingEvents) {
        if (Event.Type == CGameManialinkScriptEvent::Type::KeyPress) {
		if(Event.CharPressed == "2424832") //F1
		OpenLink("maniaplanet://#join=smurfer", ::LinkType::Goto); // -> goes to server
		if(Event.CharPressed == "2490368") //F2
		OpenLink("www.smurfen.net", ::LinkType::ExternalBrowser); // -> goes to www.smurfen.net
		if(Event.CharPressed == "2555904") //F3
		OpenLink("www.smurfen.net/phpBB3/index.php", ::LinkType::ExternalBrowser); // -> goes to smurfen.net/forum
        }
    }
    yield;
}	');
		Manialink::appendScript('}');
	}

Re: Menu example code needed

Posted: 05 Feb 2012, 21:06
by Jojo_44
Cool thanks for your help w1lla.

After trying some Events, I came across a problem. I´m missing the Event type to call a own function. Something like that would be very nice:

Code: Select all

Event::addListener('tqu', 'CGameManialinkScriptEvent::Type::MouseClick', array(Action::Function, 'myownfunction'));
Ofc I could code it myself but it would save a lot of time to do it like I suggested above.

I also see now way to animate something if I use the manialib maniascript.

best regards, Jojo

Re: Menu example code needed

Posted: 05 Feb 2012, 21:25
by The_Big_Boo
Jojo_44 wrote:After trying some Events, I came across a problem. I´m missing the Event type to call a own function. Something like that would be very nice:

Code: Select all

Event::addListener('tqu', 'CGameManialinkScriptEvent::Type::MouseClick', array(Action::Function, 'myownfunction'));
Unfortunately this can't be done at the moment because there is no way to call a dynamic user function in ManiaScript (like call_user_func() does in PHP for example)... But be sure that as soon as it will be possible, it will be added in ManiaLib (we really want it too ^_^)
Jojo_44 wrote:I also see now way to animate something if I use the manialib maniascript.
ManiaScript in ManiaLib is still at its beginning and will of course be extended with time so maybe one day it will be possible.

Re: Menu example code needed

Posted: 07 Feb 2012, 12:50
by Jojo_44
Again thanks for the information. Hopefully an update for maniascript coming with MP 2.0 and all the suggestions from the community are implemented. Ah yes I hope it´s coming soon ;)

best regards, Jojo

Re: Menu example code needed

Posted: 13 Feb 2012, 11:20
by gouxim
Documentation is basically written on demand, so it's a good idea to ask your questions here. I'll write a quick doc about using the ManiaScript framework so you can get started easilly.

Re: Menu example code needed

Posted: 13 Feb 2012, 14:39
by Jojo_44
Hey,

ok last weekend I did a deeper look in manialib and I have found the Header and Footer view which are much better for a constant menu on every view as renderSubView. You should mention that in your docu ;)

Last weekend I came another problem. I wanna use FileEntries and everything works so far until I wanna upload replays/maps with special characters. My code:

Upload view:

Code: Select all

			$ui = new FileEntry(50, 5);
			$ui->setHalign('center');
			$ui->setValign('center');
			$ui->setName('inputreplay');
			$ui->setFolder('Replays');
			$ui->setDefault('Choose a replay ...');
			$ui->setPosition(65, -20, 3);
			$ui->save();
			
			$this->request->set('replayname', 'inputreplay');
			$manialink = $this->request->createLink('/upload/save/');
			
			$ui = new Label();
			$ui->setPosition(65, -35, 3);
			$ui->setText('Upload Replay');
			$ui->setManialink('POST('.$manialink.',inputreplay)');
			$ui->setHalign('center');
			$ui->setValign('center2');
			$ui->save();
Save view:

Code: Select all

			$ReplayName = $this->request->get('replayname', false);
			
			$Replay = file_get_contents('php://input');
			file_put_contents($ReplayName, $Replay);
			
			$ReplaySize = filesize($ReplayName);
			$ReplayName = htmlspecialchars($ReplayName);
			
			$manialink = $this->request->createLink('/upload/pay');
			
			$ui = new Label();
			$ui->setPosition(65, -35, 3);
			$ui->setText($ReplayName);
			$ui->setManialink($manialink);
			$ui->setHalign('center');
			$ui->setValign('center2');
			$ui->save();
I don´t know why it´s not working with special characters because I tried FileEntries without manialib and everything works fine, also special characters. Maybe my code is wrong ?

best regards, Jojo

Re: Menu example code needed

Posted: 14 Feb 2012, 10:45
by gouxim

Code: Select all

 file_put_contents($ReplayName, $Replay);
I'm not sure this works since $ReplayName is not an actual file path on your server, is it?

Re: Menu example code needed

Posted: 14 Feb 2012, 12:35
by Jojo_44
It is but I also changed it to a filepath, it doesn´t change anything.

But I have uploaded the project to my webspace and now it´s working fine -.- (localhost still don´t work)
Can someone explain me the reason for this ?

I´m now away for 1-2 weeks, so don´t expect a answer in the next days ;)

best regards, Jojo