Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Tips and tricks ➜ New custom status bar window

New custom status bar window

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


Pages: 1 2  3  4  

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Tue 30 Nov 2004 09:31 PM (UTC)
Message
Once again I am revisiting the idea of having a standalone custom status bar. This subject comes up from time to time, and it always seems a bit problematic to get it working properly.

A while back I did a Visual Basic plugin that showed an external "status bar" window, but that had various problems ...


  • To compile it you needed Visual Basic, which costs money, and takes time to learn

  • You need to register the control with the Windows registry, something that didn't always work for me

  • It used COM objects, which seem to have a habit of popping in and out of memory when you don't want them to


"There must be a better way", I thought.

So this time, I looked at doing it in a way that could be easily reproduced, using free compilers, such as Cygwin. Also, that didn't need to be registered in the Registry.

I toyed with the idea of doing it in Lua, but abandoned that principally because Lua is standard C, not a system for writing Windows GUI programs.

Then I thought of MFC (Microsoft Foundation Class) libraries, but again, you need to own them, and Visual Studio, which isn't a free solution.

Finally I reached for my old copy of "Programming Windows 95" by Charles Petzold, and looked at doing a small Windows program in C "from scratch".

This turned out to be surprisingly easy. Using an example program from Chapter 2, it was possible to do a simple external status bar program (see screen shots below).

The entire source is in a single file of just over 700 lines. The source is available in the download, so you can modify it, or just use the precompiled version if that does the trick for you.

They are both available here (33 Kb):


http://www.gammon.com.au/files/utils/statusbar.zip


The status bar window is designed to be configurable on-the-fly by MUSHclient (or another program) by sending "commands" to it, as will be discussed shortly. The commands would be to do things like:


  • Set window title

  • Set size and position of window on the screen

  • Define text colour

  • Define background colour

  • Define font for drawing text

  • Define a set of labels for status bars (eg. hp, mana, movement, xp)

  • Set current values as a percentage (eg. 80,40,70,20)

  • Set colours for drawing each bar - both "bar" colour and filler colour

  • Define how big each bar is (width and height) and gaps between linees

  • Tell the window to quit


In the next post is a screenshot of it in operation.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 30 Nov 2004 09:32 PM (UTC)
Message

Here is what the status bar window can look like (the exact appearance can be configured heavily as mentioned above) ...


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 30 Nov 2004 09:47 PM (UTC)

Amended on Tue 30 Nov 2004 09:48 PM (UTC) by Nick Gammon

Message
Communicating with the status bar

The trick with any system like this is to get messages to it - tell it to update the bar widths, for example.

I wanted to avoid using COM, which always seems to cause problems, you need to register controls, make sure they exist, worry about what happens if the control window is closed an so on.

Then the idea occurred - use UDP (User Datagram Protocol).

UDP is a "connectionless" protocol for sending packets around the Internet. It is quick because you don't need to establish a connection, however there is a danger that packets may be lost. This is not a big issue with a status bar running on your own PC. Sending a packet from one program to another on the same PC is unlikely to take very long, and is unlikely to get lost. Even if it does, it just means the status bar might be slighly out of date for a moment.

The great thing about UDP is it doesn't matter if the status bar goes away, the packets will simply be discarded. Also you can leave the status bar program running all the time. If MUSHclient sends it information it will update, and if not, no matter.

Indeed you can have a bit of fun, by using a "broadcast address" at the sending end, any PC on the same subnet can receive the same packet. So you could conceivably have multiple PCs all showing the same information.

Getting started

If you download the status bar program above, and run the statusbar.exe file, you will see a window like the one above except without text, and with a white background.

It can be moved and resized in the usual way.

Now even before using MUSHclient we can "talk" to it with any program that sends UDP packets. To help you play with it, I have written a small "UDP send" program. The source and executable (19 Kb) are available from:


http://www.gammon.com.au/files/utils/udpsend.zip


Use a command window to start udpsend like this:


udpsend 127.0.0.1 4111


This tells it to send packets to localhost (your own PC) at port 4111, which is the default port for statusbar.exe.

Now you can send commands to it, eg.


magic,title,hello there,


All being well, the title on the status bar window should update.

Then you can try changing the background colour:


magic,backcolour,25600


The window background should change to dark green.

What is all this 'magic' stuff?

The intention was to make sure that packets received by the statusbar program were intended for it. Thus, each packet is checked for a "magic string" at the start, which defaults to the word "magic". You can configure that when you execute the statusbar program. For example, if you had multiple worlds each with their own status bar, you could use the world name as the magic string.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #3 on Tue 30 Nov 2004 09:57 PM (UTC)

Amended on Wed 01 Dec 2004 04:06 AM (UTC) by Nick Gammon

Message
A more concrete example of talking to the status bar is this example, which I used to do the screenshot above. It uses the Lua socket library to send UDP packets:


dofile "lua.lua"
socket = require "socket"
s = socket.udp ()
s:setpeername ("127.0.0.1", 4111)

s:send ("magic,title,Status Bar - BabbleMUD")
s:send ("magic,config,10,5,100,15,60,320,20")
s:send ("magic,size,10,10,350,140")
s:send ("magic,textcolour," .. ColourNameToRGB ("indigo"))
s:send ("magic,backcolour," .. ColourNameToRGB ("lightsteelblue"))
s:send ("magic,labels,HP,Mana,Move,XP")
s:send ("magic,values,10,20,30,80")
s:send ("magic,font,Comic Sans MS,10,0,700")
s:send ("magic,colours," .. 
        ColourNameToRGB ("darkgreen") .. "," .. 
        ColourNameToRGB ("darkblue") .. "," .. 
        ColourNameToRGB ("saddlebrown") .. "," .. 
        ColourNameToRGB ("dimgray"))
