Text Cuts Off On The Overhotspot Gui

Started by Ghostlady, Yesterday at 04:52:02

Previous topic - Next topic

Ghostlady

I have text getting cut off on the far right hand side of the screen when it is close to the edge when it displays the label on a hotspot.

I've messed with it and can't make it stop.  Screen resolution is 640 x 480.
gGui9 is the overhotspot gui. It's dimensions are 90 (w) x 80 (h) and its label 88 (w) by 78 (h). 

This is what I have in the global script:
Code: ags
  if (mouse.y > 240/2) y = mouse.y - 10;
      else y = mouse.y+10;
  if (mouse.x > 320/2) x = mouse.x -10;
      else x = mouse.x+10;
  gGui9.SetPosition(mouse.x, mouse.y);

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Snarky

Quote from: Ghostlady on Yesterday at 04:52:02This is what I have in the global script:

The values are probably wrong (keep in mind that you're positioning the top left corner of the GUI, so mouse.x-10 will have the label run through the cursor), but from the image, it doesn't look like this code runs at all (or if it does, it is overridden by some other code). Where in the global script is it, and have you confirmed that it runs?

Ghostlady

#2
It's in the repeatedly execute area.  I did have the X and Y set to -20 but I changed it to 10.  I did a search on the script and did not find any other references to that gui.
Yes it does run through that code.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Crimson Wizard

#3
How to prevent GUI from going offscreen:

Code: ags
   if (x < 0)
      x = 0;
   if (x + gGui9.Width > Screen.Width)
      x = Screen.Width - gGui9.Width;

Other recommendations: don't use literal numbers for things like screen size, use available script properties (Screen.Width, Screen.Height, Room.Width, Room.Height etc). You may be reusing same code elsewhere, and if you use properties, then it will keep working without modifications. Also less chance to make a typo.

Name your guis according to their purpose. For example, instead of gGui9 you could name it gOverhotspot. Then you will never wonder what is "gui9" if you ever return back to your game after a while.

Ghostlady

When I use that code, it puts the text on the other side of the room.  See image. The cursor is on the doorknob on the bottom to leave the room but the text is on the far right at top.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Crimson Wizard

Quote from: Ghostlady on Today at 02:20:52When I use that code, it puts the text on the other side of the room.  See image. The cursor is on the doorknob on the bottom to leave the room but the text is on the far right at top.

It should not be happening. Please post the code that you have now.

EDIT: also, I noticed that the code that you posted earlier is strange. You are assigning x & y variables, but gGui9 is still set as "gGui9.SetPosition(mouse.x, mouse.y);". What were you using x and y for then?

Ghostlady

I am posting everything in the repeatedly execute function in the global script. There is a bunch of commented lines due to me trying things.

Code: ags
#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
  // put anything you want to happen every game cycle here
  
//Old cursor logic 
//  if (GetLocationType(mouse.x,mouse.y) > 0) {
//     if(Mouse.Mode!=eModeUseinv) mouse.UseModeGraphic(eModePointer);}
//  else {
//     Mouse.UseDefaultGraphic(); }
//Old cursor logic end  

//New cursor logic 
  if (GetLocationType(mouse.x,mouse.y) != eLocationNothing) {
      if(Mouse.Mode!=eModeUseinv)  {
//      if (player == cWoman)  Mouse.UseModeGraphic(eModeDapHandU);
      if ((player == cWoman) && (!IsGamePaused())) Mouse.UseModeGraphic(eModeDapHandU);
//    if (player == cWoman)  Mouse.ChangeModeGraphic(eModeInteract, 485);
//    if (player == cMan) Mouse.UseModeGraphic(eModePointer); } }
      if ((player == cMan) && (!IsGamePaused())) Mouse.UseModeGraphic(eModePointer); } }
//    if (player == cMan) Mouse.ChangeModeGraphic(eModeInteract,  16); } }
   else { Mouse.UseDefaultGraphic (); }
   //New cursor logic end
     
  if (player == cWoman) {
     StrFormat(herscore,"  Puzzles:  %d",GetGlobalInt(10));   
     ScoreHer.SetText(herscore);
     ScoreHer.TextColor = cWoman.SpeechColor; }
   
  if (player == cMan) { 
     StrFormat(hisscore,"  Puzzles:  %d",GetGlobalInt(20));   
     ScoreHim.SetText(hisscore);
     ScoreHim.TextColor = cMan.SpeechColor; } 
 
//  x = mouse.x + 20;
//  y = mouse.y + 20;

//  if (x - gGui9.Width > 320) { 
//      x = 320 - gGui9.Width; }
//  if (y - gGui9.Height > 200) { 
//      y = 200 - gGui9.Height; }
//  gGui9.SetPosition(mouse.x, mouse.y);

   if (x < 0)
      x = 0;
   if (x + gGui9.Width > Screen.Width)
      x = Screen.Width - gGui9.Width;

  
//  if (mouse.y > 240/2) y = mouse.y - 20;
//      else y = mouse.y+10;
//  if (mouse.x > 320/2) x = mouse.x - 20;
//      else x = mouse.x+10;
//  gGui9.SetPosition(mouse.x, mouse.y);

  if (player == cWoman) {
      charcolor.TextColor = cWoman.SpeechColor; }
  if (player == cMan) {
      charcolor.TextColor = cMan.SpeechColor; }
      
  if(gGui1.Visible) {
    if(   mouse.x < gGui1.X - CLOSING_DISTANCE
       || mouse.x > gGui1.X + gGui1.Width  + CLOSING_DISTANCE
       || mouse.y < gGui1.Y - CLOSING_DISTANCE
       || mouse.y > gGui1.Y + gGui1.Height + CLOSING_DISTANCE)
          gGui1.Visible = false;
          gGui3.Visible = true;
  }
   
  if (player.ActiveInventory == icigarbox) mouse.ChangeModeGraphic (eModeUseinv,  46); 
      else if (player.ActiveInventory == ijarcinn) mouse.ChangeModeGraphic (eModeUseinv, 295);
      else if (player.ActiveInventory == ijargarlic) mouse.ChangeModeGraphic (eModeUseinv, 296);
      else if (player.ActiveInventory == ijarcloves) mouse.ChangeModeGraphic (eModeUseinv, 297);
      else if (player.ActiveInventory == imatch) mouse.ChangeModeGraphic (eModeUseinv, 371);
      else if (player.ActiveInventory == ipicklejar) mouse.ChangeModeGraphic (eModeUseinv, 248);
      else if (player.ActiveInventory == icuestick) mouse.ChangeModeGraphic (eModeUseinv, 262);
      else if (player.ActiveInventory == irifle) mouse.ChangeModeGraphic (eModeUseinv, 292);
      else if (player.ActiveInventory == imousetrap) mouse.ChangeModeGraphic (eModeUseinv, 259);
      else if (player.ActiveInventory == imusicbook) mouse.ChangeModeGraphic (eModeUseinv, 254);
      else if (player.ActiveInventory == icowboyhat) mouse.ChangeModeGraphic (eModeUseinv, 258);
      else if (player.ActiveInventory == ioars) mouse.ChangeModeGraphic (eModeUseinv, 286);
      else if (player.ActiveInventory == itape) mouse.ChangeModeGraphic (eModeUseinv, 277);
      else if (player.ActiveInventory == iislandpic) mouse.ChangeModeGraphic (eModeUseinv, 390);
      else if (player.ActiveInventory == ikey) mouse.ChangeModeGraphic (eModeUseinv, 284);
      else if (player.ActiveInventory == igrisgris) mouse.ChangeModeGraphic (eModeUseinv, 134);
      else if (player.ActiveInventory == igrisspice) mouse.ChangeModeGraphic (eModeUseinv, 135);
      else if (player.ActiveInventory == iknife) mouse.ChangeModeGraphic (eModeUseinv, 383);
      else if (player.ActiveInventory == iberyl) mouse.ChangeModeGraphic (eModeUseinv, 301);
      else if (player.ActiveInventory == icheese) mouse.ChangeModeGraphic (eModeUseinv, 370);
      else if (player.ActiveInventory == iTeacup) mouse.ChangeModeGraphic (eModeUseinv, 391);
      else if (player.ActiveInventory == ibourbon) mouse.ChangeModeGraphic (eModeUseinv, 281);
      else if (player.ActiveInventory == isugarcubes) mouse.ChangeModeGraphic (eModeUseinv, 52);
      else if (player.ActiveInventory == ijulepglass) mouse.ChangeModeGraphic (eModeUseinv, 283);
      else if (player.ActiveInventory == icompletejulep) mouse.ChangeModeGraphic (eModeUseinv, 55);
      else if (player.ActiveInventory == ipitcher) mouse.ChangeModeGraphic (eModeUseinv, 279);
      else if (player.ActiveInventory == imint) mouse.ChangeModeGraphic (eModeUseinv, 60);
      else if (player.ActiveInventory == igrstopper) mouse.ChangeModeGraphic (eModeUseinv, 69);
      else if (player.ActiveInventory == ipinkstopper) mouse.ChangeModeGraphic (eModeUseinv, 70);
      else if (player.ActiveInventory == igrstopperbg) mouse.ChangeModeGraphic (eModeUseinv, 71);
      else if (player.ActiveInventory == ipinkstopper2) mouse.ChangeModeGraphic (eModeUseinv, 72);
      else if (player.ActiveInventory == isoap) mouse.ChangeModeGraphic (eModeUseinv, 400);
      else if (player.ActiveInventory == ieasel) mouse.ChangeModeGraphic (eModeUseinv, 261);
      else if (player.ActiveInventory == istone) mouse.ChangeModeGraphic (eModeUseinv, 267);
      else if (player.ActiveInventory == ivoodoodoll) mouse.ChangeModeGraphic (eModeUseinv, 271);
      else if (player.ActiveInventory == ifurniture) mouse.ChangeModeGraphic (eModeUseinv, 273);
      else if (player.ActiveInventory == isetvoodoo) mouse.ChangeModeGraphic (eModeUseinv, 275);
      else if (player.ActiveInventory == ipeppermint) mouse.ChangeModeGraphic (eModeUseinv, 290);
      else if (player.ActiveInventory == iteapepper) mouse.ChangeModeGraphic (eModeUseinv, 407);
      else if (player.ActiveInventory == igemstones) mouse.ChangeModeGraphic (eModeUseinv, 408);
      else if (player.ActiveInventory == igemstonesc) mouse.ChangeModeGraphic (eModeUseinv, 408);
      
}
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Crimson Wizard

