diff --git a/naledi.lisp b/naledi.lisp index f631847..0a3bc4f 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -12,12 +12,11 @@ (defun start-game () "Start the game logic and UI" - ;;FIXME revamp for networking - (start-server) (croatoan:with-screen (scr :input-blocking *framerate* :enable-colors t :input-echoing nil :cursor-visibility nil :input-reading :unbuffered) (splash-screen scr) + (choose-local-or-remote scr) (user-interface scr))) (defun splash-screen (scr) @@ -39,6 +38,43 @@ ((nil) nil) (otherwise (return-from croatoan:event-case))))) +(defun choose-local-or-remote (scr) + "Choose whether to start a local game or connect to a remote server" + (croatoan:clear scr) + (croatoan:refresh scr) + (let ((mw (make-instance 'croatoan:dialog-window + :title "Welcome!" + :center t + :border t + :width 50 + :max-item-length 42 + :input-blocking t + :cyclic-selection t + :current-item-mark "* " + :items '("Start a local game" + ;;TODO "Load a saved game" + "Connect to a remote server")))) + ;;XXX I have to effectively reimplement (select-item menu) because + ;; the screen grabs all user input and none arrives at the window + (croatoan:draw-menu mw) + (croatoan:event-case (scr event) + ((nil) nil) + ((:up :down) + (croatoan:update-menu mw event) + (croatoan:draw-menu mw)) + (#\newline + (cond ((equalp (croatoan:current-item mw) "Start a local game") + (start-server) + (sleep 0.5) ;;give the server time to start + (connect-server)) + ((equalp (croatoan:current-item mw) + "Connect to a remote server") + (connect-server (enter-server-address)))) + (return-from croatoan:event-case))))) + + +(defun enter-server-address ()) + (defun user-interface (scr) "Create the screen on the ncurses interface and hand over to window functions" (let* ((width (croatoan:.width scr)) (height (1- (croatoan:.height scr))) @@ -66,7 +102,7 @@ (#\q (disconnect) (terminate) (return-from croatoan:event-case)) ;XXX - (#\n (draw-menu (message-window))) + (#\n (croatoan:draw-menu (message-window))) (:up (decf (second me)) (update-ui mapwin playerwin placewin newswin me)) (:down (incf (second me)) (update-ui mapwin playerwin @@ -159,8 +195,7 @@ (defun message-window () "Return a dialog window with the last game messages." ;;TODO complete - ;;FIXME causes an error somewhere in the croatoan library... - (make-instance 'dialog-window + (make-instance 'croatoan:dialog-window :input-blocking t :items (break-lines (mapcar #'(lambda (n) (string-from-list (list "*" n))) @@ -172,7 +207,6 @@ :layout nil :title "Game messages" :max-item-length 50 - :scrolled-layout '(10 1) :message-height 2 :message-text "Press b to go back."))) ;;:event-handlers '((#\b #'exit-event-loop)))))