@@ -414,8 +414,9 @@ bool GUIConfigureWorld::OnEvent(const SEvent& event)
414
414
else if (selected_node != NULL && selected_node->getText () != NULL )
415
415
{
416
416
std::string modname = wide_to_narrow (selected_node->getText ());
417
- ModSpec mod = m_addonmods[modname];
418
- enableAllMods (mod.modpack_content ,true );
417
+ std::map<std::string, ModSpec>::iterator mod_it = m_addonmods.find (modname);
418
+ if (mod_it != m_addonmods.end ())
419
+ enableAllMods (mod_it->second .modpack_content ,true );
419
420
}
420
421
return true ;
421
422
}
@@ -427,8 +428,9 @@ bool GUIConfigureWorld::OnEvent(const SEvent& event)
427
428
if (selected_node != NULL && selected_node->getText () != NULL )
428
429
{
429
430
std::string modname = wide_to_narrow (selected_node->getText ());
430
- ModSpec mod = m_addonmods[modname];
431
- enableAllMods (mod.modpack_content ,false );
431
+ std::map<std::string, ModSpec>::iterator mod_it = m_addonmods.find (modname);
432
+ if (mod_it != m_addonmods.end ())
433
+ enableAllMods (mod_it->second .modpack_content ,false );
432
434
}
433
435
return true ;
434
436
}
@@ -446,7 +448,7 @@ bool GUIConfigureWorld::OnEvent(const SEvent& event)
446
448
return true ;
447
449
}
448
450
if (event.GUIEvent .EventType ==gui::EGET_TREEVIEW_NODE_SELECT &&
449
- event.GUIEvent .Caller ->getID () == GUI_ID_MOD_TREEVIEW)
451
+ event.GUIEvent .Caller ->getID () == GUI_ID_MOD_TREEVIEW)
450
452
{
451
453
selecting_dep = -1 ;
452
454
selecting_rdep = -1 ;
@@ -560,42 +562,49 @@ void GUIConfigureWorld::adjustSidebar()
560
562
modname_w = L" N/A" ;
561
563
std::string modname = wide_to_narrow (modname_w);
562
564
563
- // if no mods installed, don't show buttons or checkbox on the sidebar
565
+ ModSpec mspec;
566
+ std::map<std::string, ModSpec>::iterator it = m_addonmods.find (modname);
567
+ if (it != m_addonmods.end ())
568
+ mspec = it->second ;
569
+
570
+ m_dependencies_listbox->clear ();
571
+ m_rdependencies_listbox->clear ();
572
+
573
+ // if no mods installed, there is nothing to enable/disable, so we
574
+ // don't show buttons or checkbox on the sidebar
564
575
if (node->getParent () == m_treeview->getRoot () && !node->hasChilds ())
565
576
{
566
577
m_disableall->setVisible (false );
567
578
m_enableall->setVisible (false );
568
579
m_enabled_checkbox->setVisible (false );
580
+ return ;
569
581
}
570
- else
582
+
583
+ // a modpack is not enabled/disabled by itself, only its cotnents
584
+ // are. so we show show enable/disable all buttons, but hide the
585
+ // checkbox
586
+ if (node->getParent () == m_treeview->getRoot () ||
587
+ mspec.is_modpack )
571
588
{
572
- // if modpack, show enable/disable all buttons. otherwise, show
573
- // enabled checkbox
574
- if (node->getParent () == m_treeview->getRoot () ||
575
- m_addonmods[modname].is_modpack )
576
- {
577
- m_enabled_checkbox->setVisible (false );
578
- m_disableall->setVisible (true );
579
- m_enableall->setVisible (true );
580
- m_modname_text->setText ((L" Modpack: " +modname_w).c_str ());
581
- }
582
- else
583
- {
584
- m_disableall->setVisible (false );
585
- m_enableall->setVisible (false );
586
- m_enabled_checkbox->setVisible (true );
587
- m_modname_text->setText ((L" Mod: " +modname_w).c_str ());
588
- }
589
- }
589
+ m_enabled_checkbox->setVisible (false );
590
+ m_disableall->setVisible (true );
591
+ m_enableall->setVisible (true );
592
+ m_modname_text->setText ((L" Modpack: " +modname_w).c_str ());
593
+ return ;
594
+ }
595
+
596
+ // for a normal mod, we hide the enable/disable all buttons, but show the checkbox.
597
+ m_disableall->setVisible (false );
598
+ m_enableall->setVisible (false );
599
+ m_enabled_checkbox->setVisible (true );
600
+ m_modname_text->setText ((L" Mod: " +modname_w).c_str ());
601
+
590
602
// the mod is enabled unless it is disabled in the world.mt settings.
591
603
bool mod_enabled = true ;
592
604
if (m_settings.exists (" load_mod_" +modname))
593
605
mod_enabled = m_settings.getBool (" load_mod_" +modname);
594
606
m_enabled_checkbox->setChecked (mod_enabled);
595
607
596
- // dependencies of this mod:
597
- m_dependencies_listbox->clear ();
598
- ModSpec mspec = m_addonmods[modname];
599
608
for (std::set<std::string>::iterator it=mspec.depends .begin ();
600
609
it != mspec.depends .end (); ++it)
601
610
{
@@ -611,9 +620,7 @@ void GUIConfigureWorld::adjustSidebar()
611
620
m_dependencies_listbox->addItem (narrow_to_wide (dependency).c_str ());
612
621
}
613
622
614
-
615
623
// reverse dependencies of this mod:
616
- m_rdependencies_listbox->clear ();
617
624
std::pair< std::multimap<std::string, std::string>::iterator,
618
625
std::multimap<std::string, std::string>::iterator > rdep =
619
626
m_reverse_depends.equal_range (modname);
@@ -639,19 +646,25 @@ void GUIConfigureWorld::enableAllMods(std::map<std::string, ModSpec> mods,bool e
639
646
enableAllMods (mod.modpack_content ,enable);
640
647
else // not a modpack
641
648
setEnabled (mod.name , enable);
649
+
642
650
}
643
651
}
644
652
645
653
void GUIConfigureWorld::enableMod (std::string modname)
646
654
{
655
+ std::map<std::string, ModSpec>::iterator mod_it = m_addonmods.find (modname);
656
+ if (mod_it == m_addonmods.end ()){
657
+ errorstream << " enableMod() called with invalid mod name \" " << modname << " \" " << std::endl;
658
+ return ;
659
+ }
660
+ ModSpec mspec = mod_it->second ;
647
661
m_settings.setBool (" load_mod_" +modname,true );
648
662
std::map<std::string,gui::IGUITreeViewNode*>::iterator it =
649
663
m_nodes.find (modname);
650
- if (it != m_nodes.end ())
664
+ if (it != m_nodes.end ())
651
665
(*it).second ->setIcon (CHECKMARK_STR);
652
666
m_new_mod_names.erase (modname);
653
667
// also enable all dependencies
654
- ModSpec mspec = m_addonmods[modname];
655
668
for (std::set<std::string>::iterator it=mspec.depends .begin ();
656
669
it != mspec.depends .end (); ++it)
657
670
{
@@ -664,6 +677,12 @@ void GUIConfigureWorld::enableMod(std::string modname)
664
677
665
678
void GUIConfigureWorld::disableMod (std::string modname)
666
679
{
680
+ std::map<std::string, ModSpec>::iterator mod_it = m_addonmods.find (modname);
681
+ if (mod_it == m_addonmods.end ()){
682
+ errorstream << " disableMod() called with invalid mod name \" " << modname << " \" " << std::endl;
683
+ return ;
684
+ }
685
+
667
686
m_settings.setBool (" load_mod_" +modname,false );
668
687
std::map<std::string,gui::IGUITreeViewNode*>::iterator it =
669
688
m_nodes.find (modname);
0 commit comments