RCRPG/Julia: Difference between revisions
Content added Content deleted
m (→GUI Code) |
m (→GUI Code) |
||
Line 573: | Line 573: | ||
==GUI Code== |
==GUI Code== |
||
<lang julia> |
<lang julia>using Gtk.ShortNames, Colors, Cairo, Graphics |
||
using Gtk.ShortNames, Colors, Cairo, Graphics |
|||
#============== GUI CODE ===================# |
#============== GUI CODE ===================# |
||
Line 598: | Line 597: | ||
push!(vbox, textdisplay) |
push!(vbox, textdisplay) |
||
mainchoices = ["N", "S", "E", "W", "Up", "Down", "Inven", "inFo", "Take", "Remove", "eQuip", "Attack", "Help"] |
mainchoices = ["N", "S", "E", "W", "Up", "Down", "Inven", "inFo", "Take", "Remove", "eQuip", "Attack", "aLiases", "Help"] |
||
aliases = Dict{String, String}() |
|||
directionchoices = ["N", "S", "E", "W", "U", "D"] |
directionchoices = ["N", "S", "E", "W", "U", "D"] |
||
yesnochoices = ["Yes", "No"] |
yesnochoices = ["Yes", "No"] |
||
yesnoquitchoices = ["Yes", "No", "Quit"] |
yesnoquitchoices = ["Yes", "No", "Quit"] |
||
aliases = Dict{String, String}() |
|||
struct DisplayUpdate |
struct DisplayUpdate |
||
Line 612: | Line 613: | ||
inputchan = Channel{String}(1000) |
inputchan = Channel{String}(1000) |
||
kbinput(w, event) = (push!(inputchan, string(Char(event.keyval))); 1) |
|||
signal_connect( |
inputhid = signal_connect(kbinput, win, "key-press-event") |
||
dchan = Channel{DisplayUpdate}(100) |
dchan = Channel{DisplayUpdate}(100) |
||
Line 690: | Line 691: | ||
#============== INPUT INTERFACE BETWEEN GUI AND GAME PLAY VIA CHANNELS =======================# |
#============== INPUT INTERFACE BETWEEN GUI AND GAME PLAY VIA CHANNELS =======================# |
||
function aliasing(player) |
|||
aliaschan = Channel{String}(4) |
|||
aliaskeyhit(w, event) = push!(aliaschan, string(Char(event.keyval))) |
|||
signal_handler_block(win, inputhid) |
|||
hid = signal_connect(aliaskeyhit, win, "key-press-event") |
|||
logln("Hit the CURRENTLY DEFAULT key for function:") |
|||
oldch = take!(aliaschan) |
|||
logln("Hit the TO BE AN ALIAS key for the last key:") |
|||
newch = take!(aliaschan) |
|||
aliases[newch] = oldch |
|||
signal_handler_disconnect(win, hid) |
|||
signal_handler_unblock(win, inputhid) |
|||
end |
|||
function queryprompt(menu, options, txt="") |
function queryprompt(menu, options, txt="") |
||
Line 698: | Line 713: | ||
while true |
while true |
||
choice = uppercase(take!(inputchan)) |
choice = uppercase(take!(inputchan)) |
||
if haskey(aliases, choice) |
|||
choice = uppercase(aliases[choice]) |
|||
end |
|||
if choice in options |
if choice in options |
||
swapforlastinbox(oldmenu, vbox) |
swapforlastinbox(oldmenu, vbox) |
||
Line 956: | Line 974: | ||
help(player=nothing) = push!(lchan, |
help(player=nothing) = push!(lchan, |
||
"n north, s south, w west, e east, d down, u up, i inventory, f roominfo, t take, r drop, q equip, a attack/dig") |
"n north, s south, w west, e east, d down, u up, i inventory, f roominfo, t take, r drop, q equip, a attack/dig, l aliases") |
||
playerdisplayinventory(player) = push!(lchan, "Inventory: $(player.inventory)\nWielding: $(player.wielding)\n") |
playerdisplayinventory(player) = push!(lchan, "Inventory: $(player.inventory)\nWielding: $(player.wielding)\n") |
||
Line 1,180: | Line 1,198: | ||
"U" => playerup, "D" => playerdown, "I" => playerdisplayinventory, |
"U" => playerup, "D" => playerdown, "I" => playerdisplayinventory, |
||
"F" => playerroominfo, "T" => playertake, "R" => playerremove, |
"F" => playerroominfo, "T" => playertake, "R" => playerremove, |
||
"Q" => playerequip, "A" => playerdig, "H" => help) |
"Q" => playerequip, "A" => playerdig, "L" => aliasing, "H" => help) |
||
function rungame() |
function rungame() |