Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Anchoring Knockoff. (https://forums.graalonline.com/forums/showthread.php?t=87462)

Mark Sir Link 08-18-2009 09:18 AM

Anchoring Knockoff.
 
Trying to emulate the anchoring support I asked for.

It appears to be hitting the proper case in switch statement, yet does not set x and y accordingly.

Adding debug checks such as "player.chat = this.ANCHOR_TOP[0] - (GControl.width / 2);" give me the position I want, but the x/y always ends up being 0.

edit: also not complete, once I get this issue out of the way I'll add x-y offsets as well.

PHP Code:

function onCreated()
{
findplayer("mark sir link").addweapon(this.name);
}

//#CLIENTSIDE
function onCreated()
{
  
this.ANCHOR_TOP = {screenwidth/20}; //12 O'Clock
  
this.ANCHOR_TOPRIGHT = {screenwidth0}; //between 1-2 O'Clock
  
this.ANCHOR_RIGHT = {screenwidthscreenheight/2}; //3 O'Clock
  
this.ANCHOR_BOTTOMRIGHT = {screenwidthscreenheight}; //between 4-5 O'Clock
  
this.ANCHOR_BOTTOM = {screenwidth/2screenheight}; //6 O'Clock
  
this.ANCHOR_BOTTOMLEFT = {0screenheight}; //between 7-8 O'Clock
  
this.ANCHOR_LEFT = {0screenheight/2}; //9 O'Clock
  
this.ANCHOR_TOPLEFT = {00}; //between 10-11 O'Clock
  
  
this.ANCHORS = {ANCHOR_TOPANCHOR_TOPRIGHTANCHOR_RIGHTANCHOR_BOTTOMRIGHTANCHOR_BOTTOMANCHOR_BOTTOMLEFTANCHOR_LEFTANCHOR_TOPLEFT};  

  new 
GuiWindowCtrl("Test_Window") {
  
profile "GuiBlueWindowProfile";
  
this.anchor "TOP";
  
width 160;
  
height 80;
  
text "Window";
  
canmove true;
  
editing true;
  
canclose true;
  
destroyonhide true;
}
  
anchorPosition(Test_Window);

}


function 
anchorPosition(GControl)
{
  
with(GControl)
  {
    switch (
this.anchor)
    {
    case 
"TOP":
      
text thiso.test;
      
thiso.ANCHOR_TOP[0] - (width 2);
      
thiso.ANCHOR_TOP[1];
      break;
    case 
"TOPRIGHT":
      
thiso.ANCHOR_TOPRIGHT[0] - width;
      
thiso.ANCHOR_TOPRIGHT[1];
      break;
    case 
"RIGHT":
      
thiso.ANCHOR_RIGHT[0] - width;
      
thiso.ANCHOR_RIGHT[1] - (height 2);
      break;
    case 
"BOTTOMRIGHT":
      
thiso.ANCHOR_BOTTOMRIGHT[0] - width;
      
thiso.ANCHOR_BOTTOMRIGHT[1] - height;
      break;
    case 
"BOTTOM":
      
thiso.ANCHOR_BOTTOM[0] - (width 2);
      
thiso.ANCHOR_BOTTOM[1] - height;
      break;
    case 
"BOTTOMLEFT":
      
thiso.ANCHOR_BOTTOMLEFT[0];
      
thiso.ANCHOR_BOTTOMLEFT[1]; - height;
      break;
    case 
"LEFT":
      
thiso.ANCHOR_LEFT[0];
      
thiso.ANCHOR_LEFT[1] - (height 2);
      break;
    case 
"TOPLEFT":
      
thiso.ANCHOR_TOPLEFT[0];
      
thiso.ANCHOR_TOPLEFT[1];
      break;
    default:
      
0;
      
0;
    }
  }



Deas_Voice 08-18-2009 09:21 AM

picture?
image?
screenshot!?

Mark Sir Link 08-18-2009 09:23 AM

I fell through every case like a *****. Not scripting in awhile has taken it's toll.

I edited the code with the fixed version.

WhiteDragon 08-18-2009 06:31 PM

Just a comment on the code, you should either use const/enum, or not use the all-caps convention associated with constants when they aren't.

Although, const/enum can be problematic since they just replace the variables at compile-time, so if you do anything dynamic with them it'll fail.

An alternative route would be to use a TStaticVar:
PHP Code:

this.anchors = new TStaticVar();
this.anchors.top = {screenwidth/20};
this.anchors.topRight = {screenwidth0}; 

Glad you got it working though.

fowlplay4 08-20-2009 06:11 PM

Your anchors will need to update if the player re-sizes the window, so why bother with those this.anchor.var's at all.

The default needs a break too.


All times are GMT +2. The time now is 05:49 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.