Author Topic: Place button on screen center?  (Read 648 times)

Basically, I want to have a button (Floating, no gui window) in the center of the users window no matter what resolution they are running at. The one little flaw to my plan is that I've got no idea how to do it.

I've searched for a topic that may contain the answer, but I couldn't find one. Thanks to anyone that can help.

Edit: I partially got it working. I made the position a variable and then got the resolution from getRes();, then divided by two. The problem with this is that it's placing the button in the center from the buttons top left corner. Can anyone suggest a way to make it in the dead center?

« Last Edit: July 26, 2009, 07:42:11 PM by Intrebal »

It would be possible to create a button and have its parent be whatever the gui is (like playgui for ingame stuff) and then have those two things set to being center.  Haven't worked with guis for a while but I will check it out next time I use editor mode in Blockland if nobody can answer this.

I've got this so far:

Quote
%c = getRes();
%a = 0.5 * getwords(%c, 0);
%b = 0.5 * getwords(%c, 1);
$InteractPosition = %a SPC %b;

echo($InteractPosition);
//--- OBJECT WRITE BEGIN ---
new GuiControl(Interact) {
   profile = "GuiDefaultProfile";
   horizSizing = "right";
   vertSizing = "bottom";
   position = "0 0";
   extent = "640 480";
   minExtent = "8 2";
   visible = "1";

   new GuiBitmapButtonCtrl() {
      profile = "BlockButtonProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = $InteractPosition;
      extent = "85 30";
      minExtent = "8 2";
      visible = "1";
      command = "Testcommand();";
      text = "Interact";
      groupNum = "-1";
      buttonType = "PushButton";
      bitmap = "base/client/ui/button1";
      lockAspectRatio = "0";
      alignLeft = "0";
      overflowImage = "0";
      mKeepCached = "0";
      mColor = "0 200 100 255";
      closeCommand = "canvas.popdialog(Interact);";
   };
   
};
//--- OBJECT WRITE END ---

There are probably better ways to do this, please point them out if you see them. I still need to get it in the dead center. I'm running on a resolution of 1152x864, and I'm pretty sure I need to push the button 42.5 to the left, and 15 up; I'm just not sure how to do it for all resolutions.

Thanks.

Set horizSizing and vertSizing to "center"

Yeh, that works. Thanks :)

How would I go about making a gui auto display when a player joins? I've tried a few gameconnections, but none of them seem to work.

Also, how do I make it so the mouse isn't automatically used when the gui is displayed?

I think there may be a GuiNoMouseCtrl somewhere in there but I don't know.  If you are having the client open it after downloading, try something like
Code: [Select]
function clientCmdOpen()
{
canvas.pushdialog(Interact);
}
and then you can do something like
Code: [Select]
package spawn
{
function gameconnection::spawnplayer(%this)
{
parent::spawnplayer(%this);
commandtoclient(%this,'open');
}
};
Of course, that would be every time the player would spawn.  For the first time do the same but replace ::spawnplayer with ::onClientEnterGame.  Also, in RTB3 there will be a feature allowing you to make players download GUIs so they don't have to download it manually, but RTB3 is not released yet.

If you need any clarification just ask.  I'm sort of tired now and am really lazy and my neck hurts.