Adventure Game Studio | Forums

AGS Support => Advanced Technical Forum => Topic started by: Loslem on 19 Nov 2017, 15:40

Title: Trying to use the Magnifier Module in AGS 3.4.1.
Post by: Loslem on 19 Nov 2017, 15:40
Hi guys!

Trying to avoid necroposting here. If an admin thinks this belongs to the module thread, I'm begging your pardon :/

So, I upgraded to the newest AGS Version. Looks, nice, works nice, all good.

I wanna use the Magnifier-Module for animating a Sniper-Crosshair while using a rifle.
So far so good. I used the magnifier Module before, in AGS 3.2.1. and it worked.
So, I set up the code provided by the Manual, but this time I got the error "Attributes of identifier do not match prototype", and it refers the first line of this chunk of code from the magnifier.ash.


Code: Adventure Game Studio
  1. bool IsModeEnabled(this Mouse*, CursorMode mode) {
  2.   CursorMode prevmode = this.Mode;
  3.   this.Mode = mode;
  4.   bool enabled = (this.Mode == mode);
  5.   this.Mode = prevmode;
  6.   return enabled;
  7. }

Any ideas?
Title: Re: Trying to use the Magnifier Module in AGS 3.4.1.
Post by: Crimson Wizard on 19 Nov 2017, 16:12
Mouse.IsModeEnabled was added to AGS built-in functions in 3.4.1, which means that you need to disable (comment out) it in the script module.
Title: Re: Trying to use the Magnifier Module in AGS 3.4.1.
Post by: Loslem on 19 Nov 2017, 16:39
Aha, yes that worked!
Thank you so much :)

Ah By the way... I just realized it doens't work in scrolling rooms... I'll check if anything is mentioned in the Module Thread.
Title: Re: Trying to use the Magnifier Module in AGS 3.4.1.
Post by: Loslem on 01 Dec 2017, 16:16
Hi! Smee again!

I have a further question:
If I have a scrolling room, aand I enable the magnifier - The picture behind the magnifier (which I think is the dynamic sprite from the background) will only show magnified whats in the first picture of the room, regarding my room resolution. So put simple: I walk right, the room scrolls, the magnifier acts as if the room would not scroll.
I know it's asked way to much of you to go trough all the Modules Code, if you don't have time/mood it's okay.



