ManiaControl Promotion plugin

ManiaControl, the completely new designed and easy to use controller managing all your Maniaplanet server.

Moderators: kremsy, Jocy, Wabbitface, steeffeen, NADEO

User avatar
chco
Posts: 256
Joined: 24 Dec 2012, 09:11

Re: ManiaControl Promotion plugin

Post by chco » 04 Jul 2014, 13:19

No, I get that and much appreciated! :)
Image

kremsy
Posts: 1723
Joined: 21 Jul 2011, 09:51

Re: ManiaControl Promotion plugin

Post by kremsy » 07 Jul 2014, 23:16

Also a small hint for the loadIntoArray() Method, you can just put all this if's into a loop:

Code: Select all

if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_PROMOTE_TXT_0) != '')
{
	$this->message[]=$this->maniaControl->settingManager->getSetting($this, self::SETTING_PROMOTE_TXT_0);
}
Just to:

Code: Select all

for(int i = 0; i < self::MESSAGE_COUNT; i++){
 if ($this->maniaControl->settingManager->getSetting($this, constant("self::SETTING_PROMOTE_TXT_".$i)))
 {
	$this->message[]=$this->maniaControl->settingManager->getSetting($this, constant("self::SETTING_PROMOTE_TXT_".$i);
 }
}
I haven't testet that yet, but that should work ;).

http://php.net/manual/en/function.constant.php
Lukas alias Kremsy, Developer of:
ManiaControl: http://www.maniacontrol.com
ParagonLeague: http://league.paragon-esports.com
MPAseco: http://mpaseco.org
ManiaViewer: http://www.maniaviewer.com

User avatar
steeffeen
Translator
Translator
Posts: 2472
Joined: 14 Oct 2012, 16:22
Location: Germany

Re: ManiaControl Promotion plugin

Post by steeffeen » 08 Jul 2014, 02:29

i kinda doubt that "self::.." will work, you might need to use the class name directly

my attempt:

Code: Select all

const SETTING_PROMOTE = 'Message text ';
// ..
for (int i = 0; i < self::MESSAGE_COUNT; i++) {
	$settingName = self::SETTING_PROMOTE . $i;
	$settingValue = $this->maniaControl->settingManager->getSettingValue($settingName);
	if ($settingValue) {
		array_push($this->message, $settingValue);
	}
}
or if you like fewer lines

Code: Select all

// ..
for (int i = 0; i < self::MESSAGE_COUNT; i++) {
	if ($settingValue = $this->maniaControl->settingManager->getSettingValue(self::SETTING_PROMOTE . $i)) {
		array_push($this->message, $settingValue);
	}
}
>> not tested
note the single get() instead of two calls

(setting names have numbers instead of characters that way though, which scales better anyways)
    Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

    ManiaControl, FancyManiaLinks

    User avatar
    chco
    Posts: 256
    Joined: 24 Dec 2012, 09:11

    Re: ManiaControl Promotion plugin

    Post by chco » 08 Jul 2014, 07:08

    Thanks for the examples guys!
    Btw, the reason it didn't have numbers is the fact that in the settings screen of mc you get:
    Setting 1
    Setting 10
    Setting 2
    Setting 3

    That is why I used a, b,c...
    I'll try out your suggestions gentlemen.
    Thanks!
    Image

    kremsy
    Posts: 1723
    Joined: 21 Jul 2011, 09:51

    Re: ManiaControl Promotion plugin

    Post by kremsy » 08 Jul 2014, 08:39

    The Numbers in Steeffeens example are only for accassing the Settings (they have nothing todo with the displayed names).

    What I would do is to define another setting which is called Count of Messages, and after that I would dynamically generating the Settings for each Messages, so you are independend if someone wants 50 Messages or just 5.

    Would do it something like that (just Pseudocode):

    Code: Select all

    1) Make Constant Text MESSAGE_TEXT
    2) get Setting MessageCount
    
    3) for(int i = 0; i < MessageCount; i++){
        setSetting(self::MESSAGE_TEXT . $i);
    }
    
    4) getSetting like steff described (loop through the settings again and push them to array)
    
    5) Implement the setChangedCallback -> if setting got changed, chnage maybe amount of settings, and refill the array
    Lukas alias Kremsy, Developer of:
    ManiaControl: http://www.maniacontrol.com
    ParagonLeague: http://league.paragon-esports.com
    MPAseco: http://mpaseco.org
    ManiaViewer: http://www.maniaviewer.com

    User avatar
    steeffeen
    Translator
    Translator
    Posts: 2472
    Joined: 14 Oct 2012, 16:22
    Location: Germany

    Re: ManiaControl Promotion plugin

    Post by steeffeen » 08 Jul 2014, 09:01

    kremsy wrote:The Numbers in Steeffeens example are only for accassing the Settings (they have nothing todo with the displayed names).
    that's not correct ^^
    the numbers are part of the message
    chco wrote:That is why I used a, b,c...
    you're right there, that comes from the alphabetical ordering
    either you format the numbers to look like 01, 02, .., 11, ..
    or simply use chr() to get the characters from the loop counter
    (A = 65, B = 66, ..)

    Code: Select all

    $x = chr(65 + $i);
      Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

      ManiaControl, FancyManiaLinks

      kremsy
      Posts: 1723
      Joined: 21 Jul 2011, 09:51

      Re: ManiaControl Promotion plugin

      Post by kremsy » 08 Jul 2014, 09:33

      steeffeen wrote:
      kremsy wrote:The Numbers in Steeffeens example are only for accassing the Settings (they have nothing todo with the displayed names).
      that's not correct ^^
      the numbers are part of the message
      Ups my fault :D.
      Lukas alias Kremsy, Developer of:
      ManiaControl: http://www.maniacontrol.com
      ParagonLeague: http://league.paragon-esports.com
      MPAseco: http://mpaseco.org
      ManiaViewer: http://www.maniaviewer.com

      User avatar
      steeffeen
      Translator
      Translator
      Posts: 2472
      Joined: 14 Oct 2012, 16:22
      Location: Germany

      Re: ManiaControl Promotion plugin

      Post by steeffeen » 05 Aug 2014, 17:35

      please fix the errors of the plugin, check out http://maniacontrol.com/user/errors
        Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

        ManiaControl, FancyManiaLinks

        User avatar
        chco
        Posts: 256
        Joined: 24 Dec 2012, 09:11

        Re: ManiaControl Promotion plugin

        Post by chco » 06 Aug 2014, 15:00

        I've passed one on to you guys (when settings are changed part) as I cannot reproduce this error.
        New version (1.2) is uploaded..

        Sorry it took a while, was away much.
        Image

        User avatar
        steeffeen
        Translator
        Translator
        Posts: 2472
        Joined: 14 Oct 2012, 16:22
        Location: Germany

        Re: ManiaControl Promotion plugin

        Post by steeffeen » 06 Aug 2014, 15:23

        chco wrote:I've passed one on to you guys (when settings are changed part) as I cannot reproduce this error.

        Code: Select all

        public function handleSettingChangedCallback(Setting $setting)
        you have to add a use statement for the settings namespace
          Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

          ManiaControl, FancyManiaLinks

          Post Reply

          Return to “ManiaControl”

          Who is online

          Users browsing this forum: No registered users and 1 guest