Trying to use the Magnifier Module in AGS 3.4.1.

Started by Loslem, Sun 19/11/2017 15:40:28

Previous topic - Next topic

Loslem

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: ags

bool IsModeEnabled(this Mouse*, CursorMode mode) {
  CursorMode prevmode = this.Mode;
  this.Mode = mode;
  bool enabled = (this.Mode == mode);
  this.Mode = prevmode;
  return enabled;
}


Any ideas?

Crimson Wizard

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.

Loslem

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.

Loslem

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: ags

void Update(this MagnifierType*) {
  if ((this.AGSGUI == null) || (this.Sprite <= 0)) {
    this.Enabled = false;
    return;
  }
  if (this.prevenabled != this.Enabled) { // toggle on/off
    if ((this.HideMouseCursor) || (this.prevhidemouse)) {
      if (this.Enabled) this.HideCursor();
      else this.ShowCursor();
    }
  }
  else if ((this.prevhidemouse != this.HideMouseCursor) && (this.Enabled)) {
    if (this.HideMouseCursor) this.HideCursor();
    else this.ShowCursor();
  }
  this.prevhidemouse = this.HideMouseCursor;
  if (this.ScaleFactor <= 0.0) this.ScaleFactor = 0.1;
  this.prevenabled = this.Enabled;
  this.AGSGUI.Visible = false;
  if (!this.Enabled) return;
  this.AGSGUI.BackgroundGraphic = 0;
  this.X = mouse.x;
  this.Y = mouse.y;
  if ((this.X + this.XOffset) < 0) this.AGSGUI.X = 0;
  else if ((this.X + this.XOffset) >= System.ViewportWidth) this.AGSGUI.X = (System.ViewportWidth - 1);
  else this.AGSGUI.X = (this.X + this.XOffset);
  if ((this.Y + this.YOffset) < 0) this.AGSGUI.Y = 0;
  else if ((this.Y + this.YOffset) >= System.ViewportHeight) this.AGSGUI.Y = (System.ViewportHeight - 1);
  else this.AGSGUI.Y = (this.Y + this.YOffset);
  DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(this.Sprite, false);
  int x = (FloatToInt(IntToFloat(this.X) * this.ScaleFactor) + this.XOffset);
  int y = (FloatToInt(IntToFloat(this.Y) * this.ScaleFactor) + this.YOffset);
  sprite.ChangeCanvasSize(FloatToInt(IntToFloat(System.ViewportWidth) * this.ScaleFactor), FloatToInt(IntToFloat(System.ViewportHeight) * this.ScaleFactor), x, y);
  this.BackgroundSprite = DynamicSprite.CreateFromBackground();
  DrawingSurface *surface = this.BackgroundSprite.GetDrawingSurface();
  int i = 0;
  while ((i < Game.CharacterCount) || (i < Room.ObjectCount)) {
    if (i < Game.CharacterCount) {
      if (character[i].Room == player.Room) {
        ViewFrame *frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
        int w = ((Game.SpriteWidth[frame.Graphic] * character[i].Scaling) / 100);
        int h = ((Game.SpriteHeight[frame.Graphic] * character[i].Scaling) / 100);
        surface.DrawImage(character[i].x - (w / 2), character[i].y - h, frame.Graphic, 0, w, h);
      }
    }
    if (i < Room.ObjectCount) {
      if (object[i].Visible) {
        int graphic = object[i].Graphic;
        if (object[i].View) {
          ViewFrame *frame = Game.GetViewFrame(object[i].View, object[i].Loop, object[i].Frame);
          graphic = frame.Graphic;
        }
        int w = Game.SpriteWidth[graphic];
        int h = Game.SpriteHeight[graphic];
        if (!object[i].IgnoreScaling) {
          int scale = GetScalingAt(object[i].X, object[i].Y);
          w = ((w * scale) / 100);
          h = ((h * scale) / 100);
        }
        surface.DrawImage(object[i].X, object[i].Y - Game.SpriteHeight[graphic], graphic);
      }
    }
    i++;
  }
  surface.Release();
  this.BackgroundSprite.Resize(FloatToInt(IntToFloat(this.BackgroundSprite.Width) * this.ScaleFactor), FloatToInt(IntToFloat(this.BackgroundSprite.Height) * this.ScaleFactor));
  sprite.ChangeCanvasSize(this.BackgroundSprite.Width, this.BackgroundSprite.Height, 0, 0);
  this.BackgroundSprite.CopyTransparencyMask(sprite.Graphic);
  int w = Game.SpriteWidth[this.Sprite];
  int h = Game.SpriteHeight[this.Sprite];
  int ww = this.BackgroundSprite.Width;
  int hh = this.BackgroundSprite.Height;
  if ((ww > w) && (hh > h)) this.BackgroundSprite.Crop(x, y, w, h);
  else if (ww > w) {
    this.BackgroundSprite.Crop(x, 0, w, hh);
    if (hh < h) this.BackgroundSprite.ChangeCanvasSize(w, h, 0, (h - hh) / 2);
  }
  else if (hh > h) {
    this.BackgroundSprite.Crop(0, y, ww, h);
    if (ww < w) this.BackgroundSprite.ChangeCanvasSize(w, h, (w - ww) / 2, 0);
  }
  else this.BackgroundSprite.ChangeCanvasSize(w, h, (w - ww) / 2, (h - hh) / 2);
  if ((ww <= w) || (hh <= h)) {
    sprite = this.BackgroundSprite;
    this.BackgroundSprite = DynamicSprite.Create(w, h, false);
    surface = this.BackgroundSprite.GetDrawingSurface();
    surface.Clear(0);
    surface.DrawImage(0, 0, sprite.Graphic);
    surface.Release();
  }
  surface = this.BackgroundSprite.GetDrawingSurface();
  if (this.ScaleFactor < 1.0) {
    surface.DrawingColor = 0;
    int xm = FloatToInt(IntToFloat(System.ViewportWidth) * this.ScaleFactor);
    int xx = (x + w);
    if (x < 0) surface.DrawRectangle(0, 0, -x, surface.Height);
    if (xx >= xm) surface.DrawRectangle(xm - x, 0, xx - x, surface.Height);
    int ym = FloatToInt(IntToFloat(System.ViewportHeight) * this.ScaleFactor);
    int yy = (y + h);
    if (y < 0) surface.DrawRectangle(0, 0, surface.Width, -y);
    if (yy >= ym) surface.DrawRectangle(0, ym - y, surface.Width, yy - y);
    if ((x < 0) || (y < 0) || (xx >= xm) || (yy >= ym)) {
      surface.Release();
      sprite = DynamicSprite.CreateFromExistingSprite(this.Sprite, false);
      this.BackgroundSprite.CopyTransparencyMask(sprite.Graphic);
      surface = this.BackgroundSprite.GetDrawingSurface();
    }
  }
  surface.DrawImage(0, 0, this.Sprite);
  surface.Release();
  x = (this.X + this.XOffset);
  y = (this.Y + this.YOffset);
  int xx = (x + w);
  int yy = (y + h);
  if ((xx <= 0) || (yy <= 0) || (x >= System.ViewportWidth) || (y >= System.ViewportHeight)) {
    this.BackgroundSprite = null;
    this.AGSGUI.BackgroundGraphic = 0;
    this.AGSGUI.Width = 1;
    this.AGSGUI.Height = 1;
  }
  else {
    if ((x < 0) && (y < 0)) this.BackgroundSprite.Crop(-x, -y, this.BackgroundSprite.Width + x, this.BackgroundSprite.Height + y);
    else if (x < 0) this.BackgroundSprite.Crop(-x, 0, this.BackgroundSprite.Width + x, this.BackgroundSprite.Height);
    else if (y < 0) this.BackgroundSprite.Crop(0, -y, this.BackgroundSprite.Width, this.BackgroundSprite.Height + y);
    this.AGSGUI.BackgroundGraphic = this.BackgroundSprite.Graphic;
    this.AGSGUI.Width = this.BackgroundSprite.Width;
    this.AGSGUI.Height = this.BackgroundSprite.Height;
  }
  this.AGSGUI.Visible = true;
}

Khris

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.

SMF spam blocked by CleanTalk