/// /// \brief 传送对象 /// \date 8/7/2009 /// \author Albert /// xgc_bool XGameMap::TeleportTo( XGameObject* pObject, XVector3 &vPositionNew, xgc_uintptr lpContext ) { XGC_CHECK_REENTER_CALL( mDynamicChecker ); XGC_ASSERT_RETURN( pObject->GetParent() == GetObjectID(), false, "对象不在该场景,却请求在该场景移动。" ); xgc_bool ret = true; XVector3 vPositionOld = pObject->GetPosition(); iPoint iOldCell = WorldToCell( vPositionOld.x, vPositionOld.y ); iPoint iNewCell = WorldToCell( vPositionNew.x, vPositionNew.y ); //XGC_DEBUG_CODE( CMapBlock *pArea = GetBlock(x,y); if( pArea ) XGC_ASSERT_MSG( pArea->CheckExist(pObj->GetObjID()), "发现飞机。" ); ) iPoint iOldArea = WorldToArea( vPositionOld.x, vPositionOld.y ); iPoint iNewArea = WorldToArea( vPositionNew.x, vPositionNew.y ); pObject->OnTeleport( 0, vPositionNew, lpContext ); ExchangeBlock( pObject, iOldCell, iPoint( -1, -1 ) ); ExchangeArea( pObject, iOldArea, iSize( -1, -1 ), mMapConf.mEyesight ); pObject->OnTeleport( 1, vPositionNew, lpContext ); pObject->SetPosition( vPositionNew ); //设置新位置 ExchangeBlock( pObject, iPoint( -1, -1 ), iNewCell ); ExchangeArea( pObject, iSize( -1, -1 ), iNewArea, mMapConf.mEyesight ); pObject->OnTeleport( 2, vPositionOld, lpContext ); return ret; }
bool MakeBitFont(const iStringT& face_name, sint32 siz, LONG style, const iStringT& fname) { iStringT pngName = fname+_T(".png"); printf("%s (%s) : ",face_name.CStr(),fname.CStr()); /* if (iFile::Exists(pngName)){ printf("Already exists. Skiped...\n"); return false; }*/ HFONT hFont = CreateFont(siz,0,0,0, style, FALSE, FALSE, FALSE, RUSSIAN_CHARSET, OUT_RASTER_PRECIS, CLIP_STROKE_PRECIS, NONANTIALIASED_QUALITY, DEFAULT_PITCH, face_name.CStr()); iMemoryDC memDC(iSize(4096,128)); memDC.SetFont(hFont); // calculate widths for whole table int *fntW = new int[0xFFFF]; if (!GetCharWidth32(memDC,0,0xFFFF,fntW)) { printf("Error: 0x%X\n",GetLastError()); return false; } // calculate total width of all required characters int tw=0; for (uint32 cc=0; cc<CHS_COUNT; ++cc) { for (uint32 xx=CHARSET_TABLES[cc][0]; xx<=CHARSET_TABLES[cc][1]; ++xx) tw += (fntW[xx]); } // Prepare text metrics and dib TEXTMETRIC tm; GetTextMetrics(memDC,&tm); memDC.Resize(iSize(tw,tm.tmHeight+3)); memDC.m_Dib.Fill(cColorBlack, BLEND_SRCCOPY); memDC.SetFont(hFont); memDC.SetTextBkMode(TRANSPARENT); int px=0; for (cc=0; cc<CHS_COUNT; ++cc) { for (uint32 xx=CHARSET_TABLES[cc][0]; xx<=CHARSET_TABLES[cc][1]; ++xx) { ComposeCharacter(memDC, xx, px, fntW[xx]); px += (fntW[xx]); } } iDibColorChannel::FillChannel(memDC.m_Dib, Channel_Alpha, 0xFF); if (!iDibSaver::SavePNG(memDC.m_Dib,pngName)){ printf("Error! Unable to save png file!\n"); return false; } printf("Done!\n"); return true; }
iSize iMLInfoDlg::ClientSize() const { sint32 w = 130; if (m_text.Length() > 20) w += iCLAMP<sint32>(0,70,m_text.Length()/4); sint32 h = 0; // title if (!m_title.Empty()) { iSize s = gTextComposer.GetTextBoxSize(m_title, w, dlgfc_hdr); h += s.h; h += 10; } // text if (!m_text.Empty()) { iSize s = gTextComposer.GetTextBoxSize(m_text, w, dlgfc_plain); h += s.h; h += 10; } // icon if (!m_text.Empty()) { h += 50; } // ok button h += DEF_BTN_HEIGHT; return iSize(w, h); }
/* * Hero Child */ iHeroChild::iHeroChild(iViewMgr* pViewMgr, IViewCmdHandler* pCmdHandler, iSimpleArray<iArtDragDropItem*>& competitors, const iPoint& pos) : iView(pViewMgr, iRect(pos.x, pos.y, 320, 109), GENERIC_VIEWPORT, 200, Enabled | Visible), m_pHero(NULL), m_pFriend(NULL) { AddChild(m_pPortrait = new iHeroBigPortBtn(pViewMgr, this, iRect(3,20,48,48), 201)); AddChild(m_pArtBackPackCtrl = new iArtBackPackCtrl(competitors, pViewMgr, this, iPoint(55,20+18), iSize(32,30), 7, iArtBackPackCtrl::Horizontal, 120)); AddChild(m_pSplitBtn = new iCheckButton(pViewMgr, this, iRect(m_Rect.w-23,m_Rect.h-38,20,36), PDGG_BTN_SPLIT, 140)); AddChild(m_pArmyList = new iArmyListEx(pViewMgr,this,iPoint(3,53+18), m_pSplitBtn, iSize(41,36),110)); }
// 移动对象 void XUI_Wnd::MoveWindow( int left, int top, int right, int bottom, bool notify ) { m_WindowPosition = iPoint( left, top ); m_WindowSize = iSize( abs(right - left), abs(bottom - top) ); if( notify ) { // 发送位置变更消息 OnMoveWindow( iRect( left, top, right, bottom ) ); } }
bool iDisplay::Init(HWND hwnd, const iSize& siz, uint32 flags) { check(!m_bInited); m_Flags = flags; m_hWnd = hwnd; if ( (m_Flags & GXLF_LANDSCAPE) && !(m_Flags & GXLF_DEV_LANDSCAPE)) m_Siz = iSize(siz.h,siz.w); else m_Siz = siz; m_BackBuff.Init(m_Siz,iDib::RGB); return m_bInited = true; }
bool iComposer::InitComposer(iMapHandler* pmap) { m_pMap=pmap; iDibLoader::LoadPng(m_dibSelCell,GetAppPath()+_T("cell_sel.png")); iDibLoader::LoadPng(m_dibSelNode,GetAppPath()+_T("node_sel.png")); iDibLoader::LoadPng(m_dibGrid,GetAppPath()+_T("cell_grid.png")); iDibLoader::LoadPng(m_dibRedCell,GetAppPath()+_T("cell_red.png")); iDibLoader::LoadPng(m_dibYelCell,GetAppPath()+_T("cell_yel.png")); m_ComposeMemDC.InitDC(iSize(100,100)); return true; }
iSize iDlg_TownList::ClientSize() const { sint32 w = 200; sint32 h = 0; // title h += 20; // town list h += 5+130+5; // buttons h += DEF_BTN_HEIGHT; return iSize(w,h); }
void iDangerMap::UpdateDangerMap() { iTimer timer; // Reset danger map m_dangerMap.ZeroMem(0xFF); // Prepare actors list m_enActors.RemoveAll(); for (iGameWorld::iPLIt pit = gGame.Map().m_Players.First(); pit != gGame.Map().m_Players.End(); ++pit) { if ((*pit)->PlayerId() == m_owner) continue; for (iPlayer::iHLIt hit = (*pit)->HeroFirst(); hit != (*pit)->HeroEnd(); ++hit) { m_enActors.Add(*hit); } } // No enemy heroes, so no danger if (!m_enActors.GetSize()) return; // Make danger map for (uint32 actorId = 0; actorId < m_enActors.GetSize(); ++actorId) { // Prepare pass map iDistMapProcessor hdm(iSize(gGame.Map().m_PassMap.GetWidth(),gGame.Map().m_PassMap.GetHeight())); hdm.MakeDistMap(m_enActors[actorId]->Pos(), m_enActors[actorId]->Army().ArmyPower(), m_enActors[actorId]->MoveCostBonus(), m_enActors[actorId]->Owner()->PlayerId(), m_enActors[actorId]->TotalMoves()); iDistMapProcessor::iMark* pMark = hdm.m_distMap.GetPtr(); uint8* pDanger = m_dangerMap.GetPtr(); sint32 count = m_dangerMap.GetWidth() * m_dangerMap.GetHeight(); while (count--) { if (pMark->move != 0x3FFF || pMark->touch != 0x3FFF) { if ( *pDanger == 0xFF || m_enActors[actorId]->Army().ArmyPower() > m_enActors[*pDanger]->Army().ArmyPower()) { *pDanger = (uint8)actorId; } } pDanger++; pMark++; } } // Prepare danger enemy heroes list iPlayer* pOwner = gGame.Map().FindPlayer(m_owner); check(pOwner); for (iPlayer::iCtLIt cit = pOwner->CastleFirst(); cit != pOwner->CastleEnd(); ++cit) { uint8 eidx = m_dangerMap.GetAt((*cit)->Pos().x, (*cit)->Pos().y); if (eidx != 0xFF) { m_danActors.Add(m_enActors[eidx]); } } }
iSize iDlg_RiseSkeletons::ClientSize() const { sint32 w = 150; sint32 h = 0; // title h += 20; // text h += gTextComposer.GetTextBoxSize(iFormat(gTextMgr[TRID_MSG_RISE_SKELETONS], m_quant, gTextMgr[TRID_CREATURE_PEASANT_F3+m_ct*3]), w, dlgfc_splain).h; h += 5; // icon and quantity h += 42; // button h += DEF_BTN_HEIGHT + 10; return iSize(w,h); }
iSize iDlg_LeaveGuards::ClientSize() const { sint32 w = 280; sint32 h = 0; // title h += 15; // Construction's army list h += 40; // Hero's army list h += 42; // buttons h += DEF_BTN_HEIGHT; return iSize(w,h); }
iSize iDlg_CreatInfo::ClientSize() const { sint32 w = 150; sint32 h = 0; // title h += 15; // icon h += 45; // perks if (CREAT_DESC[m_cGroup.Type()].perks != CPERK_NONE) h += 15; // characteristics h += 8*10+10; // buttons h += DEF_BTN_HEIGHT; return iSize(w,h); }
iSize ClientSize() const { sint32 w = 155; sint32 h = 0; // title h += 20; // perks for (uint32 nn=0; nn<m_perks.GetSize(); ++nn) { h += gTextComposer.GetTextBoxSize(gTextMgr[TRID_CPERK_DOUBLESHOT+m_perks[nn]], 120, dlgfc_plain).h; h += 8; } // ok button h += DEF_BTN_HEIGHT; return iSize(w,h); }
void ComposeShadow(const iDib& src, iDib& dst, const iPoint& pos) { uint32 nh = (src.GetHeight()+1) / 2; uint32 nw = src.GetWidth() + nh; iDib sdib(iSize(nw,nh)); for (sint32 yy = 0; yy<(sint32)src.GetHeight(); yy+=2){ sint32 ny = yy/2; iColor* pDst = sdib.GetLine(ny) + ny; const iColor* pSrc = src.GetLine(yy); for (uint32 xx=0; xx<src.GetWidth(); ++xx){ if (pSrc->GetA()) { pDst->SetA(64); } pDst++; pSrc++; } } sdib.CopyToDibXY(&dst,iPoint(pos.x-nh,pos.y+nh),BLEND_ALPHABLEND); }
void iMinimapView::Compose(HDC hdc) { iRect clRect = iWMetrics::GetClRect(m_hWnd); m_outBuff.m_Dib.Fill(cColorBlack); if (m_pMap) { iRect frc(Screen2Map(m_frameLT, m_pMap->GetWidth()), Screen2Map(m_frameRB, m_pMap->GetWidth())); if (m_dibMap.GetWidth() > clRect.w || m_dibMap.GetHeight() > clRect.h){ uint32 factor = iMAX<uint32>(m_dibMap.GetWidth()/clRect.w, m_dibMap.GetHeight()/clRect.h )+1; iDib ndib(iSize(m_dibMap.GetWidth()/factor,m_dibMap.GetHeight()/factor)); iDibTransformer::Stretch(m_dibMap, ndib, iDibTransformer::Pyramidal); iPoint offset(clRect.w/2 - ndib.GetSize().w/2, clRect.h/2 - ndib.GetSize().h/2); ndib.CopyToDibXY(&m_outBuff.m_Dib, offset, BLEND_ALPHABLEND); frc.x /= factor; frc.y /= factor; frc.w /= factor; frc.h /= factor; frc.Move(offset.x, offset.y); } else { uint32 factor = iMIN<uint32>(clRect.w / m_dibMap.GetWidth(), clRect.h / m_dibMap.GetHeight()); if (factor > 1) { iDib ndib(m_dibMap); iDibTransformer::MultiplySize(ndib, factor); iPoint offset(clRect.w/2 - ndib.GetSize().w/2, clRect.h/2 - ndib.GetSize().h/2); ndib.CopyToDibXY(&m_outBuff.m_Dib, offset, BLEND_ALPHABLEND); frc.x *= factor; frc.y *= factor; frc.w *= factor; frc.h *= factor; frc.Move(offset.x, offset.y); } else { iPoint offset(clRect.w/2 - m_dibMap.GetSize().w/2, clRect.h/2 - m_dibMap.GetSize().h/2); m_dibMap.CopyToDibXY(&m_outBuff.m_Dib, offset, BLEND_ALPHABLEND); frc.Move(offset.x, offset.y); } } iDibPrimitives::DrawFrame(m_outBuff.m_Dib, frc, iColor(255,255,0,255), BLEND_SRCCOPY); } ::BitBlt(hdc,0,0, clRect.w,clRect.h,m_outBuff,0,0,SRCCOPY); }
iSize iDlg_ArtInfo::ClientSize() const { sint32 w = 150; sint32 h = 0; // title h += gTextComposer.GetTextBoxSize(gTextMgr[gGame.ItemMgr().m_artMgr[m_artId].NameKey(m_pOwner)], w-10, dlgfc_topic).h +5; // description h += gTextComposer.GetTextBoxSize(gTextMgr[gGame.ItemMgr().m_artMgr[m_artId].DescKey(m_pOwner)], w-10, dlgfc_plain).h + 5; // requirements if (!m_reqMsg.Empty()) h += gTextComposer.GetTextBoxSize(m_reqMsg, w-10, m_fcReqMsg).h; // icon h += gGfxMgr.Dimension(gGame.ItemMgr().m_artMgr[m_artId].Sprite()).h + 10; // ok button h += DEF_BTN_HEIGHT + 10; return iSize(w,h); }
iSize iScenPropsDlg::ClientSize() const { return iSize(270,150 + DEF_BTN_HEIGHT); }
void iArmyListEx::BeginDrag(sint8 fromCell, iCreatGroup& cGroup, const iPoint& pos) { check(!m_pDragItem); m_pDragItem = new iDragItem(this, fromCell, (m_bSplit || (m_pSplitBtn && m_pSplitBtn->IsChecked())), cGroup, pos, iSize(m_itemW,m_Rect.h), m_bCanDismiss || m_pArmy->GroupCount() > 1); m_pMgr->SetDragGlyph(m_pDragItem); Drag(pos); }
iSize iDlg_BattleLog::ClientSize() const { return iSize(260,165 + DEF_BTN_HEIGHT); }
iSize iDlg_HallOfFame::ClientSize() const { return iSize(280,180 + DEF_BTN_HEIGHT); }
void iDlg_LeaveGuards::OnCreateDlg() { iRect clRect = ClientRect(); AddChild(m_pSplitBtn = new iCheckButton(m_pMgr, this, iRect(clRect.x+5+36*7,clRect.y+20,18,34*2+1), PDGG_BTN_SPLIT, 103)); AddChild(m_pCnstArmyList = new iArmyListEx(m_pMgr,this,iPoint(clRect.x+5,clRect.y+20),m_pSplitBtn, iSize(35,34),101)); m_pCnstArmyList->SetArmy(&m_pOwnCnst->Guard(), NULL, true); AddChild(m_pHeroArmyList = new iArmyListEx(m_pMgr,this,iPoint(clRect.x+5,clRect.y+55),m_pSplitBtn, iSize(35,34),102)); m_pHeroArmyList->SetArmy(&m_pHero->Army(), m_pHero, false); m_pCnstArmyList->AddCompetitor(m_pHeroArmyList); m_pHeroArmyList->AddCompetitor(m_pCnstArmyList); AddChild(new iTextButton(m_pMgr, this, iRect((clRect.x+clRect.w/2)-20, clRect.y2()-DEF_BTN_HEIGHT, 40, DEF_BTN_HEIGHT), TRID_OK, DRC_OK)); }
iSize iGameMenuDlg::ClientSize() const { return iSize(120,5*DEF_BTN_HEIGHT+3*5+15); }
iSize iSettingsDlg::ClientSize() const { return iSize(280,175 + DEF_BTN_HEIGHT); }
void iMinimapView::ScrollMap(iPoint pos) { pos.x -= 20; pos.y -= 25; SCROLLINFO si; iRect clRect = iWMetrics::GetClRect(this->m_hWnd); //this->ClientToScreen( int left; int width; int top = 0; int height = 100; left = 24; width = 128; top = -8; height = 128; iRect frc(Screen2Map(m_frameLT, m_pMap->GetWidth()), Screen2Map(m_frameRB, m_pMap->GetWidth())); if (m_dibMap.GetWidth() > clRect.w || m_dibMap.GetHeight() > clRect.h){ uint32 factor = iMAX<uint32>(m_dibMap.GetWidth()/clRect.w, m_dibMap.GetHeight()/clRect.h )+1; iDib ndib(iSize(m_dibMap.GetWidth()/factor,m_dibMap.GetHeight()/factor)); iPoint offset(clRect.w/2 - ndib.GetSize().w/2, clRect.h/2 - ndib.GetSize().h/2); frc.x /= factor; frc.y /= factor; frc.w /= factor; frc.h /= factor; frc.Move(offset.x, offset.y); } else { uint32 factor = iMIN<uint32>(clRect.w / m_dibMap.GetWidth(), clRect.h / m_dibMap.GetHeight()); if (factor > 1) { iDib ndib(m_dibMap); iDibTransformer::MultiplySize(ndib, factor); iPoint offset(clRect.w/2 - ndib.GetSize().w/2, clRect.h/2 - ndib.GetSize().h/2); ndib.CopyToDibXY(&m_outBuff.m_Dib, offset, BLEND_ALPHABLEND); frc.x *= factor; frc.y *= factor; frc.w *= factor; frc.h *= factor; frc.Move(offset.x, offset.y); } else { iPoint offset(clRect.w/2 - m_dibMap.GetSize().w/2, clRect.h/2 - m_dibMap.GetSize().h/2); frc.Move(offset.x, offset.y); } } pos.x -= frc.w / 2; pos.y -= frc.h / 2; double hrz = 0, vrt = 0; if(pos.x <= left) hrz = 0.0; else if((unsigned)(pos.x) >= left + width) hrz = 1.0; else hrz = (double)(pos.x - left) / (double)width; if(pos.y <= top) vrt = 0.0; else if((unsigned)(pos.y) >= top + height) vrt = 1.0; else vrt = (double)(pos.y - top) / (double)height; if(pos.y < 0) vrt = 0.0; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_RANGE; m_pMainView->GetScrollInfo(SB_HORZ, &si); m_pMainView->SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, (int)((double)si.nMax * hrz))); si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_RANGE; m_pMainView->GetScrollInfo(SB_VERT, &si); m_pMainView->SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, si.nMax * vrt)); }
iSize ClientSize() const { return gTextComposer.GetTextBoxSize(gTextMgr[TRID_HKEY_PRESS_KEY], 120, dlgfc_topic) + iSize(20,60); }
iSize ClientSize() const { return iSize(170, 20 + BAT_COUNT*(DEF_BTN_HEIGHT+3) + 25); }
iSize GetDlgMetrics() const { return iSize(150,5*(DEF_BTN_HEIGHT+2) + 12); }