-- == menu subsystem == menuy = 1 function addtomenu(M, key, writer, act, hid) table.insert(M, {key = key, displayAt = writer, action = act, hidden = hid}) end function writechoice(x) return function(M) scrwrite(IMG, 1, menuy, string.upper(M.key).." - "..x, Font, vgaget(15)) menuy = menuy + 1 end end function writechoicef(x) return function(M) scrwrite(IMG, 1, menuy, string.upper(M.key).." - "..x(), Font, vgaget(15)) menuy = menuy + 1 end end function writechoicecol(x, cf) return function(M) scrwrite(IMG, 1, menuy, M.key.." - "..x, Font, vgaget(cf())) menuy = menuy + 1 end end function dfthdr(title) return function() menuy = 1 scrwrite(IMG, 1, menuy, title, Font, vgaget(14)) menuy = 3 end end function mainhdr() menuy = 6 title = hydraonly and "Hydra Slayer "..hydraver or "Necklace of the Eye "..noteyeversion.." - "..gamename scrwrite(IMG, 1, 1, title, Font, vgaget(14)) scrwrite(IMG, 1, 3, gameon and "press ENTER to resume playing" or "press ENTER to return to the main menu", Font, vgaget(7)) scrwrite(IMG, 1, 4, "NotEye website: http://roguetemple.com/z/noteye.php", Font, vgaget(7)) end function menuexecute(M, hdr, tail) while true do scrfill(IMG, 0, 0, conssize.x, conssize.y, 0) hdr() -- for k,v in pairs(M) do if not (v.hidden and v.hidden()) then v.displayAt(v) end end if tail then tail() end viewmenu() inmenu = M lev = getevent() cont = false if lev.type == evMouseDown then local y = math.floor(lev.y / fontsize.y) local x = math.floor(lev.x / fontsize.x) local ch = gch(scrget(IMG, 1, y)) lev.type = evKeyDown lev.symbol = av(string.lower(ch)) lev.chr = av(string.lower(ch)) end if lev.type == evKeyDown then userremap(lev) local chr = string.char(lev.chr) for k,v in pairs(M) do if chr == v.key and not (v.hidden and v.hidden()) then cont = v.action(v) break end end if not cont then break end elseif checkstreams() then elseif lev.type == 0 then sleep(10) end end end -- == ask for string == function askstr(text, question, warning) while true do scrfill(IMG, 0, 0, conssize.x, conssize.y, 0) local function write(y, text) scrwrite(IMG, 1, y, text, Font, vgaget(15)) end write(1, question) write(3, text) write(5, "ENTER to submit, ESC to cancel, TAB to erase") if warning then write(7, "Warning: BE CAREFUL WHILE RUNNING AS A SERVER!") write(8, "see the website for details: ") write(9, "http://www.roguetemple.com/z/noteye.php") end viewmenu() inmenu = "askstr" lev = getevent() if lev.type == evKeyDown then userremap(lev) if lev.symbol == 27 then return elseif lev.symbol == SDLK_TAB then text = "" elseif lev.symbol == SDLK_RETURN then return text elseif lev.symbol == SDLK_BACKSPACE then text = string.sub(text, 0, #text-1) elseif lev.chr > 0 then text = text .. string.char(lev.chr) end elseif checkstreams() then elseif lev.type == 0 then sleep(10) end end end -- == fonts menu == fontsmenu = {} function addFont(key,name,a,b,c,d,menu) addtomenu(menu or fontsmenu, key, writechoice(name), function () print("action called") selectfontfull(loadfont(a,b,c,d)) end ) end function addFontScaled(key,name,a,b,c,d,e,f) addtomenu(fontsmenu, key, writechoice(name), function () selectfontfull(scalefont(loadfont(a,b,c,d),e,f,d)) end ) end addFont("q", "VGA font 8x16 (DOS default)", "cp437-16", 32, 8, fontSimple) addFont("a", "VGA font 8x14", "cp437-14", 32, 8, fontSimple) addFont("z", "VGA font 8x8", "cp437-8", 32, 8, fontSimple) addFont("w", "VGA font 12x24 (3/2 size)", "cp437-24", 32, 8, fontSimple) addFontScaled("e", "VGA font 16x32 (double size)", "cp437-16", 32, 8, fontSimple, 2, 2) addFontScaled("d", "VGA font 16x28 (double size)", "cp437-14", 32, 8, fontSimple, 2, 2) addFontScaled("c", "VGA font 16x16 (double size)", "cp437-8", 32, 8, fontSimple, 2, 2) addFont("t", "Fantasy font 16x32", "fantasy-32", 32, 8, fontSimple) addFont("b", "Fantasy font 16x16", "fantasy-16s", 32, 8, fontSimple) addFont("g", "Fantasy font 8x16", "fantasy-16", 32, 8, fontSimple) addFont("u", "DejaVu Mono 10x20", "dejavu-20", 32, 8, fontSimple) if havebrogue then for u=1,5 do addFont(""..u, "Brogue font #"..u, "BrogueFont"..u, 16, 16, fontBrogue ) end end -- == graphical modes menu == modesmenu = {} function addgraphmode(key, text, m, menu) addtomenu(menu or modesmenu, key, writechoicecol(text, function () return mode == m and 14 or 7 end), function () mode = m end ) end addgraphmode("p", "plain ASCII only (look at the map)", modeASCII) addgraphmode("t", "tile mode", modeTiles) addgraphmode("f", "first person perspective", modeFPP) addgraphmode("i", "isometric projection", modeISO) addgraphmode("j", "mini-tile mode", modeMini) addgraphmode("d", "double mini-tiles", modeMed) -- == keys menu == keysmenu = {} addtomenu(keysmenu, "d", writechoicef(function() return "diagonal movement: "..namediag() end), function () diagleft = not diagleft if diagleft then diagright = not diagright end return true end ) addtomenu(keysmenu, "k", writechoicef(function() return "keys: "..currentKeymap.name end), function () if lastkeymap and not keymapidx then currentKeymap,lastkeymap = lastkeymap, currentKeymap keymapidx = (currentKeymap == gotKeymaps[1]) and 1 or 0 else if not lastkeymap then lastkeymap = currentKeymap end if not keymapidx then keymapidx = (currentKeymap == gotKeymaps[1]) and 1 or 0 end keymapidx = keymapidx + 1 if keymapidx > #gotKeymaps then keymapidx = 1 end currentKeymap = gotKeymaps[keymapidx] end return true end ) addtomenu(keysmenu, "r", writechoicef(function() return "user keymap (config.noe): "..boolonoff(useuserremaps) end), function() useuserremaps = not useuserremaps return 1 end, function() return not gotuserremaps end ) -- == screenshots menu == function gameonly() return gamename == "auto" end function nogameonly() return gamename ~= "auto" end shotsmenu = {} addtomenu(shotsmenu, "b", writechoice("BMP"), function() copymap() drawdisplay() local fname = shotdir..curdate()..".bmp" saveimage(1, fname) end ) addtomenu(shotsmenu, "h", writechoice("HTML"), function() scrsave(S, shotdir..curdate()..".html", 0) end ) addtomenu(shotsmenu, "p", writechoice("phpBB"), function() scrsave(S, shotdir..curdate()..".txt", 1) end ) -- == network menu == netmenu = {} addtomenu(netmenu, "v", writechoicef( function() if VIEW then return "stop viewing" elseif SERVER then return "disconnect from the server" else return "view a recording" end end), function() if VIEW then delete(VIEW) VIEW = nil elseif SERVER then delete(SERVER) SERVER = nil else--if not P then local ret = askstr(viewfile, "enter the name of the file to view") if not ret then return false end viewfile = ret startviewing() end end ) addtomenu(netmenu, "c", writechoicef(function() if VIEW then return "viewing speed: "..viewspeed elseif SERVER then return "disconnect from the server" else return "connect to a server" end end ), function() if VIEW then viewspeed = applymod(viewspeed, mod) elseif SERVER then delete(SERVER) SERVER = nil elseif not P then local ret = askstr(serverhost, "enter the host name") if not ret then return false end serverhost = ret ret = askstr("" .. portclient, "enter the port number") if not ret or not tonumber(ret) then return false end portclient = tonumber(ret) SERVER = nconnect(serverhost, portclient) if SERVER == 0 then SERVER = nil localmessage("Connection failed") else initviewer(SERVER) end end return 1 end ) addtomenu(netmenu, "p", writechoicef(function() return servemode and "send P/T/R to viewers" or "let viewers decide P/T/R" end), function() servemode = not servemode return 1 end ) addtomenu(netmenu, "r", writechoicef( function() return REC and "finish recording" or "start recording to "..recfile end), function() if REC then delete(REC) REC = nil else local ret = askstr(recfile, "enter the name of the file to record") if not ret then return false end recfile = ret startrecording() if REC then sendscreen(REC) sendfacedir(REC) sendcursor(REC) sendmode(REC) nflush(REC) end end return 1 end ) addtomenu(netmenu, "q", writechoicef(function() return "rec speed: "..recspeed end), function() recspeed = applymod(recspeed, mod) return 1 end, function() return not REC end ) addtomenu(netmenu, "s", writechoicef(function() if ACCEPT then return "disable server ("..table.getn(CLIENTS)..")" elseif network == 1 then return "run a server on port "..portserver else return "server disabled" end end), function() if network ~= 1 then elseif ACCEPT then stopserver() else ret = askstr("" .. portserver, "enter the port number", 1) if not ret or not tonumber(ret) then return false end portserver = tonumber(ret) startserver() end return 1 end ) addtomenu(netmenu, "i", writechoicef(function() return serveinput and "accept input from clients" or "reject input from clients" end), function() serveinput = not serveinput return 1 end ) addtomenu(netmenu, "e", writechoice("erase messages from the screen"), function() messages = {} return 1 end ) addtomenu(netmenu, "m", writechoice("add message"), function() local lmessage = askstr("", "Enter your message:") if lmessage then if SERVER then nwriteint(SERVER, nepMessage) nwritestr(SERVER, lmessage) nflush(SERVER) else addmessage(lmessage) end end return 1 end, function() return gameon end ) -- == tech menu == techmenu = {} addtomenu(techmenu, "s", writechoicef(function() return frames and "S - fps: "..frames/frametime or "S - measure fps" end), function() fps_start = os.clock() frames = 0 end ) addtomenu(techmenu, "r", writechoice("refresh NotEye script files"), function() print "Refreshing configuration." justrefreshing = true dofile(commondir.."generic.noe") prepareconsole() if gamename ~= "auto" then dofile(gamesdir..gamename..".noe") end prepareconsole() justrefreshing = false end ) addtomenu(techmenu, "t", writechoice("tile test"), function() dofile(commondir.."tiletest.noe") end ) addtomenu(techmenu, "c", writechoice("console helper"), function() conshelp = not conshelp end ) -- == main menu == mainmenu = {} addtomenu(mainmenu, "f", writechoice("switch fullscreen (also Alt+Enter)"), function() fscr = not fscr setvideomodex() end ) addtomenu(mainmenu, "m", writechoice("select NotEye's graphical mode"), function() menuexecute(modesmenu, dfthdr("Select your graphical mode:")) end ) addtomenu(mainmenu, "g", writechoice("grab a screenshot"), function() menuexecute(shotsmenu, dfthdr("Select the screenshot format:")) end, gameonly ) addtomenu(mainmenu, "r", writechoice("select font and resolution"), function() menuexecute(fontsmenu, dfthdr("Select your font and resolution:")) end ) addtomenu(mainmenu, "k", writechoice("configure keyboard input"), function() menuexecute(keysmenu, dfthdr("Configure input:")) end ) addtomenu(mainmenu, "n", writechoice("network, recording and viewing"), function() menuexecute(netmenu, dfthdr("Network / recording / viewing")) end ) addtomenu(mainmenu, "v", writechoicef(function() return "configure audio (sound volume "..volsound..", music volume "..volmusic..")" end), function() ret = askstr("" .. volsound, "enter the sound volume (1-128, or 0 to turn off):") if tonumber(ret) then volsound = tonumber(ret) end ret = askstr("" .. volmusic, "enter the music volume (1-128, or 0 to turn off):") if tonumber(ret) then volmusic = tonumber(ret) end musicvolume(volmusic) if volmusic == 0 then musichalt() end return 1 end, function() return not havemusic end ) addtomenu(mainmenu, "l", writechoice("connect to libtcod (Brogue etc)"), function() SERVER = nconnect(libtcodhost, libtcodport) if SERVER == 0 then SERVER = nil print("No server!") else viewmode = true initviewer(SERVER) viewmode = false gamename = "auto" return true end end, nogameonly ) addtomenu(mainmenu, "d", writechoice("NotEye development functions"), function() menuexecute(techmenu, dfthdr("Development functions:")) end ) addtomenu(mainmenu, "c", writechoice("view using a selected config"), function() viewmode = true end, nogameonly ) addtomenu(mainmenu, "q", writechoice("stop viewing mode"), function() stoploop = true end, function() return not viewmode end ) -- == ok, done == if usermenus then usermenus() end function noteyemenu() keymapidx = nil menuexecute(mainmenu, mainhdr) end