Ticket #4069: 4069_chat_history_v1.2.patch

File 4069_chat_history_v1.2.patch, 12.8 KB (added by Imarok, 8 years ago)

always center(with offset) the window. move the filterdropdown to the top. rename lobby.chattimestamp to chat.timestamp

  • binaries/data/config/default.cfg

     
    350350zoom.in = 5
    351351zoom.out = 4
    352352
     353[chat]
     354timestamp = false                   ; Show time chat message was posted
     355
    353356[lobby]
    354 chattimestamp = false               ; Show time chat message was posted
    355357history = 0                         ; Number of past messages to display on join
    356358room = "arena21"                    ; Default MUC room to join
    357359server = "lobby.wildfiregames.com"  ; Address of lobby server
  • binaries/data/mods/public/gui/lobby/lobby.js

     
    1111/**
    1212 * Whether or not to display timestamps in the chat window.
    1313 */
    14 const g_ShowTimestamp = Engine.ConfigDB_GetValue("user", "lobby.chattimestamp") == "true";
     14const g_ShowTimestamp = Engine.ConfigDB_GetValue("user", "chat.timestamp") == "true";
    1515
    1616/**
    1717 * Mute clients who exceed the rate of 1 message per second for this time
  • binaries/data/mods/public/gui/options/options.json

     
    9090            "label": "Batch Training Size",
    9191            "tooltip": "Number of units trained per batch",
    9292            "parameters": { "config": "gui.session.batchtrainingsize", "min": 1, "max": 20 }
     93        },
     94        {
     95            "type": "boolean",
     96            "label": "Chat Timestamp",
     97            "tooltip": "Show time that messages are posted in the chat",
     98            "parameters": { "config": "chat.timestamp" }
    9399        }
    94100    ],
    95101    "graphicsSetting":
     
    245251            "label": "Chat Backlog",
    246252            "tooltip": "Number of backlogged messages to load when joining the lobby",
    247253            "parameters": { "config": "lobby.history", "min": "0" }
    248         },
    249         {
    250             "type": "boolean",
    251             "label": "Chat Timestamp",
    252             "tooltip": "Show time that messages are posted in the lobby chat",
    253             "parameters": { "config": "lobby.chattimestamp" }
    254254        }
    255255    ]
    256256}
  • binaries/data/mods/public/gui/session/chat_window.xml

     
    11<?xml version="1.0" encoding="utf-8"?>
    22
    3 <object name="chatDialogPanel" size="50%-180 50%-66 50%+180 50%+54" type="image" hidden="true" sprite="genericPanel">
     3<object name="chatDialogPanel" size="50%-200 50%-410 50%+200 50%+60" type="image" hidden="true" sprite="genericPanel">
    44
    5     <!-- Message addressee -->
    6     <object size="16 14 50 38" type="text" style="chatPanel">
    7         <translatableAttribute id="caption" context="chat input">To:</translatableAttribute>
    8     </object>
    9     <object size="75 12 100%-16 36" name="chatAddressee" type="dropdown" style="ModernDropDown" tooltip_style="sessionToolTipBold">
    10         <translatableAttribute id="tooltip" context="chat input">Select chatmessage addressee</translatableAttribute>
    11     </object>
     5    <object type="image" name="chatHistoryPage" size="0 0 100% 350" hidden="false">
     6        <!-- Chat History Filter -->
     7        <object size="16 12 60 32" name="chatHistoryFilterLabel" type="text" style="chatPanel">
     8            <translatableAttribute id="caption" context="chat input">Filter:</translatableAttribute>
     9        </object>
     10        <object size="75 10 100%-16 34" name="chatHistoryFilter" type="dropdown" style="ModernDropDown" tooltip_style="sessionToolTipBold">
     11            <translatableAttribute id="tooltip" context="chat input">Filter the chat history.</translatableAttribute>
     12            <action on="SelectionChange">updateChatHistory();</action>
     13        </object>
    1214
    13     <!-- Message text -->
    14     <object size="16 46 50 70" type="text" style="chatPanel">
    15         <translatableAttribute id="caption" context="chat input">Text:</translatableAttribute>
     15        <object name="chatHistory" type="text" size="10 46 100%-10 100%" sprite="ModernDarkBoxGold"  style="chatHistory"/>
    1616    </object>
    17     <object name="chatInput" size="75 44 100%-16 68" type="input" style="ModernInput" max_length="80">
    18         <translatableAttribute id="tooltip" context="chat input">Type the message to send.</translatableAttribute>
    19         <action on="Press">submitChatInput();</action>
    20         <action on="Tab">
    21             let playernames = [];
    22             for (let player in g_PlayerAssignments)
    23                 playernames.push(g_PlayerAssignments[player].name);
    24             autoCompleteNick(this, playernames);
    25         </action>
    26     </object>
    2717
    28     <!-- Cancel Button -->
    29     <object size="16 100%-40 30%+16 100%-12" type="button" style="StoneButton">
    30         <translatableAttribute id="caption">Cancel</translatableAttribute>
    31         <action on="Press">closeChat();</action>
    32     </object>
     18    <object name="chatPage" size="0 100%-120 100% 100%">
     19        <!-- Message addressee -->
     20        <object size="16 100%-106 50 100%-82" type="text" style="chatPanel">
     21            <translatableAttribute id="caption" context="chat input">To:</translatableAttribute>
     22        </object>
     23        <object size="75 100%-108 100%-16 100%-84" name="chatAddressee" type="dropdown" style="ModernDropDown" tooltip_style="sessionToolTipBold">
     24            <translatableAttribute id="tooltip" context="chat input">Select chatmessage addressee.</translatableAttribute>
     25        </object>
    3326
    34     <!-- Send Button -->
    35     <object size="60%+16 100%-40 100%-16 100%-12" type="button" style="StoneButton">
    36         <translatableAttribute id="caption">Send</translatableAttribute>
    37         <action on="Press">submitChatInput();</action>
     27        <!-- Message text -->
     28        <object size="16 100%-74 50 100%-50" type="text" style="chatPanel">
     29            <translatableAttribute id="caption" context="chat input">Text:</translatableAttribute>
     30        </object>
     31        <object name="chatInput" size="75 100%-76 100%-16 100%-52" type="input" style="ModernInput" max_length="80">
     32            <translatableAttribute id="tooltip" context="chat input">Type the message to send.</translatableAttribute>
     33            <action on="Press">submitChatInput();</action>
     34            <action on="Tab">
     35                let playernames = [];
     36                for (let player in g_PlayerAssignments)
     37                    playernames.push(g_PlayerAssignments[player].name);
     38                autoCompleteNick(this, playernames);
     39            </action>
     40        </object>
     41
     42        <!-- Cancel Button -->
     43        <object size="16 100%-40 30%+16 100%-12" type="button" style="StoneButton">
     44            <translatableAttribute id="caption">Cancel</translatableAttribute>
     45            <action on="Press">closeChat();</action>
     46        </object>
     47       
     48        <!-- Extended Chat Checkbox -->
     49        <object name="extendedChat" type="checkbox" checked="false" style="ModernTickBox" size="50%-50 100%-38 50%-24 100%-12">
     50            <action on="Press">resizeChatWindow();</action>
     51        </object>
     52
     53        <!-- Extended Chat Label -->
     54        <object type="text" size="50%-24 100%-38 50%+40 100%-12" text_align="left" textcolor="white">
     55            <translatableAttribute id="caption" context="extended chat">Extended</translatableAttribute>
     56        </object>
     57
     58        <!-- Send Button -->
     59        <object size="60%+16 100%-40 100%-16 100%-12" type="button" style="StoneButton">
     60            <translatableAttribute id="caption">Send</translatableAttribute>
     61            <action on="Press">submitChatInput();</action>
     62        </object>
    3863    </object>
    39 
    4064</object>
  • binaries/data/mods/public/gui/session/menu.js

     
    217217    let command = teamChat ? (g_IsObserver ? "/observers" : "/allies") : "";
    218218    chatAddressee.selected = chatAddressee.list_data.indexOf(command);
    219219
    220     Engine.GetGUIObjectByName("chatInput").focus();
    221220    Engine.GetGUIObjectByName("chatDialogPanel").hidden = false;
     221
     222    resizeChatWindow();
    222223}
    223224
    224225function closeChat()
     
    228229    Engine.GetGUIObjectByName("chatDialogPanel").hidden = true;
    229230}
    230231
     232function resizeChatWindow()
     233{
     234    let extended = Engine.GetGUIObjectByName("extendedChat").checked;
     235    let chatDialogPanel = Engine.GetGUIObjectByName("chatDialogPanel");
     236    let chatHistoryPage = Engine.GetGUIObjectByName("chatHistoryPage");
     237    let chatPage = Engine.GetGUIObjectByName("chatPage");
     238    let panelSize = chatDialogPanel.size;
     239    let topOffset = 60;
     240    let height = -chatPage.size.top + (extended ? chatHistoryPage.size.bottom : 0);
     241    panelSize.top = -height / 2 - topOffset;
     242    panelSize.bottom = height / 2 - topOffset;
     243    chatDialogPanel.size = panelSize;
     244
     245    if (extended)
     246    {
     247        let chatHistoryFilter = Engine.GetGUIObjectByName("chatHistoryFilter");
     248        chatHistoryFilter.hidden = g_IsObserver;
     249        Engine.GetGUIObjectByName("chatHistoryFilterLabel").hidden = g_IsObserver;
     250        let chatHistory = Engine.GetGUIObjectByName("chatHistory");
     251        let chatHistorySize = chatHistory.size;
     252        chatHistorySize.top = g_IsObserver ? chatHistoryFilter.size.top : chatHistoryFilter.size.bottom + 12;
     253        chatHistorySize.rtop = g_IsObserver ? chatHistoryFilter.size.rtop : chatHistoryFilter.size.rbottom;
     254        chatHistory.size = chatHistorySize;
     255        if (g_IsObserver)
     256            chatHistoryFilter.selected = 0;
     257        updateChatHistory();
     258    }
     259    chatHistoryPage.hidden = !extended;
     260    Engine.GetGUIObjectByName("chatInput").focus();
     261}
     262
     263function initChatHistoryFilter()
     264{
     265    let chatHistoryFilter = Engine.GetGUIObjectByName("chatHistoryFilter");
     266    chatHistoryFilter.list = [translate("All"), translate("Chat"), translate("Players chat"), translate("Ally chat")];
     267    chatHistoryFilter.list_data = ["all", "isChat", "noObserver", "isAlly"];
     268    chatHistoryFilter.selected = 0;
     269}
     270
     271function updateChatHistory()
     272{
     273    let chatHistoryFilter = Engine.GetGUIObjectByName("chatHistoryFilter");
     274    let selected = chatHistoryFilter.list_data[chatHistoryFilter.selected];
     275    Engine.GetGUIObjectByName("chatHistory").caption = g_ChatHistory.filter(msg => selected == "all" || msg[selected]).map(
     276        msg => Engine.ConfigDB_GetValue("user", "chat.timestamp") == "true" ?
     277            sprintf(translate("%(time)s %(message)s"), {
     278                "time": msg.timePrefix,
     279                "message": msg.txt
     280            }) :
     281            msg.txt).join("\n");
     282}
     283
    231284function openDiplomacy()
    232285{
    233286    closeOpenDialogs();
  • binaries/data/mods/public/gui/session/messages.js

     
    1515const g_ChatLines = 20;
    1616
    1717/**
    18  * The strings to be displayed including sender and formating.
     18 * The currently displayed strings, limited by the given timeframe and limit above.
    1919 */
    2020var g_ChatMessages = [];
    2121
    2222/**
     23 * All unparsed chat messages received since connect, including timestamp.
     24 */
     25var g_ChatHistory = [];
     26
     27/**
    2328 * Holds the timer-IDs used for hiding the chat after g_ChatTimeout seconds.
    2429 */
    2530var g_ChatTimers = [];
     
    703708    if (!formatted)
    704709        return;
    705710
     711    // Remember the original text as it depends on g_PlayerAssignments
     712    let time = new Date(Date.now());
     713    let senderID = g_PlayerAssignments[msg.guid] ? g_PlayerAssignments[msg.guid].player : 0;
     714    g_ChatHistory.push({
     715        "txt": formatted,
     716        "timePrefix": sprintf(translate("\\[%(time)s]"), {
     717            "time": Engine.FormatMillisecondsIntoDateString(time.getTime(), translate("HH:mm"))
     718        }),
     719        "isChat": msg.type == "message",
     720        "noObserver": msg.type == "message" && senderID > 0 && !isPlayerObserver(senderID),
     721        "isAlly": msg.type == "message" && g_Players[Engine.GetPlayerID()] && g_Players[Engine.GetPlayerID()].isAlly[senderID]
     722    });
     723    if (!Engine.GetGUIObjectByName("chatDialogPanel").hidden)
     724        updateChatHistory();
     725
    706726    g_ChatMessages.push(formatted);
    707727    g_ChatTimers.push(setTimeout(removeOldChatMessage, g_ChatTimeout * 1000));
    708728
  • binaries/data/mods/public/gui/session/session.js

     
    294294        Engine.GetGUIObjectByName("menuExitButton").enabled = false;
    295295
    296296    initHotkeyTooltips();
     297    initChatHistoryFilter();
    297298
    298299    if (hotloadData)
    299300        g_Selection.selected = hotloadData.selection;
  • binaries/data/mods/public/gui/session/styles.xml

     
    247247        textcolor_selected="darkgray"
    248248    />
    249249
     250    <style name="chatHistory"
     251        buffer_zone="5"
     252        font="sans-13"
     253        scrollbar="true"
     254        scrollbar_style="ModernScrollBar"
     255        scroll_bottom="true"
     256        textcolor="white"
     257        textcolor_selected="gold"
     258        text_align="left"
     259        text_valign="center"
     260    />
     261
    250262    <style name="notificationPanel"
    251263        buffer_zone="5"
    252264        font="sans-bold-stroke-14"