From: Anders R. <ma...@us...> - 2003-04-14 18:07:29
|
Update of /cvsroot/planeshift/planeshift/src/client/aws In directory sc8-pr-cvs1:/tmp/cvs-serv16693/src/client/aws Modified Files: psaws.cpp psaws.h psinventorywindow.cpp psinventorywindow.h Added Files: psexchangewindow.cpp psexchangewindow.h Log Message: - Removed all use of depricated CS interfaces. - Implemented the exchange items window. - Added a exchange.def to the gui.zip file. - All item defs in DB have to have bulk as default slot (first slot in slot list) to be able to pick them up. - Created an exchangemanager in the server to handle exchanges. - New psGUIExchangeMessage to handle communication with client. - Removed some compiler warnings. --- NEW FILE: psexchangewindow.cpp --- /* * psexchangewindow.cpp by Anders Reggestad <an...@pv...> * * Copyright (C) 2001 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * 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. * */ #include <config.h> // CS INCLUDES #include <iutil/databuff.h> #include <iutil/cfgmgr.h> #include <ivideo/graph3d.h> #include <ivideo/txtmgr.h> #include <cssys/sysfunc.h> #include <csutil/scfstr.h> #include <csutil/util.h> // PS INCLUDES #include "psaws.h" #include "pscomp.h" #include "psobjectview.h" #include "psexchangewindow.h" #include "iclient/psengine.h" #include "pscelclient.h" #include "net/messages.h" #include "util/psxmlparser.h" char * psExchangeWindow::inventory_slots[] = {"Bulk0","Bulk1","Bulk2","Bulk3", "Bulk4","Bulk5","Bulk6","Bulk7", "Bulk8","Bulk9","Bulk10","Bulk11", "Bulk12","Bulk13","Bulk14","Bulk15", "circles","octas","hexas","trias", "offering_Bulk0","offering_Bulk1","offering_Bulk2","offering_Bulk3", "offering_circles","offering_octas","offering_hexas","offering_trias", 0 }; char * psExchangeWindow::receiving_slots[] = {"receiving_Bulk0","receiving_Bulk1","receiving_Bulk2","receiving_Bulk3", "receiving_circles","receiving_octas","receiving_hexas","receiving_trias", 0 }; psExchangeWindow::psExchangeWindow(iObjectRegistry* objectReg, psAwsManager* awsmgr) { sink = NULL; msgHandler = NULL; object_reg = objectReg; aws = awsmgr; statusTime = 0; } psExchangeWindow::~psExchangeWindow() { SCF_DEC_REF(sink); } void psExchangeWindow::CreateSink(iAws* aws) { sink = aws->GetSinkMgr()->CreateSink(this); sink->RegisterTrigger("Accept", &psExchangeWindow::Accept); sink->RegisterTrigger("Cancel", &psExchangeWindow::Cancel); sink->RegisterTrigger("ClickedSlot", &psExchangeWindow::ClickedSlot); aws->GetSinkMgr()->RegisterSink("ExchangeWindow", sink); } bool psExchangeWindow::Create(iAws* aws) { CreateSink(aws); aws->GetPrefMgr()->Load("/this/data/exchange.def"); mainWindow = aws->CreateWindowFrom("Exchange Window"); if ( !mainWindow ) return false; mainWindow->Hide(); offeringFrame = mainWindow->FindChild("Offering Frame"); receivingFrame = mainWindow->FindChild("Receiving Frame"); return true; } bool psExchangeWindow::SendCommand( const char* cmd, void* ) { /* If we have no msghandler yet then try and get one from the main * PlaneShift engine. */ if ( msgHandler == NULL ) { csRef<iPSEngine> psengine = CS_QUERY_REGISTRY (object_reg, iPSEngine); msgHandler = psengine->GetMsgHandler(); if ( !msgHandler ) return false; } return true; } bool psExchangeWindow::ClearStatus() { if (statusTime && statusTime < csGetTicks()){ statusTime = 0; // Update the status psComponentTextBox* comp; comp = (psComponentTextBox*)mainWindow->FindChild("Status"); comp->SetText(""); } return true; } void psExchangeWindow::HandleMessage( MsgEntry* me ) { /* The only incomming messages should be the GUI exchange msg. */ psGUIExchangeMessage incomming(me); // printf("ExchangeWindow:HandleMessage Exchange(%d,%s)\n",incomming.command, (const char*)incomming.commandData); /* If we have no msghandler yet then try and get one from the main * PlaneShift engine. */ if ( msgHandler == NULL ) { csRef<iPSEngine> psengine = CS_QUERY_REGISTRY (object_reg, iPSEngine); msgHandler = psengine->GetMsgHandler(); if ( !msgHandler ) return; } // Handle the command switch (incomming.command) { case psGUIExchangeMessage::EXCHANGE: { HandleExchange(incomming.commandData); break; } case psGUIExchangeMessage::INVENTORY: { HandleInventory(incomming.commandData); break; } case psGUIExchangeMessage::RECEIVING: { HandleReceiving(incomming.commandData); break; } case psGUIExchangeMessage::CANCEL: { // Hide the window mainWindow->Hide(); exchangeID = 0; break; } case psGUIExchangeMessage::STATUS: { // Update the status psComponentTextBox* comp; comp = (psComponentTextBox*)mainWindow->FindChild("Status"); comp->SetText((const char*)incomming.commandData); statusTime = csGetTicks() + 2000; // Hack to run a timer in the ExchangeWindow. Should be replaced // with some code to do this in the psExchangeWindow. aws->exchangeWindowStatusTime = statusTime; break; } } } void psExchangeWindow::HandleExchange(csString exchange) { psXMLString mainString (exchange); psXMLTag tag(mainString,0); csString id; csString offering; csString receiving; tag.GetTagParm("ID",id); tag.GetTagParm("OFFERING",offering); tag.GetTagParm("RECEIVING",receiving); exchangeID = atoi((const char*)id); mainWindow->Show(); psComponentImage * offering_bg = (psComponentImage*)offeringFrame->FindChild("BackDrop"); if (!offering_bg) return; psComponentImage * receiving_bg = (psComponentImage*)receivingFrame->FindChild("BackDrop"); if (!receiving_bg) return; if (offering == "ACCEPTED") { offering_bg->ChangeImage("/planeshift/art/gui/invback_highlighted.png"); } else { offering_bg->ChangeImage("/planeshift/art/gui/invback.png"); } if (receiving == "ACCEPTED") { receiving_bg->ChangeImage("/planeshift/art/gui/invback_highlighted.png"); } else { receiving_bg->ChangeImage("/planeshift/art/gui/invback.png"); } } void psExchangeWindow::HandleInventory(csString inventory) { ClearInventory(); InsertItems(inventory); } void psExchangeWindow::HandleReceiving(csString inventory) { ClearReceiving(); InsertItems(inventory); } void psExchangeWindow::ClearInventory() { int n = 0; while (inventory_slots[n]){ psComponentItemSlot* itemSlot = (psComponentItemSlot*)mainWindow->FindChild(inventory_slots[n]); if ( itemSlot != NULL ) { itemSlot->RemoveItem(); } n++; } } void psExchangeWindow::ClearReceiving() { int n = 0; while (receiving_slots[n]){ psComponentItemSlot* itemSlot = (psComponentItemSlot*)mainWindow->FindChild(receiving_slots[n]); if ( itemSlot != NULL ) { itemSlot->RemoveItem(); } n++; } } void psExchangeWindow::InsertItems(csString items) { psXMLString mainString (items); int start = mainString.FindTag("ITEM"); do { csString slotName; csString imageName; csString weight; csString count; slotName.Clear(); imageName.Clear(); psXMLTag tag(mainString, start); tag.GetTagParm("SLT", slotName); tag.GetTagParm("IMG", imageName); tag.GetTagParm("WT", weight); tag.GetTagParm("C", count); if ( imageName.Length() != 0 ) { psComponentItemSlot* itemSlot = (psComponentItemSlot*)mainWindow->FindChild(slotName); if ( itemSlot != NULL ) { itemSlot->PlaceItem(imageName); itemSlot->SetStackCount(count); } } start = mainString.FindTag("ITEM", start+1); } while ( start != -1 ); } void psExchangeWindow::Accept() { // Notify the server of accept. char commandData[100]; // Tell it the two slots that are involved sprintf(commandData, "<A ID=\"%d\"/>", exchangeID); psGUIExchangeMessage outgoing(psGUIExchangeMessage::ACCEPT, commandData); msgHandler->SendMessage(outgoing.msg); } void psExchangeWindow::Cancel() { // Notify the server of cancel char commandData[100]; // Tell it the two slots that are involved sprintf(commandData, "<C ID=\"%d\"/>", exchangeID); psGUIExchangeMessage outgoing(psGUIExchangeMessage::CANCEL, commandData); msgHandler->SendMessage(outgoing.msg); } void psExchangeWindow::ClickedSlot( iAwsComponent* comp ) { int z = 0; // This is a very bad way to do this but AWS does support // getting the name of the component from the name. iAwsPrefManager* pref = mainWindow->WindowManager()->GetPrefMgr(); while (inventory_slots[z]) { if ( comp->GetID() == pref->NameToId( inventory_slots[z] ) ) { ClickedSlot( inventory_slots[z] ); } z++; } } void psExchangeWindow::ClickedSlot( const char * clickedSlot ) { psComponentItemSlot *slot = (psComponentItemSlot*)mainWindow->FindChild(clickedSlot); // If the slot is occupied remove the item from the slot and change // the mouse cursor. if ( slot->IsOccupied() && (aws->GetMode() != iPSWindowMgr::ITEM_DRAGGING) ) { iTextureHandle* newImage = slot->GetItemImage(); if ( newImage ) { aws->ChangeMouseCursor( newImage ); aws->SetMode ( iPSWindowMgr::ITEM_DRAGGING ); } slot->RemoveItem(); floatingSlot = clickedSlot; } else // if ( !slot->IsOccupied() ) { // Check to see if we have an item. if ( aws->GetMode() == iPSWindowMgr::ITEM_DRAGGING ) { // Check to make sure that an actual change took place. if ( !strcmp( floatingSlot,clickedSlot ) ) { slot->ReplaceItem(); } else { // Notify the server of exchange change. char commandData[100]; // Tell it the two slots that are involved sprintf(commandData, "<M ID=\"%d\" T=\"%s\" F=\"%s\" />", exchangeID, clickedSlot, (const char*)floatingSlot); psGUIExchangeMessage outgoing(psGUIExchangeMessage::MOVE_ITEM, commandData); msgHandler->SendMessage(outgoing.msg); } aws->SetMode(iPSWindowMgr::NORMAL); aws->SetNoMouseCursor(); } } } //------------------------------------------------------------------- // Function Pointers //------------------------------------------------------------------- void psExchangeWindow::ClickedSlot(void* sink, iAwsSource* source) { psExchangeWindow* window = (psExchangeWindow*)sink; window->ClickedSlot(source->GetComponent()); } void psExchangeWindow::Accept(void* sink, iAwsSource*) { psExchangeWindow* window = (psExchangeWindow*)sink; window->Accept(); } void psExchangeWindow::Cancel(void* sink, iAwsSource*) { psExchangeWindow* window = (psExchangeWindow*)sink; window->Cancel(); } //------------------------------------------------------------------- --- NEW FILE: psexchangewindow.h --- /* * psexchangewindow.h by Anders Reggestad <an...@pv...> * * Copyright (C) 2001 PlaneShift Team (in...@pl..., * http://www.planeshift.it) * * 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. * * */ #ifndef PS_EXCHANGE_WINDOW #define PS_EXCHANGE_WINDOW // CS INCLUDES #include <csutil/scf.h> #include <iutil/objreg.h> #include <iaws/aws.h> // PS INCLUDES #include "pscomp.h" #include "net/msghandler.h" #include "iclient/iwinmgr.h" #include "util/psxmlparser.h" class psAwsManager; /// Exchange Window. /* This handles all the details about how the exchange works. */ class psExchangeWindow : public iPSWindow { public: psExchangeWindow(iObjectRegistry* obj, psAwsManager* mgr); virtual ~psExchangeWindow(); virtual char* GetName() { return "Exchange Window"; } virtual iAwsWindow* GetAWSWindow() { return mainWindow; } bool SendCommand( const char* cmd, void* ); /// Clear the status field if timed out bool ClearStatus(); /// Handles messages from the server. void HandleMessage( MsgEntry* me ); /// Creates the main aws window. bool Create(iAws* aws); /// Creates the neccessary sinks that the aws will used to handle messags. void CreateSink(iAws* aws); /// Funtion Pointers static void Accept( void* sink, iAwsSource* source ); static void Cancel( void* sink, iAwsSource* source ); static void ClickedSlot( void* sink, iAwsSource* source ); /// Handle clicked slots void ClickedSlot( const char * clickedSlot ); /// Triggered when a slot is clicked. void ClickedSlot( iAwsComponent* comp ); /// Player accept the exchange void Accept(); /// Player cancel the exchange void Cancel(); /// Holds the main graphics AWS window. iAwsWindow* mainWindow; protected: /// Handle the start exchange message from server void HandleExchange(csString exchange); /// Handle the inventory message from server void HandleInventory(csString inventory); /// Handle the receiving message from server void HandleReceiving(csString inventory); /// Clear all inventory slots void ClearInventory(); /// Clear all receiving slots void ClearReceiving(); /// Insert items from XML string into slots void InsertItems(csString items); /// The sink where all the messages for this window are sent. iAwsSink* sink; MsgHandler* msgHandler; /// Usefull for getting stuff. iObjectRegistry* object_reg; /// Holds the offering frame for quick access iAwsComponent* offeringFrame; /// Holds the receiving frame for quick access iAwsComponent* receivingFrame; /// Main PlaneShift GUI Manager psAwsManager* aws; /// The timer that make status messages dissapere csTicks statusTime; /// Used when an item has been selected ( ie Clicked ). csString floatingSlot; /// A ID identfying the current exchange. To be used // when communication with the server. int exchangeID; // List of inventory slots static char * inventory_slots[]; // List of receiving slots static char * receiving_slots[]; }; #endif Index: psaws.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/aws/psaws.cpp,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** psaws.cpp 15 Feb 2003 19:21:32 -0000 1.40 --- psaws.cpp 14 Apr 2003 18:06:22 -0000 1.41 *************** *** 42,45 **** --- 42,46 ---- #include "psmainbar.h" #include "psstatusbar.h" + #include "psexchangewindow.h" #include "iclient/iwinmgr.h" *************** *** 62,65 **** --- 63,67 ---- chatWindowFocused = false; + exchangeWindowStatusTime = 0; } *************** *** 88,92 **** msghandler->Unsubscribe(this, MSGTYPEGUIINTERACT); msghandler->Unsubscribe(this, MSGTYPEGUIINVENTORY); ! msghandler->Unsubscribe(this, MSGTYPEGUIITEMDESC); } } --- 90,95 ---- msghandler->Unsubscribe(this, MSGTYPEGUIINTERACT); msghandler->Unsubscribe(this, MSGTYPEGUIINVENTORY); ! msghandler->Unsubscribe(this, MSGTYPEGUIITEMDESC); ! msghandler->Unsubscribe(this, MSGTYPEGUIEXCHANGE); } } *************** *** 255,258 **** --- 258,268 ---- windows.Put(key, (iPSWindow*) sbar); } + else if ( strcmp(window, "Exchange Window") == 0 ) + { + psExchangeWindow* ew = new psExchangeWindow(object_reg, this); + + ew->Create(aws); + windows.Put(key, (iPSWindow*) ew); + } else *************** *** 508,511 **** --- 518,535 ---- } + // Hack to run a timer in the ExchangeWindow. Should be replaced + // with some code to do this in the psExchangeWindow. + if (e.Type == csevBroadcast && e.Command.Code == cscmdPreProcess) + { + if (exchangeWindowStatusTime && exchangeWindowStatusTime < csGetTicks()){ + psExchangeWindow * ev = (psExchangeWindow*)GetPSWindow("Exchange Window"); + if (ev) + { + exchangeWindowStatusTime = 0; + ev->ClearStatus(); + } + } + } + return aws->HandleEvent(e); } *************** *** 560,563 **** --- 584,589 ---- if ( !msghandler->Subscribe(this, MSGTYPEGUIITEMDESC) ) return false; + if ( !msghandler->Subscribe(this, MSGTYPEGUIEXCHANGE) ) + return false; return true; *************** *** 584,592 **** break; } ! case MSGTYPEGUIITEMDESC: { iPSWindow* win = GetPSWindow("Item Description Window"); psItemDescriptionWindow* itemWin = ( psItemDescriptionWindow* ) win; itemWin->HandleMessage(me); break; } --- 610,625 ---- break; } ! case MSGTYPEGUIITEMDESC: { iPSWindow* win = GetPSWindow("Item Description Window"); psItemDescriptionWindow* itemWin = ( psItemDescriptionWindow* ) win; itemWin->HandleMessage(me); + break; + } + case MSGTYPEGUIEXCHANGE: + { + iPSWindow* win = GetPSWindow("Exchange Window"); + psExchangeWindow* invWin = ( psExchangeWindow* ) win; + invWin->HandleMessage(me); break; } Index: psaws.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/aws/psaws.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** psaws.h 15 Feb 2003 19:21:33 -0000 1.16 --- psaws.h 14 Apr 2003 18:06:22 -0000 1.17 *************** *** 182,185 **** --- 182,191 ---- bool chatWindowFocused; + + public: + /// Timer for the exchange window + // Hack to run a timer in the ExchangeWindow. Should be replaced + // with some code to do this in the psExchangeWindow. + csTicks exchangeWindowStatusTime; }; Index: psinventorywindow.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/aws/psinventorywindow.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** psinventorywindow.cpp 12 Mar 2003 18:51:22 -0000 1.18 --- psinventorywindow.cpp 14 Apr 2003 18:06:23 -0000 1.19 *************** *** 38,41 **** --- 38,47 ---- #include "util/psxmlparser.h" + + char * psInventoryWindow::inventory_slots[] = { + "back", "head", "neck", "arms", "gloves", "lefthand", + "boots", "legs", "belt", "righthand", "bracers", "torso", + "circles", "octas", "hexas", "trias", 0}; + psInventoryWindow::psInventoryWindow(iObjectRegistry* objectReg, psAwsManager* awsmgr) *************** *** 144,147 **** --- 150,154 ---- incomming.command == psGUIInventoryMessage::SEND_ENTIRE_FORCE) { + ClearInventory(); psXMLString mainString (incomming.commandData); *************** *** 191,194 **** --- 198,215 ---- } + void psInventoryWindow::ClearInventory() + { + int n = 0; + while (inventory_slots[n]){ + psComponentItemSlot* itemSlot = + (psComponentItemSlot*)mainWindow->FindChild(inventory_slots[n]); + if ( itemSlot != NULL ) + { + itemSlot->RemoveItem(); + } + n++; + } + } + void psInventoryWindow::Stats() *************** *** 345,354 **** int z; char *clickedSlot; - char *slots[] = {"back", "head", "neck", "arms", "gloves", "lefthand", "boots", "legs", "belt", "righthand", "bracers", "torso", 0}; // This is a very bad way to do this but AWS does support // getting the name of the component from the name. iAwsPrefManager* pref = mainWindow->WindowManager()->GetPrefMgr(); ! for (z=0,clickedSlot=slots[0]; ; clickedSlot=slots[++z]) { if (clickedSlot == 0) --- 366,374 ---- int z; char *clickedSlot; // This is a very bad way to do this but AWS does support // getting the name of the component from the name. iAwsPrefManager* pref = mainWindow->WindowManager()->GetPrefMgr(); ! for (z=0,clickedSlot=inventory_slots[0]; ; clickedSlot=inventory_slots[++z]) { if (clickedSlot == 0) *************** *** 414,419 **** void psInventoryWindow::DropItem() { // Tell the server to drop this item ! psGUIInventoryMessage dropMessage(0, floatingSlot.GetData(), psGUIInventoryMessage::DROP_ITEM); --- 434,448 ---- void psInventoryWindow::DropItem() { + char commandData[100]; + + // TODO: Let user deside drop count + int dropCount = 5; + + // Tell server the two slots and count that are involved + sprintf(commandData, "<D F=\"%s\" C=\"%d\" />", + (const char*)floatingSlot,dropCount); + // Tell the server to drop this item ! psGUIInventoryMessage dropMessage(0, commandData, psGUIInventoryMessage::DROP_ITEM); Index: psinventorywindow.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/aws/psinventorywindow.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** psinventorywindow.h 10 Feb 2003 21:03:31 -0000 1.7 --- psinventorywindow.h 14 Apr 2003 18:06:24 -0000 1.8 *************** *** 52,55 **** --- 52,58 ---- void HandleMessage( MsgEntry* me ); + /// Empty all inventory slots + void ClearInventory(); + /// Creates the main aws window. bool Create(iAws* aws); *************** *** 125,128 **** --- 128,135 ---- /// Used when an item has been selected ( ie Clicked ). csString floatingSlot; + + // List of inventory slots + static char * inventory_slots[]; + }; |