The online racing simulator
Insim Buttons
(24 posts, started )
Insim Buttons
Some time ago I have started doing my own local insim from scratch, meaning there is no libraries of any kind and such.
Program does part of things as standard DX overlay (because its drawing exact car shapes in radar for cars around) and mainly via insim for menus ...

It does buttons pretty efficiently IMO, I store all buttons data in buttons class, when deleting I only delete button which are actually there, as well as I only update button when its data has changed.
This simplifies code (which draw menus ...) there is no need to check each iteration if buttons should be updated, in fact it only upates changed buttons which is more efficient, as well as redrawing is way faster.
Recently I realized a lot of button IDs are often unused while on other side I actually lack button.
Current code does things as efficiently as it can, IDs are more or less static, for example couple of functions (which cannot be run simultaneously) have assigned same range of about 200 IDs.
So as possible solution for problem I thought to implement dynamic assigning of IDs, which will allow me more efficent usage of IDs, because sometimes not all static IDs are used (user can choose to not display all data, in cases like speedometer, fuel, rpm,...) or this is a bit overkill, because it complicates code, and I will have to handle all cases like when maximum number of buttons is reached, in case I choose to display even more data ...

To be honest I never even looked at any insim program code or library. I would like to hear opinions of others about this, how people handle such things, all comments are welcome.

Here is example on what I'm wasting all these IDs
Quote from DANIEL-CRO :

To be honest I never even looked at any insim program code or library.

Already done. PRISM button manager module.
Quote from cargame.nl :Already done. PRISM button manager module.

