[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Miniwindows
. . -> [Subject]  Changing the background messes with slider

Changing the background messes with slider

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Fri 01 Apr 2016 01:34 PM (UTC)
Message
I've tried countless times to fix this issue as I didn't want to try to explain what I've built on here, but have had no luck so here goes...

I built a button that you can drag within a track to resize a couple mini-windows horizontally.

I made it so the track doesn't appear until you mouseover it.

The problem is whenever I change the background image, it messes up my slider, like the positions go all screwy. It still works, but everything connected to it is off.

Let me try to explain this with a couple screen shots.

In the first screenshot, I have dragged the slider up, and you can see how the separator line and the windows are perfect right on top of it.

http://i.imgur.com/OxrMcYt.png

In the second screenshot, I have changed the background, and started to drag it. See how the line is now underneath it? Now if I change the background image again, it becomes even more messed up.

http://i.imgur.com/XGXnBZC.png

This completely baffles me as the background image shouldn't mess with that at all.

Here's some code to show how the background image shouldn't mess with my slider.

This is from a settings menu I built, so here's one of the elseif statements when a different background is selected.

 elseif result == "4" then
    filename = nil
    SetVariable("castle_checked", "two")
	DeleteVariable("bgColour")
    print("Background Selected: Castle 2")
    SetBackgroundImage(GetInfo (66) .. "Generic/layout/outer_background_two.png", 0)


Pretty simple right? So why does it mess with my slider?

Now the more complicated code. I basically took what I learned from being able to drag an image inside a window and made a horizontal slider.
http://www.gammon.com.au/forum/?id=13327



Ok, so I was going to post the full code, but it is very long and quite complicated, and doesn't help at all why the background image would mess with it.

So here's just the dragging part of it, and as you see it doesn't use any info that has to deal with the background image.


function drag_resize(flags, hotspot_id)
 button_y_current = GetInfo(284)
 delta_y = button_y_current-button_y_original+WINDOW_BORDER_Y
 -- keep it from going past the track
 if delta_y > 55 then
  delta_y = 55
 elseif delta_y < -30 then
  delta_y = -30
 end
 WindowRectOp (chat_border_button, 2, 0, 0, 0, 0, ColourNameToRGB("black")) -- clear window
 DrawThemed3DRect(chat_border_button, 5, 0, 10, 100) -- slider track
 DrawThemed3DRect(chat_border_button, 0, delta_y + 31, 15, delta_y + 15 + 31) -- draggable slider button
 points_sep = string.format ("%i,%i,%i,%i,%i,%i", 3, delta_y + 5 + 31, 7, delta_y + 9 + 31, 11, delta_y + 5 + 31) -- down arrow
 WindowPolygon (chat_border_button, points_sep,
    theme.DETAIL, miniwin.pen_solid, 1,   -- pen (solid, width 1)
    theme.DETAIL, miniwin.brush_solid, --brush (solid)
    true, --close
    false) --alt fill
 WindowMoveHotspot(chat_border_button, "seperator", 0, delta_y + 30, 15, delta_y + 16 + 30)	
 WINDOW_SEPERATOR_TOP = delta_y + 76
 window_seperator_line () -- so seperator line moves to give visual of where windows will be when done dragging
 Redraw()
end -- function drag_resize


I can drag the slider up and down a hundred times without a single problem, but the moment I change the background image, everything around the slider goes off.

I wasn't quite sure how to explain this problem, so hopefully I've got the point across what is going on.
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Fri 01 Apr 2016 03:16 PM (UTC)
Message
I think I need to be able to run the plugin to answer this.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #2 on Fri 01 Apr 2016 05:38 PM (UTC)

Amended on Fri 01 Apr 2016 06:15 PM (UTC) by Wuggly

Message
Thanks for looking into it. The code is quite a mess except towards the bottom where I finally started organizing and cleaning it all up. This is also where the dragging code is.

Most everything is labeled in the code.

You can download the plugin here..
http://s000.tinyupload.com/index.php?file_id=95470391194836454418

The dll's in it are actually straight from your aardwolf github, another player from that mud helped me put together a plugin updater so that's why those are in there. heh.

Anyways, just extract it into your main MUSHclient folder, and load up the plugin. It's in the Generic/worlds/plugins folder.

Reason it's setup like that is I wanted to keep everything in it's own folder so it could easily be removed, which now with the updater I'll have to think of another way..

Also I never knew you were the one who originally created the outlined_text functions and the 3d themed rects. This was all already in the sample msdp gui that I downloaded and started adapting, redesigning, and adding stuff into.

And yes... a lot of the code needs to be redone, and some are unused and/or pointless. Just feel like I needed to say these things as it's like someone is about to look under my skirt. lol

Oh right, the vertical and horizontal labels are backwards... had them mixed up and haven't went back to correct the labels
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #3 on Sun 03 Apr 2016 12:23 AM (UTC)

Amended on Sun 03 Apr 2016 12:25 AM (UTC) by Wuggly

Message
If you feel paranoid about the dlls or the zip file here's a link to this plugin on my GitHub account.
https://github.com/TFC-Fumino/MUSHclient_Plugins/tree/master/MSDP-GUI

That way you could download it without the dlls and still run the plugin.

Most of the things will show without being connected to the server. Only things that won't show are the character name, classes, and the spell icons, but you'll be able to see the problem I'm having with the slider messing up when the background is changed. It also occasionally happens when you change the prompt bar colors.

Or if you just don't feel like looking it let me know so I can delete this thread.

I know this is a support site and not meant for others to write code for me, but I just hit this little roadblock and really wanted this to work.
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #4 on Sun 03 Apr 2016 03:15 AM (UTC)

Amended on Sun 03 Apr 2016 04:22 AM (UTC) by Fiendish

Message
I just haven't gotten to it yet. No worries.

(Also, why would I be worried about DLLs that by your account I already have and therefore don't need to use?)

Quote:
The dll's in it are actually straight from your aardwolf github, another player from that mud helped me put together a plugin updater so that's why those are in there. heh.

Yup. I recognize the async.lua I wrote. ^_^
Wait...you went on Aardwolf and asked someone _else_ there how to make an updater? Jeez, nobody ever asks me the fun questions.

Quote:
Also I never knew you were the one who originally created the outlined_text functions and the 3d themed rects. This was all already in the sample msdp gui that I downloaded and started adapting, redesigning, and adding stuff into.

I suppose it's possible. I certainly created things like that for me, but, like, outlining text for readability wasn't exactly a novel concept when I did it. I can't claim to have written any code found in some other packages from someone else. From your screenshot it looks like you're using KaVir's drop-in GUI. He seems like a pretty clever guy. I don't want to take any of the credit for his work. He certainly made a lot of progress very quickly on something that lots of MUDs can use while I was mucking about trying to perfect scrolling text in a miniwindow without realizing that I should have made that a library instead of a one-off plugin (a mistake I still regret and will one day eventually fix). Besides, there are enough other things that I (probably) did first in MUSHclient. Like HTTPS asynchronous sockets!

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #5 on Sun 03 Apr 2016 04:46 AM (UTC)

Amended on Sun 03 Apr 2016 05:23 AM (UTC) by Fiendish

Message
Ahhhhh...

Ok, the first thing you need to know is that OnPluginWorldOutputResized gets called like a thousand times when MUSHclient activates a world.
( See these posts: http://www.mushclient.com/forum/?id=11228 and http://www.mushclient.com/forum/?id=12421&reply=1#reply1 )

Do NOT do heavy work in there without sanity checks. It completely hangs my client when loading the world.

You also don't create the layout anywhere else, so just installing the plugin doesn't do enough unless I add create_layout() to the end of OnPluginInstall.

With create_layout() added at the end of OnPluginInstall, and then removed from OnPluginWorldOutputResized for my computer's health and wellbeing, I get the layout showing. But with only those changes your slider works fine for me. I switch the background image and I don't get any jumping. I do notice that I have to click again in the main area after choosing from the menu to get the hover to work, but that's a side issue.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Sun 03 Apr 2016 10:18 AM (UTC)
Message
Fiendish said:

Ok, the first thing you need to know is that OnPluginWorldOutputResized gets called like a thousand times when MUSHclient activates a world.


As I said in the other thread, I am just passing on those Windows messages, crazy though they might be. :)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #7 on Sun 03 Apr 2016 10:30 AM (UTC)
Message
Nick Gammon said:

Fiendish said:

Ok, the first thing you need to know is that OnPluginWorldOutputResized gets called like a thousand times when MUSHclient activates a world.


As I said in the other thread, I am just passing on those Windows messages, crazy though they might be. :)
Yeah. Wuggly just needs to know.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #8 on Sun 03 Apr 2016 12:51 PM (UTC)
Message
Ah, you're right. Looks like I got plenty of more work to do as well getting the windows lined up again.

Originally in kaVir's sample msdp gui every window was created in the create_layout() function.
(original: http://tintin.sourceforge.net/msdp/ )

I was slowly veering away from that and putting each window in its own function so I could easily manipulate it later on without having to rebuild all of the windows at once, like what I did with the main text area and the MUD's logo (which has the settings button in it).

So when the slider goes down, I could just adjust the window width, height, top, and such variables on the MouseUp, which it would then call the functions for those specific windows where it would rebuild them with the new dimensions.

Probably better, more efficient ways to do that, but I just do it as I learn. When I learn a new way, I go back and redo it. (I'm a slow learner lol)

Anyways before I start rambling, thank you for looking into it, and thanks for the tips. Hopefully if I ever get stuck again and come back here, the code will be all nice, clean, organized, and properly labeled by that time lol.

=)

-Wuggly
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #9 on Sun 03 Apr 2016 03:55 PM (UTC)
Message
Would it be possible for me to perhaps use the wait function
https://github.com/nickgammon/mushclient/blob/master/lua/wait.lua

within the OnPluginWorldOutputResized () to do what Twisol's example shows? Where it would delay a timer?

Twisol said:


Many browsers have the same issue with the onresize event. A common practice is to delay the event by 50-100ms, and if another onresize occurs during that period, the timer is reset. It basically waits until the last onresize has arrived.


function delay(f, time) {
  var id = null;
  return function() {
    var context = this;
    var args = Array.prototype.slice(arguments);
    
    if (id) { window.clearTimeout(id); }
    
    id = window.setTimeout(function() {
      id = null;
      f.apply(context, args);
    }, time);
  };
}

$(window).resize(delay(function() {
  // do stuff
}, 100));



That way I would still be able to auto re-size all the mini-windows when they re-size their client or world window?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Sun 03 Apr 2016 08:12 PM (UTC)
Message
I don't think you want to queue up 1000 timers when OnPluginWorldOutputResized is called. You are better off resizing a couple of seconds after the world is opened.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Wuggly   USA  (112 posts)  [Biography] bio
Date Reply #11 on Mon 04 Apr 2016 07:51 PM (UTC)

Amended on Mon 04 Apr 2016 08:09 PM (UTC) by Wuggly

Message
I just meant a timer that would reset every time OnPluginWorldOutputResized () is called.

Then when it isn't called for a bit, the timer would expire, and run whatever commands.
(for me it would be re-aligning miniwindows in case the player has made the text input box bigger/smaller or have re-sized the world/client window, so my prompt bars would line back up right on top of the text input box, and miniwindows would stretch or shrink to fit the window perfectly again).

For example, something along the lines of this..


<timers>

 <timer
  name="output_resized"
  script="do_this"
  enabled="y"
  second="0.8"
  send_to="12">
 </timer>

</timers>

<script>
<![CDATA[

function OnPluginWorldOutputResized ()

 ResetTimer("output_resized")

end -- function OnPluginWorldOutputResized


function do_this ()
 
 -- Run whatever here

end -- function do_this

]]>
</script>


Just trying to think of a way so I could use that function again.

I mean, I know that isn't perfect, but is a good example of what I am trying to accomplish.

I imagine it would be like a one-shot timer. After the first OnPluginWorldOutputResized () is called, it could build a timer that resets like that, then after the last one is called, the timer would expire, run the commands, and possibly delete itself?

I'm not quite sure how to build something like that. Perhaps have OnPluginWorldOutputResized () set a variable to true and when the timer expires turn it to false?

I hope you get what I am trying to say. heh, I'm not too good at explaining things clearly.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #12 on Mon 04 Apr 2016 08:21 PM (UTC)
Message
You won't get away with putting OnPluginWorldOutputResized inside "send to script" like that, because the function doesn't exist until the script is executed.

But in principle you could have OnPluginWorldOutputResized add a timer if necessary, or if it already exists, reset it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


28,605 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]