Exemple #1
0
void FleetButton::SizeMove(const GG::Pt& ul, const GG::Pt& lr) {
    GG::Pt sz = Size();

    Button::SizeMove(ul, lr);

    if (sz == Size())
        return;

    LayoutIcons();
}
Exemple #2
0
void FleetButton::SetSelected(bool selected) {
    m_selected = selected;

    if (!m_selected) {
        DetachChild(m_selection_indicator);
        m_selection_indicator->Hide();
        return;
    }

    AttachChild(m_selection_indicator);
    m_selection_indicator->Show();
    MoveChildDown(m_selection_indicator);
    LayoutIcons();
}
void CGuiHandler::DrawButtons()
{
	glDisable(GL_DEPTH_TEST);
	if(needShift && !keys[SDLK_LSHIFT]){
		if(showingMetal){
			showingMetal=false;
			groundDrawer->SetExtraTexture(0,0,false);
		}
		inCommand=-1;
		needShift=false;
	}

	if (selectedUnits.CommandsChanged()) {LayoutIcons();fadein=100;}
	else if (fadein>0) fadein-=5;

	int mouseIcon=IconAtPos(mouse->lastx,mouse->lasty);

	GLfloat x1,x2,y1,y2;
	GLfloat scalef;


	// Rita "container"ruta
	if (total_active_icons > 0) {
		
		glDisable(GL_TEXTURE_2D);
		glColor4f(0.2f,0.2f,0.2f,0.4f);
		glBegin(GL_QUADS);

		GLfloat fx = 0;//-.2f*(1-fadein/100.0)+.2f;
		glVertex2f(buttonBox.x1-fx, buttonBox.y1);
		glVertex2f(buttonBox.x1-fx, buttonBox.y2);
		glVertex2f(buttonBox.x2-fx, buttonBox.y2);
		glVertex2f(buttonBox.x2-fx, buttonBox.y1);
		glVertex2f(buttonBox.x1-fx, buttonBox.y1);

		glEnd();
	}
	
	// För varje knapp (rita den)
	int buttonStart=max(0,(int)(min(activePage*NUMICOPAGE,(int)total_active_icons)));
	int buttonEnd=max(0,int(min((activePage+1)*NUMICOPAGE,(int)total_active_icons)));

	for(unsigned int nr=buttonStart;nr<buttonEnd;nr++) {

		if(commands[nr].onlyKey)
			continue;
		x1 = curricon[nr].x1;
		y1 = curricon[nr].y1;
		x2 = curricon[nr].x2;
		y2 = curricon[nr].y2;
		
		glDisable(GL_TEXTURE_2D);
		
		if(mouseIcon==nr || nr ==inCommand){
			glBegin(GL_QUADS);

			if(mouse->buttons[SDL_BUTTON_LEFT].pressed)
				glColor4f(0.5,0,0,0.2f);
			else if (nr == inCommand)
				glColor4f(0.5,0,0,0.8f);
			else
				glColor4f(0,0,0.5,0.2f);

			glVertex2f(x1,y1);
			glVertex2f(x2,y1);
			glVertex2f(x2,y2);
			glVertex2f(x1,y2);
			glVertex2f(x1,y1);
			glEnd();
		} 
		//else
		//glBegin(GL_LINE_STRIP);

		// "markerad" (lägg mörkt fält över)
		glEnable(GL_TEXTURE_2D);
		glColor4f(1,1,1,0.8f);

		if(UnitDef *ud = unitDefHandler->GetUnitByName(commands[nr].name))
		{
			// unitikon
			glBindTexture(GL_TEXTURE_2D, unitDefHandler->GetUnitImage(ud));
			glBegin(GL_QUADS);
			glTexCoord2f(0,0);
			glVertex2f(x1,y1);
			glTexCoord2f(1,0); 
			glVertex2f(x2,y1);
			glTexCoord2f(1,1);
			glVertex2f(x2,y2);
			glTexCoord2f(0,1);
			glVertex2f(x1,y2);
			glEnd();
			if(!commands[nr].params.empty()){			//skriv texten i första param ovanpå
				string toPrint=commands[nr].params[0];

				if (toPrint.length() > 6) 
					scalef = toPrint.length()/4.0;
				else 
					scalef = 6.0/4.0;
				
				glTranslatef(x1+.004f,y1-.039f,0.0f);
				glScalef(0.02f/scalef,0.03f/scalef,0.1f);
				font->glPrint("%s",toPrint.c_str()); 
			}
		}
		else {
			if (iconmap.find(curricon[nr].id) != iconmap.end() && iconmap[curricon[nr].id].has_bitmap) {
				// Bitmapikon
				glBindTexture(GL_TEXTURE_2D, iconmap[curricon[nr].id].texture);
				glBegin(GL_QUADS);
				glTexCoord2f(0,0);
				glVertex2f(x1,y1);
				glTexCoord2f(1,0); 
				glVertex2f(x2,y1);
				glTexCoord2f(1,1);
				glVertex2f(x2,y2);
				glTexCoord2f(0,1);
				glVertex2f(x1,y2);
				glEnd();
			}
			// skriv text
			string toPrint=commands[nr].name;
			if(commands[nr].type==CMDTYPE_ICON_MODE && (atoi(commands[nr].params[0].c_str())+1)<commands[nr].params.size()){
				toPrint=commands[nr].params[atoi(commands[nr].params[0].c_str())+1];
			}

			if (toPrint.length() > 6) 
				scalef = toPrint.length()/4.0;
			else 
				scalef = 6.0/4.0;
			
		  glTranslatef(x1+.004f,y1-.039f,0.0f);
			glScalef(0.02f/scalef,0.03f/scalef,0.1f);
			font->glPrint("%s",toPrint.c_str()); 
		}

		glLoadIdentity();
	}
	if (total_active_icons > 0) {
		glColor4f(1,1,1,0.6f);
		if(selectedUnits.selectedGroup!=-1){
			font->glPrintAt(0.02,0.13,0.6,"Group %i selected ",selectedUnits.selectedGroup); 
		} else {
			font->glPrintAt(0.02,0.13,0.6,"Selected units %i",selectedUnits.selectedUnits.size()); 
		}
	}
	if(GetReceiverAt(mouse->lastx,mouse->lasty)){
			mouse->cursorText="";
	} else {
		if(inCommand>=0 && inCommand<commands.size()){
			mouse->cursorText=commands[guihandler->inCommand].name;
		} else {
			int defcmd;
			if(mouse->buttons[SDL_BUTTON_RIGHT].pressed && mouse->activeReceiver==this)
				defcmd=defaultCmdMemory;
			else
				defcmd=GetDefaultCommand(mouse->lastx,mouse->lasty);
			if(defcmd>=0 && defcmd<commands.size())
				mouse->cursorText=commands[defcmd].name;
			else
				mouse->cursorText="";
		}
	}
}
Exemple #4
0
void FleetButton::Init(const std::vector<int>& fleet_IDs, SizeType size_type) {
    //std::cout << "FleetButton::Init" << std::endl;

    // get fleets
    std::vector<TemporaryPtr<const Fleet> > fleets;
    for (std::vector<int>::const_iterator it = fleet_IDs.begin(); it != fleet_IDs.end(); ++it) {
        TemporaryPtr<const Fleet> fleet = GetFleet(*it);
        if (!fleet) {
            ErrorLogger() << "FleetButton::FleetButton couldn't get fleet with id " << *it;
            continue;
        }
        m_fleets.push_back(*it);
        fleets.push_back(fleet);
    }

    // determine owner(s) of fleet(s).  Only care whether or not there is more than one owner, as owner
    // is used to determine colouration
    int owner_id = ALL_EMPIRES;
    int multiple_owners = false;
    if (fleets.empty()) {
        // leave as ALL_EMPIRES
    } else if (fleets.size() == 1) {
        owner_id = (*fleets.begin())->Owner();
    } else {
        owner_id = (*fleets.begin())->Owner();
        // use ALL_EMPIRES if there are multiple owners (including no owner and an owner)
        for (std::vector<TemporaryPtr<const Fleet> >::const_iterator it = fleets.begin(); it != fleets.end(); ++it) {
            TemporaryPtr<const Fleet> fleet = *it;
            if (fleet->Owner() != owner_id) {
                owner_id = ALL_EMPIRES;
                multiple_owners = true;
                break;
            }
        }
    }


    // get fleet colour
    if (multiple_owners) {
        SetColor(GG::CLR_WHITE);
    } else if (owner_id == ALL_EMPIRES) {
        // all ships owned by now empire
        bool monsters = true;
        // find if any ship in fleets in button is not a monster
        for (std::vector<TemporaryPtr<const Fleet> >::const_iterator it = fleets.begin(); it != fleets.end(); ++it) {
            TemporaryPtr<const Fleet> fleet = *it;
            for (std::set<int>::const_iterator ship_it = fleet->ShipIDs().begin();
                    ship_it != fleet->ShipIDs().end(); ++ship_it)
            {
                if (TemporaryPtr<const Ship> ship = GetShip(*ship_it)) {
                    if (!ship->IsMonster()) {
                        monsters = false;
                        break;
                    }
                }
            }
        }

        if (monsters)
            SetColor(GG::CLR_RED);
        else
            SetColor(GG::CLR_WHITE);
    } else {
        // single empire owner
        if (const Empire* empire = GetEmpire(owner_id))
            SetColor(empire->Color());
        else
            SetColor(GG::CLR_GRAY); // should never be necessary... but just in case
    }


    // determine direction button should be rotated to orient along a starlane
    GLfloat pointing_angle = 0.0f;

    TemporaryPtr<const Fleet> first_fleet;
    if (!m_fleets.empty())
        first_fleet = *fleets.begin();
    if (first_fleet && first_fleet->SystemID() == INVALID_OBJECT_ID && first_fleet->NextSystemID() != INVALID_OBJECT_ID) {
        int next_sys_id = first_fleet->NextSystemID();
        if (TemporaryPtr<const UniverseObject> obj = GetUniverseObject(next_sys_id)) {
            // fleet is not in a system and has a valid next destination, so can orient it in that direction
            // fleet icons might not appear on the screen in the exact place corresponding to their
            // actual universe position, but if they're moving along a starlane, this code will assume
            // their apparent position will only be different from their true position in a direction
            // parallel with the starlane, so the direction from their true position to their destination
            // position can be used to get a direction vector to orient the icon
            float dest_x = obj->X(), dest_y = obj->Y();
            float cur_x = first_fleet->X(), cur_y = first_fleet->Y();
            const MapWnd* map_wnd = ClientUI::GetClientUI()->GetMapWnd();
            GG::Pt dest = map_wnd->ScreenCoordsFromUniversePosition(dest_x, dest_y);
            GG::Pt cur = map_wnd->ScreenCoordsFromUniversePosition(cur_x, cur_y);
            GG::Pt direction_vector = dest - cur;

            if (direction_vector.x != GG::X0 || direction_vector.y != GG::Y0)
                pointing_angle = 360.0f / TWO_PI * std::atan2(static_cast<float>(Value(direction_vector.y)), static_cast<float>(Value(direction_vector.x))) + 90;
        }
    }


    // select icon(s) for fleet(s)
    int num_ships = 0;
    for (std::vector<TemporaryPtr<const Fleet> >::const_iterator it = fleets.begin(); it != fleets.end(); ++it) {
        TemporaryPtr<const Fleet> fleet = *it;
        if (fleet)
            num_ships += fleet->NumShips();
    }
    boost::shared_ptr<GG::Texture> size_texture = FleetSizeIcon(num_ships, size_type);
    std::vector<boost::shared_ptr<GG::Texture> > head_textures = FleetHeadIcons(fleets, size_type);


    // add RotatingGraphics for all icons needed
    if (size_texture) {
        RotatingGraphic* icon = new RotatingGraphic(size_texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE);
        icon->SetPhaseOffset(pointing_angle);
        icon->SetRPM(0.0f);
        icon->SetColor(this->Color());
        m_icons.push_back(icon);
        Resize(GG::Pt(size_texture->DefaultWidth(), size_texture->DefaultHeight()));
        AttachChild(icon);
    }

    for (std::vector<boost::shared_ptr<GG::Texture> >::const_iterator it = head_textures.begin();
            it != head_textures.end(); ++it)
    {
        RotatingGraphic* icon = new RotatingGraphic(*it, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE);
        icon->SetPhaseOffset(pointing_angle);
        icon->SetRPM(0.0f);
        icon->SetColor(this->Color());
        m_icons.push_back(icon);
        if (Width() < (*it)->DefaultWidth())
            Resize(GG::Pt((*it)->DefaultWidth(), (*it)->DefaultHeight()));
        AttachChild(icon);
    }

    // set up selection indicator
    m_selection_indicator = new RotatingGraphic(FleetSelectionIndicatorIcon(), GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE);
    m_selection_indicator->SetRPM(ClientUI::SystemSelectionIndicatorRPM());

    LayoutIcons();

    // Scanlines for not currently-visible objects?
    int empire_id = HumanClientApp::GetApp()->EmpireID();
    if (empire_id == ALL_EMPIRES || !GetOptionsDB().Get<bool>("UI.system-fog-of-war"))
        return;

    bool at_least_one_fleet_visible = false;
    for (std::vector<int>::const_iterator it = m_fleets.begin(); it != m_fleets.end(); ++it) {
        if (GetUniverse().GetObjectVisibilityByEmpire(*it, empire_id) >= VIS_BASIC_VISIBILITY) {
            at_least_one_fleet_visible = true;
            break;
        }
    }

    // Create scanline renderer control
    m_scanline_control = new ScanlineControl(GG::X0, GG::Y0, Width(), Height());

    if (!at_least_one_fleet_visible)
        AttachChild(m_scanline_control);
}