/* * guihandler.cpp * * Copyright (C) 2005 Atomic Blue (info@planeshift.it, http://www.atomicblue.org) * * Credits : * Keith Fulton * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation (version 2 * of the License). * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Creation Date: 4/20/2005 * Description : Handles network messages to and from the GUI, using PAWS pub/sub system. * */ #include #include #include "globals.h" #include "net/messages.h" #include "net/msghandler.h" #include "guihandler.h" GUIHandler::GUIHandler() : psCmdBase(NULL,NULL,psengine->GetObjectRegistry()) { // Subscribe our message types that we are interested in. psengine->GetMsgHandler()->Subscribe( this, MSGTYPE_GUIINVENTORY ); inventoryCache = psengine->GetInventoryCache(); } void GUIHandler::HandleMessage(MsgEntry* me) { switch( me->GetType() ) { case MSGTYPE_GUIINVENTORY: HandleInventory(me); break; } } void GUIHandler::HandleInventory(MsgEntry* me) { psGUIInventoryMessage incoming(me); // merge the received inventory list into the client's inventory cache if (incoming.command == psGUIInventoryMessage::LIST) // for the whole lot { inventoryCache->EmptyInventory(); // empty the inventory first inventoryCache->SetCacheStatus(psCache::VALID); } for ( size_t z = 0; z < incoming.totalItems; z++ ) // cache inventory items { inventoryCache->SetInventoryItem(incoming.items[z].slot, incoming.items[z].container, incoming.items[z].name.GetData(), incoming.items[z].weight, incoming.items[z].size, incoming.items[z].stackcount, incoming.items[z].iconImage.GetData(), incoming.items[z].purifyStatus); } if (incoming.command == psGUIInventoryMessage::UPDATE_LIST) for ( size_t z = 0; z < incoming.totalEmptiedSlots; z++) { inventoryCache->EmptyInventoryItem( incoming.items[incoming.totalItems+z].slot, incoming.items[incoming.totalItems+z].container); } PawsManager::GetSingleton().Publish("sigClearSlot", 0 ); float itemWeight = 0.0; float totalSize = 0.0; // publish the inventory from the cache for ( int z = 0; z < INVENTORY_BULK_COUNT; z++ ) { psInventoryCache::CachedItemDescription item; bool ret = inventoryCache->GetInventoryItem(z, CONTAINER_INVENTORY_BULK, &item); if (item.stackCount>0 && item.iconImage.Length() != 0) { csString sigData, data; sigData.Format("sigbulk_%d", z); data.Format( "%s %d %d %s", item.iconImage.GetData(), item.stackCount, item.purifyStatus, item.name.GetData()); PawsManager::GetSingleton().Publish(sigData, data ); itemWeight += item.weight; totalSize += item.size; } } for ( int z = 0; z < INVENTORY_EQUIP_COUNT; z++ ) { psInventoryCache::CachedItemDescription item; bool ret = inventoryCache->GetInventoryItem(z, CONTAINER_INVENTORY_EQUIPMENT, &item); if (item.stackCount>0 && item.iconImage.Length() != 0) { csString sigData, data; sigData.Format("sigslot_%s", psengine->slotName.GetName(z) ); data.Format( "%s %d %d %s", item.iconImage.GetData(), item.stackCount, item.purifyStatus, item.name.GetData()); PawsManager::GetSingleton().Publish(sigData, data ); itemWeight += item.weight; totalSize += item.size; } } PawsManager::GetSingleton().Publish( "fcurrcap", totalSize ); PawsManager::GetSingleton().Publish( "sigInvMoney", incoming.money.ToString() ); PawsManager::GetSingleton().Publish( "sigInvMoneyTotal", incoming.money.GetTotal() ); csString weight = csString().Format("%.2f/%.2f",itemWeight, incoming.maxWeight); PawsManager::GetSingleton().Publish( "sigInvWeightTotal", weight ); }