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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Miniwindows
. . -> [Subject]  Adapting AARDWOLF inventory miniwindow

Adapting AARDWOLF inventory miniwindow

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


Pages: 1  2 

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #15 on Sat 20 Jan 2018 03:55 AM (UTC)

Amended on Sat 20 Jan 2018 05:23 AM (UTC) by Nick Gammon

Message
It's not that hard, I think you are confusing yourself.

You basically need two functions. One that the trigger calls, that needs to take the wildcards and work out the values for the bars.

It can also make the window and draw the background, etc.

The second function (DoGauge) draws the actual bars (so it is called three times). That draws the text of what the bar represents, followed by the box which is the bar itself. If you put this in your script file it should work:


-- where to start each gauge
GAUGE_LEFT = 55
-- height of gauge
GAUGE_HEIGHT = 15

-- width of health bar window
WINDOW_WIDTH = 200
-- height of it
WINDOW_HEIGHT = 65
-- how many ticks to draw
NUMBER_OF_TICKS = 5
  
-- assorted colours
BACKGROUND_COLOUR = ColourNameToRGB "rosybrown"
FONT_COLOUR       = ColourNameToRGB "darkred"
BORDER_COLOUR     = ColourNameToRGB "darkorchid"
FILL_COLOUR       = ColourNameToRGB "lightgrey"
GAUGE_BORDER      = ColourNameToRGB "dimgray"

function DoGauge (sPrompt, Percent, Colour)

  local Fraction = tonumber (Percent)
  
  if Fraction > 1 then Fraction = 1 end
  if Fraction < 0 then Fraction = 0 end
   
  local width = WindowTextWidth (win, font_id, sPrompt)
  
  -- prompt on left (eg. "HP:")
  WindowText (win, font_id, sPrompt,
                             GAUGE_LEFT - width, vertical, 0, 0, FONT_COLOUR)

  -- fill entire box with "unused" colour
  WindowRectOp (win, 2, GAUGE_LEFT, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT, 
                          FILL_COLOUR)  -- fill entire box
 
  
  local gauge_width = (WINDOW_WIDTH - GAUGE_LEFT - 5) * Fraction
  
   -- box size must be > 0 or WindowGradient fills the whole thing 
  if math.floor (gauge_width) > 0 then
    
    -- top half
    WindowGradient (win, GAUGE_LEFT, vertical, GAUGE_LEFT + gauge_width, vertical + GAUGE_HEIGHT / 2, 
                    0x000000,
                    Colour, 2) 
    
    -- bottom half
    WindowGradient (win, GAUGE_LEFT, vertical + GAUGE_HEIGHT / 2, 
                    GAUGE_LEFT + gauge_width, vertical +  GAUGE_HEIGHT,   
                    Colour,
                    0x000000,
                    2) 

  end -- non-zero
  
  -- show ticks
  local ticks_at = (WINDOW_WIDTH - GAUGE_LEFT - 5) / (NUMBER_OF_TICKS + 1)
  
  -- ticks
  for i = 1, NUMBER_OF_TICKS do
    WindowLine (win, GAUGE_LEFT + (i * ticks_at), vertical, 
                GAUGE_LEFT + (i * ticks_at), vertical + GAUGE_HEIGHT, ColourNameToRGB ("silver"), 0, 1)
  end -- for

  -- draw a box around it
  check (WindowRectOp (win, 1, GAUGE_LEFT, vertical, WINDOW_WIDTH - 5, vertical + GAUGE_HEIGHT, 
          GAUGE_BORDER))  -- frame entire box
  
  vertical = vertical + font_height + 3
end -- function DoGauge

