Advertisement
Guest User

windowcommands.patch

a guest
Sep 29th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 16.48 KB | None | 0 0
  1. Index: src/client/cmdusers.cpp
  2. ===================================================================
  3. --- src/client/cmdusers.cpp (revision 8452)
  4. +++ src/client/cmdusers.cpp (working copy)
  5. @@ -112,6 +112,7 @@
  6.      cmdsource->Subscribe("/roll",          this);
  7.      cmdsource->Subscribe("/rotate",        this);
  8.      cmdsource->Subscribe("/sell",          this);
  9. +    cmdsource->Subscribe("/setwindowpos",  this);
  10.      cmdsource->Subscribe("/show",          this);
  11.      cmdsource->Subscribe("/sit",           this);
  12.      //cmdsource->Subscribe("/spawn",       this);
  13. @@ -138,6 +139,7 @@
  14.      cmdsource->Subscribe("/setoocdesc",    this); // set the ooc description of a char
  15.      cmdsource->Subscribe("/loaddesc",      this); // load a description for this char from a file
  16.      cmdsource->Subscribe("/loadoocdesc",   this); // load a ooc description for this char from a file
  17. +    cmdsource->Subscribe("/togglerun",     this); // changes the run status of the character
  18.  }
  19.  
  20.  psUserCommands::~psUserCommands()
  21. @@ -190,6 +192,7 @@
  22.      cmdsource->Unsubscribe("/roll",                  this);
  23.      cmdsource->Unsubscribe("/rotate",                this);
  24.      cmdsource->Unsubscribe("/sell",                  this);
  25. +    cmdsource->Unsubscribe("/setwindowpos",          this);
  26.      cmdsource->Unsubscribe("/show",                  this);
  27.      cmdsource->Unsubscribe("/sit",                   this);
  28.      //cmdsource->Unsubscribe("/spawn",               this);
  29. @@ -216,6 +219,7 @@
  30.      cmdsource->Unsubscribe("/setoocdesc",            this);
  31.      cmdsource->Unsubscribe("/loaddesc",              this);
  32.      cmdsource->Unsubscribe("/loadoocdesc",           this);
  33. +    cmdsource->Unsubscribe("/togglerun",             this);
  34.  
  35.  
  36.  
  37. @@ -311,7 +315,7 @@
  38.  
  39.      if (  words[0] == "/show")
  40.      {
  41. -        if (words.GetCount() > 1)
  42. +        if (words.GetCount() == 2)
  43.          {
  44.              pawsControlWindow* ctrlWindow = dynamic_cast<pawsControlWindow*>(PawsManager::GetSingleton().FindWidget("ControlWindow"));
  45.              if(!ctrlWindow || ctrlWindow->HandleWindowName(words[1]))
  46. @@ -319,8 +323,54 @@
  47.  
  48.              else return "That window cannot be found.";
  49.          }
  50. -        return "You need to specify a window to show";
  51. +        else if (words.GetCount() == 3)
  52. +   {
  53. +       if (words[2] == "show")
  54. +       {
  55. +       pawsControlWindow* ctrlWindow = dynamic_cast<pawsControlWindow*>(PawsManager::GetSingleton().FindWidget("ControlWindow"));
  56. +       if(!ctrlWindow || ctrlWindow->showWindowName(words[1]))
  57. +       {
  58. +           return NULL;
  59. +       }
  60. +       else
  61. +       {
  62. +           return "That window cannot be found.";
  63. +       }
  64. +       }
  65. +       if (words[2] == "hide")
  66. +       {
  67. +       pawsControlWindow* ctrlWindow = dynamic_cast<pawsControlWindow*>(PawsManager::GetSingleton().FindWidget("ControlWindow"));
  68. +       if(!ctrlWindow || ctrlWindow->hideWindowName(words[1]))
  69. +       {
  70. +           return NULL;
  71. +       }
  72. +       else
  73. +       {
  74. +           return "That window cannot be found.";
  75. +       }
  76. +       }
  77. +   }
  78. +        return "Usage: /show [windowname] [hide|show]";
  79.      }
  80. +    else if ( words[0] == "/setwindowpos" )
  81. +    {
  82. +   if (words.GetCount() == 4)
  83. +   {
  84. +       if ((isdigit(words[2].GetAt(0))) && (isdigit(words[3].GetAt(0))))
  85. +       {
  86. +       pawsControlWindow* ctrlWindow = dynamic_cast<pawsControlWindow*>(PawsManager::GetSingleton().FindWidget("ControlWindow"));
  87. +       if(!ctrlWindow || ctrlWindow->setWindowPositionName(words[1], atoi(words[2]), atoi(words[3])))
  88. +       {
  89. +           return NULL;
  90. +       }
  91. +       else
  92. +       {
  93. +           return "That window cannot be found.";
  94. +       }
  95. +       }
  96. +   }
  97. +   return "Usage: /setwindowpos [windowname] [x] [y]";
  98. +    }
  99.      else if ( words[0] == "/study" )
  100.      {
  101.          pawsWidget * widget = PawsManager::GetSingleton().FindWidget("CraftWindow");
  102. @@ -1121,6 +1171,41 @@
  103.  
  104.          }
  105.      }
  106. +    else if (words[0] == "/togglerun")
  107. +    {
  108. +   if ((psengine) && (psengine->GetCharControl()) && (psengine->GetCharControl()->GetMovementManager()))
  109. +   {
  110. +       if (words.GetCount() < 2)
  111. +       {
  112. +       // No parameter so just toggle the current running status of the character
  113. +           psengine->GetCharControl()->GetMovementManager()->ToggleRun();
  114. +       return "Run mode toggled";
  115. +       }
  116. +       else if (words.GetCount() == 2)
  117. +       {
  118. +       // Oh...we have one parameter. Lets see if it's a valid one...and then act accordingly
  119. +       if (words[1] == "run")
  120. +       {
  121. +           // So we should run now? Fine master...whatever you want
  122. +           psengine->GetCharControl()->GetMovementManager()->setRun(true);
  123. +           return "Run mode enabled";
  124. +       }
  125. +       else if (words[1] == "walk")
  126. +       {
  127. +           // time for some relaxing walking for a change
  128. +           psengine->GetCharControl()->GetMovementManager()->setRun(false);
  129. +           return "Run mode disabled";
  130. +       }
  131. +       }
  132. +       // well...if we didn't return yet the syntax was invalid so lets give a hint about the correct usage
  133. +       return "Usage: /togglerun [run/walk]";
  134. +   }
  135. +   else
  136. +   {
  137. +       // if this ever happens a useful error-message is the least of our worries
  138. +       return "Something went really wrong. Couldn't find a valid movement manager...how do you play this game at the moment at all?";
  139. +   }
  140. +    }
  141.      else
  142.      {
  143.          psUserCmdMessage cmdmsg(cmd);
  144. Index: src/client/gui/pawscontrolwindow.h
  145. ===================================================================
  146. --- src/client/gui/pawscontrolwindow.h  (revision 8452)
  147. +++ src/client/gui/pawscontrolwindow.h  (working copy)
  148. @@ -85,6 +85,39 @@
  149.       * @return TRUE if the toggle was possible, returns FALSE if it was not found.
  150.       */
  151.      bool HandleWindowName(csString widgetStr);
  152. +    
  153. +    /** Used to show a window.
  154. +     * If the window was already shown nothing happens.
  155. +     * @param widgetStr: The window to show
  156. +     * @return FALSE in case of an error otherwise TRUE
  157. +     */
  158. +    bool showWindow(csString widgetStr);
  159. +    /** Used to hide a window.
  160. +     * If the window was already hidden nothing happens.
  161. +     * @param widgetStr: The window to show
  162. +     * @return FALSE in case of an error otherwise TRUE
  163. +     */
  164. +    bool hideWindow(csString widgetStr);
  165. +    /** Used to show a window from a command.
  166. +     * If the window was already shown nothing happens.
  167. +     * @param widgetStr: The window to hide (command form, translated to the actual window name by the function)
  168. +     * @return FALSE in case of an error otherwise TRUE
  169. +     */
  170. +    bool showWindowName(csString widgetStr);
  171. +    /** Used to hide a window from a command.
  172. +     * If the window was already hidden nothing happens.
  173. +     * @param widgetStr: The window to hide (command form, translated to the actual window name by the function)
  174. +     * @return FALSE in case of an error otherwise TRUE
  175. +     */
  176. +    bool hideWindowName(csString widgetStr);
  177. +    
  178. +    /** Used to set the position of windows from a command.
  179. +     *  @param widgetStr: The window to hide (command form, translated to the actual window name by the function)
  180. +     *  @param x: New x postion ofthe window
  181. +     *  @param y: New y postion ofthe window
  182. +     *  @return FALSE in case of an error otherwise TRUE
  183. +     */
  184. +    bool setWindowPositionName(csString widgetStr, int x, int y);
  185.  
  186.      /** When the quit button is pressed this method displays the yes/no dialog
  187.       * box to confirm that a user really wants to quit.
  188. @@ -146,6 +179,15 @@
  189.      bool Contains( int x, int y );
  190.  
  191.  private:
  192. +    /** helper function for commands to translate to widget names from a more readable form
  193. +     *  This is copied from a previous version so don't blame me for it. I think it's very badly done
  194. +     *  and it contains hardcoded widget names. So if anyone needs to add a new window to PS this function
  195. +     *  must be altered. The "correct" way would be probably to put these translations in an xml file that comes
  196. +     *  with the gui...but can't be bothered to write that.
  197. +     *  @param widgetStr: The widget name to be translated
  198. +     *  @return The actual widget name used by the system or an empty string if this widget is unkown to this function
  199. +     */  
  200. +    csString translateWidgetName(csString widgetStr);
  201.      unsigned short int style;
  202.      bool hidden;
  203.      csArray<WBName> wbs;
  204. Index: src/client/gui/pawscontrolwindow.cpp
  205. ===================================================================
  206. --- src/client/gui/pawscontrolwindow.cpp    (revision 8452)
  207. +++ src/client/gui/pawscontrolwindow.cpp    (working copy)
  208. @@ -295,86 +295,279 @@
  209.  
  210.  bool pawsControlWindow::HandleWindowName(csString widgetStr)
  211.  {
  212. -    csString widget;
  213. +    csString widget = translateWidgetName(widgetStr);
  214. +    
  215. +    if(widget == "quit")
  216. +    {
  217. +        HandleQuit();
  218. +        return true;
  219. +    }
  220. +    if(widget == "buy")
  221. +    {
  222. +        psengine->GetCmdHandler()->Execute("/buy");
  223. +        return true;
  224. +    }
  225. +    if(widget != "")
  226. +    {
  227. +        HandleWindow(widget);
  228. +        return true;
  229. +    }
  230. +    else return false;
  231. +}
  232. +
  233. +bool pawsControlWindow::showWindow(csString widgetStr)
  234. +{
  235. +    // lets see if we can find the specified window
  236. +    pawsWidget* widget = PawsManager::GetSingleton().FindWidget(widgetStr.GetData());
  237. +    if (!widget)
  238. +    {
  239. +        // doesn't look like it, log and return with an error
  240. +        Error2("%s isn't loaded", widgetStr.GetData());
  241. +        return false;
  242. +    }
  243. +    // if the window was not visible before we show it now.
  244. +    if ( !widget->IsVisible() )
  245. +    {
  246. +   widget->Show();
  247. +    }
  248. +    return true;
  249. +}
  250. +
  251. +bool pawsControlWindow::hideWindow(csString widgetStr)
  252. +{
  253. +    // lets see if we can find the specified window
  254. +    pawsWidget* widget = PawsManager::GetSingleton().FindWidget(widgetStr.GetData());
  255. +    if (!widget)
  256. +    {
  257. +        // doesn't look like it, log and return with an error
  258. +        Error2("%s isn't loaded", widgetStr.GetData());
  259. +        return false;
  260. +    }
  261. +    // if the window was not visible before we show it now.
  262. +    if ( widget->IsVisible() )
  263. +    {
  264. +   widget->Hide();
  265. +   // Don't leave focus on us after hiding
  266. +        if ( this->Includes(PawsManager::GetSingleton().GetCurrentFocusedWidget()) )
  267. +   {
  268. +            PawsManager::GetSingleton().SetCurrentFocusedWidget(NULL);
  269. +   }
  270. +    }
  271. +    return true;
  272. +}
  273. +
  274. +bool pawsControlWindow::showWindowName(csString widgetStr)
  275. +{
  276. +    csString widget = translateWidgetName(widgetStr);
  277. +    
  278. +    // special handling for a few widgets
  279. +    if(widget == "quit")
  280. +    {
  281. +        HandleQuit();
  282. +        return true;
  283. +    }
  284. +    if(widget == "buy")
  285. +    {
  286. +        psengine->GetCmdHandler()->Execute("/buy");
  287. +        return true;
  288. +    }
  289. +    // otherwise just show the window
  290. +    if(widget != "")
  291. +    {
  292. +        return showWindow(widget);
  293. +    }
  294. +    else return false;
  295. +}
  296. +
  297. +bool pawsControlWindow::hideWindowName(csString widgetStr)
  298. +{
  299. +    csString widget = translateWidgetName(widgetStr);
  300. +    
  301. +    // special handling for a few widgets
  302. +    if(widget == "quit")
  303. +    {
  304. +        // actually we don't do anything here...makes no sense to hide the quit dialog
  305. +        return true;
  306. +    }
  307. +    if(widget == "buy")
  308. +    {
  309. +   // we don't do anything here either...might be changed at some point.
  310. +        return true;
  311. +    }
  312. +    // otherwise just hide the window
  313. +    if(widget != "")
  314. +    {
  315. +        return hideWindow(widget);
  316. +    }
  317. +    else return false;
  318. +}
  319. +
  320. +bool pawsControlWindow::setWindowPositionName(csString widgetStr, int x, int y)
  321. +{
  322. +    csString widget = translateWidgetName(widgetStr);
  323. +    
  324. +    // special handling for a few widgets
  325. +    if(widget == "quit")
  326. +    {
  327. +        // actually we don't do anything here...always in the middle of the screen
  328. +        return true;
  329. +    }
  330. +    if(widget == "buy")
  331. +    {
  332. +   // we don't do anything here either...might be changed at some point.
  333. +        return true;
  334. +    }
  335. +    // otherwise set the new position of the window
  336. +    if(widget != "")
  337. +    {
  338. +   pawsWidget* w = PawsManager::GetSingleton().FindWidget(widget.GetData());
  339. +   if (!w)
  340. +   {
  341. +       Error2("%s isn't loaded", widget.GetData());
  342. +       return false;
  343. +   }
  344. +   w->SetRelativeFramePos(x,y);
  345. +   return true;
  346. +    }
  347. +    return false;
  348. +}
  349. +
  350. +csString pawsControlWindow::translateWidgetName(csString widgetStr)
  351. +{
  352. +    csString widget = "";
  353.      widgetStr.Downcase();
  354.      if(widgetStr == "options" )
  355. +    {
  356.          widget = "ConfigWindow";
  357. +    }
  358.      else if(widgetStr == "stats" || widgetStr =="skills")
  359. +    {  
  360.          widget = "SkillWindow";
  361. +    }
  362.      else if(widgetStr == "spell book" || widgetStr == "spells")
  363. +    {
  364.          widget = "SpellBookWindow";
  365. +    }
  366.      else if(widgetStr == "inventory" || widgetStr == "inv")
  367. +    {  
  368.          widget = "InventoryWindow";
  369. +    }
  370.      else if(widgetStr == "help")
  371. +    {
  372.          widget = "HelpWindow";
  373. +    }
  374.      else if(widgetStr == "buddy")
  375. +    {
  376.          widget = "BuddyWindow";
  377. +    }
  378.      else if(widgetStr == "info")
  379. +    {
  380.          widget = "InfoWindow";
  381. +    }
  382.      else if(widgetStr == "petition" || widgetStr == "petitions")
  383. +    {
  384.          widget = "PetitionWindow";
  385. +    }
  386.      else if(widgetStr == "quest")
  387. +    {
  388.          widget = "QuestNotebook";
  389. +    }
  390.      else if(widgetStr == "gm")
  391. +    {
  392.          widget = "GmGUI";
  393. +    }
  394.      else if(widgetStr == "shortcut")
  395. +    {
  396.          widget = "ShortcutWindow";
  397. +    }
  398.      else if(widgetStr == "group")
  399. +    {
  400.          widget = "GroupWindow";
  401. +    }
  402.      else if(widgetStr == "guild")
  403. +    {
  404.          widget = "GuildWindow";
  405. +    }
  406.      else if(widgetStr == "glyph")
  407. +    {
  408.          widget = "GlyphWindow";
  409. +    }
  410.      else if(widgetStr == "sketch")
  411. +    {
  412.          widget = "SketchWindow";
  413. +    }
  414.      else if(widgetStr == "merchant")
  415. +    {
  416.          widget = "MerchantWindow";
  417. +    }
  418.      else if(widgetStr == "loot")
  419. +    {
  420.          widget = "LootWindow";
  421. +    }
  422.      else if(widgetStr == "detail")
  423. +    {
  424.          widget = "DetailWindow";
  425. +    }
  426.      else if(widgetStr == "exchange")
  427. +    {
  428.          widget = "ExchangeWindow";
  429. +    }
  430.      else if(widgetStr == "write")
  431. +    {
  432.          widget = "WritingWindow";
  433. +    }
  434.      else if(widgetStr == "read")
  435. +    {
  436.          widget = "BookReadingWindow";
  437. +    }
  438.      else if(widgetStr == "questreward")
  439. +    {
  440.          widget = "QuestRewardWindow";
  441. +    }
  442.      else if(widgetStr == "craft")
  443. +    {
  444.          widget = "CraftWindow";
  445. +    }
  446.      else if(widgetStr == "ignore")
  447. +    {
  448.          widget = "IgnoreWindow";
  449. +    }
  450.      else if(widgetStr == "bag" || widgetStr == "smallinventory")
  451. +    {
  452.          widget = "SmallInventoryWindow";
  453. +    }
  454.      else if(widgetStr == "talk" || widgetStr == "chat" || widgetStr == "communications")
  455. +    {
  456.          widget = "ChatWindow";
  457. +    }
  458.      else if(widgetStr == "activemagic")
  459. +    {
  460.          widget = "ActiveMagicWindow";
  461. +    }
  462.      else if(widgetStr == "managepetitions")
  463. +    {
  464.          widget = "PetitionGMWindow";
  465. +    }
  466.      else if(widgetStr == "quickspell")
  467. +    {
  468.          widget = "HotBar";
  469. +    }
  470.      else if(widgetStr == "music")
  471. +    {
  472.          widget = "MusicWindow";
  473. +    }
  474.      else if(widgetStr == "quit")
  475.      {
  476. -        HandleQuit();
  477. -        return true;
  478. +   widget = "quit";
  479.      }
  480.      else if(widgetStr == "buy")
  481.      {
  482. -        psengine->GetCmdHandler()->Execute("/buy");
  483. -        return true;
  484. +   widget = "buy";
  485.      }
  486. -    if(widget)
  487. -    {
  488. -        HandleWindow(widget);
  489. -        return true;
  490. -    }
  491. -    else return false;
  492. +    return widget;
  493.  }
  494.  
  495. +
  496.  void pawsControlWindow::HandleQuit()
  497.  {
  498.      PawsManager::GetSingleton().CreateYesNoBox( "\nDo you really wish to leave Yliakum?", this );
  499. Index: src/client/psmovement.h
  500. ===================================================================
  501. --- src/client/psmovement.h (revision 8452)
  502. +++ src/client/psmovement.h (working copy)
  503. @@ -194,6 +194,11 @@
  504.      
  505.      void ToggleAutoMove();
  506.      void ToggleRun();
  507. +    /**
  508. +     * Changes the run state of the actor
  509. +     * @param runState true sets the actor to running mode while false makes the actor walk
  510. +     */
  511. +    void setRun(bool runState);
  512.  
  513.      void SetSneaking(bool v) { sneaking = v; }
  514.      bool Sneaking() { return sneaking; }
  515. Index: src/client/psmovement.cpp
  516. ===================================================================
  517. --- src/client/psmovement.cpp   (revision 8452)
  518. +++ src/client/psmovement.cpp   (working copy)
  519. @@ -1000,3 +1000,19 @@
  520.          toggleRun = true;
  521.      }
  522.  }
  523. +
  524. +void psMovementManager::setRun(bool runState)
  525. +{
  526. +    if (runState)
  527. +    {
  528. +   defaultmode = run;
  529. +        Start(run);
  530. +        toggleRun = true;
  531. +    }
  532. +    else
  533. +    {
  534. +   defaultmode = walk;
  535. +        Stop(run);
  536. +        toggleRun = false;
  537. +    }
  538. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement