//TODO 屏蔽事件穿透 void BattleScene::createBottomBar() { LayerColor *bottom = LayerColor::create(Color4B(0, 0, 100, 100)); bottom->setContentSize(Size(WINSIZE.width, 120)); bottom->setPosition(Point(0, 0)); addChild(bottom); int totalCount = 11; int index = 0; Vector<MenuItem *> items; auto soldierInCamp = BattleData::getInstance()->getAttackSoldierInCamp(); map<int, vector<DSoldier *>>::iterator it; for(it=soldierInCamp.begin(); it!=soldierInCamp.end(); it++) { MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this)); item->setTag(it->first); items.pushBack(item); index++; //head Size size = item->getContentSize(); char img[20]; sprintf(img, "ui/%d.png", it->first / 100); auto head = Sprite::create(img); head->setAnchorPoint(Point(0.5, 0.5)); head->setPosition(size.width/2, size.height/2); item->addChild(head); char text[20]; sprintf(text, "X %d", it->second.size()); TTFConfig config("fonts/tahoma.ttf",16); auto count = Label::createWithTTF(config, text, TextHAlignment::LEFT); count->setPosition(size.width/2, size.height - count->getContentSize().height); item->addChild(count); //初始化为第一个兵种 if (m_selectedSoldierType <= 0) { m_selectedSoldierType = it->first; } } for (int i = index; i < totalCount; i++) { MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this)); item->setEnabled(false); items.pushBack(item); } Size bottomSize = bottom->getContentSize(); Sprite *spItem = Sprite::create("ui/618.0.png"); Size itemSize = spItem->getContentSize(); float padding = (bottomSize.width - itemSize.width * totalCount) / (totalCount + 1); UIRadioButton *radio = UIRadioButton::createWithArray(items); radio->alignItemsHorizontallyWithPadding(padding); radio->setPosition(Point(bottomSize.width / 2, bottomSize.height / 2)); radio->setSelectedIndex(0); bottom->addChild(radio); }
UIRadioButton* UI::addRadioButton(int id, int x, int y, int width, int height) { UIRadioButton* radioBtn = new UIRadioButton(mRootNode); radioBtn->nodeID = id; radioBtn->setPos(x, y); radioBtn->setSize(width, height); nodeList.push_back(radioBtn); return radioBtn; }
void PostProcessingApp::OldFashionHandler(UIRadioButton const & sender) { if (sender.GetChecked()) { active_pp_ = old_fashion_; } }
void PostProcessingApp::HDRHandler(UIRadioButton const & sender) { if (sender.GetChecked()) { active_pp_ = hdr_; } }
void PostProcessingApp::NightVisionHandler(UIRadioButton const & sender) { if (sender.GetChecked()) { active_pp_ = night_vision_; } }
void PostProcessingApp::CartoonHandler(UIRadioButton const & sender) { if (sender.GetChecked()) { active_pp_ = cartoon_; } }
void PostProcessingApp::TilingHandler(UIRadioButton const & sender) { if (sender.GetChecked()) { active_pp_ = tiling_; } }
void PostProcessingApp::AsciiArtsHandler(UIRadioButton const & sender) { if (sender.GetChecked()) { active_pp_ = ascii_arts_; } }
void PostProcessingApp::FrostedGlassHandler(UIRadioButton const & sender) { if (sender.GetChecked()) { active_pp_ = frosted_glass_; } }
void PostProcessingApp::CrossStitchingHandler(UIRadioButton const & sender) { if (sender.GetChecked()) { active_pp_ = cross_stitching_; } }
void PostProcessingApp::SepiaHandler(UIRadioButton const & sender) { if (sender.GetChecked()) { active_pp_ = sepia_; } }
UIWidget* UI::WrapWidget(tb::TBWidget* widget) { if (!widget) return NULL; if (widgetWrap_.Contains(widget)) return widgetWrap_[widget]; // switch this to use a factory? // this is order dependent as we're using IsOfType which also works if a base class if (widget->IsOfType<TBPopupWindow>()) { UIPopupWindow* popupWindow = new UIPopupWindow(context_, false); popupWindow->SetWidget(widget); WrapWidget(popupWindow, widget); return popupWindow; } if (widget->IsOfType<TBDimmer>()) { UIDimmer* dimmer = new UIDimmer(context_, false); dimmer->SetWidget(widget); WrapWidget(dimmer, widget); return dimmer; } if (widget->IsOfType<TBScrollContainer>()) { UIScrollContainer* container = new UIScrollContainer(context_, false); container->SetWidget(widget); WrapWidget(container, widget); return container; } if (widget->IsOfType<TBInlineSelect>()) { UIInlineSelect* select = new UIInlineSelect(context_, false); select->SetWidget(widget); WrapWidget(select, widget); return select; } if (widget->IsOfType<TBSlider>()) { UISlider* slider = new UISlider(context_, false); slider->SetWidget(widget); WrapWidget(slider, widget); return slider; } if (widget->IsOfType<TBScrollBar>()) { UIScrollBar* slider = new UIScrollBar(context_, false); slider->SetWidget(widget); WrapWidget(slider, widget); return slider; } if (widget->IsOfType<TBColorWidget>()) { UIColorWidget* colorWidget = new UIColorWidget(context_, false); colorWidget->SetWidget(widget); WrapWidget(colorWidget, widget); return colorWidget; } if (widget->IsOfType<TBColorWheel>()) { UIColorWheel* colorWheel = new UIColorWheel(context_, false); colorWheel->SetWidget(widget); WrapWidget(colorWheel, widget); return colorWheel; } if (widget->IsOfType<TBSection>()) { UISection* section = new UISection(context_, false); section->SetWidget(widget); WrapWidget(section, widget); return section; } if (widget->IsOfType<TBSeparator>()) { UISeparator* sep = new UISeparator(context_, false); sep->SetWidget(widget); WrapWidget(sep, widget); return sep; } if (widget->IsOfType<TBContainer>()) { UIContainer* container = new UIContainer(context_, false); container->SetWidget(widget); WrapWidget(container, widget); return container; } if (widget->IsOfType<TBSelectDropdown>()) { UISelectDropdown* select = new UISelectDropdown(context_, false); select->SetWidget(widget); WrapWidget(select, widget); return select; } if (widget->IsOfType<TBPulldownMenu>()) { UIPulldownMenu* select = new UIPulldownMenu(context_, false); select->SetWidget(widget); WrapWidget(select, widget); return select; } if (widget->IsOfType<TBButton>()) { // don't wrap the close button of a TBWindow.close if (widget->GetID() == TBIDC("TBWindow.close")) return 0; UIButton* button = new UIButton(context_, false); button->SetWidget(widget); WrapWidget(button, widget); return button; } if (widget->IsOfType<TBTextField>()) { UITextField* textfield = new UITextField(context_, false); textfield->SetWidget(widget); WrapWidget(textfield, widget); return textfield; } if (widget->IsOfType<TBEditField>()) { UIEditField* editfield = new UIEditField(context_, false); editfield->SetWidget(widget); WrapWidget(editfield, widget); return editfield; } if (widget->IsOfType<TBSkinImage>()) { UISkinImage* skinimage = new UISkinImage(context_, "", false); skinimage->SetWidget(widget); WrapWidget(skinimage, widget); return skinimage; } if (widget->IsOfType<TBImageWidget>()) { UIImageWidget* imagewidget = new UIImageWidget(context_, false); imagewidget->SetWidget(widget); WrapWidget(imagewidget, widget); return imagewidget; } if (widget->IsOfType<TBClickLabel>()) { UIClickLabel* nwidget = new UIClickLabel(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBCheckBox>()) { UICheckBox* nwidget = new UICheckBox(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBRadioButton>()) { UIRadioButton* nwidget = new UIRadioButton(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBBarGraph>()) { UIBargraph* nwidget = new UIBargraph(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBSelectList>()) { UISelectList* nwidget = new UISelectList(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBMessageWindow>()) { UIMessageWindow* nwidget = new UIMessageWindow(context_, NULL, "", false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBPromptWindow>()) { UIPromptWindow* nwidget = new UIPromptWindow(context_, NULL, "", false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBFinderWindow>()) { UIFinderWindow* nwidget = new UIFinderWindow(context_, NULL, "", false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBTabContainer>()) { UITabContainer* nwidget = new UITabContainer(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<SceneViewWidget>()) { UISceneView* nwidget = new UISceneView(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBLayout>()) { UILayout* layout = new UILayout(context_, (UI_AXIS) widget->GetAxis(), false); layout->SetWidget(widget); WrapWidget(layout, widget); return layout; } if (widget->IsOfType<TBWidget>()) { UIWidget* nwidget = new UIWidget(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } return 0; }