View difference between Paste ID: zqDVrPLQ and g4PgX1Su
SHOW: | | - or go back to the newest paste.
1
function layout()
2
	-- Here we define our Border sizes. Left and Right are dynamic, so we use up all the available space
3-
setBorderLeft(210)
3+
	-- on either side of the main console. We assign some static values for top and bottom, though that's
4-
left_container = Geyser.Container:new({
4+
	-- not generally best practices for distribution. 100 could be a lot of real estate on, say, a
5-
  name = "left_container",    -- give it a unique name here
5+
	-- netbook.
6-
  x=0, y=0,                   -- have it start at the top-left corner of mudlet
6+
	Vyzor.Options.Borders = {Left = "dynamic", Right = "dynamic", Top = 100, Bottom = 100}
7-
  width = 200, height="100%", -- with a width of 200, and a height of the full screen, hence 100%
7+
8-
})
8+
	-- All of the Frames share the same Border, so we only need to instantiate it once. This will
9
	-- be re-used.
10-
setBorderRight(210)
10+
	ui_border = Vyzor.Border(
11-
right_container = Geyser.Container:new({
11+
						2,																			-- Width.
12-
  name = "right_container",    -- give it a unique name here
12+
						Vyzor.BorderStyle.Solid,												-- Style.
13-
  x=0, y=0,                   -- have it start at the top-left corner of mudlet
13+
						Vyzor.Brush( Vyzor.Color( Vyzor.ColorMode.Name, "grey" ) ),	-- Color.
14-
  width = 200, height="100%", -- with a width of 200, and a height of the full screen, hence 100%
14+
						10																			-- Radius.
15-
})
15+
					)
16
17-
setBorderTop(100)
17+
	-- Because the space at the top is NOT the entire length of the window, we make another Frame
18-
top_container = Geyser.Container:new({
18+
	-- to act as the inner space. We make it the full size of Vyzor.Top (top border) for now; we
19-
  name = "top_container",    -- give it a unique name here
19+
	-- will be adjusting its size dynamically later.
20-
  x=0, y=0,                   -- have it start at the top-left corner of mudlet
20+
	top_container = Vyzor.Frame( "top_container" )
21-
  width ="100%", height= 100, -- with a width of 200, and a height of the full screen, hence 100%
21+
	-- Add this Frame to Vyzor.Top; a Frame fits inside its parent, and all scalar values are
22-
})
22+
	-- relative to its parent.
23
	Vyzor.Top:Add( top_container )
24-
setBorderBottom(100)
24+
	-- Add our shared border.
25-
bottom_container = Geyser.Container:new({
25+
	top_container:Add( ui_border )
26-
  name = "bottom_container",    -- give it a unique name here
26+
	-- We add a Background. In practice, adding a black Background is redundant, since it's going
27-
  x=0, y=0,                   -- have it start at the top-left corner of mudlet
27+
	-- to be black anyway. This might be necessary if you layer multiple Frames, and you want to hide
28-
  width = "100%", height= 100, -- with a width of 200, and a height of the full screen, hence 100%
28+
	-- what's underneath. I left this here for illustrative purposes.
29-
})
29+
	top_container:Add(
30
		Vyzor.Background(
31
			Vyzor.Brush( Vyzor.Color( Vyzor.ColorMode.Name, "black" ) )
32-
Top_Border = Geyser.Label:new({
32+
		)
33-
  name = "Top_Border",
33+
	)
34-
  x = "15%", y = "0%",
34+
	-- Now we add our Font. Sizes are different in my rewrite because, for some reason
35-
  width = "70%", height = "95%",
35+
	-- completely inexplicable, my Vyzor's 40px is different from Geyser's 40px. I have no
36-
  message = [[<center><font size=40>SLOTHMUD - A RETURN TO ITS ORIGINS</font></center>]]
36+
	-- idea, since it's all the same Stylesheet business underneath.
37-
}, top_container)
37+
	top_container:Add(
38-
Top_Border:setStyleSheet([[
38+
		Vyzor.Font(
39-
  background-color: black;
39+
			30,							-- Size.
40-
  border-width: 2px;
40+
			"Monospace",				-- Family.
41-
  border-style: solid;
41+
			Vyzor.FontWeight.Bold	-- Weight.
42-
  border-color: grey;
42+
		)
43-
  border-radius: 10px;
43+
	)
44-
  font: bold "Monospace";
44+
	-- This sets the text color. I wouldn't have thought this necessary, but everything
45-
  font-size: 14px;
45+
	-- was black for me. Might be a Qt default.
46-
]])
46+
	top_container:Add( Vyzor.Color( Vyzor.ColorMode.Name, "white" ) )
47
48-
Locations = Geyser.Label:new({
48+
	-- Like our top_container, we make a new Frame. This time, though, we set our dimensions.
49-
  name = "Locations",
49+
	-- Height is .25 (or 25% of its parent). In this case, the parent is Vyzor.Left, a Border
50-
  x = "0%", y = "0%",
50+
	-- Frame Vyzor creates that is exactly the size of Mudlet's left border.
51-
  width = "100%", height = "25%"
51+
	Locations = Vyzor.Frame( "Locations", 0, 0, 1, .25 )
52-
}, left_container)
52+
	-- Shared border.
