Menu example code needed

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

Moderator: NADEO

Re: Menu example code needed

Postby 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 XP
MB: MS-7599
Processor: AMD Athlon II X2 250
RAM Memory: 4 GB DDR3
Video: ATI HD Radeon 5500 1 GB

Mode Creation

ManiaScript Docs
User avatar
w1lla
 
Posts: 1419
Joined: 15 Jun 2010, 11:09
Location: Netherlands
Manialink: maniaplanetblog

Re: Menu example code needed

Postby 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
Jojo_44
 
Posts: 394
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Manialink: zero
TrackMania Forever:
Nickname: zeroつoっo 
Zone: Germany»Bavaria»Nürnberg

Re: Menu example code needed

Postby 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.
Image
User avatar
The_Big_Boo
 
Posts: 675
Joined: 15 Jun 2010, 15:46

Re: Menu example code needed

Postby 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
Jojo_44
 
Posts: 394
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Manialink: zero
TrackMania Forever:
Nickname: zeroつoっo 
Zone: Germany»Bavaria»Nürnberg

Re: Menu example code needed

Postby 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
gouxim
Nadeo
Nadeo
 
Posts: 691
Joined: 14 Jun 2010, 17:20
TrackMania Forever:
Nickname: gu ツ
Zone: France»Ile-de-France»Paris
Solo ranking: 34 023
Multiplayer ranking: 298 561

Re: Menu example code needed

Postby 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
Jojo_44
 
Posts: 394
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Manialink: zero
TrackMania Forever:
Nickname: zeroつoっo 
Zone: Germany»Bavaria»Nürnberg

Re: Menu example code needed

Postby 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
gouxim
Nadeo
Nadeo
 
Posts: 691
Joined: 14 Jun 2010, 17:20
TrackMania Forever:
Nickname: gu ツ
Zone: France»Ile-de-France»Paris
Solo ranking: 34 023
Multiplayer ranking: 298 561

Re: Menu example code needed

Postby 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 ;)
User avatar
Jojo_44
 
Posts: 394
Joined: 12 Jul 2010, 15:58
Location: Germany->Bavaria
Manialink: zero
TrackMania Forever:
Nickname: zeroつoっo 
Zone: Germany»Bavaria»Nürnberg

Previous

Return to ManiaLib

Who is online

Users browsing this forum: No registered users and 0 guests