bool GamePlayLayer::init(std::string uuid) { if(!Layer::init()) { return false; } m_gameBoardHeight = m_squareRowCount * s_squareSize.y; m_gameBoardWidth = m_squareColumnCount * s_squareSize.x; m_BackgroundBoard = new int[m_squareRowCount * m_squareColumnCount]; //test for(int i = 0;i < m_squareRowCount * m_squareColumnCount; i++) { m_BackgroundBoard[i] = 0; if(i > 14 && i < 100) { m_BackgroundBoard[i] = 1; } } auto s = Director::getInstance()->getWinSize(); m_drawNode = DrawNode::create(); addChild(m_drawNode, 10); m_pSquareBaseplateLayer = SquareBaseplateLayer::create(); m_pSquareBaseplateLayer->setPosition(Vec2(50, 300)); //m_pSquareBaseplateLayer->readMapBufTest(); std::string path = FileUtils::getInstance()->getWritablePath(); // localStorageInit(path + "/map"); std::string _mapBuffer; _mapBuffer = GameDB::getInstance()->getMapBuffer(uuid); m_pSquareBaseplateLayer->readMapBuf(_mapBuffer); // localStorageFree(); addChild(m_pSquareBaseplateLayer, 0); rapidjson::Document _json; _json.Parse<0>(_mapBuffer.c_str()); rapidjson::Value &groupListValue = _json["group_list"]; for (rapidjson::SizeType i = 0; i < groupListValue.Size(); i++) { rapidjson::Value& object = groupListValue[i]; rapidjson::Value& groupType = object["group_type"]; rapidjson::Value& groupColor = object["group_color"]; auto sg = SquareGroup::create(); sg->SetSquareGroup(s_squareSize, SquareGroup::SQUAREGROUP_TYPE(groupType.GetInt()), Square::SQUARE_COLOR(groupColor.GetInt())); sg->setPosition(Vec2((i %5) * s_squareSize.x * 4, (i/5) * s_squareSize.y * 4)); sg->DrawGroup(); addChild(sg, 1); } m_pSquareBaseplateLayer->drawBasesplate(s_squareSize); return true; }
void Render::Draw() { glBegin(GL_TRIANGLES); for (auto item : Mesh::groups) { glPushName(item.first); DrawGroup(item.second); } glEnd(); }
bool MapMakerScene::init() { if (!Layer::init()) { return false; } m_lastSelectGroup = nullptr; Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto s = Director::getInstance()->getWinSize(); //input map name auto pTextField = TextFieldTTF::textFieldWithPlaceHolder(std::string(LocalizedCStringByKey("input_map_name")), "fonts/arial.ttf", 48); addChild(pTextField,0,"tbMapName"); pTextField->setPosition(Vec2(s.width / 2,s.height - 250)); //输入事件 auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [pTextField](Touch* touch, Event*) { auto beginPos = touch->getLocation(); Rect rect; rect.size = pTextField->getContentSize(); auto clicked = isScreenPointInRect(beginPos, Camera::getVisitingCamera(), pTextField->getWorldToNodeTransform(), rect, nullptr); if (clicked) { return true; } pTextField->detachWithIME(); return false; }; listener->onTouchEnded = [pTextField](Touch* touch, Event* event) { auto endPos = touch->getLocation(); Rect rect; rect.size = pTextField->getContentSize(); auto clicked = isScreenPointInRect(endPos, Camera::getVisitingCamera(), pTextField->getWorldToNodeTransform(), rect, nullptr); if (clicked) { pTextField->attachWithIME(); } }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //返回主菜单 auto returnToMainMenuItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(MapMakerScene::returnToMainMenuCallback, this) ); returnToMainMenuItem->setPosition(Vec2(origin.x + visibleSize.width - returnToMainMenuItem->getContentSize().width / 2, origin.y + returnToMainMenuItem->getContentSize().height / 2)); auto menu = Menu::create(returnToMainMenuItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); //baseplate auto baseplateLayer = SquareBaseplateLayer::create(); baseplateLayer->createEmptyMap(BaseSize(15,15)); baseplateLayer->drawBasesplate(Vec2(32,32)); baseplateLayer->setPosition(Vec2(100,200)); addChild(baseplateLayer); //菜单,创建group auto menuItemCreateGroup = MenuItemFont::create(LocalizedCStringByKey("create_group")); menuItemCreateGroup->setCallback( [=](Ref*) { auto squareGroup = SquareGroupMapMaker::create(); squareGroup->setPosition(Vec2(100,100)); squareGroup->SetSquareGroup(Vec2(32,32),SquareGroup::SQUAREGROUP_TYPE::ST_Z,Square::SQUARE_COLOR::SC_GREEN); squareGroup->DrawGroup(); squareGroup->setSelectedListener( [=](SquareGroup* sg) { m_lastSelectGroup = sg; }); this->addChild(squareGroup); } ); //菜单,删除group auto menuItemDeleteSelectedGroup = MenuItemFont::create(LocalizedCStringByKey("delete_group")); menuItemDeleteSelectedGroup->setCallback( [=](Ref*) { for(Node* node:this->getChildren()) { SquareGroupMapMaker* sg = dynamic_cast<SquareGroupMapMaker*>(node); if(sg != nullptr) { if(sg->getGroupState() == SGS_SELECTED) { assert(m_lastSelectGroup == sg); m_lastSelectGroup = nullptr; this->removeChild(node); } } } } ); //菜单,保存地图 auto menuItemSaveMap = MenuItemFont::create(LocalizedCStringByKey("save_map")); menuItemSaveMap->setCallback( [=](Ref*) { saveMapToFile(); } ); //创建菜单组 auto operationMenu = Menu::create(menuItemCreateGroup,menuItemDeleteSelectedGroup,menuItemSaveMap, NULL); operationMenu->alignItemsVerticallyWithPadding(20); addChild(operationMenu); operationMenu->setPosition(Vec2(s.width / 2, s.height - 100)); //产生本地图的guid m_guid = std::string(GameUilityTools::CreateGuidString()); //添加选择颜色的层 auto colorLayer = SelectColorLayer::create(); colorLayer->setPosition(Vec2(0, 0)); colorLayer->setColorChangeListener( [=](Square::SQUARE_COLOR color){ //todo xuhua if (m_lastSelectGroup) { m_lastSelectGroup->setSquareGroupColor(color); m_lastSelectGroup->DrawGroup(); } } ); addChild(colorLayer, 0); return true; }
void CFeedIcoItemListCtrl::DrawGroupInfo(CDC & dcMem, const CRect & rectClip, const CRect & rectClient) { dcMem.SelectObject(&m_FontBold); if (thePrefs.GetWindowsVersion() >= _WINVER_VISTA_ ) { int n = GetGroupCount(); for(int i = 0 ; i < n; ++i) { CString strGroupCaption = GetGroupCaption( i ); CString strGroupTotals; if ( strGroupCaption == m_mapGroups.GetKeyAt(i) ) { const CSimpleArray<int>& groupRows = m_mapGroups.GetValueAt(i); strGroupTotals.Format(_T("(共%d个)"), groupRows.GetSize()); } LVGROUP lg = GetGroupInfoByIndex(i, LVGF_GROUPID); CRect rcGroup = GetRectbyGroupID(lg.iGroupId, LVGGR_HEADER); CRect rcIntersect; rcIntersect.IntersectRect(rectClip, rcGroup); //rcGroup.DeflateRect(0, 7);//缩小7像素高度 //rcGroup.OffsetRect(0, -7);//向上偏移7像素 if ( !rcIntersect.IsRectEmpty() ) { DrawGroup(dcMem, rcGroup, strGroupCaption, strGroupTotals); } #ifdef LVGS_COLLAPSIBLE // Maintain LVGS_COLLAPSIBLE state CRect rcDropDown(rcGroup.right - 20, rcGroup.top + 10, rcGroup.right - 5, rcGroup.bottom - 3); if (HasGroupState(i, LVGS_COLLAPSED)) { if (m_imageRss_Group_Drop_Up_Nor) { m_imageRss_Group_Drop_Up_Nor->Draw(dcMem, rcDropDown.left, rcDropDown.top); } } else if (HasGroupState(i, LVGS_NORMAL)) { if (m_imageRss_Group_Drop_Down_Nor) { m_imageRss_Group_Drop_Down_Nor->Draw(dcMem, rcDropDown.left, rcDropDown.top); } } #endif //CRect rcDropDown(rcGroup.right - 20, rcGroup.top + 7, rcGroup.right - 5, rcGroup.bottom - 3); //CRgn rgDropDown;//画圆角矩形 //rgDropDown.CreateRoundRectRgn( rcDropDown.left, rcDropDown.top, rcDropDown.right, rcDropDown.bottom, 3, 3 ); // //CBrush* brushFrame; //brushFrame = new CBrush( GetSysColor(COLOR_GRAYTEXT) ); //dcMem.FrameRgn(&rgDropDown,brushFrame,1,1);//画焦点边框 //delete brushFrame; } } else { if ( nGroupHeight == -1 ) { CRect rcFirstItem;//算法有待优化 GetItemRect(0, rcFirstItem, LVIR_BOUNDS); if ( !rcFirstItem.IsRectEmpty() ) { nGroupHeight = rcFirstItem.top; } }//计算group 高度 CFeedCatalogs & feedCatalogs = CFeedCatalogs::GetInstance(); //遍历Catlogs 获得每个一级分类的Start RssData[只要用第一个就行了....第一个向上偏移绘制] for ( CFeedCatalogs::iterator it = feedCatalogs.GetBegin(); it != feedCatalogs.GetEnd(); ++it ) { FeedCatalog & feedCatlog = it->second; if ( feedCatlog.IsTop() && feedCatlog.GetFeedCount() > 0 ) { CRssFeedBase* feedStart = feedCatlog.GetFirstFeed(); int nStartIndex = GetItemIndex( (CRssFeed*)feedStart );//确定第一个item位置 if ( nStartIndex > -1 ) { int nGroupID = GetGroupIDByItemIndex( nStartIndex ); CString strGroupCaption = GetGroupCaption( nGroupID ); CString strGroupTotals; const CSimpleArray<int>& groupRows = m_mapGroups.GetValueAt(nGroupID); strGroupTotals.Format(_T("(共%d个)"), groupRows.GetSize()); //strGroupTotals.Format(_T("(共 %n 个)"), GetGroupCount()); CRect itemRect; GetItemRect(nStartIndex, &itemRect, LVIR_BOUNDS); //根据item rect获得group rect CRect rcGroup(rectClient.left, itemRect.top - nGroupHeight, rectClient.right, itemRect.top - 6); CRect rtIntersect; rtIntersect.IntersectRect(rectClip, rcGroup); if ( !rtIntersect.IsRectEmpty() ) { DrawGroup(dcMem, rcGroup, strGroupCaption, strGroupTotals); } } } } } }