Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
NavDlg.cpp
Go to the documentation of this file.
1 /* Project Starshatter 5.0
2  Destroyer Studios LLC
3  Copyright © 1997-2007. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: NavDlg.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12 */
13 
14 #include "MemDebug.h"
15 #include "NavDlg.h"
16 #include "MapView.h"
17 #include "MsnElemDlg.h"
18 #include "BaseScreen.h"
19 #include "Element.h"
20 #include "Ship.h"
21 #include "ShipDesign.h"
22 #include "Sim.h"
23 #include "Galaxy.h"
24 #include "StarSystem.h"
25 #include "Instruction.h"
26 #include "NavSystem.h"
27 #include "FormatUtil.h"
28 #include "Campaign.h"
29 #include "Contact.h"
30 #include "Mission.h"
31 
32 #include "Game.h"
33 #include "Keyboard.h"
34 #include "Mouse.h"
35 #include "ListBox.h"
36 
37 // +--------------------------------------------------------------------+
38 // DECLARE MAPPING FUNCTIONS:
39 DEF_MAP_CLIENT(NavDlg, OnView);
40 DEF_MAP_CLIENT(NavDlg, OnFilter);
41 DEF_MAP_CLIENT(NavDlg, OnSelect);
42 DEF_MAP_CLIENT(NavDlg, OnCommit);
43 DEF_MAP_CLIENT(NavDlg, OnCancel);
44 DEF_MAP_CLIENT(NavDlg, OnEngage);
45 DEF_MAP_CLIENT(NavDlg, OnMapDown);
46 DEF_MAP_CLIENT(NavDlg, OnMapMove);
47 DEF_MAP_CLIENT(NavDlg, OnMapClick);
48 DEF_MAP_CLIENT(NavDlg, OnClose);
49 
50 // +--------------------------------------------------------------------+
51 
52 static char* filter_name[] = {
53  "SYSTEM", "PLANET",
54  "SECTOR", "STATION",
55  "STARSHIP", "FIGHTER"
56 };
57 
58 static char* commit_name = "Commit";
59 static char* cancel_name = "Cancel";
60 
61 static Color commit_color(53,159,67);
62 static Color cancel_color(160,8,8);
63 
64 
65 // Supported Selection Modes:
66 
67 const int SELECT_NONE = -1;
68 const int SELECT_SYSTEM = 0;
69 const int SELECT_PLANET = 1;
70 const int SELECT_REGION = 2;
71 const int SELECT_STATION = 3;
72 const int SELECT_STARSHIP = 4;
73 const int SELECT_FIGHTER = 5;
74 
75 const int VIEW_GALAXY = 0;
76 const int VIEW_SYSTEM = 1;
77 const int VIEW_REGION = 2;
78 
79 // +--------------------------------------------------------------------+
80 
82 : FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
83 loc_labels(0), dst_labels(0), loc_data(0), dst_data(0),
84 seln_list(0), info_list(0), seln_mode(SELECT_REGION),
85 nav_edit_mode(NAV_EDIT_NONE), star_map(0), map_win(0),
86 star_system(0), ship(0), mission(0), editor(false)
87 {
88  Init(def);
89 }
90 
92 { }
93 
94 void
96 {
97  int i;
98 
99  map_win = FindControl(100);
100 
101  if (map_win) {
102  star_map = new(__FILE__,__LINE__) MapView(map_win);
103 
107  }
108 
109  for (i = 0; i < 3; i++) {
110  view_btn[i] = (Button*) FindControl(101 + i);
112  }
113 
114  close_btn = (Button*) FindControl(2);
115 
116  if (close_btn)
118 
119  zoom_in_btn = (Button*) FindControl(110);
120  zoom_out_btn = (Button*) FindControl(111);
121 
122  for (i = 0; i < 6; i++) {
123  filter_btn[i] = (Button*) FindControl(401 + i);
125  }
126 
127  commit_btn = (Button*) FindControl(1);
128 
129  if (commit_btn) {
131  }
132 
133  loc_labels = FindControl(601);
134  dst_labels = FindControl(602);
135  loc_data = FindControl(701);
136  dst_data = FindControl(702);
137 
138  seln_list = (ListBox*) FindControl(801);
139 
140  if (seln_list) {
143  }
144 
145  info_list = (ListBox*) FindControl(802);
146 
147  if (star_map) {
149  view_btn[1]->SetButtonState(1);
150 
152  }
153 
154  UpdateSelection();
155 }
156 
157 // +--------------------------------------------------------------------+
158 
159 void
161 {
162  if (star_system == s)
163  return;
164 
165  star_system = s;
166 
167  if (star_map) {
169  Sim* sim = Sim::GetSim();
170 
171  if (sim && sim->GetSystemList().size()) {
173  }
174  else if (mission && mission->GetSystemList().size()) {
176  }
177  else if (c && c->GetSystemList().size()) {
179  }
180  else {
182  if (g)
184  }
185 
186  star_map->SetSystem(s);
187  }
188 
189  // flush old object pointers:
190  stars.clear();
191  planets.clear();
192  regions.clear();
193  contacts.clear();
194 
195  if (star_system) {
196  // insert objects from star system:
198  while (++star) {
199  switch (star->Type()) {
200  case Orbital::STAR: stars.append(star.value());
201  break;
202  case Orbital::PLANET:
203  case Orbital::MOON: planets.append(star.value());
204  break;
205  }
206 
207  ListIter<OrbitalBody> planet = star->Satellites();
208  while (++planet) {
209  planets.append(planet.value());
210 
211  ListIter<OrbitalBody> moon = planet->Satellites();
212  while (++moon) {
213  planets.append(moon.value());
214  }
215  }
216  }
217 
219  while (++rgn)
220  regions.append(rgn.value());
221  }
222 
223  // sort region list by distance from the star:
224  regions.sort();
225 }
226 
227 // +--------------------------------------------------------------------+
228 
229 void
231 {
232  if (ship == s)
233  return;
234 
235  ship = s;
236 
237  if (ship)
239 
240  if (star_map) {
241  Sim* sim = Sim::GetSim();
242 
243  if (sim && sim->GetSystemList().size())
245 
247 
248  if (ship) {
252  }
253  }
254 
255  for (int i = 0; i < 6; i++)
256  filter_btn[i]->SetButtonState(0);
257 
260  UpdateSelection();
261 }
262 
263 // +--------------------------------------------------------------------+
264 
265 void
267 {
268  if (!m && mission == m)
269  return;
270 
271  if (mission == m && star_system == m->GetStarSystem())
272  return;
273 
274  mission = m;
275 
276  if (mission) {
278  }
279 
280  if (star_map) {
282  Sim* sim = Sim::GetSim();
283 
284  star_map->SetMission(0); // prevent building map menu twice
285 
286  if (sim && sim->GetSystemList().size()) {
288  }
289  else if (mission && mission->GetSystemList().size()) {
291  }
292  else if (c && c->GetSystemList().size()) {
294  }
295  else {
297  if (g)
299  }
300 
301  if (mission) {
304 
305  if (star_map->GetViewMode() == VIEW_REGION) {
307  while (++elem) {
308  MissionElement* e = elem.value();
309 
310  if (e->Player())
312  }
313  }
314  }
315  }
316 
317  bool updated = false;
318 
319  if (mission) {
320  Orbital* rgn = 0;
322 
323  if (rgn) {
324  SelectRegion((OrbitalRegion*) rgn);
325  updated = true;
326  }
327  }
328 
329  if (!updated)
330  UpdateSelection();
331 }
332 
333 // +--------------------------------------------------------------------+
334 
335 void
337 {
338  editor = e;
339 
340  if (star_map)
342 }
343 
344 // +--------------------------------------------------------------------+
345 
346 void
348 {
349  Sim* sim = Sim::GetSim();
350 
351  if (loc_labels && ship) {
352  char loc_buf[512];
353  char x[16];
354  char y[16];
355  char z[16];
356  char d[16];
357 
358  FormatNumber(x, -ship->Location().x);
359  FormatNumber(y, ship->Location().z);
360  FormatNumber(z, ship->Location().y);
361 
362  strcpy_s(loc_buf, Game::GetText("NavDlg.loc-labels").data());
363  loc_labels->SetText(loc_buf);
364 
365  if (sim->GetActiveRegion()) {
366  sprintf_s(loc_buf, "\n%s\n%s\n%s, %s, %s",
367  (const char*) star_system->Name(),
368  (const char*) sim->GetActiveRegion()->Name(),
369  x, y, z);
370 
371  }
372  else {
373  sprintf_s(loc_buf, "\n%s\nPlanck Space?\n%s, %s, %s",
374  (const char*) star_system->Name(), x, y, z);
375  }
376 
377  loc_data->SetText(loc_buf);
378 
379  if (ship) {
380  NavSystem* navsys = ship->GetNavSystem();
381 
382  if (ship->GetNextNavPoint() == 0 || !navsys) {
383  commit_btn->SetText(Game::GetText("NavDlg.commit"));
384  commit_btn->SetBackColor(commit_color);
385  commit_btn->SetEnabled(false);
386  }
387  else if (navsys) {
388  commit_btn->SetEnabled(true);
389 
390  if (navsys->AutoNavEngaged()) {
391  commit_btn->SetText(Game::GetText("NavDlg.cancel"));
392  commit_btn->SetBackColor(cancel_color);
393  }
394  else {
395  commit_btn->SetText(Game::GetText("NavDlg.commit"));
396  commit_btn->SetBackColor(commit_color);
397  }
398  }
399  }
400 
401  if (dst_labels) {
402  Instruction* navpt = ship->GetNextNavPoint();
403 
404  if (navpt && navpt->Region()) {
405  FormatNumber(x, navpt->Location().x);
406  FormatNumber(y, navpt->Location().y);
407  FormatNumber(z, navpt->Location().z);
408 
409  double distance = 0;
410  Point npt = navpt->Region()->Location() + navpt->Location();
411  if (sim->GetActiveRegion())
412  npt -= sim->GetActiveRegion()->Location();
413 
414  npt = npt.OtherHand();
415 
416  // distance from self to navpt:
417  distance = Point(npt - ship->Location()).length();
418  FormatNumber(d, distance);
419 
420  strcpy_s(loc_buf, Game::GetText("NavDlg.dst-labels").data());
421  dst_labels->SetText(loc_buf);
422 
423  sprintf_s(loc_buf, "\n%s\n%s\n%s, %s, %s\n%s",
424  (const char*) star_system->Name(),
425  (const char*) navpt->Region()->Name(),
426  x, y, z, d);
427  dst_data->SetText(loc_buf);
428  }
429  else {
430  dst_labels->SetText(Game::GetText("NavDlg.destination"));
431  dst_data->SetText(Game::GetText("NavDlg.not-avail"));
432  }
433  }
434  }
435 
436  UpdateSelection();
437  UpdateLists();
438 
439  if (Keyboard::KeyDown(VK_ADD) ||
440  (zoom_in_btn && zoom_in_btn->GetButtonState() > 0)) {
441  star_map->ZoomIn();
442  }
443  else if (Keyboard::KeyDown(VK_SUBTRACT) ||
445  star_map->ZoomOut();
446  }
447 
448  else if (star_map->TargetRect().Contains(Mouse::X(),Mouse::Y())) {
449 
450  if (Mouse::Wheel() > 0) {
451  star_map->ZoomIn();
452  star_map->ZoomIn();
453  star_map->ZoomIn();
454  }
455 
456  else if (Mouse::Wheel() < 0) {
457  star_map->ZoomOut();
458  star_map->ZoomOut();
459  star_map->ZoomOut();
460  }
461  }
462 
465  else
467 }
468 
469 // +--------------------------------------------------------------------+
470 
471 void
473 {
474  int use_filter_mode = -1;
475 
479 
480  if (view_btn[0] == event->window) {
483  use_filter_mode = SELECT_SYSTEM;
484  }
485 
486  else if (view_btn[VIEW_SYSTEM] == event->window) {
489  use_filter_mode = SELECT_REGION;
490  }
491 
492  else if (view_btn[VIEW_REGION] == event->window) {
495  use_filter_mode = SELECT_STARSHIP;
496  }
497 
498  if (use_filter_mode >= 0) {
499  for (int i = 0; i < 6; i++) {
500  if (i == use_filter_mode)
501  filter_btn[i]->SetButtonState(1);
502  else
503  filter_btn[i]->SetButtonState(0);
504  }
505 
506  UseFilter(use_filter_mode);
507  }
508 }
509 
510 // +--------------------------------------------------------------------+
511 
512 void
514 {
515  int filter_index = -1;
516  for (int i = 0; i < 6; i++) {
517  if (filter_btn[i] == event->window) {
518  filter_index = i;
519  filter_btn[i]->SetButtonState(1);
520  }
521  else {
522  filter_btn[i]->SetButtonState(0);
523  }
524  }
525 
526  if (filter_index >= 0)
527  UseFilter(filter_index);
528 }
529 
530 void
531 NavDlg::UseFilter(int filter_index)
532 {
533  seln_mode = filter_index;
534 
536  UpdateSelection();
537  UpdateLists();
538 }
539 
540 // +--------------------------------------------------------------------+
541 
542 void
544 {
545  if (mode >= 0 && mode < 3) {
546  int use_filter_mode = -1;
547 
551 
552  if (mode == 0) {
555  use_filter_mode = SELECT_SYSTEM;
556  }
557 
558  else if (mode == 1) {
561  use_filter_mode = SELECT_REGION;
562  }
563 
564  else if (mode == 2) {
567  use_filter_mode = SELECT_STARSHIP;
568  }
569 
570  if (use_filter_mode >= 0) {
571  for (int i = 0; i < 6; i++) {
572  filter_btn[i]->SetButtonState(i == use_filter_mode);
573  }
574 
575  UseFilter(use_filter_mode);
576  }
577  }
578 }
579 
580 void
582 {
583  UseViewMode(0);
584 
585  if (stars.size()) {
586  int sel = 0;
587 
588  ListIter<Orbital> iter = stars;
589  while (++iter) {
590  if (iter.value() == star) {
591  int old_seln_mode = seln_mode;
593  SelectObject(sel);
594  UseFilter(old_seln_mode);
595  return;
596  }
597 
598  sel++;
599  }
600  }
601 }
602 
603 void
605 {
606  UseViewMode(1);
607 
608  if (planets.size()) {
609  int sel = 0;
610 
611  ListIter<Orbital> iter = planets;
612  while (++iter) {
613  if (iter.value() == planet) {
614  int old_seln_mode = seln_mode;
616  SelectObject(sel);
617  UseFilter(old_seln_mode);
618  return;
619  }
620 
621  sel++;
622  }
623  }
624 }
625 
626 void
628 {
629  UseViewMode(2);
630 
631  if (regions.size()) {
632  int sel = 0;
633 
635  while (++iter) {
636  if (iter.value() == rgn) {
637  int old_seln_mode = seln_mode;
639  SelectObject(sel);
640  UseFilter(old_seln_mode);
641  return;
642  }
643 
644  sel++;
645  }
646  }
647 }
648 
649 // +--------------------------------------------------------------------+
650 
651 void
653 {
654  int index = -1;
655 
656  for (int i = 0; i < seln_list->NumItems(); i++)
657  if (seln_list->IsSelected(i))
658  index = i;
659 
660  if (index >= 0)
661  SelectObject(index);
662 }
663 
664 // +--------------------------------------------------------------------+
665 
666 void
668 {
669  Text selected = seln_list->GetItemText(index);
670  int selection = seln_list->GetItemData(index);
671 
672  star_map->SetSelection(selection);
674 }
675 
676 // +--------------------------------------------------------------------+
677 
678 void
680 {
681  if (!info_list)
682  return;
683 
684  if (!star_map)
685  return;
686 
688 
689  Text units_km = Text(" ") + Game::GetText("NavDlg.units.kilometers");
690  Text units_tonnes = Text(" ") + Game::GetText("NavDlg.units.tonnes");
691 
692  if (seln_mode <= SELECT_REGION) {
693  Orbital* s = star_map->GetSelection();
694 
695  if (s) {
696  char radius[32];
697  char mass[32];
698  char orbit[32];
699  char period[32];
700  char units[32];
701 
702  double p = s->Period();
703 
704  if (p < 60) {
705  sprintf_s(units, " %s", Game::GetText("NavDlg.units.seconds").data());
706  }
707  else if (p < 3600) {
708  p /= 60;
709  sprintf_s(units, " %s", Game::GetText("NavDlg.units.minutes").data());
710  }
711  else if (p < 24 * 3600) {
712  p /= 3600;
713  sprintf_s(units, " %s", Game::GetText("NavDlg.units.hours").data());
714  }
715  else if (p < 365.25 * 24 * 3600) {
716  p /= 24*3600;
717  sprintf_s(units, " %s", Game::GetText("NavDlg.units.days").data());
718  }
719  else {
720  p /= 365.25*24*3600;
721  sprintf_s(units, " %s", Game::GetText("NavDlg.units.years").data());
722  }
723 
724  FormatNumberExp(radius, s->Radius()/1000);
725  FormatNumberExp(mass, s->Mass()/1000);
726  FormatNumberExp(orbit, s->Orbit()/1000);
727  FormatNumberExp(period, p);
728 
729  strcat_s(radius, units_km.data());
730  strcat_s(mass, units_tonnes.data());
731  strcat_s(orbit, units_km.data());
732  strcat_s(period, units);
733 
734  if (seln_mode >= SELECT_SYSTEM) {
735  info_list->AddItem(Game::GetText(Text("NavDlg.filter.") + filter_name[seln_mode]));
736  info_list->AddItem(Game::GetText("NavDlg.radius"));
737  if (s->Mass() > 0)
738  info_list->AddItem(Game::GetText("NavDlg.mass"));
739  info_list->AddItem(Game::GetText("NavDlg.orbit"));
740  info_list->AddItem(Game::GetText("NavDlg.period"));
741 
742  int row = 0;
743  info_list->SetItemText(row++, 1, s->Name());
744  info_list->SetItemText(row++, 1, radius);
745  if (s->Mass() > 0)
746  info_list->SetItemText(row++, 1, mass);
747  info_list->SetItemText(row++, 1, orbit);
748  info_list->SetItemText(row++, 1, period);
749  }
750  }
751  }
752 
753  else if (seln_mode == SELECT_STATION ||
756 
757  Ship* sel_ship = star_map->GetSelectedShip();
758  MissionElement* sel_elem = star_map->GetSelectedElem();
759 
760  if (sel_ship) {
761  Text order_desc = Game::GetText("NavDlg.none");
762  char shield[16];
763  char hull[16];
764  char range[32];
765 
766  sprintf_s(shield, "%03d", sel_ship->ShieldStrength());
767  sprintf_s(hull, "%03d", sel_ship->HullStrength());
768  sprintf_s(range, Game::GetText("NavDlg.not-avail").data());
769 
770  if (ship) {
771  FormatNumberExp(range, Point(sel_ship->Location()-ship->Location()).length()/1000);
772  strcat_s(range, units_km.data());
773  }
774 
775  info_list->AddItem(Game::GetText("NavDlg.name"));
776  info_list->AddItem(Game::GetText("NavDlg.class"));
777  info_list->AddItem(Game::GetText("NavDlg.sector"));
778  info_list->AddItem(Game::GetText("NavDlg.shield"));
779  info_list->AddItem(Game::GetText("NavDlg.hull"));
780  info_list->AddItem(Game::GetText("NavDlg.range"));
781  info_list->AddItem(Game::GetText("NavDlg.orders"));
782 
783  int row = 0;
784  info_list->SetItemText(row++, 1, sel_ship->Name());
785  info_list->SetItemText(row++, 1, Text(sel_ship->Abbreviation()) + Text(" ") + Text(sel_ship->Design()->display_name));
786  info_list->SetItemText(row++, 1, sel_ship->GetRegion()->Name());
787  info_list->SetItemText(row++, 1, shield);
788  info_list->SetItemText(row++, 1, hull);
789  info_list->SetItemText(row++, 1, range);
790  info_list->SetItemText(row++, 1, order_desc);
791  }
792 
793  else if (sel_elem) {
794  Text order_desc = Game::GetText("NavDlg.none");
795  char range[32];
796 
797  MissionElement* self = mission->GetElements()[0];
798  if (self)
799  FormatNumberExp(range, Point(sel_elem->Location()-self->Location()).length()/1000);
800  else
801  strcpy_s(range, "0");
802 
803  strcat_s(range, units_km.data());
804 
805  info_list->AddItem(Game::GetText("NavDlg.name"));
806  info_list->AddItem(Game::GetText("NavDlg.class"));
807  info_list->AddItem(Game::GetText("NavDlg.sector"));
808  info_list->AddItem(Game::GetText("NavDlg.range"));
809  info_list->AddItem(Game::GetText("NavDlg.orders"));
810 
811  int row = 0;
812  info_list->SetItemText(row++, 1, sel_elem->Name());
813 
814  if (sel_elem->GetDesign())
815  info_list->SetItemText(row++, 1, sel_elem->Abbreviation() + Text(" ") + sel_elem->GetDesign()->name);
816  else
817  info_list->SetItemText(row++, 1, Game::GetText("NavDlg.unknown"));
818 
819  info_list->SetItemText(row++, 1, sel_elem->Region());
820  info_list->SetItemText(row++, 1, range);
821  info_list->SetItemText(row++, 1, order_desc);
822  }
823  }
824 }
825 
826 // +--------------------------------------------------------------------+
827 
828 void
830 {
831  if (!seln_list)
832  return;
833 
834  int seln_index = -1;
835  int top_index = -1;
836 
837  if (seln_list->IsSelecting())
838  seln_index = seln_list->GetListIndex();
839 
840  top_index = seln_list->GetTopIndex();
841 
843 
844  switch (seln_mode) {
845  case SELECT_SYSTEM:
846  {
847  seln_list->SetColumnTitle(0, Game::GetText(Text("NavDlg.filter.") + filter_name[seln_mode]));
848  int i = 0;
850  while (++iter)
851  seln_list->AddItemWithData(iter->Name(), i++);
852  }
853  break;
854 
855  case SELECT_PLANET:
856  {
857  seln_list->SetColumnTitle(0, Game::GetText(Text("NavDlg.filter.") + filter_name[seln_mode]));
858  int i = 0;
859  ListIter<Orbital> iter = planets;
860  while (++iter) {
861  if (iter->Type() == Orbital::MOON)
862  seln_list->AddItemWithData(Text("- ") + Text(iter->Name()), i++);
863  else
864  seln_list->AddItemWithData(iter->Name(), i++);
865  }
866  }
867  break;
868 
869  case SELECT_REGION:
870  {
871  seln_list->SetColumnTitle(0, Game::GetText(Text("NavDlg.filter.") + filter_name[seln_mode]));
872  int i = 0;
874  while (++iter) {
875  seln_list->AddItemWithData(iter->Name(), i++);
876  }
877  }
878  break;
879 
880  case SELECT_STATION:
881  case SELECT_STARSHIP:
882  case SELECT_FIGHTER:
883  {
884  seln_list->SetColumnTitle(0, Game::GetText(Text("NavDlg.filter.") + filter_name[seln_mode]));
885  int i = 0;
886 
887  if (mission) {
889  while (++elem) {
890  MissionElement* e = elem.value();
891  bool filter_ok =
892  (seln_mode == SELECT_STATION && e->IsStatic()) ||
893  (seln_mode == SELECT_STARSHIP && e->IsStarship() && !e->IsStatic()) ||
894  (seln_mode == SELECT_FIGHTER && e->IsDropship() && !e->IsSquadron());
895 
896  if (filter_ok) {
897  bool visible = editor ||
898  e->GetIFF() == 0 ||
899  e->GetIFF() == mission->Team() ||
900  e->IntelLevel() > Intel::KNOWN;
901 
902  if (visible)
903  seln_list->AddItemWithData(e->Name(), e->Identity());
904  }
905  }
906  }
907 
908  else if (ship) {
909  Sim* sim = Sim::GetSim();
910  ListIter<SimRegion> r_iter = sim->GetRegions();
911  while (++r_iter) {
912  SimRegion* rgn = r_iter.value();
913 
914  ListIter<Ship> s_iter = rgn->Ships();
915  while (++s_iter) {
916  Ship* s = s_iter.value();
917  bool filter_ok =
918  (seln_mode == SELECT_STATION && s->IsStatic()) ||
919  (seln_mode == SELECT_STARSHIP && s->IsStarship() && !s->IsStatic()) ||
920  (seln_mode == SELECT_FIGHTER && s->IsDropship());
921 
922 
923  if (filter_ok) {
924  bool visible = s->GetIFF() == 0 ||
925  s->GetIFF() == ship->GetIFF() ||
926  s->GetElement() &&
928 
929  if (visible)
930  seln_list->AddItemWithData(s->Name(), s->Identity());
931  }
932  }
933  }
934  }
935  }
936  break;
937 
938  default:
939  break;
940  }
941 
942  if (top_index >= 0)
943  seln_list->ScrollTo(top_index);
944 
945  if (seln_index >= 0)
946  seln_list->SetSelected(seln_index);
947 
948  else
950 }
951 
952 // +--------------------------------------------------------------------+
953 
954 void
956 {
957  bool hide = false;
958 
959  if (ship) {
960  NavSystem* navsys = ship->GetNavSystem();
961  if (navsys) {
962  if (navsys->AutoNavEngaged()) {
963  navsys->DisengageAutoNav();
964  commit_btn->SetText(Game::GetText("NavDlg.commit"));
965  commit_btn->SetBackColor(commit_color);
966  }
967  else {
968  navsys->EngageAutoNav();
969  commit_btn->SetText(Game::GetText("NavDlg.cancel"));
970  commit_btn->SetBackColor(cancel_color);
971  hide = true;
972  }
973 
974  Sim* sim = Sim::GetSim();
975  if (sim)
976  ship->SetControls(sim->GetControls());
977  }
978  }
979 
980  if (manager && hide)
981  manager->ShowNavDlg(); // also hides
982 }
983 
984 // +--------------------------------------------------------------------+
985 
986 void
988 {
989  if (manager)
990  manager->ShowNavDlg(); // also hides
991 }
992 
993 
994 // +--------------------------------------------------------------------+
995 
996 void
998 {
999  if (manager)
1000  manager->ShowNavDlg(); // also hides
1001 }
1002 
1003 // +--------------------------------------------------------------------+
1004 
1005 void
1007 {
1008  if (nav_edit_mode != mode) {
1009  if (mode != NAV_EDIT_NONE) {
1010  int map_mode = star_map->GetSelectionMode();
1011  if (map_mode != -1)
1012  seln_mode = map_mode;
1013 
1015  }
1016  else {
1018  }
1019 
1020  nav_edit_mode = mode;
1021  }
1022 }
1023 
1024 int
1026 {
1027  return nav_edit_mode;
1028 }
1029 
1030 void
1032 {
1033 }
1034 
1035 void
1037 {
1038 }
1039 
1040 void
1042 {
1043  static DWORD click_time = 0;
1044 
1047 
1048  // double-click:
1049  if (Game::RealTime() - click_time < 350) {
1051  MsnElemDlg* msn_elem_dlg = manager->GetMsnElemDlg();
1052 
1053  if (elem && msn_elem_dlg) {
1054  msn_elem_dlg->SetMission(mission);
1055  msn_elem_dlg->SetMissionElement(elem);
1057  }
1058  }
1059 
1060  click_time = Game::RealTime();
1061 }
1062 
1063 void
1065 {
1066  if (!seln_list || !star_map)
1067  return;
1068 
1069  switch (seln_mode) {
1070  default:
1071  case SELECT_SYSTEM:
1072  case SELECT_PLANET:
1073  case SELECT_REGION:
1074  {
1076 
1077  Orbital* selected = star_map->GetSelection();
1078 
1079  if (selected) {
1080  for (int i = 0; i < seln_list->NumItems(); i++) {
1081  if (seln_list->GetItemText(i) == selected->Name() ||
1082  seln_list->GetItemText(i) == Text("- ") + selected->Name()) {
1083  seln_list->SetSelected(i, true);
1084  }
1085  }
1086  }
1087  }
1088  break;
1089 
1090  case SELECT_STATION:
1091  case SELECT_STARSHIP:
1092  case SELECT_FIGHTER:
1093  {
1095 
1096  Ship* selected = star_map->GetSelectedShip();
1098 
1099  if (selected) {
1100  for (int i = 0; i < seln_list->NumItems(); i++) {
1101  if (seln_list->GetItemText(i) == selected->Name()) {
1102  seln_list->SetSelected(i, true);
1103  }
1104  }
1105  }
1106 
1107  else if (elem) {
1108  for (int i = 0; i < seln_list->NumItems(); i++) {
1109  if (seln_list->GetItemText(i) == elem->Name()) {
1110  seln_list->SetSelected(i, true);
1111  }
1112  }
1113  }
1114  }
1115  break;
1116  }
1117 }
1118 
1119 // +--------------------------------------------------------------------+
1120 
1121 void
1123 {
1124  if (manager)
1125  manager->HideNavDlg();
1126 }