string Shapes::toString() const { std::ostringstream sout; sout << "Shape Information" << "\n-----------------\n"; sout << "Type of this:\t" << typeid(this).name() << "\n"; sout << "Type of *this:\t" << typeid(*this).name() << "\n"; sout << "Generic name:\t" << getGenericName() << "\n"; sout << "Description:\t" << getDesripName() << "\n"; sout << "id:\t\t" << myUniqueID << "\n"; // force derived classes to call members sout << "H extent:\t"<< getHorizontalExtend()<< "\n"; sout << "V extent:\t"<< getVerticalExtend()<< "\n"; sout << "Scr area:\t"<< getScreenArea()<< "\n"; sout << "Geo area:\t"<< getArea()<< "\n"; sout << "Scr perimeter:\t"<< getScreenPerimeter()<< "\n"; sout << "Geo perimeter:\t"<< getPerimeter()<< "\n"; return sout.str(); }
void TargetDisplayWindowUpdator::risingMessage( game::Unit* unit, const std::string& text, int style ) { if( unit == NULL ) { Logger::getInstance()->error( "TargetDisplayWindowUpdator::risingMessage() - could not create a message for a null unit" ); return; } std::list< Unit* >::iterator i = std::find( risingMessages.begin(), risingMessages.end(), unit ); if( i == risingMessages.end() ) { float updateDistance = updateItemsInsideDistance * updateItemsInsideDistance; float distance = calculateDistance( unit->getPosition(), game ); if( distance < updateDistance ) { if(unit && unit->getVisualObject() && unit->getVisualObject()->getStormModel()) { IStorm3D_Model *m = unit->getVisualObject()->getStormModel(); Rect rect = getScreenArea(m->GetBoundingBox(), game); // hack: allow rising messages on units with highlight void *p = ((char *)unit) + 1; if(window->setRisingText( p, rect.x, rect.y, rect.w, rect.h, ( distance / updateDistance ), style ) ) { window->setText(p, text ); } risingMessages.push_back( unit ); } } } else { // TODO log a warning message // Logger::getInstance()->Warning( ); } }
void TargetDisplayWindowUpdator::update() { TargetDisplayButtonManager *manager = window->getManager(); // rect tmp = getTargetScreenRect( game ); // window->setRect( 0, tmp.x, tmp.y, tmp.w, tmp.h ); { float updateDistance = itemDistance * itemDistance; std::list< Item* >::iterator it; for( it = itemsToBeUpdated.begin(); it != itemsToBeUpdated.end(); ++it ) { //Point tmp = convertVC3toScreen( (*it)->getPosition(), game ); Item *item = *it; float distance = calculateDistance( item->getPosition(), game ); if( distance < updateDistance ) { if(item && item->getVisualObject() && item->getVisualObject()->getStormModel()) { IStorm3D_Model *m = item->getVisualObject()->getStormModel(); Rect rect = getScreenArea(m->GetBoundingBox(), game); if(window->setRect(item, rect.x, rect.y, rect.w, rect.h, ( distance / updateDistance ), item->getHighlightStyle())) { if(item->hasHighlightText()) window->setText(item, item->getHighlightText()); } if( false ) // items cant have health thus they cant have the health bar window->setSliderValue( item, 1.0f, 1.0f ); } /* if( window->setRect( (*it), tmp.x - 12, tmp.y - 8, 35, 35, (int)( ( distance / updateDistance ) * 100.0f ), (*it)->getStyle() ) ) { if( (*it)->hasStyleText() ) window->setText( (*it), (*it)->getStyleText() ); } */ } } } { float updateDistance = unitDistance * unitDistance; std::list< Unit* >::iterator it; for( it = unitsToBeUpdated.begin(); it != unitsToBeUpdated.end(); ++it ) { //point tmp = convertVC3toScreen( (*it)->getPosition(), game ); float distance = calculateDistance( (*it)->getPosition(), game ); if( distance < updateDistance ) { Unit *unit = *it; if(unit && unit->getVisualObject() && unit->getVisualObject()->getStormModel()) { UnitType *ut = unit->getUnitType(); IStorm3D_Model *m = unit->getVisualObject()->getStormModel(); Rect rect; // two rects, one for highlight and another for target lock rect for(int i = 0; i < 2; i++) { void *p = unit; int style = unit->getHighlightStyle(); float rect_scale = 1.0f; const char *text = NULL; // target lock rect if(i == 1) { int max = unit->getTargetLockCounterMax(); if(unit->getTargetLockCounter() <= 0) { // no target lock continue; } else if(unit->getTargetLockCounter() < max) { style = 5; rect_scale = 2.0f - 1.0f * (unit->getTargetLockCounter() / (float) max); text = NULL; } else { style = 6; rect_scale = 1.0f; text = "gui_target_locked"; } p = ((char *)unit) + 2; } const TargetDisplayButtonManager::ButtonCreator &bc = window->getManager()->getButtonStyle( style ); if(bc.rect_style == 0) { rect = getScreenArea(m->GetBoundingBox(), game); } else if(bc.rect_style == 1) { // unit size based rect // IStorm3D_Scene *scene = game->getGameScene()->getStormScene(); IStorm3D_Camera *cam = scene->GetCamera(); VC3 pos = m->GetPosition() + VC3(0, ut->getSize() * ut->getTargetRectHeightScale(), 0); VC3 pos_screen = VC3(0,0,0); VC3 pos_screen2 = VC3(0,0,0); float rhw = 0; float real_z = 0; bool visible = cam->GetTransformedToScreen(pos, pos_screen, rhw, real_z); if(!visible) continue; pos += cam->GetUpVecReal() * ut->getSize() * 0.5f; visible = cam->GetTransformedToScreen(pos, pos_screen2, rhw, real_z); if(!visible) continue; VC3 diff = pos_screen - pos_screen2; float radius = rect_scale * ut->getTargetRectScale() * sqrtf(diff.x * diff.x + diff.y * diff.y); pos_screen.x *= 1024.0f; pos_screen.y *= 768.0f; rect.x = (int)(pos_screen.x - radius * 1024.0f); rect.y = (int)(pos_screen.y - radius * 768.0f); rect.w = (int)(radius * 1024.0f * 2.0f); rect.h = (int)(radius * 768.0f * 2.0f); } if(window->setRect(p, rect.x, rect.y, rect.w, rect.h, ( distance / updateDistance ), style )) { if(unit->hasHighlightText() ) window->setText(p, unit->getHighlightText() ); if(text) window->setText(p, text ); } window->setSliderValue(p, ( (float)unit->getHP() / (float)unit->getMaxHP() ), unit->getUnitType()->getHealthSliderScale() ); } } } } } { float updateDistance = itemDistance * itemDistance; std::list< Unit* >::iterator it; for( it = risingMessages.begin(); it != risingMessages.end(); ) { Unit *unit = *it; float distance = calculateDistance( unit->getPosition(), game ); if(unit && unit->getVisualObject() && unit->getVisualObject()->getStormModel() && distance < updateDistance) { IStorm3D_Model *m = unit->getVisualObject()->getStormModel(); Rect rect = getScreenArea(m->GetBoundingBox(), game); // hack: allow rising messages on units with highlight void *p = ((char *)unit) + 1; if(window->setRect(p, rect.x, rect.y, rect.w, rect.h, ( distance / updateDistance ), risingMessageStyle )) { /*if(unit->hasHighlightText() ) window->setText(p, unit->getHighlightText() ); */ } } else { // keep rising message visible even if unit was blown up // hack: allow rising messages on units with highlight void *p = ((char *)unit) + 1; window->updateRect(p); } // hack: allow rising messages on units with highlight void *p = ((char *)(*it)) + 1; if( window->hasEnded( p ) == false ) { ++it; } else { std::list< Unit* >::iterator remove = it; ++it; risingMessages.erase( remove ); } } } currentFrame++; if( currentFrame >= removeUnnessary ) { currentFrame = 0; window->removeRest(); } else { window->hideRest(); } if( currentFrame%updateTargets == 0 ) updateUpdatables(); }