Geyser UI Scripts

Share your scripts and packages with other Mudlet users.
User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Geyser UI Scripts

Post by chris »

I think it would be nice to have some more abstractable user interface options with Geyser. The first one that came to my mind was a prompt for a user to click on:
Code: [show] | [select all] lua
-------------------------------------------------
--         Put your Lua functions here.        --
--                                             --
-- Note that you can also use external Scripts --
-------------------------------------------------
prompter = {}
function prompter:decisionBox(title, message,onYes,onNo)
	local w, h
	w,h = getMainWindowSize()
	prompter.dec = {}
	prompter.w=300
	prompter.h=100
	prompter.cw=25
	prompter.ch=40
	prompter.dec["yes"] = Geyser.Label:new({
		name="yesBox",
		message="<center>Yes</center>",
		x=w/2-prompter.w/2,
		y=h/2+prompter.h/2,
		width=prompter.w/2,
		height=prompter.ch,
		callback=onYes
	})
	prompter.dec["no"] = Geyser.Label:new({
		name="noBox",
		message="<center>No</center>",
		x=w/2,
		y=h/2+prompter.h/2,
		width=prompter.w/2,
		height=prompter.ch,
		callback=onNo
	})
	setLabelStyleSheet("yesBox", [[
		background-color: green;
		color: black;
		]])
	setLabelStyleSheet("noBox", [[
		background-color: red;
		color: black;
		]])
	prompter.dec["frame"] = Geyser.Label:new({
      name="promptDecision",
		message="<center>"..message.."</center>",
		x=w/2-prompter.w/2,
		y=h/2-prompter.h/2,
		width=prompter.w,
		height=prompter.h,
    })
	setLabelStyleSheet("promptDecision", [[
		background-color: grey;
		]])
end
function prompter:Dest()
	prompter.dec["frame"]:hide()
	prompter.dec["yes"]:hide()
	prompter.dec["no"]:hide()
end
function onDecYes(args)
	display('yes')
	prompter:Dest()
end
function onDecNo(args)
	display('no')
	prompter:Dest()
end
prompter:decisionBox("title frame", "do you want to do this","onDecYes","onDecNo")
I'd love to see what others have made

Silvine
Posts: 142
Joined: Sat Oct 23, 2010 2:36 pm

Re: Geyser UI Scripts

Post by Silvine »

Quite Brilliant!!!
And beautifully demonstrated.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Geyser UI Scripts

Post by Vadi »

Oh, that is a neat idea.

Milamber!
Posts: 1
Joined: Tue Dec 11, 2012 10:59 am

Re: Geyser UI Scripts

Post by Milamber! »

Brilliant. Now if only you could make a Dialog Input box that would ask for a spicific Value, such as, "What city would you like to add this Person to?" with an input field. Stupid example, but the usages would be endless. Bit then again, you could probably just use the Mudlet Prompt.

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: Geyser UI Scripts

Post by chris »

There is no text focus for labels, but it'd be trivial to accept things like the next input in the command line following a click

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Geyser UI Scripts

Post by Vadi »

Here's that idea materialized:
Code: [show] | [select all] lua
-------------------------------------------------
--         Put your Lua functions here.        --
--                                             --
-- Note that you can also use external Scripts --
-------------------------------------------------
prompter = {}
function prompter:questionBox(title, message,onAnswer)
        local w, h
        w,h = getMainWindowSize()
        prompter.dec = {}
        prompter.w=300
        prompter.h=100
        prompter.cw=25
        prompter.ch=40
        prompter.dec["frame"] = Geyser.Label:new({
      name="promptDecision",
                message="<center>"..message.."</center>",
                x=w/2-prompter.w/2,
                y=h/2-prompter.h/2,
                width=prompter.w,
                height=prompter.h,
    })
        setLabelStyleSheet("promptDecision", [[
                background-color: grey;
                ]])

  prompter.onAnswer = onAnswer
  if prompter.tempalias then killAlias(prompter.tempalias) end
  prompter.tempalias = tempAlias("^", [[
    killAlias(prompter.tempalias); prompter.tempalias = nil
    prompter:Dest()
    prompter.onAnswer(command)
  ]])
end
function prompter:Dest()
  prompter.dec["frame"]:hide()
end

function onDecAnswer(args)
  display("Answer given was: "..args)
end

prompter:questionBox("title frame", "Which fruit would you like to eat?",onDecAnswer)
Note that it takes in the function, not the function name as a callback. There's loads of improvements you can do on this, it is just a basic example.

User avatar
chris
Posts: 493
Joined: Fri Jun 17, 2011 5:39 am

Re: Geyser UI Scripts

Post by chris »

To get a line-break, use the <br> character as well. \n doesn't work, HTML formatting seems to be needed. For my instance, I use this script to handle room collisions. If a player has a room colliding it'll prompt to have the map manage the collision automatically or cancel room creation.

User avatar
Akaya
Posts: 414
Joined: Thu Apr 19, 2012 1:36 am

Re: Geyser UI Scripts

Post by Akaya »

Here's my own attempt at it. The idea was to have it create a custom label. After the label is created, it will loop back to the original prompter.
Label Creation.mpackage.zip
Corrected the image path
(6.28 MiB) Downloaded 734 times
Last edited by Akaya on Sat Dec 15, 2012 8:20 am, edited 3 times in total.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Geyser UI Scripts

Post by Vadi »

Haha, that's really interesting. The font size on the label though was too big until after the X position question, after that it scaled down and all the text fit.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Geyser UI Scripts

Post by Vadi »

The images don't show though, you hardcoded them to your computer - changing to the following, as an example:
Code: [show] | [select all] lua
border-image: url(]]..getMudletHomeDir()..[[/LabelCreation/red.png);
Would fix it.

Post Reply