Advertisement
Guest User

Untitled

a guest
Jan 6th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function layout()
  2.     -- Here we define our Border sizes. Left and Right are dynamic, so we use up all the available space
  3.     -- on either side of the main console. We assign some static values for top and bottom, though that's
  4.     -- not generally best practices for distribution. 100 could be a lot of real estate on, say, a
  5.     -- netbook.
  6.     Vyzor.Options.Borders = {Left = "dynamic", Right = "dynamic", Top = 100, Bottom = 100}
  7.  
  8.     -- All of the Frames share the same Border, so we only need to instantiate it once. This will
  9.     -- be re-used.
  10.     ui_border = Vyzor.Border(
  11.                         2,                                                                          -- Width.
  12.                         Vyzor.BorderStyle.Solid,                                                -- Style.
  13.                         Vyzor.Brush( Vyzor.Color( Vyzor.ColorMode.Name, "grey" ) ), -- Color.
  14.                         10                                                                          -- Radius.
  15.                     )
  16.  
  17.     -- Because the space at the top is NOT the entire length of the window, we make another Frame
  18.     -- to act as the inner space. We make it the full size of Vyzor.Top (top border) for now; we
  19.     -- will be adjusting its size dynamically later.
  20.     top_container = Vyzor.Frame( "top_container" )
  21.     -- Add this Frame to Vyzor.Top; a Frame fits inside its parent, and all scalar values are
  22.     -- relative to its parent.
  23.     Vyzor.Top:Add( top_container )
  24.     -- Add our shared border.
  25.     top_container:Add( ui_border )
  26.     -- We add a Background. In practice, adding a black Background is redundant, since it's going
  27.     -- to be black anyway. This might be necessary if you layer multiple Frames, and you want to hide
  28.     -- what's underneath. I left this here for illustrative purposes.
  29.     top_container:Add(
  30.         Vyzor.Background(
  31.             Vyzor.Brush( Vyzor.Color( Vyzor.ColorMode.Name, "black" ) )
  32.         )
  33.     )
  34.     -- Now we add our Font. Sizes are different in my rewrite because, for some reason
  35.     -- completely inexplicable, my Vyzor's 40px is different from Geyser's 40px. I have no
  36.     -- idea, since it's all the same Stylesheet business underneath.
  37.     top_container:Add(
  38.         Vyzor.Font(
  39.             30,                         -- Size.
  40.             "Monospace",                -- Family.
  41.             Vyzor.FontWeight.Bold   -- Weight.
  42.         )
  43.     )
  44.     -- This sets the text color. I wouldn't have thought this necessary, but everything
  45.     -- was black for me. Might be a Qt default.
  46.     top_container:Add( Vyzor.Color( Vyzor.ColorMode.Name, "white" ) )
  47.  
  48.     -- Like our top_container, we make a new Frame. This time, though, we set our dimensions.
  49.     -- Height is .25 (or 25% of its parent). In this case, the parent is Vyzor.Left, a Border
  50.     -- Frame Vyzor creates that is exactly the size of Mudlet's left border.
  51.     Locations = Vyzor.Frame( "Locations", 0, 0, 1, .25 )
  52.     -- Shared border.
  53.     Locations:Add( ui_border )
  54.     -- Font.
  55.     Locations:Add( Vyzor.Font( 10, "Monospace", Vyzor.FontWeight.Bold ) )
  56.     -- Color.
  57.     Locations:Add( Vyzor.Color( Vyzor.ColorMode.Name, "white" ) )
  58.     -- And add the new Frame (Locations) to Vyzor.Left.
  59.     Vyzor.Left:Add( Locations )
  60.  
  61.     -- Much of the same. y = .25, or 25% of the way down Vyzor.Left.
  62.     Grouping = Vyzor.Frame( "Grouping", 0, .25, 1, .35 )
  63.     Grouping:Add( ui_border )
  64.     Grouping:Add( Vyzor.Font( 12, "Monospace", Vyzor.FontWeight.Bold ) )
  65.     Grouping:Add( Vyzor.Color( Vyzor.ColorMode.Name, "white" ) )
  66.     Vyzor.Left:Add( Grouping )
  67.  
  68.     -- Statistics completely fill Vyzor.Right. In fact, we could have just applied all of the
  69.     -- Components to the Vyzor.Right. But, since it's a logically separate widget, it makes
  70.     -- sense to make something specifically for it. You never know when you'd rather the
  71.     -- widget take up 50% instead of 100%.
  72.     Statistics = Vyzor.Frame( "Statistics" )
  73.     Statistics:Add( ui_border )
  74.     Statistics:Add( Vyzor.Font( 14, "Monospace", Vyzor.FontWeight.Bold ) )
  75.     Statistics:Add( Vyzor.Color( Vyzor.ColorMode.Name, "white" ) )
  76.     Vyzor.Right:Add( Statistics )
  77.  
  78.     -- This is the last part of any Vyzor GUI. You must Vyzor.HUD:Draw(). It's only necessary
  79.     -- to call it once. You can also draw Frames individually, if you feel it necessary. But,
  80.     -- standard practice is to make all of your Frames, call this, then hide the ones you don't
  81.     -- want visible. This ensures proper layering (z-order) of the underlying labels.
  82.     Vyzor.HUD:Draw()
  83.  
  84.     -- And now that the Frame exists, we can echo to it. Since this never changes, we only need
  85.     -- echo once, so we do it here.
  86.     top_container:Echo( [[<center>SLOTHMUD - A RETURN TO ITS ORIGINS</center>]] )
  87. end
  88.  
  89. -- This function will handle all of the dynamic bits of the UI, like the changing values in
  90. -- your variables. We also make sure the top_container is where it's supposed to be
  91. -- relative to everything else.
  92. function updateUi ()
  93.     -- We need to know how big everything is. We could also get Vyzor.HUD.Size.AbsoluteWidth
  94.     -- instead of calling this function.
  95.     local screen_width = getMainWindowSize()
  96.     -- This is our left border.
  97.     local left_width = Vyzor.Left.Size.AbsoluteWidth
  98.     -- This is our right border.
  99.     local right_width = Vyzor.Right.Size.AbsoluteWidth
  100.  
  101.     -- top_container should starter where the left border ends.
  102.     top_container:Move( left_width )
  103.     -- And it should fit between both borders.
  104.     top_container:Resize( screen_width - (left_width + right_width) )
  105.  
  106.     -- Honestly, this isn't the best way to handle this sort of thing. Personally, I would use Box Compounds,
  107.     -- give each line its own Frame. Then I might handle updating the values separately; you can echo to
  108.     -- Frames from anywhere, so the updating could be handled in a logically more appropriate function.
  109.     -- However, this works, and if you only ever need to display this information (and not process it),
  110.     -- updating it in a UI update function makes sense.
  111.     -- Also, these long, concatenated strings are a pain to modify.
  112.     Locations:Echo("LOCATION INFORMATION:<br><hr><br>Continent:".."nil".."<hr>Area: ".."nil".."<hr>Room: ".."nil".."<hr>Exits: ".."nil".."<hr>Terrain: ".."nil".."<hr>Room ID: ".."nil")
  113.  
  114.     Grouping:Echo("GROUP FIGHTING:<br><hr><br>Group Leader: ".."nil".."<hr>Tank Name: ".."nil".."<hr>Tank Health: ".."nil".."/".."nil".."<hr>Tank Level: ".."nil".."<hr><br>Enemy: ".."nil".."<hr>Level: ".."nil".."<hr>Health: ".."nil".."/".."nil")
  115.  
  116.     Statistics:Echo("STATS INFORMATION:<hr>Name: ".."nil".."<br>Citizen of ".."nil".."<br> Your alignment is: ".."nil".."<br>Sex: ".."nil".."<hr>Money: ".."nil".."<br>Drachma: ".."nil".."<hr>Levels:<br>".."nil".." ".."nil".." ".."nil".." ".."nil".." ".."nil".." ".."nil".." ".."nil".." ".."nil".."<br>".."nil".." ".."nil".." ".."nil".." ".."nil".." ".."nil".." ".."nil".." ".."nil".." ".."nil".."<br>Avatar: ".."nil".." ".."nil".."<hr> Experience: ".."nil".."<hr>Health: ".."nil".." / ".."nil".."<hr> Mana: ".."nil".." / ".."nil".."<hr> Moves: ".."nil".." / ".."nil".."<hr> AC: ".."nil".."<hr> HONOR: ".."nil".."<hr> STR:".."nil".."/".."nil".." CON:".."nil".."/".."nil".."<br> DEX:".."nil".."/".."nil".." WIS:".."nil".."/".."nil".."<br>INT:".."nil".."/".."nil".." CHAR:".."nil".."/".."nil".."<hr>Spells and Damage:<br>Weapon Damage: ".."nil".."<br>Stab Damage: ".."nil".."/".."nil".."<br>Hand Damage: ".."nil".."/".."nil".."<br> Undead Cont: ".."nil".."/".."nil".."<br>Spell Bonus: ".."nil".."/".."nil".."<br>Heal Bonus: ".."nil".."/".."nil".."<hr>Hitroll: ".."nil".."<hr>Damroll: ".."nil".."<hr>Damage Red: ".."nil".."/".."nil")
  117. end
  118.  
  119. -- I wouldn't normally use an anonymous event handler, but for demonstration purposes, this works best.
  120. -- Best practices: use the Script editor, add an event handler, and carry out the logic there.
  121. -- But what this does, basically, is react every time Vyzor reports that it has resized (which
  122. -- happens after Mudlet has resized). This ensures that all values you need (like Frame sizes) are
  123. -- accurate and up-to-date.
  124. registerAnonymousEventHandler( "VyzorResizedEvent", "updateUi" )
  125.  
  126. -- Vyzor doesn't like it when you try to redraw some stuff, so we only want to call layout once.
  127. if not uiDrawn then
  128.     layout()
  129.     uiDrawn = true
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement