Menu

Inserting web pages into LAC missions

bbosen
2020-06-02
2023-02-19
  • bbosen

    bbosen - 2020-06-02

    Since version 8.11, we have been encouraging LAC users to install the free, well-known "firefox" web browser in their LINUX computers hosting LAC. This is optional, and LAC will run without firefox, but almost everybody has firefox anyway, so it isn't usually a problem. Alternatively, if the user has "chromium" installed, they can use that. LAC missions can invoke either of those two very popular web browsers when it's appropriate to show a web page on top of or within a mission.

    In support of this, LAC already has an infrastructure that players can use to designate their preferred browser. This is controlled by the "PreferredBrowser" configuration variable within the user's ~home/.LAC/LacConfig.txt configuration file. By editing that variable, users can choose either browser, or if they set that variable to "none", then LAC will harmlessly skip any attempt by any mission to use a browser.

    Here is a very simple code block sample showing how to invoke a browser from within a LAC mission:

    > if (!strcmp (&PreferredBrowser[0], "firefox"))
    >    { // Get here if the user's Preferred Browser is firefox
    >    sprintf (DebugBuf, "%s -width %d -height %d https://AskMisterWizard.com/2019/LinuxAirCombat/Planes/%.2d.htm", PreferredBrowser, BrowserWidth, BrowserHeight, SelectedAircraft);
    >    display (DebugBuf, LOG_MOST);
    >    // Now use that command line to invoke the browser:
    >    PopenStatus = popen(DebugBuf, "r");
    >    if (PopenStatus != NULL)
    >       { // Get here if popen() was at least partially successful.
    >       sprintf (DebugBuf, "callbackSwitchMultimedia() is attempting to invoke %s.", PreferredBrowser);
    >       display (DebugBuf, LOG_MOST);
    >       sound->haltMusic(); // shut off LAC's music in favor of firefox media
    >       sound->stopAll();
    >       }
    >    else
    >       {
    >       display ((char *)"callbackSwitchMultimedia(): LINUX reported an error after attempting to invoke PreferredBrowser.",LOG_MOST);
    >       }
    >    }
    > else if (!strcmp (&PreferredBrowser[0], "chromium"))
    >    { // Get here if preferred browser is "chromium"
    >    sprintf (DebugBuf, "%s --app=\"https://AskMisterWizard.com/2019/LinuxAirCombat/Planes/%.2d.htm\"", PreferredBrowser, SelectedAircraft);
    >    // Try to open a browser based on that command line:
    >    FILE* PopenStatus;
    >    PopenStatus = popen(DebugBuf, "r");
    >    if (PopenStatus != NULL)
    >       { // Get here if popen() was at least partially successful.
    >       display ((char *)"callbackSwitchMultimedia() is attempting to invoke chromium.", LOG_MOST);
    >       sound->haltMusic(); // shut off LAC's music in favor of firefox media
    >       sound->stopAll();
    >       }
    >    }
    > 
    

    That little block of code will open the user's preferred browser (firefox or chromium) and display the referenced web page. It also shuts off LAC's sound effects, which is handy in case the referenced web page makes sounds of its own.

    Note that this mechanism can be use to play a YouTube video clip.

    Mission designers can insert blocks of code like this to display web pages during missions. The designated web browser will "pop up" at the appropriate point in the mission and immediately display the referenced web page right on top of LAC. Experimentation is in order to determine whether the browser should be invoked in background mode while the mission continues (not shown above), or in foreground mode.

     

    Last edit: bbosen 2022-04-11
  • bbosen

    bbosen - 2023-02-19

    Note that the user's web browser may not be visible if the player is in flight and running LAC in full-screen mode. In that case, the web browser will be invoked, but it is invisible until the player exits from LAC. You can test this on your own computer while running LAC. From LAC's main menu, click "ONLINE DOCUMENTATION". If your browser pops into view, then your current LAC and LINUX configuration should allow you to pop a browser into view during flight.

    If your mission design demands visibility of web pages, you should check to see if the player is running LAC in "full-screen" mode. This can be done by consulting the global integer variable "fullscreen". If it is set to "0", the full-screen mode is not in use and players that have installed a web browser and configured it as LAC's Preferred Browser" should be able to see web pages that you invoke from within your mission. (It's NOT a good idea to change the value of "fullscreen" from within a mission. Just give the player a message advising him to do so and then re-start the mission.)

    Players should be advised of related complexities. For example, many versions of desktop LINUX allow simultaneous management of multiple, virtual desktops. If the browser is already visible on a different virtual desktop, your new web page may appear there instead of popping up on top of LAC.

     

    Last edit: bbosen 2023-07-09

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.