From: <hei...@us...> - 2008-07-28 17:33:48
|
Revision: 1951 http://planeshift.svn.sourceforge.net/planeshift/?rev=1951&view=rev Author: heinchen Date: 2008-07-28 17:33:57 +0000 (Mon, 28 Jul 2008) Log Message: ----------- -fix for FS#1909 patch by Weltall, typofix for FS#707, check against "trias" case insensitive Modified Paths: -------------- trunk/data/gui/illumination.xml trunk/docs/history.txt trunk/src/client/gui/pawsilluminationwindow.cpp trunk/src/client/gui/pawsilluminationwindow.h trunk/src/server/adminmanager.cpp Modified: trunk/data/gui/illumination.xml =================================================================== --- trunk/data/gui/illumination.xml 2008-07-28 17:27:57 UTC (rev 1950) +++ trunk/data/gui/illumination.xml 2008-07-28 17:33:57 UTC (rev 1951) @@ -62,6 +62,16 @@ <bgimage resource="TextTool" /> <eventMouseDown>Ret = SketchWindow:ClickNameTool()</eventMouseDown> </widget> + <widget name="SaveButton" factory="pawsButton" id="111" tooltip="Save (s)"> + <frame x="180" y="0" width="16" height="16" /> + <bgimage resource="FeatherTool" /> + <eventMouseDown>Ret = SketchWindow:ClickSaveButton()</eventMouseDown> + </widget> + <widget name="LoadButton" factory="pawsButton" id="112" tooltip="Load (l)"> + <frame x="200" y="0" width="16" height="16" /> + <bgimage resource="FeatherTool" /> + <eventMouseDown>Ret = SketchWindow:ClickLoadButton()</eventMouseDown> + </widget> </widget> </widget_description> Modified: trunk/docs/history.txt =================================================================== --- trunk/docs/history.txt 2008-07-28 17:27:57 UTC (rev 1950) +++ trunk/docs/history.txt 2008-07-28 17:33:57 UTC (rev 1951) @@ -1,11 +1,8 @@ *** 2008-07-28 by Andreas Heinchen - Fix for FS#1692 - fixing 2 bugs that caused entities to get lost in a temporary sector - -*** 2008-07-28 by Andreas Heinchen - Cleaned up fix for FS#707 - -*** 2008-07-28 by Andreas Heinchen - Fixed FS#1826 +- Fixed FS#1909, patch by Weltall. *** 2008-07-28 by Mike Gist - Fixed FS#1925, patch by peeg. Modified: trunk/src/client/gui/pawsilluminationwindow.cpp =================================================================== --- trunk/src/client/gui/pawsilluminationwindow.cpp 2008-07-28 17:27:57 UTC (rev 1950) +++ trunk/src/client/gui/pawsilluminationwindow.cpp 2008-07-28 17:33:57 UTC (rev 1951) @@ -54,6 +54,17 @@ bool pawsSketchWindow::PostSetup() { psengine->GetMsgHandler()->Subscribe(this, MSGTYPE_VIEW_SKETCH); + //setup an easy way to access our widgets + FeatherTool = dynamic_cast<pawsWidget*> (FindWidget("FeatherTool")); + TextTool = dynamic_cast<pawsWidget*> (FindWidget("TextTool")); + LineTool = dynamic_cast<pawsWidget*> (FindWidget("LineTool")); + PlusTool = dynamic_cast<pawsWidget*> (FindWidget("PlusTool")); + LeftArrowTool = dynamic_cast<pawsWidget*> (FindWidget("LeftArrowTool")); + RightArrowTool = dynamic_cast<pawsWidget*> (FindWidget("RightArrowTool")); + DeleteTool = dynamic_cast<pawsWidget*> (FindWidget("DeleteTool")); + NameTool = dynamic_cast<pawsWidget*> (FindWidget("NameTool")); + SaveButton = dynamic_cast<pawsWidget*> (FindWidget("SaveButton")); + LoadButton = dynamic_cast<pawsWidget*> (FindWidget("LoadButton")); return true; } @@ -72,14 +83,63 @@ currentItemID = msg.ItemID; Notify4(LOG_PAWS,"Got Sketch for item %u: %s\nLimits:%s\n", msg.ItemID, msg.Sketch.GetData(), msg.limits.GetDataSafe()); objlist.Empty(); - - ParseSketch(msg.Sketch); + dirty = false; ParseLimits(msg.limits); - + ParseSketch(msg.Sketch); + // if char does not have the right to edit (ie not the originator-artist)... if (!msg.rightToEdit) readOnly = true; + + if(readOnly) + { + //hide useless widgets in the window so the sketch is more clean + //to whoever looks at it while not being the author + if(FeatherTool) + FeatherTool->Hide(); + if(TextTool) + TextTool->Hide(); + if(LineTool) + LineTool->Hide(); + if(PlusTool) + PlusTool->Hide(); + if(LeftArrowTool) + LeftArrowTool->Hide(); + if(RightArrowTool) + RightArrowTool->Hide(); + if(DeleteTool) + DeleteTool->Hide(); + if(NameTool) + NameTool->Hide(); + if(SaveButton) + SaveButton->Hide(); + if(LoadButton) + LoadButton->Hide(); + } + else //we have editing rights so let's show buttons to do some editing + { + if(FeatherTool) + FeatherTool->Show(); + if(TextTool) + TextTool->Show(); + if(LineTool) + LineTool->Show(); + if(PlusTool) + PlusTool->Show(); + if(LeftArrowTool) + LeftArrowTool->Show(); + if(RightArrowTool) + RightArrowTool->Show(); + if(DeleteTool) + DeleteTool->Show(); + if(NameTool) + NameTool->Show(); + if(SaveButton) + SaveButton->Show(); + if(LoadButton) + LoadButton->Show(); + } sketchName = msg.name; SetTitle(sketchName); @@ -182,6 +242,16 @@ OnKeyDown(0,'n',0); return 0.0; } + else if (!strcasecmp(functionName,"ClickSaveButton")) + { + OnKeyDown(0,'s',0); + return 0.0; + } + else if (!strcasecmp(functionName,"ClickLoadButton")) + { + OnKeyDown(0,'l',0); + return 0.0; + } // else call parent version to inherit other functions return pawsWidget::CalcFunction(functionName,params); @@ -225,6 +295,11 @@ } return true; } + else if (key == 's' && !readOnly) //allow saving also when not in edit mode but check if the player saving the sketch + { //has editing rights over the sketch it's being saved + SaveSketch(); + return true; + } else if (editMode) { if (key == '+') // keycode is the kbd scan code, key is the ASCII @@ -247,6 +322,11 @@ ChangeSketchName(); return true; } + else if (key == 'l') //allow loading only in editing mode + { + LoadSketch(); + return true; + } switch (keyCode) { case CSKEY_DEL: RemoveSelected(); @@ -301,7 +381,6 @@ { int x = (ScreenFrame().xmax + ScreenFrame().xmin)/2 - ScreenFrame().xmin; int y = (ScreenFrame().ymax + ScreenFrame().ymin)/2 - ScreenFrame().ymin; - SketchText *text = new SketchText(x,y,value,this); objlist.Push(text); } @@ -310,7 +389,24 @@ sketchName = value; SetTitle(sketchName); } - + else if (!strcasecmp(name,"FileNameBox")) + { + //we got to load the sketch we were asked for + csRef<iVFS> vfs = psengine->GetVFS(); + csString tempFileName; + tempFileName.Format("/planeshift/userdata/sketches/%s", value); + if (!vfs->Exists(tempFileName)) + { + psSystemMessage msg(0, MSG_ERROR, "File not found!" ); + msg.FireEvent(); + return; + } + csRef<iDataBuffer> buff = vfs->ReadFile(tempFileName); //reads the file + csString sketchxml = buff->operator*(); //converts what we have read in something our ParseSketch function can + //understand + objlist.Empty(); //clears the objlist to start loading our new sketch from clean + ParseSketch(sketchxml); //loads our sketch + } } void pawsSketchWindow::AddSketchLine() @@ -401,6 +497,57 @@ } } +void pawsSketchWindow::SaveSketch() +{ + csString xml; + //generates the xml document from the objects currently displayed in the sketch + xml = "<pages><page "; + xml.AppendFmt("l=\"%d\" t=\"%d\" w=\"%d\" h=\"%d\">", + GetLogicalWidth(screenFrame.xmin), + GetLogicalHeight(screenFrame.ymin), + GetLogicalWidth(screenFrame.xmax-screenFrame.xmin), + GetLogicalHeight(screenFrame.ymax-screenFrame.ymin)); + + for (size_t i=0; i<objlist.GetSize(); i++) + objlist[i]->WriteXml(xml); + + xml += "</page></pages>"; + csRef<iVFS> vfs = psengine->GetVFS(); + unsigned int tempNumber = 0; + //searchs for a free sketch slot in the user directory and write in it + csString tempFileNameTemplate = "/planeshift/userdata/sketches/%s.xml", tempFileName; + if (filenameSafe(sketchName).Length()) + { + tempFileName.Format(tempFileNameTemplate, filenameSafe(sketchName).GetData()); + } + else + { + tempFileNameTemplate = "/planeshift/userdata/books/book%d.txt"; + do + { + tempFileName.Format(tempFileNameTemplate, tempNumber); + tempNumber++; + } while (vfs->Exists(tempFileName)); + } + + vfs->WriteFile(tempFileName, xml, xml.Length()); + psSystemMessage msg(0, MSG_ACK, "Sketch saved to %s", tempFileName.GetData()+30 ); + msg.FireEvent(); +} + +void pawsSketchWindow::LoadSketch() +{ + if (!stringPending) + { + stringPending = true; + + //This window calls OnStringEntered when Ok is pressed. + //Asks to the user the file name of the sketch inside the sketches directory under their user directory + pawsStringPromptWindow::Create("Enter local filename", "", + false, 220, 20, this, "FileNameBox",0,true); + } +} + bool pawsSketchWindow::OnMouseDown( int button, int modifiers, int x, int y ) { if (!editMode) @@ -556,6 +703,8 @@ SketchObject *obj=NULL; csRef<iDocumentNode> tmp = pagenodes->Next(); csString type = tmp->GetValue(); + if((int)objlist.GetSize() >= primCount) //are we under the limitations?... + break; //...it seems we aren't so break before going on, at least one part of sketch is available // Determine what type to create, and create it if (type == "ic") // icon obj = new SketchIcon; @@ -937,3 +1086,23 @@ } } } + +bool pawsSketchWindow::isBadChar(char c) +{ + csString badChars = "/\\?%*:|\"<>"; + if (badChars.FindFirst(c) == (size_t) -1) + return false; + else + return true; +} + +csString pawsSketchWindow::filenameSafe(const csString &original) +{ + csString safe; + size_t len = original.Length(); + for (size_t c = 0; c < len; ++c) { + if (!isBadChar(original[c])) + safe += original[c]; + } + return safe; +} Modified: trunk/src/client/gui/pawsilluminationwindow.h =================================================================== --- trunk/src/client/gui/pawsilluminationwindow.h 2008-07-28 17:27:57 UTC (rev 1950) +++ trunk/src/client/gui/pawsilluminationwindow.h 2008-07-28 17:33:57 UTC (rev 1951) @@ -115,6 +115,17 @@ int primCount; bool readOnly; bool stringPending; + + pawsWidget* FeatherTool; + pawsWidget* TextTool; + pawsWidget* LineTool; + pawsWidget* PlusTool; + pawsWidget* LeftArrowTool; + pawsWidget* RightArrowTool; + pawsWidget* DeleteTool; + pawsWidget* NameTool; + pawsWidget* SaveButton; + pawsWidget* LoadButton; void DrawSketch(); bool ParseSketch(const char *xml); @@ -127,6 +138,10 @@ void NextPrevIcon(int delta); void MoveObject(int dx, int dy); void ChangeSketchName(); + void SaveSketch(); + void LoadSketch(); + bool isBadChar(char c); + csString filenameSafe(const csString &original); csString sketchName; Modified: trunk/src/server/adminmanager.cpp =================================================================== --- trunk/src/server/adminmanager.cpp 2008-07-28 17:27:57 UTC (rev 1950) +++ trunk/src/server/adminmanager.cpp 2008-07-28 17:33:57 UTC (rev 1951) @@ -5939,7 +5939,7 @@ psCharacter* targetchar = target->GetCharacterData(); psCharacter* sourcechar = source->GetCharacterData(); - if (data.item == "tria") + if (data.item.Downcase() == "tria") { psMoney srcMoney = sourcechar->Money(); psMoney targetMoney = targetchar->Money(); @@ -5970,7 +5970,7 @@ if (target->GetClientNum() != me->clientnum) { psserver->SendSystemOK(target->GetClientNum(), - "%d tria was by GM %s.", value, + "%d tria was given by GM %s.", value, source->GetActor()->GetName()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |