From: Xordan <mg...@us...> - 2007-09-14 21:46:28
|
Update of /cvsroot/planeshift/planeshift/src/client/gui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv596/src/client/gui Added Files: pawsbankwindow.cpp pawsbankwindow.h Log Message: - Added first implementation of banks. Currently supported is a personal account and a guild account (only accessible to the guild leader currently). On both accounts you can withdraw and deposit money. To access, click on a banker npc (in cvs it is the merchant) and type /bank [personal|guild] depending on which one you want. Transactions are then made using the banking window. => NETVERSION BUMPED! --- NEW FILE: pawsbankwindow.cpp --- /* * pawsbankwindow.cpp - Author: Mike Gist * * Copyright (C) 2007 Atomic Blue (in...@pl..., http://www.atomicblue.org) * * * 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 <psconfig.h> #include "globals.h" #include <csstring.h> #include "net/messages.h" #include "net/msghandler.h" #include "pawsbankwindow.h" /* Widget ID's */ #define WITHDRAW 1003 #define DEPOSIT 1004 pawsBankWindow::pawsBankWindow() { } pawsBankWindow::~pawsBankWindow() { msgHandler->Unsubscribe(this, MSGTYPE_BANKING); } bool pawsBankWindow::PostSetup() { msgHandler = psengine->GetMsgHandler(); if(!msgHandler) return false; if(!msgHandler->Subscribe(this, MSGTYPE_BANKING)) return false; circlesCanWithdraw = dynamic_cast <pawsTextBox*> (FindWidget("CirclesCanWithdraw")); if(!circlesCanWithdraw) return false; octasCanWithdraw = dynamic_cast <pawsTextBox*> (FindWidget("OctasCanWithdraw")); if(!octasCanWithdraw) return false; hexasCanWithdraw = dynamic_cast <pawsTextBox*> (FindWidget("HexasCanWithdraw")); if(!hexasCanWithdraw) return false; triasCanWithdraw = dynamic_cast <pawsTextBox*> (FindWidget("TriasCanWithdraw")); if(!triasCanWithdraw) return false; circlesCanDeposit = dynamic_cast <pawsTextBox*> (FindWidget("CirclesCanDeposit")); if(!circlesCanDeposit) return false; octasCanDeposit = dynamic_cast <pawsTextBox*> (FindWidget("OctasCanDeposit")); if(!octasCanDeposit) return false; hexasCanDeposit = dynamic_cast <pawsTextBox*> (FindWidget("HexasCanDeposit")); if(!hexasCanDeposit) return false; triasCanDeposit = dynamic_cast <pawsTextBox*> (FindWidget("TriasCanDeposit")); if(!triasCanDeposit) return false; circlesToWithdraw = dynamic_cast <pawsEditTextBox*> (FindWidget("CirclesToWithdraw")); if(!circlesToWithdraw) return false; circlesToWithdraw->SetText("0"); octasToWithdraw = dynamic_cast <pawsEditTextBox*> (FindWidget("OctasToWithdraw")); if(!octasToWithdraw) return false; octasToWithdraw->SetText("0"); hexasToWithdraw = dynamic_cast <pawsEditTextBox*> (FindWidget("HexasToWithdraw")); if(!hexasToWithdraw) return false; hexasToWithdraw->SetText("0"); triasToWithdraw = dynamic_cast <pawsEditTextBox*> (FindWidget("TriasToWithdraw")); if(!triasToWithdraw) return false; triasToWithdraw->SetText("0"); circlesToDeposit = dynamic_cast <pawsEditTextBox*> (FindWidget("CirclesToDeposit")); if(!circlesToDeposit) return false; circlesToDeposit->SetText("0"); octasToDeposit = dynamic_cast <pawsEditTextBox*> (FindWidget("OctasToDeposit")); if(!octasToDeposit) return false; octasToDeposit->SetText("0"); hexasToDeposit = dynamic_cast <pawsEditTextBox*> (FindWidget("HexasToDeposit")); if(!hexasToDeposit) return false; hexasToDeposit->SetText("0"); triasToDeposit = dynamic_cast <pawsEditTextBox*> (FindWidget("TriasToDeposit")); if(!triasToDeposit) return false; triasToDeposit->SetText("0"); return true; } void pawsBankWindow::HandleMessage( MsgEntry* me ) { if(me->GetType() == MSGTYPE_BANKING) { psGUIBankingMessage incoming(me); switch(incoming.command) { case psGUIBankingMessage::VIEWBANK: { if(!IsVisible() && incoming.openWindow) { Show(); } csString circles; csString octas; csString hexas; csString trias; csString circlesBanked; csString octasBanked; csString hexasBanked; csString triasBanked; circlesCanDeposit->SetText(circles.AppendFmt("%i", incoming.circles)); octasCanDeposit->SetText(octas.AppendFmt("%i", incoming.octas)); hexasCanDeposit->SetText(hexas.AppendFmt("%i", incoming.hexas)); triasCanDeposit->SetText(trias.AppendFmt("%i", incoming.trias)); circlesCanWithdraw->SetText(circlesBanked.AppendFmt("%i", incoming.circlesBanked)); octasCanWithdraw->SetText(octasBanked.AppendFmt("%i", incoming.octasBanked)); hexasCanWithdraw->SetText(hexasBanked.AppendFmt("%i", incoming.hexasBanked)); triasCanWithdraw->SetText(triasBanked.AppendFmt("%i", incoming.triasBanked)); guild = incoming.guild; break; } } } } bool pawsBankWindow::OnButtonPressed( int mouseButton, int keyModifier, pawsWidget* widget ) { if(widget->GetID() == WITHDRAW) { int circles = 0; sscanf(circlesToWithdraw->GetText(), "%d", &circles); int octas = 0; sscanf(octasToWithdraw->GetText(), "%d", &octas); int hexas = 0; sscanf(hexasToWithdraw->GetText(), "%d", &hexas); int trias = 0; sscanf(triasToWithdraw->GetText(), "%d", &trias); psGUIBankingMessage outgoing(psGUIBankingMessage::WITHDRAWFUNDS, guild, circles, octas, hexas, trias); msgHandler->SendMessage( outgoing.msg ); // Reset to 0. circlesToWithdraw->SetText("0"); octasToWithdraw->SetText("0"); hexasToWithdraw->SetText("0"); triasToWithdraw->SetText("0"); return true; } if(widget->GetID() == DEPOSIT) { int circles = 0; sscanf(circlesToDeposit->GetText(), "%d", &circles); int octas = 0; sscanf(octasToDeposit->GetText(), "%d", &octas); int hexas = 0; sscanf(hexasToDeposit->GetText(), "%d", &hexas); int trias = 0; sscanf(triasToDeposit->GetText(), "%d", &trias); psGUIBankingMessage outgoing(psGUIBankingMessage::DEPOSITFUNDS, guild, circles, octas, hexas, trias); msgHandler->SendMessage( outgoing.msg ); // Reset to 0. circlesToDeposit->SetText("0"); octasToDeposit->SetText("0"); hexasToDeposit->SetText("0"); triasToDeposit->SetText("0"); return true; } return false; } --- NEW FILE: pawsbankwindow.h --- /* * pawsbankwindow.h - Author: Mike Gist * * Copyright (C) 2007 Atomic Blue (in...@pl..., http://www.atomicblue.org) * * * 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 __PAWS_BANK_WINDOW_H__ #define __PAWS_BANK_WINDOW_H__ #include "net/cmdbase.h" #include "paws/pawswidget.h" #include "paws/pawstextbox.h" class MsgHandler; class pawsMoney; /** The bank window in PlaneShift. * This is the window that people will use to interact with their bank accounts. */ class pawsBankWindow : public pawsWidget, public psClientNetSubscriber { public: pawsBankWindow(); virtual ~pawsBankWindow(); /* From pawsWidget */ bool PostSetup(); bool OnButtonPressed( int mouseButton, int keyModifier, pawsWidget* widget ); /* From iNetSubscriber */ void HandleMessage( MsgEntry* me ); protected: /* Text that shows the total amount of money available to withdraw. */ pawsTextBox *circlesCanWithdraw, *octasCanWithdraw, *hexasCanWithdraw, *triasCanWithdraw; /* Text that shows the total amount of money available to deposit. */ pawsTextBox *circlesCanDeposit, *octasCanDeposit, *hexasCanDeposit, *triasCanDeposit; /* Box for specifying how much to withdraw. */ pawsEditTextBox *circlesToWithdraw, *octasToWithdraw, *hexasToWithdraw, *triasToWithdraw; /* Box for specifying how much to deposit. */ pawsEditTextBox *circlesToDeposit, *octasToDeposit, *hexasToDeposit, *triasToDeposit; /* Whether or not this is a guild bank account. */ bool guild; csRef<MsgHandler> msgHandler; }; CREATE_PAWS_FACTORY( pawsBankWindow ); #endif // __PAWS_BANK_WINDOW_H__ |