Ticket #3739: lobby_ask_observer_join_v1.patch

File lobby_ask_observer_join_v1.patch, 3.8 KB (added by elexis, 8 years ago)
  • binaries/data/mods/public/gui/lobby/lobby.js

    function updateGameSelection()  
    608608}
    609609
    610610/**
    611611 * Start the joining process on the currectly selected game.
    612612 */
    613 function joinSelectedGame()
     613function joinButton()
     614{
     615    let game = selectedGame();
     616    if (!game)
     617        return;
     618
     619    let username = g_UserRating ? g_Username + " (" + g_UserRating + ")" : g_Username;
     620
     621    if (game.state == "init" || game.players.split(", ").indexOf(username) > -1)
     622        joinSelectedGame();
     623    else
     624        messageBox(
     625            400, 200,
     626            translate("The game has already started.") + "\n" + translate("Do you want to join as observer?"),
     627            translate("Confirmation"),
     628            0,
     629            [translate("No"), translate("Yes")],
     630            [null, joinSelectedGame]
     631        );
     632}
     633
     634function selectedGame()
    614635{
    615636    var gamesBox = Engine.GetGUIObjectByName("gamesBox");
    616637    if (gamesBox.selected < 0)
     638        return undefined;
     639
     640    return g_GameList[gamesBox.list_data[gamesBox.selected]];
     641}
     642
     643function joinSelectedGame()
     644{
     645    let game = selectedGame();
     646    if (!game)
    617647        return;
    618648
    619     var ipAddress = g_GameList[gamesBox.list_data[gamesBox.selected]].ip;
    620     if (ipAddress.split('.').length != 4)
     649    if (game.ip.split('.').length != 4)
    621650    {
    622         addChatMessage({ "from": "system", "text": sprintf(translate("This game's address '%(ip)s' does not appear to be valid."), { "ip": ipAddress }) });
     651        addChatMessage({
     652            "from": "system",
     653            "text": sprintf(
     654                translate("This game's address '%(ip)s' does not appear to be valid."),
     655                { "ip": game.ip }
     656            )
     657        });
    623658        return;
    624659    }
    625660
    626     Engine.PushGuiPage("page_gamesetup_mp.xml", { "multiplayerGameType": "join", "name": g_Username, "ip": ipAddress, "rating": g_UserRating });
     661    Engine.PushGuiPage("page_gamesetup_mp.xml", {
     662        "multiplayerGameType": "join",
     663        "ip": game.ip,
     664        "name": g_Username,
     665        "rating": g_UserRating
     666    });
    627667}
    628668
    629669/**
    630670 * Open the dialog box to enter the game name.
    631671 */
  • binaries/data/mods/public/gui/lobby/lobby.xml

     
    152152                </object>
    153153            </object>
    154154            <object name="joinGameButton" type="button" style="ModernButtonRed" size="0 100%-85 100% 100%-60" hidden="true">
    155155                <translatableAttribute id="caption" comment="Join the game currently selected in the list.">Join Game</translatableAttribute>
    156156                <action on="Press">
    157                     joinSelectedGame();
     157                    joinButton();
    158158                </action>
    159159            </object>
    160160            <object name="hostButton" type="button" style="ModernButtonRed" size="0 100%-55 100% 100%-30">
    161161                <translatableAttribute id="caption">Host Game</translatableAttribute>
    162162                <action on="Press">
     
    173173        <!-- Middle panel: Filters, game list, chat box. -->
    174174        <object name="middlePanel" size="20%+5 5% 100%-255 97.2%">
    175175            <object name="gamesBox" style="ModernList" sprite_asc="ModernArrowDown" default_column="status" default_column_order="1" sprite_desc="ModernArrowUp" sprite_not_sorted="ModernNotSorted" type="olist" sortable="true" size="0 25 100% 48%" font="sans-stroke-13">
    176176                <action on="SelectionChange">updateGameSelection();</action>
    177177                <action on="SelectionColumnChange">applyFilters();</action>
    178                 <action on="mouseleftdoubleclickitem">joinSelectedGame();</action>
     178                <action on="mouseleftdoubleclickitem">joinButton();</action>
    179179                <def id="name" color="0 60 0" width="27%">
    180180                    <translatableAttribute id="heading">Name</translatableAttribute>
    181181                </def>
    182182                <!--<def id="ip" heading="IP" color="0 128 128" width="170"/>-->
    183183                <def id="mapName" color="128 128 128" width="25%">