CInputReceiver::CInputReceiver(Where w) { if (w == FRONT) GetInputReceivers().push_front(this); else if (w == BACK) GetInputReceivers().push_back(this); }
CInputReceiver::CInputReceiver(Where w) { switch (w) { case FRONT: { GetInputReceivers().push_front(this); break; } case BACK: { GetInputReceivers().push_back(this); break; } } }
void CMouseHandler::MousePress(int x, int y, int button) { if (button > NUM_BUTTONS) return; dir=hide ? camera->forward : camera->CalcPixelDir(x,y); gs->players[gu->myPlayerNum]->currentStats->mouseClicks++; #ifdef NEW_GUI activeButton=button; if(GUIcontroller::MouseDown(x, y, button)) return; #endif if(button==4){ if (guihandler->buildSpacing > 0) guihandler->buildSpacing --; /* CUnit* u; float dist=helper->GuiTraceRay(camera->pos,hide ? camera->forward : camera->CalcPixelDir(x,y),9000,u,20,false); if(dist<8900 && gs->cheatEnabled){ float3 pos=camera->pos+(hide ? camera->forward : camera->CalcPixelDir(x,y))*dist; helper->Explosion(pos,DamageArray()*600,64,0); }/**/ //make network compatible before enabling return; } if(button==5){ guihandler->buildSpacing++; return; } buttons[button].pressed=true; buttons[button].time=gu->gameTime; buttons[button].x=x; buttons[button].y=y; buttons[button].camPos=camera->pos; buttons[button].dir=hide ? camera->forward : camera->CalcPixelDir(x,y); buttons[button].movement=0; activeButton=button; if(inMapDrawer && inMapDrawer->keyPressed){ inMapDrawer->MousePress(x,y,button); return; } if(button==SDL_BUTTON_MIDDLE){ return; } #ifndef NEW_GUI std::deque<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::deque<CInputReceiver*>::iterator ri; for(ri=inputReceivers.begin();ri!=inputReceivers.end();++ri){ if((*ri)->MousePress(x,y,button)){ activeReceiver=*ri; return; } } #endif }
// CALLINFO: // LuaUnsyncedRead::GetCurrentTooltip // CTooltipConsole::Draw --> CMouseHandler::GetCurrentTooltip std::string CMouseHandler::GetCurrentTooltip(void) { std::string s; std::deque<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::deque<CInputReceiver*>::iterator ri; for (ri = inputReceivers.begin(); ri != inputReceivers.end(); ++ri) { CInputReceiver* recv=*ri; if (recv && recv->IsAbove(lastx, lasty)) { s = recv->GetTooltip(lastx, lasty); if (s != "") { return s; } } } const string buildTip = guihandler->GetBuildTooltip(); if (!buildTip.empty()) { return buildTip; } GML_RECMUTEX_LOCK(sel); // GetCurrentTooltip - anti deadlock GML_RECMUTEX_LOCK(quad); // GetCurrentTooltip - called from ToolTipConsole::Draw --> MouseHandler::GetCurrentTooltip const float range = (gu->viewRange * 1.4f); const CUnit* unit = NULL; float udist = helper->GuiTraceRay(camera->pos, dir, range, unit, true); const CFeature* feature = NULL; float fdist = helper->GuiTraceRayFeature(camera->pos, dir, range, feature); if ((udist > (range - 300.0f)) && (fdist > (range - 300.0f)) && (unit == NULL)) { return ""; } if (udist > fdist) { unit = NULL; } else { feature = NULL; } if (unit) { return CTooltipConsole::MakeUnitString(unit); } if (feature) { return CTooltipConsole::MakeFeatureString(feature); } const string selTip = selectedUnits.GetTooltip(); if (selTip != "") { return selTip; } if (udist < (range - 100.0f)) { const float3 pos = camera->pos + (dir * udist); return CTooltipConsole::MakeGroundString(pos); } return ""; }
CInputReceiver* CInputReceiver::GetReceiverAt(int x,int y) { std::deque<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::deque<CInputReceiver*>::iterator ri; for(ri=inputReceivers.begin();ri!=inputReceivers.end();++ri){ if((*ri) && (*ri)->IsAbove(x,y)) return *ri; } return 0; }
void CMouseHandler::MousePress(int x, int y, int button) { if (button > NUM_BUTTONS) return; dir=hide ? camera->forward : camera->CalcPixelDir(x,y); if(!game->gameOver) gs->players[gu->myPlayerNum]->currentStats->mouseClicks++; #ifdef NEW_GUI activeButton=button; if(GUIcontroller::MouseDown(x, y, button)) return; #endif if(button==4){ if (guihandler->buildSpacing > 0) guihandler->buildSpacing --; return; } if(button==5){ guihandler->buildSpacing++; return; } buttons[button].pressed=true; buttons[button].time=gu->gameTime; buttons[button].x=x; buttons[button].y=y; buttons[button].camPos=camera->pos; buttons[button].dir=hide ? camera->forward : camera->CalcPixelDir(x,y); buttons[button].movement=0; activeButton=button; if(inMapDrawer && inMapDrawer->keyPressed){ inMapDrawer->MousePress(x,y,button); return; } if(button==SDL_BUTTON_MIDDLE){ return; } #ifndef NEW_GUI std::deque<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::deque<CInputReceiver*>::iterator ri; for(ri=inputReceivers.begin();ri!=inputReceivers.end();++ri){ if((*ri)->MousePress(x,y,button)){ activeReceiver=*ri; return; } } #endif }
CInputReceiver* CInputReceiver::GetReceiverAt(int x,int y) { std::list<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::list<CInputReceiver*>::iterator ri; for (ri = inputReceivers.begin(); ri != inputReceivers.end(); ++ri) { CInputReceiver* recv = *ri; if (recv && recv->IsAbove(x,y)) { return recv; } } return NULL; }
void CInputReceiver::CollectGarbage() { // erase one NULL element each call (should be enough for now) // called once every sec from CGame::Update std::deque<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::deque<CInputReceiver*>::iterator ri; for(ri=inputReceivers.begin();ri!=inputReceivers.end();++ri){ if (*ri == NULL) { inputReceivers.erase(ri); break; } } }
// CALLINFO: // LuaUnsyncedRead::GetCurrentTooltip // CTooltipConsole::Draw --> CMouseHandler::GetCurrentTooltip std::string CMouseHandler::GetCurrentTooltip() { std::string s; std::list<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::list<CInputReceiver*>::iterator ri; for (ri = inputReceivers.begin(); ri != inputReceivers.end(); ++ri) { CInputReceiver* recv=*ri; if (recv && recv->IsAbove(lastx, lasty)) { s = recv->GetTooltip(lastx, lasty); if (s != "") { return s; } } } const string buildTip = guihandler->GetBuildTooltip(); if (!buildTip.empty()) { return buildTip; } const float range = (globalRendering->viewRange * 1.4f); float dist = 0.0f; CUnit* unit; CFeature* feature; { GML_THRMUTEX_LOCK(unit, GML_DRAW); // GetCurrentTooltip GML_THRMUTEX_LOCK(feat, GML_DRAW); // GetCurrentTooltip dist = TraceRay::GuiTraceRay(camera->pos, dir, range, NULL, unit, feature, true, false, true); if (unit) return CTooltipConsole::MakeUnitString(unit); if (feature) return CTooltipConsole::MakeFeatureString(feature); } const string selTip = selectedUnits.GetTooltip(); if (selTip != "") { return selTip; } if (dist <= range) { const float3 pos = camera->pos + (dir * dist); return CTooltipConsole::MakeGroundString(pos); } return ""; }
CInputReceiver::~CInputReceiver() { if (activeReceiver == this) { activeReceiver = NULL; } std::deque<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::deque<CInputReceiver*>::iterator ri; for(ri=inputReceivers.begin();ri!=inputReceivers.end();++ri){ if(*ri==this){ // we may be deleted while there are still iterators active //inputReceivers.erase(ri); *ri = NULL; break; } } }
std::string CMouseHandler::GetCurrentTooltip(void) { std::deque<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::deque<CInputReceiver*>::iterator ri; for(ri=inputReceivers.begin();ri!=inputReceivers.end();++ri){ if((*ri)->IsAbove(lastx,lasty)){ std::string s=(*ri)->GetTooltip(lastx,lasty); if(s!="") return s; } } std::string s=selectedUnits.GetTooltip(); if(s!="") return s; CUnit* unit=0; float dist=helper->GuiTraceRay(camera->pos,dir,9000,unit,20,false); if(unit){ s=unit->tooltip; char tmp[500]; //sprintf(tmp,"\nHealth %.0f/%.0f \nExperience %.2f Cost %.0f Range %.0f \n\xff\xd3\xdb\xffMetal: \xff\x50\xff\x50%.1f\xff\x90\x90\x90/\xff\xff\x50\x01-%.1f\xff\xd3\xdb\xff Energy: \xff\x50\xff\x50%.1f\xff\x90\x90\x90/\xff\xff\x50\x01-%.1f", // unit->health,unit->maxHealth,unit->experience,unit->metalCost+unit->energyCost/60,unit->maxRange, unit->metalMake, unit->metalUse, unit->energyMake, unit->energyUse); float3 rmp = unit->midPos; sprintf(tmp,"\nHealth %.0f/%.0f \nExperience %.2f Cost %.0f Range %.0f \n\xff\xd3\xdb\xffMetal: \xff\x50\xff\x50%.1f\xff\x90\x90\x90/\xff\xff\x50\x01-%.1f\xff\xd3\xdb\xff Energy: \xff\x50\xff\x50%.1f\xff\x90\x90\x90/\xff\xff\x50\x01-%.1f x:%30.20f y: %30.20f z: %30.20f", unit->health,unit->maxHealth,unit->experience,unit->metalCost+unit->energyCost/60,unit->maxRange, unit->metalMake, unit->metalUse, unit->energyMake, unit->energyUse,rmp.x,rmp.y,rmp.z); s+=tmp; return s; } else { if(dist<8900){ float3 pos=camera->pos+dir*dist; char tmp[500]; CReadMap::TerrainType* tt=&readmap->terrainTypes[readmap->typemap[min(gs->hmapx*gs->hmapy-1,max(0,((int)pos.z/16)*gs->hmapx+((int)pos.x/16)))]]; string ttype=tt->name; sprintf(tmp,"Pos %.0f %.0f Elevation %.0f\nTerrain type: %s\nSpeeds T/K/H/S %.2f %.2f %.2f %.2f\nHardness %.0f Metal %.1f",pos.x,pos.z,pos.y,ttype.c_str(),tt->tankSpeed,tt->kbotSpeed,tt->hoverSpeed,tt->shipSpeed,tt->hardness*mapDamage->mapHardness,readmap->metalMap->getMetalAmount((int)(pos.x/16),(int)(pos.z/16))); return tmp; } else { return ""; } } }
void CMouseHandler::MousePress(int x, int y, int button) { if (button > NUM_BUTTONS) return; camHandler->GetCurrentController().MousePress(x, y, button); dir = hide ? camera->forward : camera->CalcPixelDir(x, y); if (!game->gameOver) playerHandler->Player(gu->myPlayerNum)->currentStats.mouseClicks++; ButtonPressEvt& bp = buttons[button]; bp.chorded = (buttons[SDL_BUTTON_LEFT].pressed || buttons[SDL_BUTTON_RIGHT].pressed); bp.pressed = true; bp.time = gu->gameTime; bp.x = x; bp.y = y; bp.camPos = camera->pos; bp.dir = dir; bp.movement = 0; activeButton = button; if (activeReceiver && activeReceiver->MousePress(x, y, button)) return; if (inMapDrawer && inMapDrawer->IsDrawMode()) { inMapDrawer->MousePress(x, y, button); return; } // limited receivers for MMB if (button == SDL_BUTTON_MIDDLE) { if (!locked) { if (luaInputReceiver != NULL) { if (luaInputReceiver->MousePress(x, y, button)) { activeReceiver = luaInputReceiver; return; } } if ((minimap != NULL) && minimap->FullProxy()) { if (minimap->MousePress(x, y, button)) { activeReceiver = minimap; return; } } } return; } std::list<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::list<CInputReceiver*>::iterator ri; if (!game->hideInterface) { for (ri = inputReceivers.begin(); ri != inputReceivers.end(); ++ri) { CInputReceiver* recv=*ri; if (recv && recv->MousePress(x, y, button)) { if (!activeReceiver) activeReceiver = recv; return; } } } else { if (luaInputReceiver && luaInputReceiver->MousePress(x, y, button)) { if (!activeReceiver) activeReceiver = luaInputReceiver; return; } if (guihandler && guihandler->MousePress(x,y,button)) { if (!activeReceiver) activeReceiver = guihandler; // for default (rmb) commands return; } } }
std::string CMouseHandler::GetCurrentTooltip(void) { std::string s; std::deque<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::deque<CInputReceiver*>::iterator ri; for(ri=inputReceivers.begin();ri!=inputReceivers.end();++ri){ if((*ri) && (*ri)->IsAbove(lastx,lasty)){ s=(*ri)->GetTooltip(lastx,lasty); if(s!="") return s; } } #ifndef NEW_GUI s=guihandler->GetBuildTooltip(); if(s!="") return s; #endif /* NOTE: The code below (up untill "if(unit)...") is exactly the same as some lines in CGuiHandler::GetDefaultCommand(). Perhaps it would be possible to integrate the two, because now a racetray for units and features might be performed twice per frame. */ CUnit* unit=0; CFeature* feature=0; float dist=helper->GuiTraceRay(camera->pos,dir,gu->viewRange*1.4f,unit,20,true); float dist2=helper->GuiTraceRayFeature(camera->pos,dir,gu->viewRange*1.4f,feature); if(dist>gu->viewRange*1.4f-300 && dist2>gu->viewRange*1.4f-300 && unit==0){ return ""; } if(dist>dist2) unit=0; else feature=0; if(unit){ // don't show the tooltip if it's a radar dot if(!gu->spectatingFullView && gs->AllyTeam(unit->team) != gu->myAllyTeam && !loshandler->InLos(unit,gu->myAllyTeam)){ return "Enemy unit"; } // show the player name instead of unit name if it has FBI tag showPlayerName if(unit->unitDef->showPlayerName){ s=gs->players[gs->Team(unit->team)->leader]->playerName.c_str(); } else { s=unit->tooltip; } // don't show the unit health and other info if it has FBI tag hideDamage and isn't on our ally team if(!(!gu->spectatingFullView && unit->unitDef->hideDamage && gs->AllyTeam(unit->team) != gu->myAllyTeam)){ char tmp[500]; sprintf(tmp,"\nHealth %.0f/%.0f",unit->health,unit->maxHealth); s+=tmp; if(unit->unitDef->maxFuel>0){ sprintf(tmp," Fuel %.0f/%.0f",unit->currentFuel,unit->unitDef->maxFuel); s+=tmp; } sprintf(tmp,"\nExperience %.2f Cost %.0f Range %.0f \n\xff\xd3\xdb\xffMetal: \xff\x50\xff\x50%.1f\xff\x90\x90\x90/\xff\xff\x50\x01-%.1f\xff\xd3\xdb\xff Energy: \xff\x50\xff\x50%.1f\xff\x90\x90\x90/\xff\xff\x50\x01-%.1f", unit->experience,unit->metalCost+unit->energyCost/60,unit->maxRange, unit->metalMake, unit->metalUse, unit->energyMake, unit->energyUse); s+=tmp; } if (gs->cheatEnabled) { char buf[32]; SNPRINTF(buf, 32, "\xff\xc0\xc0\xff [TechLevel %i]", unit->unitDef->techLevel); s += buf; } return s; } if(feature){ if(feature->def->description==""){ s="Feature"; } else { s=feature->def->description; } float remainingMetal = feature->RemainingMetal(); float remainingEnergy = feature->RemainingEnergy(); std::string metalColor = remainingMetal > 0 ? "\xff\x50\xff\x50" : "\xff\xff\x50\x01"; std::string energyColor = remainingEnergy > 0 ? "\xff\x50\xff\x50" : "\xff\xff\x50\x01"; char tmp[500]; sprintf(tmp,"\n\xff\xd3\xdb\xffMetal: %s%.0f \xff\xd3\xdb\xff Energy: %s%.0f", metalColor.c_str(), remainingMetal, energyColor.c_str(), remainingEnergy); s+=tmp; return s; } s=selectedUnits.GetTooltip(); if(s!="") return s; if(dist<gu->viewRange*1.4f-100){ float3 pos=camera->pos+dir*dist; char tmp[500]; CReadMap::TerrainType* tt=&readmap->terrainTypes[readmap->typemap[min(gs->hmapx*gs->hmapy-1,max(0,((int)pos.z/16)*gs->hmapx+((int)pos.x/16)))]]; string ttype=tt->name; sprintf(tmp,"Pos %.0f %.0f Elevation %.0f\nTerrain type: %s\nSpeeds T/K/H/S %.2f %.2f %.2f %.2f\nHardness %.0f Metal %.1f",pos.x,pos.z,pos.y,ttype.c_str(),tt->tankSpeed,tt->kbotSpeed,tt->hoverSpeed,tt->shipSpeed,tt->hardness*mapDamage->mapHardness,readmap->metalMap->getMetalAmount((int)(pos.x/16),(int)(pos.z/16))); return tmp; } return ""; }
void CMouseHandler::MousePress(int x, int y, int button) { if (button > NUM_BUTTONS) return; dir=hide ? camera->forward : camera->CalcPixelDir(x,y); if(!game->gameOver) gs->players[gu->myPlayerNum]->currentStats->mouseClicks++; if(button==4){ if (guihandler->buildSpacing > 0) guihandler->buildSpacing --; return; } if(button==5){ guihandler->buildSpacing++; return; } buttons[button].chorded = buttons[SDL_BUTTON_LEFT].pressed || buttons[SDL_BUTTON_RIGHT].pressed; buttons[button].pressed = true; buttons[button].time=gu->gameTime; buttons[button].x=x; buttons[button].y=y; buttons[button].camPos=camera->pos; buttons[button].dir=hide ? camera->forward : camera->CalcPixelDir(x,y); buttons[button].movement=0; activeButton=button; if(inMapDrawer && inMapDrawer->keyPressed){ inMapDrawer->MousePress(x,y,button); return; } if (button==SDL_BUTTON_MIDDLE){ if ((minimap != NULL) && minimap->FullProxy() && !locked) { if (minimap->MousePress(x, y, button)) { activeReceiver = minimap; } } return; } #ifndef NEW_GUI std::deque<CInputReceiver*>& inputReceivers = GetInputReceivers(); std::deque<CInputReceiver*>::iterator ri; if (!game->hideInterface) { for(ri=inputReceivers.begin();ri!=inputReceivers.end();++ri){ if((*ri) && (*ri)->MousePress(x,y,button)){ activeReceiver=*ri; return; } } } else if (guihandler) { if (guihandler->MousePress(x,y,button)) { activeReceiver = guihandler; } } #endif }