Esempio n. 1
0
UIElement *UserInterface::createElement(SlotType *iter, UIElement* parent) {
    UIElement *el = nullptr;
    //  ----------- КНОПКА
    if (iter->choiceValue.button != nullptr) {
        Button *b = new Button(iter);
        el = b;
        buttonIndex[b->getName()] = b;
    } else if (iter->choiceValue.image != nullptr) {
        el = new Image(iter);
    } else if (iter->choiceValue.text != nullptr) {
        el = new TextLabel(iter);
    } else if (iter->choiceValue.tableContainer != nullptr) {
        TableContainer *tabCont = new TableContainer(iter);
        for (auto subIter : iter->choiceValue.tableContainer->slot) {
            tabCont->add(createElement(subIter, tabCont));
        }
        tabCont->pack();
        el = tabCont;
        tableIndex[tabCont->getName()] = tabCont;
    } else if (iter->choiceValue.input != nullptr) {
        InputField *ipf = new InputField(iter);
        el = ipf;
        inputIndex[ipf->getName()] = ipf;
    } else if (iter->choiceValue.ddlb != nullptr) {
        DropDownListBox *lb = new DropDownListBox(iter);
        ddlbIndex[lb->getName()] = lb;
        el = lb;
    } else if (iter->choiceValue.context != nullptr) {
        ButtonContextMenu *b = new ButtonContextMenu(iter);
        el = b;
        if (b->getName().size() > 0) {
            if (contextMenuIndex.find(el->getName()) != contextMenuIndex.end()) {
                logger.warn("Context Menu with name %s already exists!", el->getName().c_str());
            }
            contextMenuIndex[el->getName()] = b;
        }
    } else if (iter->choiceValue.dialog != nullptr) {
        Dialog *d = new Dialog(iter);
        for (auto subIter : iter->choiceValue.dialog->slot) {
            d->add(createElement(subIter));
        }
        el = d;
    } else if (iter->choiceValue.imagePicker != nullptr) {
        ImagePicker *ip = new ImagePicker(iter);
        imagePickerIndex[ip->getName()] = ip;
        el = ip;
    } else if (iter->choiceValue.rgb != nullptr) {
        RGBSlider *s = new RGBSlider(iter);
        el = s;
        rgbSliderIndex[s->getName()] = s;
    } else if (iter->choiceValue.healthbar != nullptr) {
        el = new Healthbar(iter);
    } else if (iter->choiceValue.slider != nullptr) {
        Slider *s = new Slider(iter);
        el = s;
        sliderIndex[s->getName()] = s;
    } else if (iter->choiceValue.checkbox != nullptr) {
        Checkbox *lb = new Checkbox(iter);
        checkboxIndex[lb->getName()] = lb;
        el = lb;
    } else if (iter->choiceValue.radio != nullptr) {
        RadioButton *r = new RadioButton(iter);
        checkboxIndex[r->getName()] = r;
        el = r;
    } else if (iter->choiceValue.labelsList!=nullptr){
        LabelsList* ll = new LabelsList(iter);
        el = ll;
    } else if (iter->choiceValue.lineContainer!=nullptr){
        el = new LineContainer(iter);
    } else if(iter->choiceValue.containerSelector!=nullptr){
        ContainerSelector* cs;
        if(parent==nullptr) {
            cs = new ContainerSelector(iter,nullptr);
        }else{
            TableContainer *contParent = dynamic_cast<TableContainer *>(parent);
            if(contParent==nullptr){
                logger.error("ContainerSelector [%s] parent can be only TableContainer", iter->name.c_str());
                return nullptr;
            }
            cs = new ContainerSelector(iter,contParent);
        }
        containerSelectorIndex[cs->getName()]=cs;
        el=cs;
    }

    //common atrs
    if (el != nullptr) {
        el->setVisible(iter->visible);
        el->setEnabled(iter->enabled);
    }

    return el;
}