CodeLibrary/08_Clion_Cplus_MultiLevelMenu_20240610/main.cpp

177 lines
4.5 KiB
C++
Raw Normal View History

#include <iostream>
using namespace std;
// MAShiroUI
#include "mashiroui.h"
/*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD>
* 0 - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* 1 - <EFBFBD><EFBFBD>
* 2 - <EFBFBD><EFBFBD>
* 3 - ȷ<EFBFBD><EFBFBD>
* 4 - <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* */
int key_status = 0;
/*
* <EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>ʾ״̬
* 0 - <EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
* 1 - <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> main_menu
* */
int display_status = 0;
menu_table main_menu [] = {
{3, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>-01", main_menu, nullptr, function_01},
{3, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>-02", main_menu, fun_01_menu, nullptr},
{3, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>-03", main_menu, nullptr, nullptr},
};
menu_table fun_01_menu [] = {
{4, "a", main_menu, nullptr, nullptr},
{4, "b", main_menu, nullptr, nullptr},
{4, "c", main_menu, nullptr, nullptr},
{4, "d", main_menu, nullptr, nullptr},
};
// <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
menu_table *current_table = main_menu;
// <20><>ǰ<EFBFBD><C7B0>ѡ
int current_table_page = 0;
// <20><>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
char getInputToChar(){
char temp;
cout << "= u -> <20><> e -> ȷ<><C8B7>" << endl;
cout << "= d -> <20><> r -> <20><><EFBFBD><EFBFBD>" << endl;
cout << "Input: ";
cin >> temp;
return temp;
}
void update_keyStatus(char uin){
int tempKey = 0;
if (uin == 'u'){
tempKey = 1;
}
if (uin == 'd'){
tempKey = 2;
}
if (uin == 'e'){
tempKey = 3;
}
if (uin == 'r'){
tempKey = 4;
}
key_status = tempKey;
}
int main() {
while (true){
system("cls");
if (key_status != 0){
int table_length = current_table[0].length;
// up
if (key_status == 1){
if (display_status != 1){
if (display_status == 0){
display_status = 2;
} else {
display_status = 0;
}
} else {
if (current_table_page - 1 < 0){
current_table_page = table_length - 1;
} else {
current_table_page--;
}
}
}
if (key_status == 2){
if (display_status != 1){
if (display_status == 0){
display_status = 2;
} else {
display_status = 0;
}
} else {
if (current_table_page + 2 > table_length){
current_table_page = 0;
} else {
current_table_page++;
}
}
}
if (key_status == 3){
if (display_status != 1){
display_status = 1;
current_table = main_menu;
} else {
if (current_table[current_table_page].sub_table == nullptr &&
current_table[current_table_page].function != nullptr){
(current_table[current_table_page].function)();
}
if (current_table[current_table_page].sub_table != nullptr &&
current_table[current_table_page].function == nullptr){
current_table = current_table[current_table_page].sub_table;
}
}
}
if (key_status == 4){
if (current_table == main_menu){
display_status = 0;
} else {
current_table = current_table[current_table_page].parent_table;
}
}
key_status = 0;
}
if (current_table_page + 1 > current_table[0].length){
current_table_page = 0;
}
// <20>ж<EFBFBD><D0B6><EFBFBD>Ҫ<EFBFBD><D2AA>ʾ<EFBFBD>IJ˵<C4B2>
if (display_status == 0){
cout << "this is main" << endl;
}
if (display_status == 1){
int i;
cout << "+";
for (i = 0; i < 20; i++){
cout << "-";
}
cout << "+" << endl;
for (i = 0; i < current_table[0].length; i++){
cout << "+ [";
if (current_table_page == i){
cout << "0";
} else {
cout << " ";
}
cout << "] - " << current_table[i].table_title;
cout << endl;
}
cout << "+";
for (i = 0; i < 20; i++){
cout << "-";
}
cout << "+" << endl;
}
if (display_status == 2){
cout << "this is main 02" << endl;
}
// <20><>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>״̬
update_keyStatus(getInputToChar());
}
return 0;
}