void Decoration::parseBoundingQuadSize(const char* modelFileName) { boundingQuadSizeX = 0.0f; boundingQuadSizeY = 0.0f; if(visualObject) { IStorm3D_Model *model = visualObject->getStormModel(); if(model) { const AABB &aabb = model->GetBoundingBox(); boundingQuadSizeX = (aabb.mmax.x - aabb.mmin.x) * .5f; boundingQuadSizeY = (aabb.mmax.z - aabb.mmin.z) * .5f; } } /* // damn this would be ALOT easier with stl :) char xSize[16]; char ySize[16]; memset(xSize, 0, sizeof(xSize)); memset(ySize, 0, sizeof(ySize)); int len = strlen(modelFileName) - 1; int i; for(i = len; i > 0; i--) { if(modelFileName[i] == '_') break; } if(i == 0) { // decoration model file name doesn't have boundaries boundingQuadSizeX = 0.0f; boundingQuadSizeY = 0.0f; return; } i++; // skip _ int a = 0; for(i; i < len; i++) { if((modelFileName[i] == 'x') || (modelFileName[i] == 'X')) break; xSize[a++] = modelFileName[i]; } if(i == len) { // decoration model file name doesn't have Y boundaries boundingQuadSizeX = 0.0f; boundingQuadSizeY = 0.0f; return; } i++; // skip x a = 0; for(i; i < len; i++) { if((modelFileName[i] == '.')) break; ySize[a++] = modelFileName[i]; } boundingQuadSizeX = static_cast<float>(atof(xSize)); boundingQuadSizeY = static_cast<float>(atof(ySize)); */ }
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(); }