ID:160360
 
I was wondering how about I would go about bringing up an in-game window where you could make selections that would effect in game. I was wondering how I could make the window pop up and how to close it and how to change what's in the window. If anyone knows, thanks!
winshow(src,"Window_Name",0)//to hide
winshow(src,"Window_Name",1) or winshow(src,"Window_Name") //to show
Speedro wrote:
I was wondering how about I would go about bringing up an in-game window where you could make selections that would effect in game. I was wondering how I could make the window pop up and how to close it and how to change what's in the window. If anyone knows, thanks!

If you have such a window already defined in your skin, just use winshow() to make it show up. Use winset() to change any values in it (I'd do so before showing it, when initializing the window), and then just hook any buttons or whatnot to different commands.

As an example, in SotS II there's a window I use for game settings. Right now the host has access to two settings: Minimum number of players in any game, and minimum players per team in a team game. The window has four buttons and two text controls. Each setting has an up and down button linked to a command that changes their value; the verb that makes the change also sends an update to the appropriate label using winset(). It generally looks something like this:

// add this verb to the game host's verb list
mob/host/verb/SettingChange(setting as text, change as num)
var/n = host_settings[setting]
var/delta = change
if(!isnull(n) && delta)
// check for fractional values so nothing gets screwed up
var/new_n = n + round(delta, 1)
var/min_n = (min_settings[setting] || 0)
var/max_n = max_settings[setting]
if(new_n < min_n)
new_n = min_n
else if(!isnull(max_n) && new_n > max_n)
new_n = max_n
if(new_n == n) return
host_settings[setting] = new_n
usr.UpdateSetting(setting)
SaveSettings()

mob/proc/UpdateSetting(setting)
var/n = host_settings[setting]
var/min_n = (min_settings[setting] || 0)
var/max_n = max_settings[setting]
src << output(GetSettingLabelText(setting), "settingswindow.label_[ckey(setting)]")
if(client) winset(src, "settingswindow.down_[ckey(setting)]", "is-disabled=[n>min_n?"false":"true"]")
if(client && !isnull(max_n)) winset(src, "settingswindow.up_[ckey(setting)]", "is-disabled=[n<max_n?"false":"true"]")


This code makes a few assumptions. It's expecting an associative list called host_settings, where the associated values (at least the ones used by this numerical routine) are numbers. host_settings["min_players"]==4 might be your default, for isntance. min_settings and max_settings are also associative lists, but you don't need to fill in values if you don't want to; the minimum is always treated as 0 in this code unless you tell it otherwise, and the max is unbounded.

Finally there's a proc called GetSettingLabelText(), which might look something like this:

proc/GetSettingLabelText(setting)
var/value = host_settings[setting]
switch(setting)
...
if("min_players")
return "[value] or more player\s per game"
if("hp")
return "[value] hit point\s per player"
...


Then when setting up your skin, each numerical setting has two buttons and a label.

label_minplayers
type=LABEL
down_minplayers
type=BUTTON
command="SettingChange \"min_players\" -1"
text="-"
up_minplayers
type=BUTTON
command="SettingChange \"min_players\" 1"
text="+"


As you can see, the output to the label will always refresh its text when the value is changed, by calling UpdateSetting(). The buttons will also enable/disable as needed. Before you first call winshow(), just be sure to call UpdateSetting() for each setting so everything is set up correctly.

Lummox JR
In response to Lummox JR
I'm finding this incredibly confusing. How am I to make a new "Skin" or whatever? I'm just looking to maybe put two selections in it, maybe am icon or two. Isn't there an easy simple way?


winset(src,"is-visible=true;text-color=#f00","heya")
That's the best I could come up with. Heck, I copied the "is-visible" stuff from the reference, so yeah.
In response to Speedro
1) You swapped the window and param parts around :P
2) Yeah, you need to make a skin to swap and add stuff, unless you feel like messing around with the default skin with winset() (or by placing the default skin into the directory, I forget where to find it though).
In response to Jeff8500
Too bad I couldn't just open up paint to make a skin.
In response to Speedro
How would that even work? You wouldn't be able to choose what you want each control can do, making most skin function worthless. You can use a picture, for a background etc., if you want, though.
In response to Lummox JR
Oh, are skins the "interface" files?
In response to Lummox JR
I'm unaware of what a "skin" actually is, and how to create one. :/
In response to Speedro
Yea..
Is there a place I can learn how to make these interface screens? I'd really like to use them for shops.