53-
Locations:setStyleSheet([[
53+
	Locations:Add( ui_border )
54-
  background-color: black;
54+
	-- Font.
55-
  border-width: 2px;
55+
	Locations:Add( Vyzor.Font( 10, "Monospace", Vyzor.FontWeight.Bold ) )
56-
  border-style: solid;
56+
	-- Color.
57-
  border-color: grey;
57+
	Locations:Add( Vyzor.Color( Vyzor.ColorMode.Name, "white" ) )
58-
  border-radius: 10px;
58+
	-- And add the new Frame (Locations) to Vyzor.Left.
59-
  font: bold "Monospace";
59+
	Vyzor.Left:Add( Locations )
60-
  font-size: 1px;
60+
61
	-- Much of the same. y = .25, or 25% of the way down Vyzor.Left.
62-
]])
62+
	Grouping = Vyzor.Frame( "Grouping", 0, .25, 1, .35 )
63-
Locations:echo("LOCATION INFORMATION:<br><hr><br>Continent:"..atcp.MSDPCONTINENT.."<hr>Area: "..atcp.MSDPAREA_NAME.."<hr>Room: "..atcp.MSDPROOM_NAME.."<hr>Exits: "..atcp.MSDPROOM_EXITS.."<hr>Terrain: "..atcp.MSDPTERRAIN.."<hr>Room ID: "..atcp.MSDPROOM_VNUM)
63+
	Grouping:Add( ui_border )
64
	Grouping:Add( Vyzor.Font( 12, "Monospace", Vyzor.FontWeight.Bold ) )
65-
Grouping = Geyser.Label:new({
65+
	Grouping:Add( Vyzor.Color( Vyzor.ColorMode.Name, "white" ) )
66-
  name = "Grouping",
66+
	Vyzor.Left:Add( Grouping )
67-
  x = "0%", y = "25%",
67+
68-
  width = "100%", height = "35%" 
68+
	-- Statistics completely fill Vyzor.Right. In fact, we could have just applied all of the
69-
}, left_container)
69+
	-- Components to the Vyzor.Right. But, since it's a logically separate widget, it makes
70-
Grouping:setStyleSheet([[
70+
	-- sense to make something specifically for it. You never know when you'd rather the
71-
  background-color: black;
71+
	-- widget take up 50% instead of 100%.
72-
  border-width: 2px;
72+
	Statistics = Vyzor.Frame( "Statistics" )
73-
  border-style: solid;
73+
	Statistics:Add( ui_border )
74-
  border-color: grey;
74+
	Statistics:Add( Vyzor.Font( 14, "Monospace", Vyzor.FontWeight.Bold ) )
75-
  border-radius: 10px;
75+
	Statistics:Add( Vyzor.Color( Vyzor.ColorMode.Name, "white" ) )
76-
  font: bold "Monospace";
76+
	Vyzor.Right:Add( Statistics )
77-
  font-size: 4px;
77+
78
	-- This is the last part of any Vyzor GUI. You must Vyzor.HUD:Draw(). It's only necessary
79-
]])
79+
	-- to call it once. You can also draw Frames individually, if you feel it necessary. But,
80-
Grouping:echo("GROUP FIGHTING:<br><hr><br>Group Leader: "..atcp.MSDPGROUP_LEADER.."<hr>Tank Name: "..atcp.MSDPTANK_NAME.."<hr>Tank Health: "..atcp.MSDPTANK_HEALTH.."/"..atcp.MSDPTANK_HEALTH_MAX.."<hr>Tank Level: "..atcp.MSDPTANK_LEVEL.."<hr><br>Enemy: "..atcp.MSDPOPPONENT_NAME.."<hr>Level: "..atcp.MSDPOPPONENT_LEVEL.."<hr>Health: "..atcp.MSDPOPPONENT_HEALTH.."/"..atcp.MSDPOPPONENT_HEALTH_MAX)
80+
	-- standard practice is to make all of your Frames, call this, then hide the ones you don't