function DoNextSimpleBar (name, line, wildcards, styles)
  
  win = GetPluginID () .. "_health_bar"
  
  font_id = "fn"
  font_name = "Fixedsys"    -- the actual font

    -- make miniwindow so I can grab the font info
  check (WindowCreate (win, 
                 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,  
                 miniwin.pos_top_left,   
                 0,   
                 BACKGROUND_COLOUR) )

  -- add the font to the window                                  
  check (WindowFont (win, font_id, font_name, 9, false, false, false, false, 0, 0))  -- normal
  font_height = WindowFontInfo (win, font_id, 1)  -- height
  

  -- copy hp, mana, movements points from wildcards
  hp, max_hp = tonumber (wildcards [1]), tonumber (wildcards [2])
  mana, max_mana = tonumber (wildcards [3]), tonumber (wildcards [4])
  move, max_move = tonumber (wildcards [5]), tonumber (wildcards [6])

  -- fill entire box to clear it
  check (WindowRectOp (win, 2, 0, 0, 0, 0, BACKGROUND_COLOUR))  -- fill entire box
  
  -- Edge around box rectangle
  check (WindowCircleOp (win, 3, 0, 0, 0, 0, BORDER_COLOUR, 0, 2, 0, 1))

  -- calculate what percentage we are of each one
  local hp_percent = hp / max_hp
  local mana_percent = mana / max_mana
  local move_percent = move / max_move

  -- where to start the first gauge
  vertical = 6
  
  -- draw the gauges
  DoGauge ("HP: ",   hp_percent,    ColourNameToRGB "darkgreen")
  DoGauge ("Mana: ", mana_percent,  ColourNameToRGB "mediumblue")
  DoGauge ("Move: ", move_percent,  ColourNameToRGB "gold")

  WindowShow (win, true)

end -- DoNextSimpleBar

- Nick Gammon

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

Posted by Death   (55 posts)  [Biography] bio
Date Reply #16 on Thu 25 Jan 2018 11:31 AM (UTC)
Message
Thanks Nick.

This fix seemed to just draw the original hp bar plugin onto the screen, while still having the awesome aardwolf one on the bottom, any when I resized the one on the bottom, the top one would get weird.

I'm trying to put my stats into the AARDWOLF one, the one that's fully customizable. I'm not just trying to make a basic HP/MANA/MOVE one with a standard theme, as I've already modified and made use of the original HP/MANA/MOVE theme you made.

--=================================================================================
-- Called when plugin receives telnet data - main entry point for actually running
-- the plugin.
--=================================================================================
function OnPluginBroadcast (msg, id, name, text)

   -- Look for GMCP handler.
   if (id == '3e7dedbe37e44942dd46d264') then
      if (text == 'reload') then
         -- invalidate current data
         page_built = false
         return
      end

      if (text == "char.base" or text == "char.vitals" or text == "char.status" or text == "char.maxstats") then
         if text == "char.base" then
            gmcp_char.base = gmcp("char.base")
         elseif text == "char.vitals" then
            gmcp_char.vitals = gmcp("char.vitals")
         elseif text == "char.status" then
            gmcp_char.status = gmcp("char.status")
         else
            gmcp_char.maxstats = gmcp("char.maxstats")
         end

         if gmcp_char.base and gmcp_char.vitals and gmcp_char.status and gmcp_char.maxstats then
            page_built = true
            DisplayStatsPage()
         end
      end
   elseif (id == "462b665ecb569efbf261422f" and msg==996 and text == "re-register z") then
      CallPlugin("462b665ecb569efbf261422f", "registerMiniwindow", win)
   end
end



This piece of code is in the original plugin, and it seems to be the entry point of the stats to enter the bars...
I'm not sure how I'd change it to fit the new scheme.

Where originally the code would be
      DoNextSimpleBar("Health", gmcp_char.vitals.hp, gmcp_char.maxstats.maxhp)
      DoNextSimpleBar("Mana", gmcp_char.vitals.mana, gmcp_char.maxstats.maxmana)
      DoNextSimpleBar("Moves", gmcp_char.vitals.moves, gmcp_char.maxstats.maxmoves)


