From: <blu...@us...> - 2008-11-10 23:17:54
|
Revision: 2409 http://planeshift.svn.sourceforge.net/planeshift/?rev=2409&view=rev Author: bluecommand Date: 2008-11-10 23:17:44 +0000 (Mon, 10 Nov 2008) Log Message: ----------- W.I.P. - NPC dialog with menu system. Modified Paths: -------------- trunk/src/client/psengine.cpp trunk/src/common/net/messages.cpp trunk/src/common/net/messages.h trunk/src/server/bulkobjects/dictionary.cpp trunk/src/server/bulkobjects/dictionary.h trunk/src/server/bulkobjects/psnpcdialog.cpp trunk/src/server/questmanager.cpp trunk/src/server/questmanager.h Added Paths: ----------- trunk/data/gui/dialog.xml trunk/src/client/gui/pawsnpcdialog.cpp trunk/src/client/gui/pawsnpcdialog.h Added: trunk/data/gui/dialog.xml =================================================================== --- trunk/data/gui/dialog.xml (rev 0) +++ trunk/data/gui/dialog.xml 2008-11-10 23:17:44 UTC (rev 2409) @@ -0,0 +1,33 @@ +<widget_description> + +<widget name="NPCDialogWindow" factory="pawsNpcDialogWindow" + visible="yes" savepositions="yes" movable="yes" keepaspect="no" configurable="yes" resizable="yes"> + + <frame x="0" y="100" width="370" height="130" border="yes" /> + <minframe width="165" height="230" /> + <maxframe width="355" height="860" /> + <title resource="Blue Title" text="Dialog" align="left" close_button="yes" /> + <bgimage resource="Buddy Background" alpha="128" /> + + + <widget name="ResponseList" factory="pawsListBox" > + <frame x="33" y="33" width="135" height="219" border="no" /> + <highlight resource="Hightlight" alpha="128" /> + <columns height="16"> + <column width="250" > + <widget name="Name" factory="pawsTextBox"> + <font name="/planeshift/data/ttf/LiberationMono-Regular.ttf" size="10" scalefont="no" /> + </widget> + </column> + </columns> + <attachpoints> + <attach point="PROPORTIONAL_RIGHT" /> + <attach point="PROPORTIONAL_TOP" /> + <attach point="PROPORTIONAL_LEFT" /> + <attach point="PROPORTIONAL_BOTTOM" /> + </attachpoints> + </widget> + +</widget> + +</widget_description> Property changes on: trunk/data/gui/dialog.xml ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/src/client/gui/pawsnpcdialog.cpp =================================================================== --- trunk/src/client/gui/pawsnpcdialog.cpp (rev 0) +++ trunk/src/client/gui/pawsnpcdialog.cpp 2008-11-10 23:17:44 UTC (rev 2409) @@ -0,0 +1,65 @@ +/* +* shadowmanager.cpp - Author: Christian Svensson +* +* Copyright (C) 2008 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 <iutil/objreg.h> + +#include "net/cmdhandler.h" +#include "net/msghandler.h" +#include "net/messages.h" + +#include "../globals.h" +#include "paws/pawslistbox.h" +#include "gui/pawscontrolwindow.h" +#include "pscelclient.h" + +#include "pawsnpcdialog.h" + +pawsNpcDialogWindow::pawsNpcDialogWindow() + +{ + responseList = NULL; +} + +bool pawsNpcDialogWindow::PostSetup() +{ + psengine->GetMsgHandler()->Subscribe( this, MSGTYPE_DIALOG_MENU ); + + responseList = (pawsListBox*)FindWidget("ResponseList"); + return true; +} + +void pawsNpcDialogWindow::OnListAction( pawsListBox* widget, int status ) +{ + if (status == LISTBOX_SELECTED) + { + printf( "Pressed: %p\n", widget->GetSelectedRow()->GetExtraData() ); + } +} + +void pawsNpcDialogWindow::HandleMessage( MsgEntry* me ) +{ + if ( me->GetType() == MSGTYPE_DIALOG_MENU ) + { + psDialogMenuMessage mesg(me); + + printf( "Got psDialogMenuMessage\n "); + + } +} Property changes on: trunk/src/client/gui/pawsnpcdialog.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/src/client/gui/pawsnpcdialog.h =================================================================== --- trunk/src/client/gui/pawsnpcdialog.h (rev 0) +++ trunk/src/client/gui/pawsnpcdialog.h 2008-11-10 23:17:44 UTC (rev 2409) @@ -0,0 +1,49 @@ +/* + * Author: Christian Svensson + * + * Copyright (C) 2008 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_NPC_DIALOG +#define PAWS_NPC_DIALOG + +#include "paws/pawswidget.h" +#include "net/subscriber.h" + +#include "gui/pawscontrolwindow.h" + +class pawsListBox; + +/** The buddy window that shows your current list of in game 'friends'. + * This allows you to send them a tell or add/remove buddies. + */ +class pawsNpcDialogWindow: public pawsControlledWindow, public psClientNetSubscriber +{ +public: + pawsNpcDialogWindow(); + + bool PostSetup(); + void HandleMessage( MsgEntry* me ); + + void OnListAction( pawsListBox* widget, int status ); + +private: + pawsListBox* responseList; + +}; + + +CREATE_PAWS_FACTORY( pawsNpcDialogWindow ); +#endif Property changes on: trunk/src/client/gui/pawsnpcdialog.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/src/client/psengine.cpp =================================================================== --- trunk/src/client/psengine.cpp 2008-11-10 21:16:47 UTC (rev 2408) +++ trunk/src/client/psengine.cpp 2008-11-10 23:17:44 UTC (rev 2409) @@ -198,6 +198,7 @@ #include "gui/pawsbankwindow.h" #include "gui/pawsconfigchatbubbles.h" #include "gui/pawsconfigshadows.h" +#include "gui/pawsnpcdialog.h" // ---------------------------------------------------------------------------- @@ -727,6 +728,7 @@ RegisterFactory (pawsBankWindowFactory); RegisterFactory (pawsConfigChatBubblesFactory); RegisterFactory (pawsConfigShadowsFactory); + RegisterFactory (pawsNpcDialogWindowFactory); } @@ -1314,6 +1316,7 @@ LoadPawsWidget( "Sketch", "data/gui/illumination.xml"); LoadPawsWidget( "GameBoard", "data/gui/gameboard.xml"); LoadPawsWidget( "Writing window", "data/gui/bookwriting.xml"); + LoadPawsWidget( "NPC dialog window", "data/gui/dialog.xml"); LoadCustomPawsWidgets("/this/data/gui/customwidgetslist.xml"); Modified: trunk/src/common/net/messages.cpp =================================================================== --- trunk/src/common/net/messages.cpp 2008-11-10 21:16:47 UTC (rev 2408) +++ trunk/src/common/net/messages.cpp 2008-11-10 23:17:44 UTC (rev 2409) @@ -7150,3 +7150,71 @@ databuf = csPtr<iDataBuffer> (new csDataBuffer (ptr, size, false)); } } + +PSF_IMPLEMENT_MSG_FACTORY(psDialogMenuMessage,MSGTYPE_DIALOG_MENU); + +psDialogMenuMessage::psDialogMenuMessage(int clientnum) +{ + this->clientnum = clientnum; + valid = false; +} + +psDialogMenuMessage::psDialogMenuMessage( MsgEntry *me ) +{ + while( ! msg->IsEmpty() ) + { + int32_t flags, id; + + id = msg->GetInt32(); + flags = msg->GetUInt32(); + + AddResponse( id, msg->GetStr(), flags ); + } + + this->clientnum = 0; +} + +void psDialogMenuMessage::AddResponse(uint32_t id, const csString &response, uint32_t flags) +{ + psDialogMenuMessage::DialogResponse new_response; + + new_response.id = id; + new_response.response = response; + new_response.flags = flags; + + responses.Push( new_response ); +} + +void psDialogMenuMessage::BuildMsg() +{ + size_t size = 0; + + for( size_t i = 0; i < responses.GetSize(); i++ ) + size += 9 + responses[ i ].response.Length(); + + msg.AttachNew( new MsgEntry( size ) ); + + for( size_t i = 0; i < responses.GetSize(); i++ ) + { + msg->Add( responses[ i ].id ); + msg->Add( responses[ i ].flags ); + msg->Add( responses[ i ].response.GetDataSafe() ); + } + + msg->SetType( MSGTYPE_DIALOG_MENU ); + msg->clientnum = clientnum; + + valid = !(msg->overrun); +} + +csString psDialogMenuMessage::ToString(AccessPointers *access_ptrs) +{ + csString text; + for( size_t i = 0; i < responses.GetSize(); i++ ) + { + text.AppendFmt( "Menu: (%d) %s -> %s\n",responses[ i ].id, + responses[ i ].flags, responses[ i ].response.GetDataSafe() ); + } + + return text; +} Modified: trunk/src/common/net/messages.h =================================================================== --- trunk/src/common/net/messages.h 2008-11-10 21:16:47 UTC (rev 2408) +++ trunk/src/common/net/messages.h 2008-11-10 23:17:44 UTC (rev 2409) @@ -246,7 +246,8 @@ MSGTYPE_INTRODUCTION, - MSGTYPE_CACHEFILE + MSGTYPE_CACHEFILE, + MSGTYPE_DIALOG_MENU }; class psMessageCracker; @@ -5044,6 +5045,7 @@ virtual csString ToString(AccessPointers * access_ptrs); }; + /** * Class to send a possibly cached file to the client. */ @@ -5072,5 +5074,46 @@ }; +//----------------------------------------------------------------------------- +/** The message sent from server to client when a menu of possible responses is available + */ + +class psDialogMenuMessage : public psMessageCracker +{ +public: + psDialogMenuMessage( int clientnum ); + psDialogMenuMessage( MsgEntry* message ); + + int clientnum; + + PSF_DECLARE_MSG_FACTORY(); + + enum + { + RESPONSE_SECRET = 0x01 + }; + + void BuildMsg(); + + /** + * @brief Converts the message into human readable string. + * + * @param access_ptrs A struct to a number of access pointers. + * @return Return a human readable string for the message. + */ + virtual csString ToString(AccessPointers * access_ptrs); + + struct DialogResponse + { + uint32_t id; + csString response; + uint32_t flags; + }; + + void AddResponse( uint32_t id, const csString& response, uint32_t flags = 0x00 ); + + csArray<DialogResponse> responses; +}; + #endif Modified: trunk/src/server/bulkobjects/dictionary.cpp =================================================================== --- trunk/src/server/bulkobjects/dictionary.cpp 2008-11-10 21:16:47 UTC (rev 2408) +++ trunk/src/server/bulkobjects/dictionary.cpp 2008-11-10 23:17:44 UTC (rev 2409) @@ -461,7 +461,7 @@ trig = triggers.Find(&key); if (trig) - { + { Debug3(LOG_NPC, client->GetClientNum(),"NPCDialogDict::FindResponse consider trig(%d): '%s'", trig->id,trig->trigger.GetDataSafe()); } @@ -1100,6 +1100,7 @@ NpcResponse::NpcResponse() { quest = NULL; + menu = NULL; active_quest = -1; } @@ -2347,3 +2348,34 @@ psserver->GetAdminManager()->HandleMessage(msg.msg, target); return true; } + +NpcDialogMenu::NpcDialogMenu() +{ + counter = 0; +} + +void NpcDialogMenu::AddTrigger(const csString &formatted, const csString &trigger) +{ + NpcDialogMenu::DialogTrigger new_trigger; + + new_trigger.formatted = formatted; + new_trigger.trigger = trigger; + new_trigger.triggerID = counter++; + + this->triggers.Push( new_trigger ); +} + +void NpcDialogMenu::ShowMenu( Client *client ) +{ + if( client == NULL ) + return; + + psDialogMenuMessage me( client->GetClientNum() ); + + for( size_t i = 0; i < counter; i++ ) + me.AddResponse( i, this->triggers[ i ].formatted ); + + me.BuildMsg(); + + me.SendMessage(); +} Modified: trunk/src/server/bulkobjects/dictionary.h =================================================================== --- trunk/src/server/bulkobjects/dictionary.h 2008-11-10 21:16:47 UTC (rev 2408) +++ trunk/src/server/bulkobjects/dictionary.h 2008-11-10 23:17:44 UTC (rev 2409) @@ -285,6 +285,29 @@ }; /** + * Holds the trigger menu, if it exists, for a given location in a dialog + */ +class NpcDialogMenu : public csRefCount +{ +protected: + struct DialogTrigger + { + unsigned int triggerID; + csString formatted; + csString trigger; + }; + + csArray<DialogTrigger> triggers; + unsigned int counter; // ID counter +public: + + NpcDialogMenu(); + + void AddTrigger( const csString &formatted, const csString &trigger ); + void ShowMenu( Client *client ); +}; + +/** * This class holds several possible responses and an * action script for the npc to run whenever an * appropriate trigger is triggered. @@ -304,6 +327,8 @@ csPDelArray<ResponseOperation> script; /// list of ops in script to execute when triggered csRef<psQuestPrereqOp> prerequisite; /// prerequisite for this Response to be available + csRef<NpcDialogMenu> menu; + enum { VALID_RESPONSE, Modified: trunk/src/server/bulkobjects/psnpcdialog.cpp =================================================================== --- trunk/src/server/bulkobjects/psnpcdialog.cpp 2008-11-10 21:16:47 UTC (rev 2408) +++ trunk/src/server/bulkobjects/psnpcdialog.cpp 2008-11-10 23:17:44 UTC (rev 2409) @@ -664,6 +664,9 @@ currentClient->GetCharacterData()->SetAssignedQuestLastResponse(resp->quest,resp->id); } + if( resp->menu ) + resp->menu->ShowMenu(currentClient); + return resp; // Found what we are looking for } else Modified: trunk/src/server/questmanager.cpp =================================================================== --- trunk/src/server/questmanager.cpp 2008-11-10 21:16:47 UTC (rev 2408) +++ trunk/src/server/questmanager.cpp 2008-11-10 23:17:44 UTC (rev 2409) @@ -560,6 +560,27 @@ Debug2( LOG_QUESTS, 0,"Player says '%s'", pending_triggers[i]); } } + else if (!strncasecmp(block,"Menu:",5)) // Menu: is an nice way of represention the various P: triggers + { + if( last_response == NULL ) + { + Error1( "Menu without previous response - dialog menus as dialog starters are not supported" ); + return line_number; + } + + csRef<NpcDialogMenu> menu = new NpcDialogMenu(); + + if (!BuildMenu(block, pending_triggers, menu)) + { + Error3("Could not determine triggers in script '%s', in line <%s>", + mainQuest->GetName(),block.GetData()); + lastError.Format("Could not determine triggers in script '%s', in line <%s>", mainQuest->GetName(),block.GetData()); + + return line_number; + } + + last_response->menu = menu; + } else if (strchr(block,':')) // text response { csString him,her,it,them,npc_name; @@ -846,6 +867,35 @@ return true; } +bool QuestManager::BuildMenu(const csString& block,const csStringArray& list, NpcDialogMenu *menu) +{ + size_t start=0, end, counter = 0; + csString response; + + while (start < block.Length()) + { + start = block.Find("Menu:",start); + if (start == SIZET_NOT_FOUND) + return true; + start += 5; // skip the actual Menu: + + // Now find next P:, if any + end = block.Find("Menu:",start); + if (end == SIZET_NOT_FOUND) + end = block.Length(); + + block.SubString(response,start,end-start); + response.Trim(); + + menu->AddTrigger( response, list[ counter++ ] ); + + start = end; // Start at next Menu: or exit loop + } + return true; +} + + + void QuestManager::CutOutParenthesis(csString &response, csString &within,char start_char,char end_char) { // now look for error msg in parenthesis Modified: trunk/src/server/questmanager.h =================================================================== --- trunk/src/server/questmanager.h 2008-11-10 21:16:47 UTC (rev 2408) +++ trunk/src/server/questmanager.h 2008-11-10 23:17:44 UTC (rev 2409) @@ -47,6 +47,7 @@ }; class gemNPC; +class NpcDialogMenu; class NpcResponse; class WordArray; class psString; @@ -72,6 +73,9 @@ bool GetResponseText(csString& block,csString& response,csString& file_path, csString& him, csString& her, csString& it, csString& them); bool BuildTriggerList(csString& block,csStringArray& list); + + bool BuildMenu(const csString& block,const csStringArray& list, NpcDialogMenu *menu); + int GetNPCFromBlock(WordArray words,csString& current_npc); bool ParseItemList(const csString & input, csString & parsedItemList); bool ParseItem(const char *text, psStringArray & xmlItems, psMoney & money); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |