aboutsummaryrefslogtreecommitdiff
path: root/src/hud.h
Commit message (Expand)AuthorAge
* Hide minimap if it has been disabled by serverest312015-09-01
* minimap: Add ability to disable from serverkwolekr2015-08-13
* Make hud use fontengine toosapier2014-11-30
* Fix heart + bubble bar size on different texture packssapier2014-05-07
* Bugfix: make waypoints respect camera offsetRealBadAngel2014-05-05
* Add support for dpi based HUD scalingsapier2014-04-27
* New HUD element - waypoint.RealBadAngel2014-01-26
* Use player:set_hotbar_image() instead of hardcoded hotbar.pngPilzAdam2013-09-05
* Add support for using textures in hotbarBlockMen2013-08-25
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
* Add drowningPilzAdam2013-06-19
* Add ObjectRef.hud_set_hotbar_itemcount and add TOCLIENT_HUD_SET_PARAMKahrl2013-05-26
* Move scriptapi to separate folder (by sapier)sapier2013-05-25
* Minor hud.cpp cleanupkwolekr2013-04-25
* Generalize hud_builtin_enable into hud_set_flagskwolekr2013-04-25
* Added support to disable built-in HUD elementsDiego Martínez2013-04-24
* Added offset support for HUD itemsDiego Martínez2013-04-23
* Added support for alignment in HUD itemsDiego Martínez2013-04-23
* Add direction parameter to statbars in HUD APIkwolekr2013-04-20
* Split HUD code off to hud.cpp, make into a class, extensive Lua HUD modificationkwolekr2013-04-18
along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "modchannels.h" #include <algorithm> #include <cassert> #include "util/basic_macros.h" bool ModChannel::registerConsumer(session_t peer_id) { // ignore if peer_id already joined if (CONTAINS(m_client_consumers, peer_id)) return false; m_client_consumers.push_back(peer_id); return true; } bool ModChannel::removeConsumer(session_t peer_id) { bool found = false; auto peer_removal_fct = [peer_id, &found](u16 p) { if (p == peer_id) found = true; return p == peer_id; }; m_client_consumers.erase( std::remove_if(m_client_consumers.begin(), m_client_consumers.end(), peer_removal_fct), m_client_consumers.end()); return found; } bool ModChannel::canWrite() const { return m_state == MODCHANNEL_STATE_READ_WRITE; } void ModChannel::setState(ModChannelState state) { assert(state != MODCHANNEL_STATE_INIT); m_state = state; } bool ModChannelMgr::channelRegistered(const std::string &channel) const { return m_registered_channels.find(channel) != m_registered_channels.end(); } ModChannel *ModChannelMgr::getModChannel(const std::string &channel) { if (!channelRegistered(channel)) return nullptr; return m_registered_channels[channel].get(); } bool ModChannelMgr::canWriteOnChannel(const std::string &channel) const { const auto channel_it = m_registered_channels.find(channel); if (channel_it == m_registered_channels.end()) { return false; } return channel_it->second->canWrite(); } void ModChannelMgr::registerChannel(const std::string &channel) { m_registered_channels[channel] = std::unique_ptr<ModChannel>(new ModChannel(channel)); } bool ModChannelMgr::setChannelState(const std::string &channel, ModChannelState state) { if (!channelRegistered(channel)) return false; auto channel_it = m_registered_channels.find(channel); channel_it->second->setState(state); return true; } bool ModChannelMgr::removeChannel(const std::string &channel) { if (!channelRegistered(channel)) return false; m_registered_channels.erase(channel); return true; } bool ModChannelMgr::joinChannel(const std::string &channel, session_t peer_id) { if (!channelRegistered(channel)) registerChannel(channel); return m_registered_channels[channel]->registerConsumer(peer_id); } bool ModChannelMgr::leaveChannel(const std::string &channel, session_t peer_id) { if (!channelRegistered(channel)) return false; // Remove consumer from channel bool consumerRemoved = m_registered_channels[channel]->removeConsumer(peer_id); // If channel is empty, remove it if (m_registered_channels[channel]->getChannelPeers().empty()) { removeChannel(channel); } return consumerRemoved; } void ModChannelMgr::leaveAllChannels(session_t peer_id) { for (auto &channel_it : m_registered_channels) channel_it.second->removeConsumer(peer_id); } static std::vector<u16> empty_channel_list; const std::vector<u16> &ModChannelMgr::getChannelPeers(const std::string &channel) const { const auto &channel_it = m_registered_channels.find(channel); if (channel_it == m_registered_channels.end()) return empty_channel_list; return channel_it->second->getChannelPeers(); }