Code: Adventure Game Studio
  1. void Update(this MagnifierType*) {
  2.   if ((this.AGSGUI == null) || (this.Sprite <= 0)) {
  3.     this.Enabled = false;
  4.     return;
  5.   }
  6.   if (this.prevenabled != this.Enabled) { // toggle on/off
  7.     if ((this.HideMouseCursor) || (this.prevhidemouse)) {
  8.       if (this.Enabled) this.HideCursor();
  9.       else this.ShowCursor();
  10.     }
  11.   }
  12.   else if ((this.prevhidemouse != this.HideMouseCursor) && (this.Enabled)) {
  13.     if (this.HideMouseCursor) this.HideCursor();
  14.     else this.ShowCursor();
  15.   }
  16.   this.prevhidemouse = this.HideMouseCursor;
  17.   if (this.ScaleFactor <= 0.0) this.ScaleFactor = 0.1;
  18.   this.prevenabled = this.Enabled;
  19.   this.AGSGUI.Visible = false;
  20.   if (!this.Enabled) return;
  21.   this.AGSGUI.BackgroundGraphic = 0;
  22.   this.X = mouse.x;
  23.   this.Y = mouse.y;
  24.   if ((this.X + this.XOffset) < 0) this.AGSGUI.X = 0;
  25.   else if ((this.X + this.XOffset) >= System.ViewportWidth) this.AGSGUI.X = (System.ViewportWidth - 1);
  26.   else this.AGSGUI.X = (this.X + this.XOffset);
  27.   if ((this.Y + this.YOffset) < 0) this.AGSGUI.Y = 0;
  28.   else if ((this.Y + this.YOffset) >= System.ViewportHeight) this.AGSGUI.Y = (System.ViewportHeight - 1);
  29.   else this.AGSGUI.Y = (this.Y + this.YOffset);
  30.   DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(this.Sprite, false);
  31.   int x = (FloatToInt(IntToFloat(this.X) * this.ScaleFactor) + this.XOffset);
  32.   int y = (FloatToInt(IntToFloat(this.Y) * this.ScaleFactor) + this.YOffset);
  33.   sprite.ChangeCanvasSize(FloatToInt(IntToFloat(System.ViewportWidth) * this.ScaleFactor), FloatToInt(IntToFloat(System.ViewportHeight) * this.ScaleFactor), x, y);
  34.   this.BackgroundSprite = DynamicSprite.CreateFromBackground();
  35.   DrawingSurface *surface = this.BackgroundSprite.GetDrawingSurface();
  36.   int i = 0;
  37.   while ((i < Game.CharacterCount) || (i < Room.ObjectCount)) {
  38.     if (i < Game.CharacterCount) {
  39.       if (character[i].Room == player.Room) {
  40.         ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
  41.         int w = ((Game.SpriteWidth[frame.Graphic] * character[i].Scaling) / 100);
  42.         int h = ((Game.SpriteHeight[frame.Graphic] * character[i].Scaling) / 100);
  43.         surface.DrawImage(character[i].x - (w / 2), character[i].y - h, frame.Graphic, 0, w, h);
  44.       }
  45.     }
  46.     if (i < Room.ObjectCount) {
  47.       if (object[i].Visible) {
  48.         int graphic = object[i].Graphic;
  49.         if (object[i].View) {
  50.           ViewFrame *frame = Game.GetViewFrame(object[i].View, object[i].Loop, object[i].Frame);
  51.           graphic = frame.Graphic;
  52.         }
  53.         int w = Game.SpriteWidth[graphic];
  54.         int h = Game.SpriteHeight[graphic];
  55.         if (!object[i].IgnoreScaling) {
  56.           int scale = GetScalingAt(object[i].X, object[i].Y);
  57.           w = ((w * scale) / 100);
  58.           h = ((h * scale) / 100);
  59.         }
  60.         surface.DrawImage(object[i].X, object[i].Y - Game.SpriteHeight[graphic], graphic);
  61.       }
  62.     }
  63.     i++;
  64.   }
  65.   surface.Release();
  66.   this.BackgroundSprite.Resize(FloatToInt(IntToFloat(this.BackgroundSprite.Width) * this.ScaleFactor), FloatToInt(IntToFloat(this.BackgroundSprite.Height) * this.ScaleFactor));
  67.   sprite.ChangeCanvasSize(this.BackgroundSprite.Width, this.BackgroundSprite.Height, 0, 0);
  68.   this.BackgroundSprite.CopyTransparencyMask(sprite.Graphic);
  69.   int w = Game.SpriteWidth[this.Sprite];
  70.   int h = Game.SpriteHeight[this.Sprite];
  71.   int ww = this.BackgroundSprite.Width;
  72.   int hh = this.BackgroundSprite.Height;
  73.   if ((ww > w) && (hh > h)) this.BackgroundSprite.Crop(x, y, w, h);
  74.   else if (ww > w) {
  75.     this.BackgroundSprite.Crop(x, 0, w, hh);
  76.     if (hh < h) this.BackgroundSprite.ChangeCanvasSize(w, h, 0, (h - hh) / 2);
  77.   }
  78.   else if (hh > h) {
  79.     this.BackgroundSprite.Crop(0, y, ww, h);
  80.     if (ww < w) this.BackgroundSprite.ChangeCanvasSize(w, h, (w - ww) / 2, 0);
  81.   }
  82.   else this.BackgroundSprite.ChangeCanvasSize(w, h, (w - ww) / 2, (h - hh) / 2);
  83.   if ((ww <= w) || (hh <= h)) {
  84.     sprite = this.BackgroundSprite;
  85.     this.BackgroundSprite = DynamicSprite.Create(w, h, false);
  86.     surface = this.BackgroundSprite.GetDrawingSurface();
  87.     surface.Clear(0);
  88.     surface.DrawImage(0, 0, sprite.Graphic);
  89.     surface.Release();
  90.   }
  91.   surface = this.BackgroundSprite.GetDrawingSurface();
  92.   if (this.ScaleFactor < 1.0) {
  93.     surface.DrawingColor = 0;
  94.     int xm = FloatToInt(IntToFloat(System.ViewportWidth) * this.ScaleFactor);
  95.     int xx = (x + w);
  96.     if (x < 0) surface.DrawRectangle(0, 0, -x, surface.Height);
  97.     if (xx >= xm) surface.DrawRectangle(xm - x, 0, xx - x, surface.Height);
  98.     int ym = FloatToInt(IntToFloat(System.ViewportHeight) * this.ScaleFactor);
  99.     int yy = (y + h);
  100.     if (y < 0) surface.DrawRectangle(0, 0, surface.Width, -y);
  101.     if (yy >= ym) surface.DrawRectangle(0, ym - y, surface.Width, yy - y);
  102.     if ((x < 0) || (y < 0) || (xx >= xm) || (yy >= ym)) {
  103.       surface.Release();
  104.       sprite = DynamicSprite.CreateFromExistingSprite(this.Sprite, false);
  105.       this.BackgroundSprite.CopyTransparencyMask(sprite.Graphic);
  106.       surface = this.BackgroundSprite.GetDrawingSurface();
  107.     }
  108.   }
  109.   surface.DrawImage(0, 0, this.Sprite);
  110.   surface.Release();
  111.   x = (this.X + this.XOffset);
  112.   y = (this.Y + this.YOffset);
  113.   int xx = (x + w);
  114.   int yy = (y + h);
  115.   if ((xx <= 0) || (yy <= 0) || (x >= System.ViewportWidth) || (y >= System.ViewportHeight)) {
  116.     this.BackgroundSprite = null;
  117.     this.AGSGUI.BackgroundGraphic = 0;
  118.     this.AGSGUI.Width = 1;
  119.     this.AGSGUI.Height = 1;
  120.   }
  121.   else {
  122.     if ((x < 0) && (y < 0)) this.BackgroundSprite.Crop(-x, -y, this.BackgroundSprite.Width + x, this.BackgroundSprite.Height + y);
  123.     else if (x < 0) this.BackgroundSprite.Crop(-x, 0, this.BackgroundSprite.Width + x, this.BackgroundSprite.Height);
  124.     else if (y < 0) this.BackgroundSprite.Crop(0, -y, this.BackgroundSprite.Width, this.BackgroundSprite.Height + y);
  125.     this.AGSGUI.BackgroundGraphic = this.BackgroundSprite.Graphic;
  126.     this.AGSGUI.Width = this.BackgroundSprite.Width;
  127.     this.AGSGUI.Height = this.BackgroundSprite.Height;
  128.   }
  129.   this.AGSGUI.Visible = true;
  130. }
  131.  
Title: Re: Trying to use the Magnifier Module in AGS 3.4.1.
Post by: Khris on 01 Dec 2017, 17:04
The module was clearly built without thinking about scrolling rooms.
It also ignores character transparency.

The best way to move forward I guess is to post in the module's thread / PM monkey.