Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
comparison FrmMain.cs @ 39:25dfeb1db285
Close #70: Add export to WinForms
* Add export menu that is only available when an army exists, with a default "basic HTML" export
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 01 Sep 2009 19:47:33 +0000 |
parents | a9c1e60d0e4d |
children | 740350673006 |
comparison
equal
deleted
inserted
replaced
38:a9c1e60d0e4d | 39:25dfeb1db285 |
---|---|
20 using IBBoard.Windows.Forms; | 20 using IBBoard.Windows.Forms; |
21 using IBBoard.Windows.Forms.I18N; | 21 using IBBoard.Windows.Forms.I18N; |
22 using IBBoard.Xml; | 22 using IBBoard.Xml; |
23 using IBBoard.WarFoundry.API; | 23 using IBBoard.WarFoundry.API; |
24 using IBBoard.WarFoundry.API.Commands; | 24 using IBBoard.WarFoundry.API.Commands; |
25 using IBBoard.WarFoundry.API.Exporters; | |
25 using IBBoard.WarFoundry.API.Objects; | 26 using IBBoard.WarFoundry.API.Objects; |
26 using IBBoard.WarFoundry.API.Savers; | 27 using IBBoard.WarFoundry.API.Savers; |
27 using IBBoard.WarFoundry.API.Factories; | 28 using IBBoard.WarFoundry.API.Factories; |
28 using IBBoard.WarFoundry.API.Factories.Xml; | 29 using IBBoard.WarFoundry.API.Factories.Xml; |
29 | 30 |
87 private IBBoard.Windows.Forms.ColorableStatusBarPanel sbPointsPanel; | 88 private IBBoard.Windows.Forms.ColorableStatusBarPanel sbPointsPanel; |
88 private System.Windows.Forms.ContextMenu undoMenu; | 89 private System.Windows.Forms.ContextMenu undoMenu; |
89 private System.Windows.Forms.ContextMenu redoMenu; | 90 private System.Windows.Forms.ContextMenu redoMenu; |
90 private IBBoard.Windows.Forms.ColorableStatusBar statusBar; | 91 private IBBoard.Windows.Forms.ColorableStatusBar statusBar; |
91 private System.Windows.Forms.Timer statusBarTimer; | 92 private System.Windows.Forms.Timer statusBarTimer; |
93 private MenuItem miExportArmyAs; | |
94 private MenuItem miExportArmyAsBasicHTML; | |
92 private System.Windows.Forms.Panel pnlRight; | 95 private System.Windows.Forms.Panel pnlRight; |
93 | 96 |
94 public FrmMain(string[] args) | 97 public FrmMain(string[] args) |
95 { | 98 { |
96 this.Closing+=new CancelEventHandler(FrmMain_Closing); | 99 this.Closing+=new CancelEventHandler(FrmMain_Closing); |
149 | 152 |
150 // hack to load default files | 153 // hack to load default files |
151 WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir)); | 154 WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir)); |
152 WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); | 155 WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); |
153 WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver()); | 156 WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver()); |
154 | |
155 /* | |
156 if (args.Length == 1) | |
157 { | |
158 logger.Debug("Attempting to load from file"); | |
159 FileInfo file = new FileInfo(args[0]); | |
160 | |
161 try | |
162 { | |
163 if (file.Extension.Equals("."+Factory.GetArmyFileExtension())) | |
164 { | |
165 WarFoundryCore.CurrentArmy = Factory.CreateArmyFromFile(file); | |
166 logger.InfoFormat("Loaded army from {0}", file.FullName); | |
167 } | |
168 else if (file.Extension.Equals("."+Factory.GetSystemFileExtension())) | |
169 { | |
170 WarFoundryCore.CurrentGameSystem = Factory.CreateGameSystemFromFile(file); | |
171 logger.InfoFormat("Loaded game system from {0}", file.FullName); | |
172 } | |
173 } | |
174 catch (InvalidFileException ex) | |
175 { | |
176 MessageBox.Show(Translation.GetTranslation("InvalidFileLoadError", "The file loaded ({0}) was not a valid WarFoundry file", file.FullName), Translation.GetTranslation("InvalidFileLoadTitle", "Invalid data file", null), MessageBoxButtons.OK, MessageBoxIcon.Error); | |
177 logger.Error(ex); | |
178 } | |
179 } | |
180 else | |
181 { | |
182 string gameSystemID = Preferences.GetStringProperty("currSystem"); | |
183 | |
184 if (gameSystemID!=null && !"".Equals(gameSystemID)) | |
185 { | |
186 logger.Debug("Attempting to load current game system from properties"); | |
187 GameSystem sys = Factory.GetGameSystem(gameSystemID); | |
188 | |
189 if (sys!=null) | |
190 { | |
191 WarFoundryCore.CurrentGameSystem = sys; | |
192 logger.InfoFormat("Loaded game system {0} from properties", gameSystemID); | |
193 } | |
194 } | |
195 }*/ | |
196 } | 157 } |
197 | 158 |
198 public static string DataPath | 159 public static string DataPath |
199 { | 160 { |
200 get { return Constants.ExecutablePath+Constants.DirectoryChar+"data"; } | 161 get { return Constants.ExecutablePath+Constants.DirectoryChar+"data"; } |
266 this.menuFile = new IBBoard.Windows.Forms.IBBMenuItem(); | 227 this.menuFile = new IBBoard.Windows.Forms.IBBMenuItem(); |
267 this.miNewArmy = new IBBoard.Windows.Forms.IBBMenuItem(); | 228 this.miNewArmy = new IBBoard.Windows.Forms.IBBMenuItem(); |
268 this.miOpenArmy = new IBBoard.Windows.Forms.IBBMenuItem(); | 229 this.miOpenArmy = new IBBoard.Windows.Forms.IBBMenuItem(); |
269 this.miSaveArmy = new IBBoard.Windows.Forms.IBBMenuItem(); | 230 this.miSaveArmy = new IBBoard.Windows.Forms.IBBMenuItem(); |
270 this.miSaveArmyAs = new IBBoard.Windows.Forms.IBBMenuItem(); | 231 this.miSaveArmyAs = new IBBoard.Windows.Forms.IBBMenuItem(); |
232 this.miExportArmyAs = new System.Windows.Forms.MenuItem(); | |
233 this.miExportArmyAsBasicHTML = new System.Windows.Forms.MenuItem(); | |
271 this.miCloseArmy = new IBBoard.Windows.Forms.IBBMenuItem(); | 234 this.miCloseArmy = new IBBoard.Windows.Forms.IBBMenuItem(); |
272 this.miSep1 = new System.Windows.Forms.MenuItem(); | 235 this.miSep1 = new System.Windows.Forms.MenuItem(); |
273 this.miChangeSystem = new IBBoard.Windows.Forms.IBBMenuItem(); | 236 this.miChangeSystem = new IBBoard.Windows.Forms.IBBMenuItem(); |
274 this.miSep2 = new System.Windows.Forms.MenuItem(); | 237 this.miSep2 = new System.Windows.Forms.MenuItem(); |
275 this.miReloadFiles = new IBBoard.Windows.Forms.IBBMenuItem(); | 238 this.miReloadFiles = new IBBoard.Windows.Forms.IBBMenuItem(); |
293 // statusBar | 256 // statusBar |
294 // | 257 // |
295 this.statusBar.Location = new System.Drawing.Point(0, 548); | 258 this.statusBar.Location = new System.Drawing.Point(0, 548); |
296 this.statusBar.Name = "statusBar"; | 259 this.statusBar.Name = "statusBar"; |
297 this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] { | 260 this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] { |
298 this.sbMainPanel, | 261 this.sbMainPanel, |
299 this.sbErrorPanel, | 262 this.sbErrorPanel, |
300 this.sbPointsPanel}); | 263 this.sbPointsPanel}); |
301 this.statusBar.ShowPanels = true; | 264 this.statusBar.ShowPanels = true; |
302 this.statusBar.Size = new System.Drawing.Size(792, 22); | 265 this.statusBar.Size = new System.Drawing.Size(792, 22); |
303 this.statusBar.TabIndex = 1; | 266 this.statusBar.TabIndex = 1; |
304 this.statusBar.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler(this.statusBar_PanelClick); | 267 this.statusBar.PanelClick += new System.Windows.Forms.StatusBarPanelClickEventHandler(this.statusBar_PanelClick); |
305 this.statusBar.DrawItem += new System.Windows.Forms.StatusBarDrawItemEventHandler(this.statusBar_DrawItem); | 268 this.statusBar.DrawItem += new System.Windows.Forms.StatusBarDrawItemEventHandler(this.statusBar_DrawItem); |
329 // | 292 // |
330 // toolBar | 293 // toolBar |
331 // | 294 // |
332 this.toolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat; | 295 this.toolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat; |
333 this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] { | 296 this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] { |
334 this.bttnNewArmy, | 297 this.bttnNewArmy, |
335 this.bttnOpenArmy, | 298 this.bttnOpenArmy, |
336 this.bttnSaveArmy, | 299 this.bttnSaveArmy, |
337 this.bttnSep1, | 300 this.bttnSep1, |
338 this.bttnUndo, | 301 this.bttnUndo, |
339 this.bttnRedo}); | 302 this.bttnRedo}); |
340 this.toolBar.ButtonSize = new System.Drawing.Size(16, 16); | 303 this.toolBar.ButtonSize = new System.Drawing.Size(16, 16); |
341 this.toolBar.DropDownArrows = true; | 304 this.toolBar.DropDownArrows = true; |
342 this.toolBar.ImageList = this.buttonIcons; | 305 this.toolBar.ImageList = this.buttonIcons; |
343 this.toolBar.Location = new System.Drawing.Point(0, 0); | 306 this.toolBar.Location = new System.Drawing.Point(0, 0); |
344 this.toolBar.Name = "toolBar"; | 307 this.toolBar.Name = "toolBar"; |
398 this.buttonIcons.Images.SetKeyName(6, ""); | 361 this.buttonIcons.Images.SetKeyName(6, ""); |
399 // | 362 // |
400 // mainMenu | 363 // mainMenu |
401 // | 364 // |
402 this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | 365 this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
403 this.menuFile, | 366 this.menuFile, |
404 this.menuEdit, | 367 this.menuEdit, |
405 this.menuHelp}); | 368 this.menuHelp}); |
406 // | 369 // |
407 // menuFile | 370 // menuFile |
408 // | 371 // |
409 this.menuFile.Index = 0; | 372 this.menuFile.Index = 0; |
410 this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | 373 this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
411 this.miNewArmy, | 374 this.miNewArmy, |
412 this.miOpenArmy, | 375 this.miOpenArmy, |
413 this.miSaveArmy, | 376 this.miSaveArmy, |
414 this.miSaveArmyAs, | 377 this.miSaveArmyAs, |
415 this.miCloseArmy, | 378 this.miExportArmyAs, |
416 this.miSep1, | 379 this.miCloseArmy, |
417 this.miChangeSystem, | 380 this.miSep1, |
418 this.miSep2, | 381 this.miChangeSystem, |
419 this.miReloadFiles, | 382 this.miSep2, |
420 this.miSep3, | 383 this.miReloadFiles, |
421 this.miExit}); | 384 this.miSep3, |
385 this.miExit}); | |
422 this.menuFile.Text = "&file"; | 386 this.menuFile.Text = "&file"; |
423 this.menuFile.Name = "menuFile"; | |
424 // | 387 // |
425 // miNewArmy | 388 // miNewArmy |
426 // | 389 // |
427 this.miNewArmy.Enabled = false; | 390 this.miNewArmy.Enabled = false; |
428 this.miNewArmy.Index = 0; | 391 this.miNewArmy.Index = 0; |
429 this.miNewArmy.Text = "&new army"; | 392 this.miNewArmy.Text = "&new army"; |
430 this.miNewArmy.Click += new System.EventHandler(this.miNewArmy_Click); | 393 this.miNewArmy.Click += new System.EventHandler(this.miNewArmy_Click); |
431 this.miNewArmy.Name = "miNewArmy"; | |
432 // | 394 // |
433 // miOpenArmy | 395 // miOpenArmy |
434 // | 396 // |
435 this.miOpenArmy.Index = 1; | 397 this.miOpenArmy.Index = 1; |
436 this.miOpenArmy.Text = "&open army"; | 398 this.miOpenArmy.Text = "&open army"; |
437 this.miOpenArmy.Click += new System.EventHandler(this.miOpenArmy_Click); | 399 this.miOpenArmy.Click += new System.EventHandler(this.miOpenArmy_Click); |
438 this.miOpenArmy.Name = "miOpenArmy"; | |
439 // | 400 // |
440 // miSaveArmy | 401 // miSaveArmy |
441 // | 402 // |
442 this.miSaveArmy.Enabled = false; | 403 this.miSaveArmy.Enabled = false; |
443 this.miSaveArmy.Index = 2; | 404 this.miSaveArmy.Index = 2; |
444 this.miSaveArmy.Text = "&save army"; | 405 this.miSaveArmy.Text = "&save army"; |
445 this.miSaveArmy.Click += new System.EventHandler(this.miSaveArmy_Click); | 406 this.miSaveArmy.Click += new System.EventHandler(this.miSaveArmy_Click); |
446 this.miSaveArmy.Name = "miSaveArmy"; | |
447 // | 407 // |
448 // miSaveArmyAs | 408 // miSaveArmyAs |
449 // | 409 // |
450 this.miSaveArmyAs.Enabled = false; | 410 this.miSaveArmyAs.Enabled = false; |
451 this.miSaveArmyAs.Index = 3; | 411 this.miSaveArmyAs.Index = 3; |
452 this.miSaveArmyAs.Text = "save army &as..."; | 412 this.miSaveArmyAs.Text = "save army &as..."; |
453 this.miSaveArmyAs.Click += new System.EventHandler(this.miSaveArmyAs_Click); | 413 this.miSaveArmyAs.Click += new System.EventHandler(this.miSaveArmyAs_Click); |
454 this.miSaveArmyAs.Name = "miSaveArmyAs"; | 414 // |
415 // miExportArmyAs | |
416 // | |
417 this.miExportArmyAs.Enabled = false; | |
418 this.miExportArmyAs.Index = 4; | |
419 this.miExportArmyAs.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | |
420 this.miExportArmyAsBasicHTML}); | |
421 this.miExportArmyAs.Text = "export army as..."; | |
422 // | |
423 // miExportArmyAsBasicHTML | |
424 // | |
425 this.miExportArmyAsBasicHTML.Index = 0; | |
426 this.miExportArmyAsBasicHTML.Text = "Basic HTML"; | |
427 this.miExportArmyAsBasicHTML.Click += new System.EventHandler(this.miExportArmyAsBasicHTML_Click); | |
455 // | 428 // |
456 // miCloseArmy | 429 // miCloseArmy |
457 // | 430 // |
458 this.miCloseArmy.Enabled = false; | 431 this.miCloseArmy.Enabled = false; |
459 this.miCloseArmy.Index = 4; | 432 this.miCloseArmy.Index = 5; |
460 this.miCloseArmy.Text = "&close army"; | 433 this.miCloseArmy.Text = "&close army"; |
461 this.miCloseArmy.Click += new System.EventHandler(this.miCloseArmy_Click); | 434 this.miCloseArmy.Click += new System.EventHandler(this.miCloseArmy_Click); |
462 this.miCloseArmy.Name = "miCloseArmy"; | |
463 // | 435 // |
464 // miSep1 | 436 // miSep1 |
465 // | 437 // |
466 this.miSep1.Index = 5; | 438 this.miSep1.Index = 6; |
467 this.miSep1.Text = "-"; | 439 this.miSep1.Text = "-"; |
468 // | 440 // |
469 // miChangeSystem | 441 // miChangeSystem |
470 // | 442 // |
471 this.miChangeSystem.Index = 6; | 443 this.miChangeSystem.Index = 7; |
472 this.miChangeSystem.Text = "change &game system"; | 444 this.miChangeSystem.Text = "change &game system"; |
473 this.miChangeSystem.Click += new System.EventHandler(this.miChangeSystem_Click); | 445 this.miChangeSystem.Click += new System.EventHandler(this.miChangeSystem_Click); |
474 this.miChangeSystem.Name = "miChangeSystem"; | |
475 // | 446 // |
476 // miSep2 | 447 // miSep2 |
477 // | 448 // |
478 this.miSep2.Index = 7; | 449 this.miSep2.Index = 8; |
479 this.miSep2.Text = "-"; | 450 this.miSep2.Text = "-"; |
480 // | 451 // |
481 // miReloadFiles | 452 // miReloadFiles |
482 // | 453 // |
483 this.miReloadFiles.Index = 8; | 454 this.miReloadFiles.Index = 9; |
484 this.miReloadFiles.Text = "&reload files"; | 455 this.miReloadFiles.Text = "&reload files"; |
485 this.miReloadFiles.Click += new System.EventHandler(this.miReloadFiles_Click); | 456 this.miReloadFiles.Click += new System.EventHandler(this.miReloadFiles_Click); |
486 this.miReloadFiles.Name = "miReloadFiles"; | |
487 // | 457 // |
488 // miSep3 | 458 // miSep3 |
489 // | 459 // |
490 this.miSep3.Index = 9; | 460 this.miSep3.Index = 10; |
491 this.miSep3.Text = "-"; | 461 this.miSep3.Text = "-"; |
492 // | 462 // |
493 // miExit | 463 // miExit |
494 // | 464 // |
495 this.miExit.Index = 10; | 465 this.miExit.Index = 11; |
496 this.miExit.Text = "e&xit"; | 466 this.miExit.Text = "e&xit"; |
497 this.miExit.Click += new System.EventHandler(this.miExit_Click); | 467 this.miExit.Click += new System.EventHandler(this.miExit_Click); |
498 this.miExit.Name = "miExit"; | |
499 // | 468 // |
500 // menuEdit | 469 // menuEdit |
501 // | 470 // |
502 this.menuEdit.Index = 1; | 471 this.menuEdit.Index = 1; |
503 this.menuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | 472 this.menuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
504 this.miUndo, | 473 this.miUndo, |
505 this.miRedo}); | 474 this.miRedo}); |
506 this.menuEdit.Text = "&edit"; | 475 this.menuEdit.Text = "&edit"; |
507 this.menuEdit.Name = "menuEdit"; | |
508 // | 476 // |
509 // miUndo | 477 // miUndo |
510 // | 478 // |
511 this.miUndo.Enabled = false; | 479 this.miUndo.Enabled = false; |
512 this.miUndo.Index = 0; | 480 this.miUndo.Index = 0; |
513 this.miUndo.Text = "&undo"; | 481 this.miUndo.Text = "&undo"; |
514 this.miUndo.Click += new System.EventHandler(this.miUndo_Click); | 482 this.miUndo.Click += new System.EventHandler(this.miUndo_Click); |
515 this.miUndo.Name = "miUndo"; | |
516 // | 483 // |
517 // miRedo | 484 // miRedo |
518 // | 485 // |
519 this.miRedo.Enabled = false; | 486 this.miRedo.Enabled = false; |
520 this.miRedo.Index = 1; | 487 this.miRedo.Index = 1; |
521 this.miRedo.Text = "&redo"; | 488 this.miRedo.Text = "&redo"; |
522 this.miRedo.Click += new System.EventHandler(this.miRedo_Click); | 489 this.miRedo.Click += new System.EventHandler(this.miRedo_Click); |
523 this.miRedo.Name = "miRedo"; | |
524 // | 490 // |
525 // menuHelp | 491 // menuHelp |
526 // | 492 // |
527 this.menuHelp.Index = 2; | 493 this.menuHelp.Index = 2; |
528 this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | 494 this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { |
529 this.miAbout, | 495 this.miAbout, |
530 this.miDebugWindow}); | 496 this.miDebugWindow}); |
531 this.menuHelp.Text = "&help"; | 497 this.menuHelp.Text = "&help"; |
532 this.menuHelp.Name = "menuHelp"; | |
533 // | 498 // |
534 // miAbout | 499 // miAbout |
535 // | 500 // |
536 this.miAbout.Enabled = false; | 501 this.miAbout.Enabled = false; |
537 this.miAbout.Index = 0; | 502 this.miAbout.Index = 0; |
538 this.miAbout.Text = "&about"; | 503 this.miAbout.Text = "&about"; |
539 this.miAbout.Name = "miAbout"; | |
540 // | 504 // |
541 // miDebugWindow | 505 // miDebugWindow |
542 // | 506 // |
543 this.miDebugWindow.Index = 1; | 507 this.miDebugWindow.Index = 1; |
544 this.miDebugWindow.Text = "&debug"; | 508 this.miDebugWindow.Text = "&debug"; |
545 this.miDebugWindow.Click += new System.EventHandler(this.miDebugWindow_Click); | 509 this.miDebugWindow.Click += new System.EventHandler(this.miDebugWindow_Click); |
546 this.miDebugWindow.Name = "miDebugWindow"; | |
547 // | 510 // |
548 // saveArmyDialog | 511 // saveArmyDialog |
549 // | 512 // |
550 this.saveArmyDialog.Title = "Translatable:saveArmyDialog"; | 513 this.saveArmyDialog.Title = "Translatable:saveArmyDialog"; |
551 // | 514 // |
610 Application.Exit(); | 573 Application.Exit(); |
611 } | 574 } |
612 | 575 |
613 private void miNewArmy_Click(object sender, System.EventArgs e) | 576 private void miNewArmy_Click(object sender, System.EventArgs e) |
614 { | 577 { |
615 createNewArmy(); | 578 CreateNewArmy(); |
616 } | 579 } |
617 | 580 |
618 private void createNewArmy() | 581 private void CreateNewArmy() |
619 { | 582 { |
620 if (closeCurrentArmy()) | 583 if (CloseCurrentArmy()) |
621 { | 584 { |
622 FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem); | 585 FrmNewArmy newArmy = new FrmNewArmy(CurrentGameSystem); |
623 DialogResult dr = newArmy.ShowDialog(); | 586 DialogResult dr = newArmy.ShowDialog(); |
624 | 587 |
625 if (dr == DialogResult.OK) | 588 if (dr == DialogResult.OK) |
627 CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); | 590 CurrentArmy = new Army(newArmy.SelectedRace, newArmy.ArmyName, newArmy.ArmySize); |
628 } | 591 } |
629 } | 592 } |
630 } | 593 } |
631 | 594 |
632 private bool openArmy() | 595 private bool OpenArmy() |
633 { | 596 { |
634 if (closeCurrentArmy()) | 597 if (CloseCurrentArmy()) |
635 { | 598 { |
636 if (openArmyDialog.Filter=="") | 599 if (openArmyDialog.Filter=="") |
637 { | 600 { |
638 string savePath = ArmiesPath; | 601 string savePath = ArmiesPath; |
639 | 602 |
675 { | 638 { |
676 return false; | 639 return false; |
677 } | 640 } |
678 } | 641 } |
679 | 642 |
680 private bool closeCurrentArmy() | 643 private bool CloseCurrentArmy() |
681 { | 644 { |
682 if (CurrentArmy!=null) | 645 if (CurrentArmy!=null) |
683 { | 646 { |
684 bool canClose = false; | 647 bool canClose = false; |
685 | 648 |
703 } | 666 } |
704 | 667 |
705 if (canClose) | 668 if (canClose) |
706 { | 669 { |
707 //do close | 670 //do close |
708 disableCategoryButtons(); | 671 DisableCategoryButtons(); |
709 CurrentArmy = null; | 672 CurrentArmy = null; |
710 return true; | 673 return true; |
711 } | 674 } |
712 else | 675 else |
713 { | 676 { |
714 return false; | 677 return false; |
715 } | 678 } |
716 } | 679 } |
717 else | 680 else |
718 { | 681 { |
719 disableCategoryButtons(); | 682 DisableCategoryButtons(); |
720 //pretend we succeeded | 683 //pretend we succeeded |
721 return true; | 684 return true; |
722 } | 685 } |
723 } | 686 } |
724 | 687 |
725 private void undoLastAction() | 688 private void UndoLastAction() |
726 { | 689 { |
727 if (commandStack.CanUndo()) | 690 if (commandStack.CanUndo()) |
728 { | 691 { |
729 commandStack.Undo(); | 692 commandStack.Undo(); |
730 } | 693 } |
731 } | 694 } |
732 | 695 |
733 private void redoAction() | 696 private void RedoAction() |
734 { | 697 { |
735 if (commandStack.CanRedo()) | 698 if (commandStack.CanRedo()) |
736 { | 699 { |
737 commandStack.Redo(); | 700 commandStack.Redo(); |
738 } | 701 } |
744 | 707 |
745 string filePath = loadedFilePath; | 708 string filePath = loadedFilePath; |
746 | 709 |
747 if (filePath == null) | 710 if (filePath == null) |
748 { | 711 { |
749 filePath = PromptForFilePath(); | 712 filePath = PromptForArmyFilePath(); |
750 } | 713 } |
751 | 714 |
752 if (filePath != null) | 715 if (filePath != null) |
753 { | 716 { |
754 saved = SaveCurrentArmyToFile(filePath); | 717 saved = SaveCurrentArmyToFile(filePath); |
758 } | 721 } |
759 | 722 |
760 private bool SaveCurrentArmyAs() | 723 private bool SaveCurrentArmyAs() |
761 { | 724 { |
762 bool saved = false; | 725 bool saved = false; |
763 string filePath = PromptForFilePath(); | 726 string filePath = PromptForArmyFilePath(); |
764 | 727 |
765 if (filePath != null) | 728 if (filePath != null) |
766 { | 729 { |
767 saved = SaveCurrentArmyToFile(filePath); | 730 saved = SaveCurrentArmyToFile(filePath); |
768 } | 731 } |
785 MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); | 748 MessageBox.Show(this, Translation.GetTranslation("SaveFailed"), Translation.GetTranslation("SaveFailedTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error); |
786 return false; | 749 return false; |
787 } | 750 } |
788 } | 751 } |
789 | 752 |
790 private string PromptForFilePath() | 753 private string PromptForArmyFilePath() |
791 { | 754 { |
792 if (saveArmyDialog.Filter == "") | 755 if (saveArmyDialog.Filter == "") |
793 { | 756 { |
794 string savePath = ArmiesPath; | 757 string savePath = ArmiesPath; |
795 | 758 |
817 | 780 |
818 private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) | 781 private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) |
819 { | 782 { |
820 if (e.Button == bttnUndo) | 783 if (e.Button == bttnUndo) |
821 { | 784 { |
822 undoLastAction(); | 785 UndoLastAction(); |
823 } | 786 } |
824 else if (e.Button == bttnRedo) | 787 else if (e.Button == bttnRedo) |
825 { | 788 { |
826 redoAction(); | 789 RedoAction(); |
827 } | 790 } |
828 else if (e.Button == bttnNewArmy) | 791 else if (e.Button == bttnNewArmy) |
829 { | 792 { |
830 createNewArmy(); | 793 CreateNewArmy(); |
831 } | 794 } |
832 else if (e.Button == bttnOpenArmy) | 795 else if (e.Button == bttnOpenArmy) |
833 { | 796 { |
834 openArmy(); | 797 OpenArmy(); |
835 } | 798 } |
836 else if (e.Button == bttnSaveArmy) | 799 else if (e.Button == bttnSaveArmy) |
837 { | 800 { |
838 SaveCurrentArmy(); | 801 SaveCurrentArmy(); |
839 } | 802 } |
840 else | 803 else |
841 { | 804 { |
842 //it must be one of our extra buttons for the categories | 805 //it must be one of our extra buttons for the categories |
843 addUnitFromCategory((Category)e.Button.Tag); | 806 AddUnitFromCategory((Category)e.Button.Tag); |
844 } | 807 } |
845 } | 808 } |
846 | 809 |
847 private GameSystem CurrentGameSystem | 810 private GameSystem CurrentGameSystem |
848 { | 811 { |
861 FrmSelectSystem selectSystem = new FrmSelectSystem(); | 824 FrmSelectSystem selectSystem = new FrmSelectSystem(); |
862 DialogResult dr = selectSystem.ShowDialog(this); | 825 DialogResult dr = selectSystem.ShowDialog(this); |
863 | 826 |
864 if (dr==DialogResult.OK) | 827 if (dr==DialogResult.OK) |
865 { | 828 { |
866 closeCurrentArmy(); | 829 CloseCurrentArmy(); |
867 CurrentGameSystem = selectSystem.GameSystem; | 830 CurrentGameSystem = selectSystem.GameSystem; |
868 } | 831 } |
869 } | 832 } |
870 | 833 |
871 private void miChangeSystem_Click(object sender, System.EventArgs e) | 834 private void miChangeSystem_Click(object sender, System.EventArgs e) |
875 | 838 |
876 private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem) | 839 private void FrmMain_GameSystemChanged(GameSystem oldSystem, GameSystem newSystem) |
877 { | 840 { |
878 miNewArmy.Enabled = newSystem != null; | 841 miNewArmy.Enabled = newSystem != null; |
879 bttnNewArmy.Enabled = newSystem != null; | 842 bttnNewArmy.Enabled = newSystem != null; |
880 setAppTitle(); | 843 SetAppTitle(); |
881 removeCategoryButtons(); | 844 RemoveCategoryButtons(); |
882 addCategoryButtons(); | 845 AddCategoryButtons(); |
883 } | 846 } |
884 | 847 |
885 private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy) | 848 private void FrmMain_ArmyChanged(Army oldArmy, Army newArmy) |
886 { | 849 { |
887 setAppTitle(); | 850 SetAppTitle(); |
888 | 851 |
889 if (oldArmy != null) | 852 if (oldArmy != null) |
890 { | 853 { |
891 oldArmy.UnitAdded += UnitAddedMethod; | 854 oldArmy.UnitAdded += UnitAddedMethod; |
892 oldArmy.UnitRemoved += UnitRemovedMethod; | 855 oldArmy.UnitRemoved += UnitRemovedMethod; |
895 | 858 |
896 if (CurrentArmy==null) | 859 if (CurrentArmy==null) |
897 { | 860 { |
898 miSaveArmyAs.Enabled = false; | 861 miSaveArmyAs.Enabled = false; |
899 miCloseArmy.Enabled = false; | 862 miCloseArmy.Enabled = false; |
900 disableCategoryButtons(); | 863 miExportArmyAs.Enabled = false; |
864 DisableCategoryButtons(); | |
901 } | 865 } |
902 else | 866 else |
903 { | 867 { |
904 newArmy.UnitAdded += UnitAddedMethod; | 868 newArmy.UnitAdded += UnitAddedMethod; |
905 newArmy.UnitRemoved += UnitRemovedMethod; | 869 newArmy.UnitRemoved += UnitRemovedMethod; |
906 newArmy.PointsValueChanged += PointsValueChangedMethod; | 870 newArmy.PointsValueChanged += PointsValueChangedMethod; |
907 //TODO: Clear all buttons | 871 //TODO: Clear all buttons |
908 miSaveArmyAs.Enabled = true; | 872 miSaveArmyAs.Enabled = true; |
909 miCloseArmy.Enabled = true; | 873 miCloseArmy.Enabled = true; |
910 enableCategoryButtons(); | 874 miExportArmyAs.Enabled = true; |
875 EnableCategoryButtons(); | |
911 | 876 |
912 if (newArmy.Race.HasCategoryOverrides()) | 877 if (newArmy.Race.HasCategoryOverrides()) |
913 { | 878 { |
914 removeCategoryButtons(); | 879 RemoveCategoryButtons(); |
915 addCategoryButtons(newArmy.Race.Categories); | 880 AddCategoryButtons(newArmy.Race.Categories); |
916 } | 881 } |
917 } | 882 } |
918 | 883 |
919 CommandStack.Reset(); | 884 CommandStack.Reset(); |
920 | 885 |
921 miSaveArmy.Enabled = false; | 886 miSaveArmy.Enabled = false; |
922 bttnSaveArmy.Enabled = false; | 887 bttnSaveArmy.Enabled = false; |
923 | 888 |
924 setPointsPanelText(); | 889 SetPointsPanelText(); |
925 } | 890 } |
926 | 891 |
927 private void addCategoryButtons() | 892 private void AddCategoryButtons() |
928 { | 893 { |
929 if (CurrentGameSystem!=null) | 894 if (CurrentGameSystem!=null) |
930 { | 895 { |
931 addCategoryButtons(CurrentGameSystem.Categories); | 896 AddCategoryButtons(CurrentGameSystem.Categories); |
932 } | 897 } |
933 } | 898 } |
934 | 899 |
935 private void addCategoryButtons(Category[] cats) | 900 private void AddCategoryButtons(Category[] cats) |
936 { | 901 { |
937 int catCount = cats.Length; | 902 int catCount = cats.Length; |
938 Category cat; | 903 Category cat; |
939 categoryButtons = new ToolBarButton[catCount+1]; | 904 categoryButtons = new ToolBarButton[catCount+1]; |
940 | 905 |
957 } | 922 } |
958 | 923 |
959 this.Invoke(new ToolBarButtonRangeDelegate(toolBar.Buttons.AddRange), new object[]{categoryButtons}); | 924 this.Invoke(new ToolBarButtonRangeDelegate(toolBar.Buttons.AddRange), new object[]{categoryButtons}); |
960 } | 925 } |
961 | 926 |
962 private void removeCategoryButtons() | 927 private void RemoveCategoryButtons() |
963 { | 928 { |
964 if (categoryButtons!=null) | 929 if (categoryButtons!=null) |
965 { | 930 { |
966 for (int i = 0; i<categoryButtons.Length; i++) | 931 for (int i = 0; i<categoryButtons.Length; i++) |
967 { | 932 { |
968 this.Invoke(new ToolBarButtonDelegate(toolBar.Buttons.Remove), new object[]{categoryButtons[i]}); | 933 this.Invoke(new ToolBarButtonDelegate(toolBar.Buttons.Remove), new object[]{categoryButtons[i]}); |
969 } | 934 } |
970 } | 935 } |
971 } | 936 } |
972 | 937 |
973 private void enableCategoryButtons() | 938 private void EnableCategoryButtons() |
974 { | 939 { |
975 setCategoryButtonState(true); | 940 SetCategoryButtonState(true); |
976 } | 941 } |
977 | 942 |
978 private void disableCategoryButtons() | 943 private void DisableCategoryButtons() |
979 { | 944 { |
980 setCategoryButtonState(false); | 945 SetCategoryButtonState(false); |
981 } | 946 } |
982 | 947 |
983 private void setCategoryButtonState(bool state) | 948 private void SetCategoryButtonState(bool state) |
984 { | 949 { |
985 if (categoryButtons!=null) | 950 if (categoryButtons!=null) |
986 { | 951 { |
987 for (int i = 0; i<categoryButtons.Length; i++) | 952 for (int i = 0; i<categoryButtons.Length; i++) |
988 { | 953 { |
1076 private void miSaveArmy_Click(object sender, System.EventArgs e) | 1041 private void miSaveArmy_Click(object sender, System.EventArgs e) |
1077 { | 1042 { |
1078 SaveCurrentArmy(); | 1043 SaveCurrentArmy(); |
1079 } | 1044 } |
1080 | 1045 |
1081 private void setAppTitle() | 1046 private void SetAppTitle() |
1082 { | 1047 { |
1083 string str = AppTitle; | 1048 string str = AppTitle; |
1084 | 1049 |
1085 if (CurrentGameSystem!=null) | 1050 if (CurrentGameSystem!=null) |
1086 { | 1051 { |
1093 } | 1058 } |
1094 | 1059 |
1095 this.Text = str; | 1060 this.Text = str; |
1096 } | 1061 } |
1097 | 1062 |
1098 private void addUnitFromCategory(Category cat) | 1063 private void AddUnitFromCategory(Category cat) |
1099 { | 1064 { |
1100 FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy); | 1065 FrmNewUnit newUnit = new FrmNewUnit(CurrentArmy.Race, cat, CurrentArmy); |
1101 DialogResult dr = newUnit.ShowDialog(this); | 1066 DialogResult dr = newUnit.ShowDialog(this); |
1102 | 1067 |
1103 if (dr == DialogResult.OK) | 1068 if (dr == DialogResult.OK) |
1166 e.Graphics.DrawRectangle(dockCuePen, new Rectangle(pnlRight.Left, pnlRight.Top, pnlRight.Width, pnlRight.Height)); | 1131 e.Graphics.DrawRectangle(dockCuePen, new Rectangle(pnlRight.Left, pnlRight.Top, pnlRight.Width, pnlRight.Height)); |
1167 } | 1132 } |
1168 | 1133 |
1169 private void miUndo_Click(object sender, System.EventArgs e) | 1134 private void miUndo_Click(object sender, System.EventArgs e) |
1170 { | 1135 { |
1171 undoLastAction(); | 1136 UndoLastAction(); |
1172 } | 1137 } |
1173 | 1138 |
1174 private void miRedo_Click(object sender, System.EventArgs e) | 1139 private void miRedo_Click(object sender, System.EventArgs e) |
1175 { | 1140 { |
1176 redoAction(); | 1141 RedoAction(); |
1177 } | 1142 } |
1178 | 1143 |
1179 private void miCloseArmy_Click(object sender, EventArgs e) | 1144 private void miCloseArmy_Click(object sender, EventArgs e) |
1180 { | 1145 { |
1181 closeCurrentArmy(); | 1146 CloseCurrentArmy(); |
1182 } | 1147 } |
1183 | 1148 |
1184 private void miOpenArmy_Click(object sender, EventArgs e) | 1149 private void miOpenArmy_Click(object sender, EventArgs e) |
1185 { | 1150 { |
1186 openArmy(); | 1151 OpenArmy(); |
1187 } | 1152 } |
1188 | 1153 |
1189 private void FrmMain_PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal) | 1154 private void FrmMain_PointsValueChangedMethod(WarFoundryObject obj, double oldVal, double newVal) |
1190 { | 1155 { |
1191 if (obj is Army) | 1156 if (obj is Army) |
1192 { | 1157 { |
1193 setPointsPanelText(); | 1158 SetPointsPanelText(); |
1194 } | 1159 } |
1195 } | 1160 } |
1196 | 1161 |
1197 private void setPointsPanelText() | 1162 private void SetPointsPanelText() |
1198 { | 1163 { |
1199 if (CurrentArmy==null) | 1164 if (CurrentArmy==null) |
1200 { | 1165 { |
1201 sbPointsPanel.Text = ""; | 1166 sbPointsPanel.Text = ""; |
1202 sbPointsPanel.ResetColor(); | 1167 sbPointsPanel.ResetColor(); |
1269 debugWindow.Focus(); | 1234 debugWindow.Focus(); |
1270 } | 1235 } |
1271 | 1236 |
1272 private void FrmMain_Closing(object sender, CancelEventArgs e) | 1237 private void FrmMain_Closing(object sender, CancelEventArgs e) |
1273 { | 1238 { |
1274 if (!closeCurrentArmy()) | 1239 if (!CloseCurrentArmy()) |
1275 { | 1240 { |
1276 e.Cancel = true; | 1241 e.Cancel = true; |
1277 } | 1242 } |
1278 } | 1243 } |
1279 | 1244 |
1295 if (e.StatusBarPanel == sbErrorPanel && sbErrorPanel.Text!="") | 1260 if (e.StatusBarPanel == sbErrorPanel && sbErrorPanel.Text!="") |
1296 { | 1261 { |
1297 MessageBox.Show(this, sbErrorPanel.TagString, Translation.GetTranslation("FailedRequirementMessage"), MessageBoxButtons.OK, MessageBoxIcon.Warning); | 1262 MessageBox.Show(this, sbErrorPanel.TagString, Translation.GetTranslation("FailedRequirementMessage"), MessageBoxButtons.OK, MessageBoxIcon.Warning); |
1298 } | 1263 } |
1299 } | 1264 } |
1265 | |
1266 private void miExportArmyAsBasicHTML_Click(object sender, EventArgs e) | |
1267 { | |
1268 SaveFileDialog dialog = new SaveFileDialog(); | |
1269 dialog.Filter = Translation.GetTranslation("armyExportBasicHtmlFilter", "HTML pages") + "|*.html"; | |
1270 dialog.Title = Translation.GetTranslation("exportArmyDialog", "Export army"); | |
1271 | |
1272 DialogResult dr = dialog.ShowDialog(this); | |
1273 | |
1274 if (dr == DialogResult.OK) | |
1275 { | |
1276 Army army = WarFoundryCore.CurrentArmy; | |
1277 string filePath = dialog.FileName; | |
1278 logger.DebugFormat("Exporting {0} to {1} as basic HTML", army.Name, filePath); | |
1279 WarFoundryHtmlExporter.GetDefault().ExportArmy(army, filePath); | |
1280 } | |
1281 } | |
1300 } | 1282 } |
1301 } | 1283 } |