#7
The code snippet that I posted earlier was only for clamping the x coordinate to the screen, nothing else. It has to be combined with the previously existed code to achieve result.

But now I see that you practically had the same code already, except you used hardcoded sizes, but idea was the same. The *only* mistake was that instead of using results of x and y variables when setting gui position, you used mouse.x, mouse.y again, thus all the calculations were lost.

The correct code might look something like:
Code: ags
int x = mouse.x + 20;
int y = mouse.y + 20;

if (x < 0)
    x = 0;
if (x + gGui9.Width > Screen.Width)
    x = Screen.Width - gGui9.Width;
if (y < 0)
    y = 0;
if (y + gGui9.Height > Screen.Height)
    y = Screen.Height - gGui9.Height;

gGui9.SetPosition(x, y); // <---- notice how SetPosition is using previously calculated x and y

Crimson Wizard

Another thing, since I see the code now, there are lots of lines like:

Code: ags
if (player.ActiveInventory == icigarbox) mouse.ChangeModeGraphic (eModeUseinv,  46); 

I suppose this is for setting cursor to the chosen inventory item.
Normally you should not be doing that, but assign inventory item's "CursorImage" property in the editor, then the cursor will switch to it automatically.

Ghostlady

I have two images for each inventory item.  One very small that sizes correctly to the room and used for the cursor. Then a larger size that goes into the inventory box.  This code is from 2004. I didn't go through the whole game and change things except where needed. Are you saying this can be done where the inventory items are defined?  I think the new things I've added I did that.  If so I could probably update all the inventory items and remove that code pretty easily.

