Pārlūkot izejas kodu

* editor menu improvements

mateuszb 13 gadi atpakaļ
vecāks
revīzija
d000c88047
1 mainītis faili ar 57 papildinājumiem un 40 dzēšanām
  1. 57 40
      Editor/Editor.cpp

+ 57 - 40
Editor/Editor.cpp

@@ -29,54 +29,71 @@ Editor::~Editor()
 
 void Editor::createMenus()
 {
-	enum MenuName {FILE, EDIT, VIEW, TOOLS, PLAYER, HELP};
+	std::map<std::string, std::function<void()> > actions; //connect these to actions
+	enum MenuName {FILE=0, EDIT, VIEW, TOOLS, PLAYER, HELP, //main level
+		TERRAIN=0, RIVER, ROADS, ERASE, OBSTACLES, OBJECTS}; //tools submenus
+
 	QMenu * menus[6];
 	for(int i=0; i<6; ++i)
 		menus[i] = menuBar()->addMenu(tr(txtEditor[751+i].c_str()));
 
-	for(int i=0; i<6; ++i)
+	auto addMenu = [&](QMenu ** menuList, int txtBegin, int count, std::string actionBase, MenuName mn, const std::vector<int> & separators)
 	{
-		if(i == 4)
-			menus[FILE]->addSeparator();
-		QAction * qa = new QAction(tr(txtEditor[758+i].c_str()), menus[FILE]);
-		menus[FILE]->addAction(qa);
-	}
+		for(int i=0; i<count; ++i)
+		{
+			if(vstd::contains(separators, i))
+				menuList[mn]->addSeparator();
+			QAction * qa = new QAction(tr(txtEditor[txtBegin+i].c_str()), menus[mn]);
+			std::string actionName = actionBase + "|" + boost::lexical_cast<std::string>(i);
+			if(vstd::contains(actions, actionName))
+			{
+				QObject::connect(qa, &QAction::triggered, actions[actionName]);
+			}
+			menuList[mn]->addAction(qa);
+		}
+	};
 
-	for(int i=0; i<10; ++i)
-	{
-		if(i == 2 || i == 6 || i == 9)
-			menus[EDIT]->addSeparator();
-		QAction * qa = new QAction(tr(txtEditor[860+i].c_str()), menus[EDIT]);
-		menus[EDIT]->addAction(qa);
-	}
+	//terrain submenus
+	QMenu* toolMenus[6];
+	for(int i=0; i<6; ++i)
+		toolMenus[i] = menus[TOOLS]->addMenu(tr(txtEditor[789+i].c_str()));
 
-	for(int i=0; i<10; ++i)
-	{
-		if(i == 2 || i == 3 || i == 7)
-			menus[VIEW]->addSeparator();
-		QAction * qa = new QAction(tr(txtEditor[778+i].c_str()), menus[VIEW]);
-		menus[VIEW]->addAction(qa);
-	}
+	using namespace boost::assign;
+	std::vector<int> seps;
+	seps += 4;
 
-	for(int i=0; i<9; ++i)
-	{
-		if(i == 6 || i == 8)
-			menus[TOOLS]->addSeparator();
-		QAction * qa = new QAction(tr(txtEditor[789+i].c_str()), menus[TOOLS]);
-		menus[TOOLS]->addAction(qa);
-	}
+	addMenu(menus, 758, 6, "file", FILE, seps);
+	
+	seps.clear(); seps += 2, 6, 8;
+	addMenu(menus, 860, 10, "edit", EDIT, seps);
 
-	for(int i=0; i<9; ++i)
-	{
-		QAction * qa = new QAction(tr(txtEditor[846+i].c_str()), menus[PLAYER]);
-		menus[PLAYER]->addAction(qa);
-	}
+	seps.clear(); seps += 2, 3, 7;
+	addMenu(menus, 778, 10, "view", VIEW, seps);
 
-	for(int i=0; i<2; ++i)
-	{
-		if(i == 1)
-			menus[HELP]->addSeparator();
-		QAction * qa = new QAction(tr(txtEditor[856+i].c_str()), menus[HELP]);
-		menus[HELP]->addAction(qa);
-	}
+	seps.clear(); seps += 0, 2;
+	addMenu(menus, 795, 3, "tools", TOOLS, seps);
+
+	seps.clear();
+	addMenu(menus, 846, 9, "player", PLAYER, seps);
+
+	seps.clear(); seps += 1;
+	addMenu(menus, 856, 2, "help", HELP, seps);
+
+	seps.clear(); seps += 4;
+	addMenu(toolMenus, 799, 14, "tools|terrain", TERRAIN, seps);
+
+	seps.clear();;
+	addMenu(toolMenus, 814, 5, "tools|rivers", RIVER, seps);
+
+	seps.clear();
+	addMenu(toolMenus, 820, 4, "tools|roads", ROADS, seps);
+
+	seps.clear();
+	addMenu(toolMenus, 825, 4, "tools|erase", ERASE, seps);
+
+	seps.clear(); seps += 16;
+	addMenu(toolMenus, 872, 17, "tools|obstacles", OBSTACLES, seps);
+
+	seps.clear();
+	addMenu(toolMenus, 830, 15, "tools|objects", OBJECTS, seps);
 }