! StatusLineColors.inf -- Source code for Inform 6.21 Library 6/10 ! ! Implemented by Jay Goemmer (downbelow@ltlink.com), with extensive ! revisions by Roger Firth (roger@firthworks.com), 01 Feb 2003. ! ! Please send any comments or suggestions you may have to Jay at the ! address above. Thanks! ! ! On 04 Jan 2003, I posted the following article to rec.arts.int-fiction. ! ! Subject: [Inform] Changing Status Line Colo(u)r ! ! << I'm working on an Inform piece in which I'm thinking of enabling the player to "turn on" ! (and off) some color status line "special effects" which change in different "zones" of ! the game. (They'd be turned off by default when the game booted, and would be completely ! optional.) I don't want to go as far as "Photopia," with colored text on the entire page, ! but *only* changing the *status line background color.* ! ! Usually I set my Inform interpreter (David Kinder's "Windows Frotz 2002") to the standard ! "B&W monochrome" color scheme, with grey foreground text, black background, white "bold" ! text, and standard "black on grey" reverse status line -- and just wanted to spice things ! up a tiny bit.>> ! ! The following source code is the result of the responses I received. --JG Constant Story "STATUS LINE COLORS"; Constant Headline "^^An Inform Source Code Example ^Implemented by Jay Goemmer (downbelow@@64ltlink.com) and Roger Firth (roger@@64firthworks.com) ^^^"; Serial "030201"; Release 1; Array printed_text --> 64; ! Center location on status line, DM4. Global StatusColors = false; ! Suggested by Roger Firth instead of Object "Color_Object." Replace DrawStatusLine; ! Location centered on status line, customized for colors. Include "Parser"; Object LibraryMessages ! Include between Parser and VerbLib with before [; Prompt: print "^> "; rtrue; ]; Include "Verblib"; ! Roger Firth wrote, "I have a few suggested changes for you." ! ! ! Status line "colors option" ! ! A set of constants for the colors is good practice: --RF ! ! ! Standard colors list (DM4, p. 311): ! ! Current color (0), default color (1), black (2), red (3), green (4), ! yellow (5), blue (6), magenta (7), cyan (8), white (9). ! Constant COL_CUR = 0; ! Constant COL_DFT = 1; Constant COL_BLK = 2; Constant COL_RED = 3; Constant COL_GRN = 4; Constant COL_YEL = 5; Constant COL_BLU = 6; Constant COL_MAG = 7; Constant COL_CYA = 8; Constant COL_WHI = 9; ! 1. It's almost /always/ a good idea to start with a Room class, ! where you can put standard stuff like "has light". In your case ! you can also deal with "OUT" here. --RF Class Room with out_to [; return self.cant_go(); ], ! Redirects "out" to "cant_go" string. has light; ! 2. Your Zone classes can now inherit from Room. Also, they can ! define their own colours. --RF Class BlackZone class Room with fg COL_WHI, bg COL_BLK; ! White on Black Class RedZone class Room with fg COL_WHI, bg COL_RED; ! Black on Red Class GreenZone class Room with fg COL_BLK, bg COL_GRN; ! Black on Green Class YellowZone class Room with fg COL_BLK, bg COL_YEL; ! Black on Yellow Class BlueZone class Room with fg COL_WHI, bg COL_BLU; ! White on Blue Class MagentaZone class Room with fg COL_BLK, bg COL_MAG; ! Black on Magenta Class CyanZone class Room with fg COL_BLK, bg COL_CYA; ! Black on Cyan Class WhiteZone class Room with fg COL_BLK, bg COL_WHI; ! Black on White ! 4. Your rooms become simpler; you can leave out the "class" bit, the ! "has light" bit, and the "out_to" bit (except in the Cyan room, where ! you override the default out_to). --RF ! Opening room uses "describe" routine instead of "description" string. BlackZone Black_Room "Black Sector -- Square One" with describe [; if (StatusColors == false) print "^ The current status line colors should be the ones you've already specified for your interpreter."; else print "^ In this room, the status line now has white text on a black background."; print "^^^Exits lead N, S, E, W, UP, DOWN, IN, and OUT.^"; ], n_to White_Room, s_to Green_Room, e_to Magenta_Room, w_to Blue_Room, u_to Yellow_Room, d_to Red_Room, in_to Cyan_Room, out_to Neutral_Room, ! For testing "default" colors in non-colored zone. --JG cant_go "^ ~Other sectors can be accessed by going N, S, E, W, UP, DOWN, IN and OUT.~"; ! Format: ! ! Class Object "Short_Name" --JG RedZone Red_Room "Red Sector -- Gehenna" with description "^ Flames lick at you as unearthly screams pierce the sulphurous air. ^^^A shaft extends upward.", u_to Black_Room, cant_go "^ ~Look to Heaven for deliverance.~"; GreenZone Green_Room "Green Sector -- Jungle" with description "^ Exceedingly high levels of humidity drench your clothes with sweat. ^^^The vegetation is thinner to the north.", n_to Black_Room, cant_go "^ ~Travel towards an arctic climate will cool you off.~"; YellowZone Yellow_Room "Yellow Sector -- Solar Orbit" with description "^ You hang suspended just outside the sun's photosphere. ^^^The Earth waits, ninety-three million miles beneath your feet.", d_to Black_Room, cant_go "^ ~Down, Rover. *Good* dog.~"; BlueZone Blue_Room "Blue Sector -- Beneath the Ocean" with description "^ Rays of sunlight piercing the waves flash briefly, reflected from exotically scaled creatures. ^^^Eastward, you sense a looming coastline.", e_to Black_Room, cant_go "^ ~Go east, young, um, er -- human.~"; MagentaZone Magenta_Room "Magenta Sector -- Undisclosed Location" with description "^ There's nothing here which would clearly identify where you are. ^^^Oddly, you found yourself drawn to the west.", w_to Black_Room, cant_go "^ ~Westward, the tide.~ Or more correctly, even *further* west."; CyanZone Cyan_Room "Cyan Sector -- Inner Sanctum" with description "^ The realm of private thought seems poorly lit. ^^^You'll probably see things more clearly once you're outside.", out_to Black_Room, cant_go "^ It's probably better to ~let it all out.~"; WhiteZone White_Room "White Sector -- Arctic Icefield" with description "^ Countless acres of ice and snow stretch away from you in all directions. ^^^Warmer climes are found toward the equator.", s_to Black_Room, cant_go "^ ~It's warmer way down south.~"; ! "Non-colored" sector room for demonstration purposes. ! Defaults to standard "reverse" color scheme. Room Neutral_Room "Deep Space -- Galactic View" with description "^ A spiral galaxy fills the void before you. ^^^It's hard to judge how far away you are from the teeming sea of stars.", in_to Black_Room, cant_go "^ ~You're so far out, it's like the Sixties again.~"; [ Initialise; Location = Black_Room; print "^^ As an Inform implementor, have you ever wanted to spice your games up with just a splash of color? This programming example will enable you to include a color option for the status line. ^^ Other Inform library extensions (notably, L. Ross Raszewski's ~Utility.h~ and Patrick Kellum's ~text_functions.h~) provide some shortcuts for game authors to ~colorize~ various strings of text -- but this example affects *only* the status line. ^^ However, some players find pre-assigned colored text schemes somewhat difficult to read, depending on their interpreter -- so the ~COLORS~ option in this programming example is turned *off* by default. The player must turn it on by typing ~COLOR~ (or ~COLOUR~) at the prompt, and the status line colors can be deactivated by typing ~COLOR OFF~ (or ~MONO,~ if you prefer). ^^ If you have any comments, please e-mail Jay at the address below. Thanks! ^^^"; ]; Include "Grammar"; ! "Color" metaverb -- turns status line "color" option on and off. Verb meta "color" "colors" "colour" "colours" * ->ColorsOn * "on" ->ColorsOn * "off" ->ColorsOff; ! Synonym suggested by Cedric Knight. Verb meta "mono" "monochrome" "monochromatic" * ->ColorsOff * "on" ->ColorsOff * "off" ->ColorsOn; ! 5. Your logic on "already activated" and "already deactivated" didn't ! work -- the "else" was pairing with the wrong "if". Also, <> is ! simpler than PlayerTo(). --RF [ ColorsOnSub; if (StatusColors == true) "^ Status line ~COLORS~ option already activated."; StatusColors = true; DrawStatusLine(); print "^ Status line ~COLORS~ option activated.^"; if (real_location == Black_Room) <>; ! Displays original room description. if (real_location == White_Room) print "^ There may be no apparent change in the status line at *this* location.^"; if (real_location == Neutral_Room) print "^ You fail to notice any chromatic deviation at your present spatial coordinates.^"; ]; [ ColorsOffSub; if (StatusColors == false) "^ Status line ~COLORS~ option already deactivated."; StatusColors = false; DrawStatusLine(); print "^ Status line ~COLORS~ option deactivated.^"; if (real_location == Black_Room) <>; ! Displays original room description. ]; ! Actually "Color_Object" isn't a good name any more. Suggest a global ! rename to "UsingStatusColors", and then the tests can be written as ! if (UsingStatusColors) ... and if (~~UsingStatusColors) ... --RF ! Location centered on status line, DM4. ! "Colors" modification assisted by Roger Firth and Cedric Knight. ! ! Insert the call to the "SetColor" routine at the appropriate place ! in your preferred "DrawStatusLine" routine. [ DrawStatusLine i j; i = 0->33; font off; @split_window 1; @set_window 1; SetColor(); ! Decide whether to apply color to status line. @set_cursor 1 1; spaces(i); @output_stream 3 printed_text; print (name) location; @output_stream -3; j = (i-(printed_text-->0))/2; @set_cursor 1 j; print (name) location; spaces(j-1); @set_cursor 1 1; style roman; @set_window 0; @set_colour 1 1; @buffer_mode 1; font on; ]; ! 6. This routine now becomes almost not worth having. Then again, ! maybe it is after all. --RF [ SetColor f b; if (StatusColors == true && real_location provides fg) { f = real_location.fg; b = real_location.bg; @set_colour f b; ! Use specified zone colors. } else style reverse; ! Use traditional inverse scheme. ]; ! HELP *meta* verb. ! Usually "Synonym" = "Verb"; but *not* so in this case. Verb meta "help" "hint" "hints" "menu" "menus" "about" "thanks" "credits" * -> Help; [ HelpSub; print "^ Obviously, the best way to use this programming example is to paste it into the existing source code for the game to which you'd like to add this ~COLORS~ option, and modify the color schemes as you see fit."; style bold; print "^^ Special thanks to Roger Firth and Cedric Knight (who recommended the ~MONO~ command to turn things off), both of whom offered suggestions for implementing this ~Status Line Colors~ option. ^^ Additional thanks to Roger, who perused my source code, and suggested not one, but *two* revisions. In effect, he clicked his tongue and shook his head, all the while leading me on to the ~Higher Path of Inform Programming.~ His suggestions are greatly appreciated, and are specifically noted herein. ^^ Also thanks to L. Ross Raszewski, Fredrik Ramsberg, and John Colagioia, for debugging the syntax error in my original ~SetColor~ routine."; style roman; print "^^--Jay Goemmer (downbelow@@64ltlink.com) ^^"; ]; End;