s:send ("magic,fillcolours," .. 
        ColourNameToRGB ("lightgreen") .. "," .. 
        ColourNameToRGB ("lightblue") .. "," .. 
        ColourNameToRGB ("tan") .. "," .. 
        ColourNameToRGB ("gainsboro"))

s:send ("magic,text,5,88,Darkhaven Square")

s:close ()


However since not everyone will want to use Lua to talk to status bars, MUSHclient 3.56 now has a UdpSend function added to it. This simply lets you send a single UDP packet to the network.

Here is an example of using the UdpSend function (in Lua again, but it could just as easily be VBscript) to capture an inventory and display it:


function multiline_trigger (name, line, wildcards)

  local function udp (msg)
    UdpSend ("127.0.0.1", 4111, "m," .. msg)
  end  

  udp ("title,Inventory")
  udp ("size,10,10,300,300")
  udp ("config,10,5,100,15,80,300,20")
  udp ("font,Harem,12")
  udp ("textcolour,0")
  udp ("backcolour,14804223")
  udp ("text,5,5," .. wildcards.inventory)

end -- function


The above example uses a "helper" function to send to the correct address and port, and put the magic word at the start of the line. It illustrates, by the way, the method of declaring "local" functions in Lua, which are functions that are visible only inside another function.

The code above sets the window title and size, sets the font to Harem, defines the text and background colours, and sends the inventory as multi-line text. See below for how it looks:



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #4 on Tue 30 Nov 2004 09:59 PM (UTC)
Message

This is the inventory window done with the above script ...


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #5 on Tue 30 Nov 2004 10:00 PM (UTC)
Message
This is the multi-line trigger used to update that window:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="20"
   match="(?P&lt;inventory&gt;You are carrying:\n(([ ]{5}.*\n)+)\n)\z"
   multi_line="y"
   regexp="y"
   script="multiline_trigger"
   sequence="100"
  >
  </trigger>
</triggers>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 30 Nov 2004 10:04 PM (UTC)
Message
If you want to add more customisation, then simply update the source for the statusbar window, and then recompile, either using Visual C++ or Cygwin (or your own favourite compiler). To compile under Cygwin:


g++ statusbar.cpp -lwsock32 -lgdi32 -o StatusBar.exe


For example, you might add the ability to play sounds, change the style of the window (maybe make it semi-transparent?), make the labels right-justified, the possibilities are endless.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #7 on Tue 30 Nov 2004 10:13 PM (UTC)
Message
Nice little program, I'll go test it right now.
By the way, if you need a better(?) UDP program, NetWorkshop on my page (www.poromenos.org) works and it's free.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #8 on Tue 30 Nov 2004 10:19 PM (UTC)
Message
Hm, there appears to be a small problem with CrLf appearing as two squares, no biggie.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #9 on Tue 30 Nov 2004 10:20 PM (UTC)
Message
I wonder how hard it would be to make it show a two dimensional progress dialog, to show you how your health or whatever changes over time... Interesting, I'll have to work on it.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #10 on Tue 30 Nov 2004 10:30 PM (UTC)

Amended on Tue 30 Nov 2004 10:34 PM (UTC) by Poromenos

Message
By the way, since MC has a UDP send function, could you add a OnUDPReceived(pckPacket) event? It would be great if we could make MC communicate with other instances/people around the world/whatever. Imagine if you could write a plugin to see your friend's status in realtime in a MC window. This would also allow callbacks, since programs could send a packet with the function name and your plugin would call it. I'm not very big on adding extra non-mud functionality, but since we already have UDP send let's be symmetric and enable receive.
Note to developers about something that has not yet even been created: If you want to communicate through UDP I would suggest you did a GetUniqueID and then sent it to the other side as a handshake, then use it as a prefix for every packet you want to receive. This way you make sure the packet is coming from the original source.
Which also leads me to think, which plugin of which world would receive the packet? They could all get it and then choose if they want it, but I'll leave that up for discussion.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #11 on Tue 30 Nov 2004 10:31 PM (UTC)
Message
Quote:

NetWorkshop on my page (www.poromenos.org) works and it's free.


Yes, thanks. Mine is free too. :)

The one I wrote comes with source, it is only 168 lines of code, so if you want to incoporate it into a bigger project, it is simple to see how it is done.

As for the cr/lf appearing as boxes, you can suppress that by using a trailing comma, as the strtok function used in the code just looks for commas as delimiters.

In a plugin (eg. a trigger) you wouldn't have cr/lf anyway.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #12 on Tue 30 Nov 2004 10:32 PM (UTC)
Message
See UdpListen.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #13 on Tue 30 Nov 2004 10:37 PM (UTC)
Message
Quote:

Yes, thanks. Mine is free too. :)

Don't be so antagonistic :P I didn't say yours wouldn't work, I was just providing an alternative (and plugging my site!).
Quote:

As for the cr/lf appearing as boxes, you can suppress that by using a trailing comma, as the strtok function used in the code just looks for commas as delimiters.

Yes yes, I noticed right after I had written the comment :)
Quote:

See UdpListen.

Niiice, do they all receive every packet coming? Sounds good.

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #14 on Tue 30 Nov 2004 10:42 PM (UTC)
Message
I didn't mean it to sound like that. I thought your comment might imply I was charging for mine. You seem to have some interesting stuff on your site. :)

Er yes, it should receive every packet directed at that port, from the IP address you specify.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


172,076 views.

This is page 1, subject is 4 pages long: 1 2  3  4  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

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