Menu example code needed

Open source, lightweight PHP framework for Manialink and Web development.

Moderator: NADEO

User avatar
w1lla
Posts: 2359
Joined: 15 Jun 2010, 11:09
Location: Netherlands
Contact:

Re: Menu example code needed

Post by w1lla » 05 Feb 2012, 19:48

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('}');
	}
TM² Info
SM Info
QM Info

OS: Windows 10 x64 Professional
MB: MSI 970A-G46
Processor: AMD FX-6300 3500 mHz
RAM Memory: 16 GB DDR3
Video: SAPPHIRE DUAL-X R9 280X 3GB GDDR5
KB: Logitech G510s
Mouse: Logitech G300s
Mode Creation
ManiaScript Docs

User avatar
Jojo_44
Posts: 500
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Contact:

Re: Menu example code needed

Post by Jojo_44 » 05 Feb 2012, 21:06

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
Image
my english sounds very unfriendly but it isn´t ;)

User avatar
The_Big_Boo
Posts: 1041
Joined: 15 Jun 2010, 15:46

Re: Menu example code needed

Post by The_Big_Boo » 05 Feb 2012, 21:25

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.
OS: Win 7 Pro x64
RAM: 2x4GB Corsair @ 1600MHz
CPU: Intel i5 760 @ 3.6GHz
Mobo: Asus P7P55D-E
GPU: NVidia GTX 760 2GB
HDD: WD Black 1TB
Sound: VIA VT1828S (onboard)
Peripherals: Razer DeathAdder - Razer DeathStalker - Logitech F310

User avatar
Jojo_44
Posts: 500
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Contact:

Re: Menu example code needed

Post by Jojo_44 » 07 Feb 2012, 12:50

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
Image
my english sounds very unfriendly but it isn´t ;)

User avatar
gouxim
Nadeo
Nadeo
Posts: 1154
Joined: 14 Jun 2010, 17:20

Re: Menu example code needed

Post by gouxim » 13 Feb 2012, 11:20

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.
Please do not PM for support. Instead, create a thread so that everyone can contribute or benefit from the answer! 8-)

User avatar
Jojo_44
Posts: 500
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Contact:

Re: Menu example code needed

Post by Jojo_44 » 13 Feb 2012, 14:39

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
Image
my english sounds very unfriendly but it isn´t ;)

User avatar
gouxim
Nadeo
Nadeo
Posts: 1154
Joined: 14 Jun 2010, 17:20

Re: Menu example code needed

Post by gouxim » 14 Feb 2012, 10:45

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?
Please do not PM for support. Instead, create a thread so that everyone can contribute or benefit from the answer! 8-)

User avatar
Jojo_44
Posts: 500
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Contact:

Re: Menu example code needed

Post by Jojo_44 » 14 Feb 2012, 12:35

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
Image
my english sounds very unfriendly but it isn´t ;)

Post Reply

Return to “ManiaLib”

Who is online

Users browsing this forum: No registered users and 1 guest