Which, at least when I tried it, seems to be a bit broken. But I heard T3charmy has his own private manager, maybe to release at some point (?).
Done quick test, it seems that lower IDs are always drawn behind higher ones. It make sense, but I didn't really noticed it untill now because I always used IDs by order.
It isn't that straight as on paper.
Here's mine. It's being used on my not released insim(which by the way doesn't look it will be used but anyway). Some things:

1. It's in C#. I use it on InSim.NET
2. It may be not optimised, i'd like to hear improvements.
3. It features Groups. You can use "" for no group or "Bananas" and then you can DeleteGroupButtons(UCID, "Bananas")!
4. Uses custom OnClickManagerButton and OnTextReceiveManagerButton. These are the callbacks you need.

1.Rename the extension to .cs
2.Just include it in your project and use the functions.

3.How to install to use the callbacks:

void OnButtonTextReceive(InSim insim, IS_BTT BTT)
{
try
{
if (BTT.Text.Length == 0) return;

string ButtonName = GetButtonName(BTT.ClickID, BTT.UCID);
if (ButtonName != "Invalid")
{
OnTextReceiveManagerButton(BTT.UCID, ButtonName, BTT.Text);
return;
}
}
catch (Exception EX) { LogTextToFile("packetError", "BTT - " + EX.Message); }
}

void OnButtonClick(InSim insim, IS_BTC BTC)
{
try
{
string ButtonName = GetButtonName(BTC.ClickID, BTC.UCID);
if (ButtonName != "Invalid")
{
OnClickManagerButton(BTC.UCID, ButtonName);
return;
}
}
catch (Exception EX) { LogTextToFile("packetError", "BTC - " + EX.Message); }
}

Attached files
ButtonManager - Released.txt - 4.4 KB - 197 views
Quote from cargame.nl :Whats broken about it? Have no problems with it.

It seems to throw some errors when I try to use it. But as I said, maybe it's just me.
#8 - PoVo
Quote from Flame CZE :It seems to throw some errors when I try to use it. But as I said, maybe it's just me.

We are using PRISM's button manager on Reality Cruise servers and it works without issues
Quote from DarkKostas :Here's mine. It's being used on my not released insim(which by the way doesn't look it will be used but anyway). Some things

I can't thank you enough for this. I was actually working on an InSim and was running out of ideas of using buttons. Naming them, instead of giving them an ID manually is the best idea I've seen so far.

Sorry to go off-topic, but is there a way I can force a button to go on top of another with your button manager?
Quote from Flame CZE :It seems to throw some errors when I try to use it. But as I said, maybe it's just me.

Thread hi-jack, what's the errors you are getting, what version of PHP are you running, and what version of PRISM are you running?
Quote from Bose321 :I can't thank you enough for this. I was actually working on an InSim and was running out of ideas of using buttons. Naming them, instead of giving them an ID manually is the best idea I've seen so far.

Sorry to go off-topic, but is there a way I can force a button to go on top of another with your button manager?

Not really, but based on the order you create the buttons you can change the order of them in-game as well. Just swap the 1st and 2nd Create functions
Quote from DarkKostas :Not really, but based on the order you create the buttons you can change the order of them in-game as well. Just swap the 1st and 2nd Create functions

They already are.
Quote from DarkKostas :Here's mine.

Grouping buttons, awesome idea

I'm using C++, syntax is more or less similar but I always prefer to write code on my own. I understand it better then

I created groups by function name from where Button::Text is called, also SubGroups can be easily created within function.

SubGroups must always have higher ID than MainGroup, that way I solved the issue of buttons appearing behind.

Thanks for great idea
Quote from Dygear :Thread hi-jack, what's the errors you are getting, what version of PHP are you running, and what version of PRISM are you running?

So I've tried it now and I don't get any errors, but the buttons don't appear. I'm running PRISM 0.4.5.2 with PHP 5.4.16.

This is what my test plugin looks like. I copied it from the welcome.php plugin and fixed the argument order in the Button constructors.

<?php 
php
class test extends Plugins
{
    const 
URL 'http://lfsforum.net/forumdisplay.php?f=312';
    const 
NAME 'Button test';
    const 
AUTHOR 'Flame CZE';
    const 
VERSION PHPInSimMod::VERSION;
    const 
DESCRIPTION 'test';

    public function 
__construct()
    {
        
$this->registerPacket('onClientConnect'ISP_NCN);
    }

    public function 
onClientConnect(IS_NCN $NCN)
    {
        if (
$NCN->UCID == 0)
            return;

        
$Title = new Button(Button::$TO_ALL'poweredBy');
        
$Title->Text('This server is powered by');
        
$Title->registerOnClick($this'onPoweredByClick');
        
$Title->T(IS_Y_MAX IS_Y_MIN)->L(IS_X_MIN)->W(IS_X_MAX)->H(8)->send();

        
$Msg = new Button(Button::$TO_ALL'prism');
        
$Msg->Text('^3PRISM ^8Version ^7'.PHPInSimMod::VERSION.'^8.');
        
$Msg->T(IS_Y_MAX IS_Y_MIN 8)->L(IS_X_MIN)->W(IS_X_MAX)->H(8)->send();
    }

    public function 
onPoweredByClick(IS_BTC $BTC)
    {
        echo 
'Button clicked! ' $BTC;
    }
}
?>

@DarkKostas, One more thing. How can I send a button to everyone? If I use 255 (which shows it to all connections IIRC) instead of the UCID, it gives back a BTC error with the message that the index is out the matrix. Not sure why it even gives a BTC error when you send a new BTN?
Quote from Flame CZE :but the buttons don't appear

Not really a surprise, you are using all kinds of vars which are not defined.. at least not in this example.


<?php 
$Title 
= new Button(Button::$TO_ALL'poweredBy');
?>



Button::$TO_ALL ? To all? What about sending it to the person who actually connects? $NCN->UCID

I don't know if To_all actually exists anyway.. At least not in my version 0.4.4 ... (I stopped coding for LFS some months ago)


<?php 
$Title
->T(IS_Y_MAX IS_Y_MIN)->L(IS_X_MIN)->W(IS_X_MAX)->H(8)->send();
?>

IS_Y_MAX, IS_Y_MIN ...? Why not keep it simple with a test and just do


<?php 
$Title 
= new Button($NCN->UCID'buttonGroupName');
$Title->L(8)->T(30)->W(20)->H(8); // * see below
$Title->BStyle |= ISB_LEFT;
$Title->Text('This server is powered by');
$Title->send(); // I prefer to keep this on a seperate line
?>

Trying to debug something is best being done using a minimum amount of variables

* by the way.. It's L T W H ...

<?php 
public static function reserveArea($L = -1$T = -1$W = -1$H = -1)
?>

#17 - PoVo
If you want to send the button to everyone, just set UCID as 255
@cargame, you should check the source code before you make false statements.

prism_packets.php, lines 2465–2468:

<?php 
define
('IS_X_MIN',    0);
define('IS_X_MAX',    110);
define('IS_Y_MIN',    30);
define('IS_Y_MAX',    170);
?>

prism_button.php, line 13:

<?php 
    
public static $TO_ALL 255;
?>

Also, I don't know why I couldn't use the dimesions and positions in whatever order I can. It's just assigning object properties, isn't it?

I will try your code now.
Quote from Flame CZE :you should check the source code before you make false statements.

And why should I check anything.. Good luck on your own, you obviously don't need any response.

There is only one false statement here and thats being made by you that it's 'a bit broken'.
Quote from Flame CZE :whatever order I can.

Yep, just mess up, good practice. It's all yours.

Ppff.. Why am I even responding on this forum, I don't know.
o/
OK, so I discovered that "my" code works fine as long as I don't set UCID to 255. When I set it to 255 or Button::$TO_ALL, it won't show the buttons. When I changed it to $NCN->UCID, it worked.
Quote from Bose321 :@DarkKostas, One more thing. How can I send a button to everyone? If I use 255 (which shows it to all connections IIRC) instead of the UCID, it gives back a BTC error with the message that the index is out the matrix. Not sure why it even gives a BTC error when you send a new BTN?

Hmm i think i haven't try it that way, try setting "string[,,] Button = new string[255, MAX_BUTTONS, 2];" to 256 from 255 and it should work.
For some reason a few buttons disappear of screen and only 3 buttons or something are shown.

edit: I see them quickly, but they disappear after a few ms.
edit2: That seemed to be caused by the other buttons I had on screen that are made in the MCI packet. When I'm specced it shows the buttons. They just get overwritten by current buttons.

Insim Buttons
(24 posts, started )
FGED GREDG RDFGDR GSFDG