In reference to an above comment about naming conventions, I learned that the hard way when I have to go through the list of gui's and figure out what is what. Second time around with this game and I now name them so they are easily recognizable but didn't go and rename all the older ones.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Ghostlady

This one with the new code looks better but seems a little too low and too right.  Potentially could disappear from the screen if mouse is moved lower.

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Crimson Wizard

#11
Quote from: Ghostlady on Today at 03:33:24This one with the new code looks better but seems a little too low and too right.  Potentially could disappear from the screen if mouse is moved lower.

I used these lines from your code:
Code: ags
int x = mouse.x + 20;
int y = mouse.y + 20;
You may adjust these to change the relation between the mouse position and the gui.

The gui should not disappear from the screen, that's what the clamping code is preventing. It's possible to test what happens if you put some hotspot at the very screen's edge.

Ghostlady

I changed Mouse X & Y to 10 instead of 20 and that helped. But none of this fixed the cutoff on the right-hand side of the screen.  It still looks the same as the first picture I posted.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Crimson Wizard

Quote from: Ghostlady on Today at 03:45:48I changed Mouse X & Y to 10 instead of 20 and that helped. But none of this fixed the cutoff on the right-hand side of the screen.  It still looks the same as the first picture I posted.

Please post the code you are currently using? (not the full code, but the part related to the positioning of this gui)