81-
--echo("Grouping", "[[<p style="font-family: monospace; font-size:small;">]][[GROUP FIGHTING: <br>==============<br>Group Leader: ]]..atcp.MSDPGROUP_LEADER..[[<br>Tank Name: ]]..atcp.MSDPTANK_NAME..[[<br>Tank Health: ]]..atcp.MSDPTANK_HEALTH..[[/]]..atcp.MSDPTANK_HEALTH_MAX..[[<br>Tank Level: ]]..atcp.MSDPTANK_LEVEL..[[<br><br>Enemy: ]]..atcp.MSDPOPPONENT_NAME..[[<br>Level: ]]..atcp.MSDPOPPONENT_LEVEL..[[<br>Health: ]]..atcp.MSDPOPPONENT_HEALTH..[[/]]..atcp.MSDPOPPONENT_HEALTH_MAX[[</p>]])
81+
	-- want visible. This ensures proper layering (z-order) of the underlying labels.
82
	Vyzor.HUD:Draw()
83-
Statistics = Geyser.Label:new({
83+
84-
  name = "Statistics",
84+
	-- And now that the Frame exists, we can echo to it. Since this never changes, we only need
85-
  x = "580%", y = "0%",
85+
	-- echo once, so we do it here.
86-
  width = "100%", height = "100%"
86+
	top_container:Echo( [[<center>SLOTHMUD - A RETURN TO ITS ORIGINS</center>]] )
87-
}, right_container)
87+
end
88-
Statistics:setStyleSheet([[
88+
89-
  background-color: black;
89+
-- This function will handle all of the dynamic bits of the UI, like the changing values in
90-
  border-width: 2px;
90+
-- your variables. We also make sure the top_container is where it's supposed to be
91-
  border-style: solid;
91+
-- relative to everything else.
92-
  border-color: grey;
92+
function updateUi ()
93-
  border-radius: 10px;
93+
	-- We need to know how big everything is. We could also get Vyzor.HUD.Size.AbsoluteWidth
94-
  font: bold "Monospace";
94+
	-- instead of calling this function.
95-
  font-size: 6px;
95+
	local screen_width = getMainWindowSize()
96-
]])
96+
	-- This is our left border.
97-
Statistics:echo("STATS INFORMATION:<hr>Name: "..atcp.MSDPCHARACTER_NAME.."<br>Citizen of "..atcp.MSDPCITIZEN.."<br> Your alignment is: "..atcp.MSDPALIGNMENT.."<br>Sex: "..atcp.MSDPSEX.."<hr>Money: "..atcp.MSDPMONEY.."<br>Drachma: "..atcp.MSDPDRACHMA.."<hr>Levels:<br>"..atcp.MSDPCLASS.." "..atcp.MSDPLEVEL.." "..atcp.MSDPCLASS_SEC.." "..atcp.MSDPLEVEL_SEC.." "..atcp.MSDPCLASS_TER.." "..atcp.MSDPLEVEL_TER.." "..atcp.MSDPCLASS_QUA.." "..atcp.MSDPLEVEL_QUA.."<br>"..atcp.MSDPCLASS_QUI.." "..atcp.MSDPLEVEL_QUI.." "..atcp.MSDPCLASS_HEX.." "..atcp.MSDPLEVEL_HEX.." "..atcp.MSDPCLASS_SEP.." "..atcp.MSDPLEVEL_SEP.." "..atcp.MSDPCLASS_OCT.." "..atcp.MSDPLEVEL_OCT.."<br>Avatar: "..atcp.MSDPCLASS_AVA.." "..atcp.MSDPLEVEL_AVA.."<hr> Experience: "..atcp.MSDPEXPERIENCE.."<hr>Health: "..atcp.MSDPHEALTH.." / "..atcp.MSDPHEALTH_MAX.."<hr> Mana: "..atcp.MSDPMANA.." / "..atcp.MSDPMANA_MAX.."<hr> Moves: "..atcp.MSDPMOVEMENT.." / "..atcp.MSDPMOVEMENT_MAX.."<hr> AC: "..atcp.MSDPAC.."<hr> HONOR: "..atcp.MSDPHONOR.."<hr> STR:"..atcp.MSDPSTR.."/"..atcp.MSDPSTR_PERM.." CON:"..atcp.MSDPCON.."/"..atcp.MSDPCON_PERM.."<br> DEX:"..atcp.MSDPDEX.."/"..atcp.MSDPDEX_PERM.." WIS:"..atcp.MSDPWIS.."/"..atcp.MSDPWIS_PERM.."<br>INT:"..atcp.MSDPINT.."/"..atcp.MSDPINT_PERM.." CHAR:"..atcp.MSDPCHARISMA.."/"..atcp.MSDPCHARISMA_CAP.."<hr>Spells and Damage:<br>Weapon Damage: "..atcp.MSDPWEAPON_DAM.."<br>Stab Damage: "..atcp.MSDPSTAB_DAM.."/"..atcp.MSDPSTAB_DAM_CAP.."<br>Hand Damage: "..atcp.MSDPHAND_DAM.."/"..atcp.MSDPHAND_DAM_CAP.."<br> Undead Cont: "..atcp.MSDPUNDEAD_CONT.."/"..atcp.MSDPUNDEAD_CONT_CAP.."<br>Spell Bonus: "..atcp.MSDPSPELL_BONUS.."/"..atcp.MSDPSPELL_BONUS_CAP.."<br>Heal Bonus: "..atcp.MSDPHEAL_BONUS.."/"..atcp.MSDPHEAL_BONUS_CAP.."<hr>Hitroll: "..atcp.MSDPHITROLL.."<hr>Damroll: "..atcp.MSDPDAMROLL.."<hr>Damage Red: "..atcp.MSDPDAM_RED.."/"..atcp.MSDPDAM_RED_CAP)
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