Tips for creating resizable GUI controls
The variables "vertSizing" and "horizSizing" let you easily make GUI controls that resize when the parent control resizes.
vertSizing is usually either "height" or "top". A value of "height" will change the height of the control as the height of the parent control changes. A value of "top" will move the control down as the parent control's height changes.
horizSizing is usually either "width" or "height". A value of "width" will change the width of the control as the width of the parent control changes. A value of "left" will move the control to the right as the width of the parent control changes.
These can be combined to do most kinds of resizing schemes.
PHP Code:
//#CLIENTSIDE
function onCreated() {
new GuiWindowCtrl("Test_Window") {
profile = GuiBlueWindowProfile;
clientRelative = true;
clientWidth = 300;
clientHeight = 300;
x = (GraalControl.width - width) / 2;
y = (GraalControl.height - height) / 2;
text = "Test Window";
new GuiControl("Test_Object1") {
useOwnProfile = true;
profile.opaque = true;
profile.fillColor = {100, 100, 100};
width = 100;
height = 215;
x = 5;
y = 5;
// do nothing as the window grows wider
horizSizing = "";
// grow taller as the window grows taller
vertSizing = "height";
}
new GuiControl("Test_Object2") {
useOwnProfile = true;
profile.opaque = true;
profile.fillColor = {150, 100, 200};
width = 185;
height = 215;
x = 110;
y = 5;
// grow wider as the window grows wider
horizSizing = "width";
// grow taller as the window grows taller
vertSizing = "height";
}
new GuiControl("Test_Object3") {
useOwnProfile = true;
profile.opaque = true;
profile.fillColor = {150, 100, 100};
width = 290;
height = 70;
x = 5;
y = 225;
// grow wider as the window grows wider
horizSizing = "width";
// move down as the window grows taller
vertSizing = "top";
}
}
}
produces this:
There are also other values for
vertSizing and
horizSizing, but I have never needed to use them. Their names should be self-explanatory.
Quote:
GuiControl.horizsizing - string - specifies the horizontal resizing behaviour when the parent control is resized: right, width, left, center or relative
GuiControl.vertsizing - string - specifies the vertical resizing behaviour when the parent control is resized: bottom, height, top, center or relative
|
Creating custom objects types
While it's not really possible to create custom object types, you can use a few tricks to replicate the functionality.
For example, let's say you're making a mail system for players to send mail back and forth, but also for scripts to send mail to players. You could do this by joining a class to every script that needs to send mail or by using a public function, but there's an even cleaner way.
First, you will need a database NPC to make the object.
PHP Code:
// database NPC "Mail"
function onCreated() {
MailMessage = new TStaticVar();
MailMessage.join("mail_message");
}
// recreate the object when the server restarts
function onInitialized() {
this.onCreated();
}
What this does is makes a global object with the name "MailMessage" and joins it to the class "mail_message". Inside the class "mail_message" we can have functions.
PHP Code:
public function send() {
// replace this with the code to store the message
printf("Sending a message to '%s' from '%s' with subject '%s' and message '%s'.", this. recipient, this.sender, this.subject, this.text);
}
Now, from any script you can do the following to send a mail message:
PHP Code:
temp.msg = new MailMessage();
msg.recipient = "cbk1994";
msg.sender = "(npcserver)";
msg.subject = "Hello world!";
msg.text = "Did it work?";
msg.send();
This technique can be used both serverside and clientside. It is especially useful for cases where passing parameters as an array would be inconvenient. I wrote a custom projectile script a few weeks back that used the same syntax as the mail message script above for parameters like "angle". It's a lot more coder-friendly than "shoot(32, 42, 0.4, 0, 0, ...)"