I cannot see the screenshots, most of them do not load up for me for some reason.

Ghostlady

How weird you can't see my screenshots. I can create a little YouTube if you need to see it.

Here's the code: I removed the int x and int y because there was already an int at the top of the script.

Code: ags
x = mouse.x + 10;
y = mouse.y + 10;

if (x < 0)
    x = 0;
if (x + gGui9.Width > Screen.Width)
    x = Screen.Width - gGui9.Width;
if (y < 0)
    y = 0;
if (y + gGui9.Height > Screen.Height)
    y = Screen.Height - gGui9.Height;

gGui9.SetPosition(x, y); // <---- notice how SetPosition is using previously calculated x and y
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Crimson Wizard

#15
Quote from: Ghostlady on Today at 03:52:02How weird you can't see my screenshots. I can create a little YouTube if you need to see it.

You could perhaps use some image hosting, like imgur (maybe there are others)?

EDIT: Hmm, actually, it finally loaded for me. Maybe that was a temporary problem.


I'm using exact same code in a dummy game, and it prevents the gui from going off screen.

Could you double check that gGui9 is not changed anywhere below? And that it actually is a gui with overhotspot text?


Ghostlady

I did a search on the whole global script and that's the only place gGui9 is referenced.  I am for sure it is the overhotspot text.
Could it be the "old" game coming into play?  The resolution or bitrate?  It's bit me before.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Crimson Wizard

#17
Quote from: Ghostlady on Today at 04:23:10Could it be the "old" game coming into play?  The resolution or bitrate?  It's bit me before.

So, I've got an idea.

Earlier you mentioned that your game is 640x480.
If you go to General Settings -> Backwards Compatibility, do you have "Use low resolution co-ordinates in script" enabled?

If so, try using Screen.Width / 2 and Height / 2 instead:

Code: ags
<...>
if (x + gGui9.Width > Screen.Width / 2)
    x = Screen.Width / 2 - gGui9.Width;
<...>
if (y + gGui9.Height > Screen.Height / 2)
    y = Screen.Height / 2 - gGui9.Height;

Alternatively you may try using a old-style System.ViewportWidth and System.ViewportHeight without division by 2, because iirc they should account for the old games coordinates division:

Code: ags
<...>
if (x + gGui9.Width > System.ViewportWidth)
    x = System.ViewportWidth - gGui9.Width;
<...>
if (y + gGui9.Height > System.ViewportHeight)
    y = System.ViewportHeight - gGui9.Height;

Ghostlady

I do have that option enabled.  Now it looks like it is going to middle of the screen.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Crimson Wizard

#19
Quote from: Ghostlady on Today at 05:03:02I do have that option enabled.  Now it looks like it is going to middle of the screen.

I had to recreate this situation in a test game, 640x400 resolution, "Use low-res coordinates" On.
Either of the above code variants is working for me (the one with "/2", and the one with the System.ViewportWidth).

EDIT: I had a typo in the second variant, it should be just System.ViewportWidth, without "/2".

Which variant did you use in the end? Please post the code that you have.

SMF spam blocked by CleanTalk