1  | 
     | 
     | 
    /*  | 
    
    
    2  | 
     | 
     | 
     *  The ManaPlus Client  | 
    
    
    3  | 
     | 
     | 
     *  Copyright (C) 2008-2009  The Mana World Development Team  | 
    
    
    4  | 
     | 
     | 
     *  Copyright (C) 2009-2010  The Mana Developers  | 
    
    
    5  | 
     | 
     | 
     *  Copyright (C) 2011-2019  The ManaPlus Developers  | 
    
    
    6  | 
     | 
     | 
     *  Copyright (C) 2019-2021  Andrei Karas  | 
    
    
    7  | 
     | 
     | 
     *  | 
    
    
    8  | 
     | 
     | 
     *  This file is part of The ManaPlus Client.  | 
    
    
    9  | 
     | 
     | 
     *  | 
    
    
    10  | 
     | 
     | 
     *  This program is free software; you can redistribute it and/or modify  | 
    
    
    11  | 
     | 
     | 
     *  it under the terms of the GNU General Public License as published by  | 
    
    
    12  | 
     | 
     | 
     *  the Free Software Foundation; either version 2 of the License, or  | 
    
    
    13  | 
     | 
     | 
     *  any later version.  | 
    
    
    14  | 
     | 
     | 
     *  | 
    
    
    15  | 
     | 
     | 
     *  This program is distributed in the hope that it will be useful,  | 
    
    
    16  | 
     | 
     | 
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
    
    
    17  | 
     | 
     | 
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  | 
    
    
    18  | 
     | 
     | 
     *  GNU General Public License for more details.  | 
    
    
    19  | 
     | 
     | 
     *  | 
    
    
    20  | 
     | 
     | 
     *  You should have received a copy of the GNU General Public License  | 
    
    
    21  | 
     | 
     | 
     *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  | 
    
    
    22  | 
     | 
     | 
     */  | 
    
    
    23  | 
     | 
     | 
     | 
    
    
    24  | 
     | 
     | 
    #include "gui/widgets/tabs/chat/partytab.h"  | 
    
    
    25  | 
     | 
     | 
     | 
    
    
    26  | 
     | 
     | 
    #include "configuration.h"  | 
    
    
    27  | 
     | 
     | 
    #include "party.h"  | 
    
    
    28  | 
     | 
     | 
    #include "soundmanager.h"  | 
    
    
    29  | 
     | 
     | 
     | 
    
    
    30  | 
     | 
     | 
    #include "being/localplayer.h"  | 
    
    
    31  | 
     | 
     | 
     | 
    
    
    32  | 
     | 
     | 
    #include "const/sound.h"  | 
    
    
    33  | 
     | 
     | 
     | 
    
    
    34  | 
     | 
     | 
    #include "gui/windows/chatwindow.h"  | 
    
    
    35  | 
     | 
     | 
     | 
    
    
    36  | 
     | 
     | 
    #include "input/inputmanager.h"  | 
    
    
    37  | 
     | 
     | 
     | 
    
    
    38  | 
     | 
     | 
    #include "net/net.h"  | 
    
    
    39  | 
     | 
     | 
    #include "net/partyhandler.h"  | 
    
    
    40  | 
     | 
     | 
     | 
    
    
    41  | 
     | 
     | 
    #include "utils/gettext.h"  | 
    
    
    42  | 
     | 
     | 
     | 
    
    
    43  | 
     | 
     | 
    #include "debug.h"  | 
    
    
    44  | 
     | 
     | 
     | 
    
    
    45  | 
     | 
     | 
    PartyTab *partyTab = nullptr;  | 
    
    
    46  | 
     | 
     | 
     | 
    
    
    47  | 
     | 
     | 
    PartyTab::PartyTab(const Widget2 *const widget) :  | 
    
    
    48  | 
     | 
     | 
        // TRANSLATORS: party chat tab name  | 
    
    
    49  | 
     | 
     | 
        ChatTab(widget, _("Party"), "", "#Party", ChatTabType::PARTY) | 
    
    
    50  | 
     | 
     | 
    { | 
    
    
    51  | 
     | 
     | 
        setTabColors(ThemeColorId::PARTY_CHAT_TAB);  | 
    
    
    52  | 
     | 
     | 
        mShowOnline = config.getBoolValue("showPartyOnline"); | 
    
    
    53  | 
     | 
     | 
        config.addListener("showPartyOnline", this); | 
    
    
    54  | 
     | 
     | 
    }  | 
    
    
    55  | 
     | 
     | 
     | 
    
    
    56  | 
     | 
     | 
    PartyTab::~PartyTab()  | 
    
    
    57  | 
     | 
     | 
    { | 
    
    
    58  | 
     | 
     | 
        config.removeListeners(this);  | 
    
    
    59  | 
     | 
     | 
        CHECKLISTENERS  | 
    
    
    60  | 
     | 
     | 
    }  | 
    
    
    61  | 
     | 
     | 
     | 
    
    
    62  | 
     | 
     | 
    void PartyTab::handleInput(const std::string &msg)  | 
    
    
    63  | 
     | 
     | 
    { | 
    
    
    64  | 
     | 
     | 
        partyHandler->chat(ChatWindow::doReplace(msg));  | 
    
    
    65  | 
     | 
     | 
    }  | 
    
    
    66  | 
     | 
     | 
     | 
    
    
    67  | 
     | 
     | 
    bool PartyTab::handleCommand(const std::string &restrict type,  | 
    
    
    68  | 
     | 
     | 
                                 const std::string &restrict args)  | 
    
    
    69  | 
     | 
     | 
    { | 
    
    
    70  | 
     | 
     | 
        if (type == "invite")  | 
    
    
    71  | 
     | 
     | 
        { | 
    
    
    72  | 
     | 
     | 
            partyHandler->invite(args);  | 
    
    
    73  | 
     | 
     | 
        }  | 
    
    
    74  | 
     | 
     | 
        else if (type == "leave")  | 
    
    
    75  | 
     | 
     | 
        { | 
    
    
    76  | 
     | 
     | 
            inputManager.executeChatCommand(InputAction::LEAVE_PARTY,  | 
    
    
    77  | 
     | 
     | 
                args,  | 
    
    
    78  | 
     | 
     | 
                this);  | 
    
    
    79  | 
     | 
     | 
        }  | 
    
    
    80  | 
     | 
     | 
        else if (type == "kick")  | 
    
    
    81  | 
     | 
     | 
        { | 
    
    
    82  | 
     | 
     | 
            inputManager.executeChatCommand(InputAction::KICK_PARTY,  | 
    
    
    83  | 
     | 
     | 
                args,  | 
    
    
    84  | 
     | 
     | 
                this);  | 
    
    
    85  | 
     | 
     | 
        }  | 
    
    
    86  | 
     | 
     | 
        else if (type == "item")  | 
    
    
    87  | 
     | 
     | 
        { | 
    
    
    88  | 
     | 
     | 
            inputManager.executeChatCommand(InputAction::PARTY_ITEM_SHARE,  | 
    
    
    89  | 
     | 
     | 
                args,  | 
    
    
    90  | 
     | 
     | 
                this);  | 
    
    
    91  | 
     | 
     | 
        }  | 
    
    
    92  | 
     | 
     | 
        else if (type == "autoitem")  | 
    
    
    93  | 
     | 
     | 
        { | 
    
    
    94  | 
     | 
     | 
            inputManager.executeChatCommand(InputAction::PARTY_AUTO_ITEM_SHARE,  | 
    
    
    95  | 
     | 
     | 
                args,  | 
    
    
    96  | 
     | 
     | 
                this);  | 
    
    
    97  | 
     | 
     | 
        }  | 
    
    
    98  | 
     | 
     | 
        else if (type == "exp")  | 
    
    
    99  | 
     | 
     | 
        { | 
    
    
    100  | 
     | 
     | 
            inputManager.executeChatCommand(InputAction::PARTY_EXP_SHARE,  | 
    
    
    101  | 
     | 
     | 
                args,  | 
    
    
    102  | 
     | 
     | 
                this);  | 
    
    
    103  | 
     | 
     | 
        }  | 
    
    
    104  | 
     | 
     | 
        else if (type == "setleader" &&  | 
    
    
    105  | 
     | 
     | 
                 Net::getNetworkType() != ServerType::TMWATHENA)  | 
    
    
    106  | 
     | 
     | 
        { | 
    
    
    107  | 
     | 
     | 
            inputManager.executeChatCommand(  | 
    
    
    108  | 
     | 
     | 
                InputAction::COMMAND_CHANGE_PARTY_LEADER,  | 
    
    
    109  | 
     | 
     | 
                args,  | 
    
    
    110  | 
     | 
     | 
                this);  | 
    
    
    111  | 
     | 
     | 
        }  | 
    
    
    112  | 
     | 
     | 
        else  | 
    
    
    113  | 
     | 
     | 
        { | 
    
    
    114  | 
     | 
     | 
            return false;  | 
    
    
    115  | 
     | 
     | 
        }  | 
    
    
    116  | 
     | 
     | 
     | 
    
    
    117  | 
     | 
     | 
        return true;  | 
    
    
    118  | 
     | 
     | 
    }  | 
    
    
    119  | 
     | 
     | 
     | 
    
    
    120  | 
     | 
     | 
    void PartyTab::getAutoCompleteList(StringVect &names) const  | 
    
    
    121  | 
     | 
     | 
    { | 
    
    
    122  | 
     | 
     | 
        if (localPlayer == nullptr)  | 
    
    
    123  | 
     | 
     | 
            return;  | 
    
    
    124  | 
     | 
     | 
     | 
    
    
    125  | 
     | 
     | 
        const Party *const p = localPlayer->getParty();  | 
    
    
    126  | 
     | 
     | 
     | 
    
    
    127  | 
     | 
     | 
        if (p != nullptr)  | 
    
    
    128  | 
     | 
     | 
            p->getNames(names);  | 
    
    
    129  | 
     | 
     | 
    }  | 
    
    
    130  | 
     | 
     | 
     | 
    
    
    131  | 
     | 
     | 
    void PartyTab::getAutoCompleteCommands(StringVect &names) const  | 
    
    
    132  | 
     | 
     | 
    { | 
    
    
    133  | 
     | 
     | 
        names.push_back("/help"); | 
    
    
    134  | 
     | 
     | 
        names.push_back("/invite "); | 
    
    
    135  | 
     | 
     | 
        names.push_back("/leave"); | 
    
    
    136  | 
     | 
     | 
        names.push_back("/kick "); | 
    
    
    137  | 
     | 
     | 
        names.push_back("/item"); | 
    
    
    138  | 
     | 
     | 
        names.push_back("/exp"); | 
    
    
    139  | 
     | 
     | 
        if (Net::getNetworkType() != ServerType::TMWATHENA)  | 
    
    
    140  | 
     | 
     | 
            names.push_back("/setleader "); | 
    
    
    141  | 
     | 
     | 
    }  | 
    
    
    142  | 
     | 
     | 
     | 
    
    
    143  | 
     | 
     | 
    void PartyTab::playNewMessageSound() const  | 
    
    
    144  | 
     | 
     | 
    { | 
    
    
    145  | 
     | 
     | 
        soundManager.playGuiSound(SOUND_PARTY);  | 
    
    
    146  | 
     | 
     | 
    }  | 
    
    
    147  | 
     | 
     | 
     | 
    
    
    148  | 
     | 
     | 
    void PartyTab::optionChanged(const std::string &value)  | 
    
    
    149  | 
     | 
     | 
    { | 
    
    
    150  | 
     | 
     | 
        if (value == "showPartyOnline")  | 
    
    
    151  | 
     | 
     | 
            mShowOnline = config.getBoolValue("showPartyOnline"); | 
    
    
    152  | 
    ✓✗✓✗
  | 
    3  | 
    }  |