Update of /cvsroot/planeshift/planeshift/src/client/paws In directory sc8-pr-cvs1:/tmp/cvs-serv16518 Modified Files: pspawsmanager.h pspawsmanager.cpp pawsmainwidget.h pawsmainwidget.cpp pawsinteractwindow.cpp Added Files: pawsconfigmouse.h pawsconfigmouse.cpp Log Message: Committing patch from Andrew Robberts for new options screen which lets you set some mouse controls. We all expect these to grow. --- NEW FILE: pawsconfigmouse.h --- /* * pawsconfigmouse.h - Author: Andrew Robberts * * Copyright (C) 2003 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 PAWS_CONFIG_MOUSE_HEADER #define PAWS_CONFIG_MOUSE_HEADER // CS INCLUDES #include <csutil/array.h> // PAWS INCLUDES #include "pawswidget.h" #include "pawsbutton.h" #include "pawstextbox.h" #include "pawsconfigwindow.h" #include "../psmousebinds.h" class psMouseBinds; ////////////////////////////////////////////////////////////////////////////// // pawsConfigMouse ////////////////////////////////////////////////////////////////////////////// class pawsConfigMouse : public pawsConfigSectionWindow { public: pawsConfigMouse(psPawsManager* manager); virtual ~pawsConfigMouse(); // from pawsConfigSectionWindow: virtual bool Initialize(iObjectRegistry* object_reg); virtual bool LoadConfig(); virtual bool IsDirty(); virtual bool SaveConfig(); virtual void SetDefault(); // from pawsWidget: virtual bool OnButtonPressed( int mouseButton, pawsWidget* widget ); protected: bool CreateTree(); // Creates the tree that makes the whole GUI. // Returns success void CreateTreeWidgets(pawsTreeNode * subtreeRoot); // Adds widgets to all nodes in subtree with root 'subtreeRoot' // -- command label, key combination label and button that opens FingeringWindow void SetActionLabels(pawsTreeNode * subtreeRoot); // Sets all labels that hold mouse events (in subtree with root 'subtreeRoot') pawsTree * tree; // the tree that makes whole window GUI iObjectRegistry* object_reg; psPawsManager* pawsManager; psMouseBinds binds; }; class pawsConfigMouseFactory : public pawsWidgetFactory { public: pawsConfigMouseFactory( psPawsManager* manager ) : pawsWidgetFactory( manager ) { Register( "pawsConfigMouse" ); } pawsWidget* Create() { return new pawsConfigMouse( mainManager ); } }; #endif --- NEW FILE: pawsconfigmouse.cpp --- /* * pawsconfigmouse.cpp - Author: AndrewRobberts * * Copyright (C) 2003 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. * */ // CS INCLUDES #include <config.h> #include <csutil/xmltiny.h> #include <csutil/objreg.h> // COMMON INCLUDES #include "../../common/util/log.h" // PAWS INCLUDES #include "pawsconfigmouse.h" #include "pawstextbox.h" #include "pspawsmanager.h" #include "pawsmainwidget.h" // layout of ConfigKeys window: #define LEFT_MARGIN 40 #define COMMAND_WIDTH 100 #define TRIGGER_WIDTH 150 #define COLUMN_SPACING 30 #define ROW_SPACING 30 #define NO_BIND "?" ////////////////////////////////////////////////////////////////////// // // pawsConfigMouse // ////////////////////////////////////////////////////////////////////// pawsConfigMouse::pawsConfigMouse(psPawsManager* manager) : pawsConfigSectionWindow(manager) { object_reg = NULL; pawsManager = manager; } pawsConfigMouse::~pawsConfigMouse() { } bool pawsConfigMouse::Initialize(iObjectRegistry* _object_reg) { object_reg = _object_reg; if ( ! CreateTree()) return false; return true; } bool pawsConfigMouse::LoadConfig() { if ( binds.LoadFromFile(object_reg, "/this/data/options/mouse.xml") ) { SetActionLabels(tree->GetRoot()); return true; } else return false; } bool pawsConfigMouse::IsDirty() { return true; } bool pawsConfigMouse::SaveConfig() { bool ok1, ok2; ok1 = binds.SaveToFile(object_reg, "/this/data/options/mouse.xml"); ok2 = (pawsManager->GetMouseBinds())->LoadFromFile(object_reg, "/this/data/options/mouse.xml"); return ok1 && ok2; } void pawsConfigMouse::SetDefault() { } bool pawsConfigMouse::CreateTree() { pawsTreeNode * root; tree = new pawsTree(windowManager); tree->MoveTo(screenFrame.xmin, screenFrame.ymin); tree->SetSize(screenFrame.Width(), screenFrame.Height()); tree->SetScrollBars(false, true); tree->SetTreeLayout(new pawsStdTreeLayout(tree, 5, 20)); tree->SetTreeDecorator(new pawsStdTreeDecorator(tree, graphics2D, windowManager, 0x0000ff, 0x00ffff, 13)); AddChild(tree); if ( ! tree->LoadFromFile("data/configmouse.xml")) return false; root = tree->GetRoot(); if (root != NULL) CreateTreeWidgets(root); return true; } void pawsConfigMouse::CreateTreeWidgets(pawsTreeNode * subtreeRoot) { pawsTextBox * label, * key; pawsButton * button; pawsSeqTreeNode * rootAsSeq; pawsTreeNode * child; rootAsSeq = dynamic_cast<pawsSeqTreeNode*> (subtreeRoot); if (rootAsSeq != NULL) { label = new pawsTextBox(windowManager); label->SetSize(COMMAND_WIDTH, 20); label->SetText(subtreeRoot->GetName()); label->SetColour(0xffffff); label->Show(); rootAsSeq->AddSeqWidget(label, COMMAND_WIDTH + COLUMN_SPACING); key = new pawsTextBox(windowManager); key->SetSize(TRIGGER_WIDTH, 20); key->SetColour(0xffffff); key->Show(); rootAsSeq->AddSeqWidget(key, TRIGGER_WIDTH + COLUMN_SPACING); button = new pawsButton(windowManager); button->SetNotify(this); button->SetSize(30, 20); button->SetUpImage("radiooff"); button->SetToggle(false); button->Show(); rootAsSeq->AddSeqWidget(button); } child = subtreeRoot->GetFirstChild(); while (child != NULL) { CreateTreeWidgets(child); child = child->GetNextSibling(); } } void pawsConfigMouse::SetActionLabels(pawsTreeNode * subtreeRoot) { pawsSeqTreeNode * rootAsSeq; pawsTreeNode * child; pawsTextBox * actionLabel; csString boundAction; rootAsSeq = dynamic_cast<pawsSeqTreeNode*> (subtreeRoot); if (rootAsSeq != NULL) { actionLabel = dynamic_cast<pawsTextBox*> (rootAsSeq->GetSeqWidget(1)); assert(actionLabel); if (binds.GetBind(subtreeRoot->GetName(), boundAction)) actionLabel->SetText(boundAction); else actionLabel->SetText(NO_BIND); } child = subtreeRoot->GetFirstChild(); while (child != NULL) { SetActionLabels(child); child = child->GetNextSibling(); } } csString GetActionOfButton(pawsWidget * widget) { pawsTreeNode * buttonNode; buttonNode = dynamic_cast <pawsTreeNode*> (widget->GetParent()); assert(buttonNode); return buttonNode->GetName(); } bool pawsConfigMouse::OnButtonPressed( int mouseButton, pawsWidget* widget ) { csString editedAction = GetActionOfButton(widget); if (editedAction == "") return false; pawsSeqTreeNode * buttonNode; pawsTextBox * textBox; buttonNode = dynamic_cast <pawsSeqTreeNode*> (tree->FindNodeByName(editedAction)); assert(buttonNode); textBox = dynamic_cast <pawsTextBox*> (buttonNode->GetSeqWidget(1)); assert(textBox); csString b = "mouse"; b += mouseButton; textBox->SetText(b); binds.Bind(editedAction, b); return true; } Index: pspawsmanager.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/paws/pspawsmanager.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** pspawsmanager.h 20 Sep 2003 14:30:18 -0000 1.14 --- pspawsmanager.h 22 Sep 2003 07:19:00 -0000 1.15 *************** *** 31,34 **** --- 31,35 ---- #include "pawsmouse.h" + #include "psmousebinds.h" #include "net/msghandler.h" *************** *** 116,119 **** --- 117,123 ---- pawsMouse* GetMouse() { return mouse; } + void SetMouseBinds(psMouseBinds* m) { mouseBinds = m; } + psMouseBinds* GetMouseBinds() { return mouseBinds; } + iCelEntity* GetMainActor() { return mainActor; } void SetMainActor( iCelEntity* entity ); *************** *** 179,182 **** --- 183,189 ---- // Mouse pointer pawsMouse* mouse; + + // the mouse bindings + psMouseBinds* mouseBinds; csPDelArray<pawsWidgetFactory> factories; Index: pspawsmanager.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/paws/pspawsmanager.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** pspawsmanager.cpp 21 Sep 2003 18:11:33 -0000 1.38 --- pspawsmanager.cpp 22 Sep 2003 07:19:00 -0000 1.39 *************** *** 62,65 **** --- 62,66 ---- #include "pawstree.h" #include "pawsconfigwindow.h" + #include "pawsconfigmouse.h" #include "pawsconfigkeys.h" #include "pawsconfigdetails.h" *************** *** 571,574 **** --- 572,576 ---- RegisterFactory (pawsFingeringWindowFactory); RegisterFactory (pawsConfigDetailsFactory); + RegisterFactory (pawsConfigMouseFactory); RegisterFactory (pawsPetitionWindowFactory); Index: pawsmainwidget.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/paws/pawsmainwidget.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** pawsmainwidget.h 1 Sep 2003 04:20:17 -0000 1.6 --- pawsmainwidget.h 22 Sep 2003 07:19:00 -0000 1.7 *************** *** 28,31 **** --- 28,32 ---- #include "pscelclient.h" #include "pawswidget.h" + #include "../psmousebinds.h" #include "util/binarytree.h" *************** *** 87,90 **** --- 88,93 ---- pawsChatWindow *chatWindow; + + psMouseBinds* mouseBinds; iCamera* guiCamera; Index: pawsmainwidget.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/paws/pawsmainwidget.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** pawsmainwidget.cpp 1 Aug 2003 20:53:17 -0000 1.13 --- pawsmainwidget.cpp 22 Sep 2003 07:19:00 -0000 1.14 *************** *** 52,55 **** --- 52,60 ---- cel = NULL; guiCamera = NULL; + + mouseBinds = new psMouseBinds(); + manager->SetMouseBinds(mouseBinds); + if ( !mouseBinds->LoadFromFile( windowManager->GetObjectRegistry(), "/this/data/options/mouse.xml" ) ) + Error1("Failed to load mouse options"); } *************** *** 125,139 **** if ( over ) { ! if ( button == 2 ) { ! pawsInfoWindow* win = (pawsInfoWindow*)FindWidget( "InfoWindow" ); ! CS_ASSERT( win ); ! win->SetTarget( over ); ! /// Notify server of selection. ! CS_ID mappedID = cel->GetNetPersist()->GetMappedID( over ); ! psUserActionMessage action( 0, mappedID, "select" ); ! windowManager->GetMessageHandler()->SendMessage( action.msg ); } } --- 130,163 ---- if ( over ) { ! csEventMouseData event; ! if ( mouseBinds->GetBind("EntitySelect", event) ) { ! if ( button == event.Button ) ! { ! pawsInfoWindow* win = (pawsInfoWindow*)FindWidget( "InfoWindow" ); ! CS_ASSERT( win ); ! win->SetTarget( over ); ! /// Notify server of selection. ! CS_ID mappedID = cel->GetNetPersist()->GetMappedID( over ); ! psUserActionMessage action( 0, mappedID, "select" ); ! windowManager->GetMessageHandler()->SendMessage( action.msg ); ! } ! } ! if ( mouseBinds->GetBind("ContextMenu", event) ) ! { ! if ( button == event.Button ) ! { ! pawsInfoWindow* win = (pawsInfoWindow*)FindWidget( "InfoWindow" ); ! CS_ASSERT( win ); ! win->SetTarget( over ); ! ! /// Notify server of selection. ! CS_ID mappedID = cel->GetNetPersist()->GetMappedID( over ); ! psUserActionMessage action( 0, mappedID, "context" ); ! ! windowManager->GetMessageHandler()->SendMessage( action.msg ); ! } } } Index: pawsinteractwindow.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/paws/pawsinteractwindow.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pawsinteractwindow.cpp 29 May 2003 23:57:04 -0000 1.1 --- pawsinteractwindow.cpp 22 Sep 2003 07:19:00 -0000 1.2 *************** *** 111,115 **** }; ! for ( int i=0; i < 5; i++ ) { --- 111,115 ---- }; ! bool hasOptions = false; for ( int i=0; i < 5; i++ ) { *************** *** 121,125 **** --- 121,128 ---- } if ( guimsg.options & types[i] ) + { + hasOptions = true; widget->Show(); + } else widget->Hide(); *************** *** 141,144 **** --- 144,150 ---- MoveTo( xPos , yPos ); + + if (!hasOptions) + Hide(); } |