I've added (with your help)
      DoNextSimpleBar("Health",    hp ,   max_hp)
      DoNextSimpleBar("Mana",  mana,  max_mana)
      DoNextSimpleBar("Moves",  move,  max_move)



For the initial code posted in this specific reply, would I need to add multiple instances (HP/MANA/MOVE) to replace each instance of "gmcp_char.vitals), because there is no mention of gmcp_char.vitals.mana, or gmcp_char.vitals.move, etc.

Meaning, would I need to do something around the lines (of course not exactly) of this?

      if (text == "char.base" or text == "hp, mana, move" or text == "char.status" or text == "max_hp, max_mana, max_moves") then
         if text == "char.base" then
            gmcp_char.base = gmcp("char.base")
         elseif text == "char.vitals" then
            gmcp_char.vitals = gmcp("hp, mana, move")
         elseif text == "char.status" then
            gmcp_char.status = gmcp("char.status")
         else
            gmcp_char.maxstats = gmcp("max_hp, max_mana, max_move")
         end

         if gmcp_char.base and gmcp_char.vitals and gmcp_char.status and gmcp_char.maxstats then
            page_built = true


I'm looking for my hp/mana/move bar to be exactly like this.
(Standard AArdwolf bar, absolutely amazing, by fiendish)
https://www.dropbox.com/preview/Screenshots/Screenshot%202018-01-25%2022.27.54.png

The code you gave me produces TWO hp bars, in the existing hp bar plugin I'm looking to modify...
Seen here.
https://www.dropbox.com/s/8wbffn7r7gecrig/Screenshot%202018-01-25%2022.30.08.png?dl=0

I'm still missing something, I guess.. All help is appreciated.
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #17 on Thu 25 Jan 2018 03:55 PM (UTC)

Amended on Thu 25 Jan 2018 04:07 PM (UTC) by Fiendish

Message
Quote:
Meaning, would I need to do something around the lines (of course not exactly) of this? ...

No. That is very very wrong.

You appear to be fumbling in the dark with something that you really don't understand at all.
Maybe it will help if I explain about entry points to you.
The entry point into any agglomeration of code is the place at which that code goes from sitting idle doing nothing to being activated to do something by some external force.

My entry point is the OnPluginBroadcast method which runs whenever any new GMCP data arrives.
Your entry point is a trigger that fires on your prompt.

That is the only difference between what I've done and what you want to do.

All that my entry point does is appropriately populate a table called gmcp_char using the GMCP data that just arrived and then call DisplayStatsPage().
Therefore, all that your entry point should do is appropriately populate a table called gmcp_char using your prompt data that just arrived and then call DisplayStatsPage().

That's it.

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

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #18 on Thu 25 Jan 2018 04:41 PM (UTC)

Amended on Thu 25 Jan 2018 04:42 PM (UTC) by Fiendish

Message
On a hopefully unrelated note, your game's website is broken. The server is distributing raw php code.

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

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #19 on Thu 25 Jan 2018 08:39 PM (UTC)
Message
Agreed - something is very wrong with the permissions or configuration of the darkwizardry.com web site.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #20 on Thu 25 Jan 2018 08:44 PM (UTC)
Message
Master Vivi said:

I'm not sure how I'd change it to fit the new scheme.
...
I'm still missing something, I guess.. All help is appreciated.


Judging by the screenshot that I could read, you have taken the Aardwolf code and are trying to retro-fit your own MUD's output into it. This might be possible but you need to understand what the code is doing.

The GMCP messages arrive "out of band" as telnet subnegotiations, and your MUD would have them in triggers. As Fiendish said, maybe you could "dummy up" GMCP tables using triggers and let the bars and other things draw themselves.

However I would be removing most of those plugins and start with something simple, and when you understand how that works, gradually improve it. For example, you could add dragging the bars around to the code I gave above, fairly simply. There is a module (movewindow.lua) which you can find by following the "modules" link at the bottom of this page.

- 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.


44,047 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

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]