コード例 #1
0
    virtual bool EventFilter(GG::Wnd*, const GG::WndEvent& event)
        {
            bool retval = false;
            if (event.Type() == GG::WndEvent::MouseEnter) {
                // TODO set cursor to edit_number_t::scrubby_cursor()
                retval = true;
            } else if (event.Type() == GG::WndEvent::MouseLeave) {
                // TODO set cursor to original
                retval = true;
            } else if (event.Type() == GG::WndEvent::LDrag) {
                GG::Pt point = event.Point();
                GG::Y delta(m_data.last_point_m.y - point.y);

                if (m_data.last_point_m.y != 0 && delta != 0)
                {
                    modifiers_t modifiers(modifier_state());

                    if (modifiers & modifiers_any_shift_s)
                        delta *= 10;

                    m_data.increment_n(Value(delta));
                }

                m_data.last_point_m = point;
                retval = true;
            } else if (event.Type() == GG::WndEvent::LButtonDown) {
                m_data.last_point_m = GG::Pt();
                retval = true;
            }
            return retval;
        }
コード例 #2
0
ファイル: ResourcePanel.cpp プロジェクト: matt474/freeorion
bool ResourcePanel::EventFilter(GG::Wnd* w, const GG::WndEvent& event) {
    if (event.Type() != GG::WndEvent::RClick)
        return false;
    const GG::Pt& pt = event.Point();

    MeterType meter_type = INVALID_METER_TYPE;
    for (const auto& meter_stat : m_meter_stats) {
        if (meter_stat.second.get() == w) {
            meter_type = meter_stat.first;
            break;
        }
    }

    if (meter_type == INVALID_METER_TYPE)
        return false;

    std::string meter_string = boost::lexical_cast<std::string>(meter_type);
    std::string meter_title;
    if (UserStringExists(meter_string))
        meter_title = UserString(meter_string);
    if (meter_title.empty())
        return false;

    bool retval = false;
    auto pedia_zoom_to_article_action = [&meter_string, &retval]() {
        retval = ClientUI::GetClientUI()->ZoomToMeterTypeArticle(meter_string); };

    auto popup = GG::Wnd::Create<CUIPopupMenu>(pt.x, pt.y);
    std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % meter_title);
    popup->AddMenuItem(GG::MenuItem(popup_label, false, false, pedia_zoom_to_article_action));
    popup->Run();

    return retval;
}
コード例 #3
0
ファイル: SpecialsPanel.cpp プロジェクト: MatGB/freeorion
bool SpecialsPanel::EventFilter(GG::Wnd* w, const GG::WndEvent& event) {
    if (event.Type() != GG::WndEvent::RClick)
        return false;
    const GG::Pt& pt = event.Point();

    for (const std::map<std::string, StatisticIcon*>::value_type& entry : m_icons)
    {
        if (entry.second != w)
            continue;

        bool retval = false;
        auto zoom_action = [&entry, &retval]() {
            retval = true;
            ClientUI::GetClientUI()->ZoomToSpecial(entry.first);
        };

        CUIPopupMenu popup(pt.x, pt.y);
        std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % UserString(entry.first));

        popup.AddMenuItem(GG::MenuItem(popup_label, false, false, zoom_action));

        popup.Run();
        return retval;
    }
    return false;
}
コード例 #4
0
ファイル: SpecialsPanel.cpp プロジェクト: adityavs/freeorion
bool SpecialsPanel::EventFilter(GG::Wnd* w, const GG::WndEvent& event) {
    if (event.Type() != GG::WndEvent::RClick)
        return false;
    const GG::Pt& pt = event.Point();

    for (std::map<std::string, StatisticIcon*>::const_iterator it = m_icons.begin();
            it != m_icons.end(); ++it)
    {
        if (it->second != w)
            continue;

        std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % UserString(it->first));

        GG::MenuItem menu_contents;
        menu_contents.next_level.push_back(GG::MenuItem(popup_label, 1, false, false));
        GG::PopupMenu popup(pt.x, pt.y, ClientUI::GetFont(), menu_contents, ClientUI::TextColor(),
                            ClientUI::WndOuterBorderColor(), ClientUI::WndColor(), ClientUI::EditHiliteColor());

        if (!popup.Run() || popup.MenuID() != 1) {
            return false;
            break;
        }

        ClientUI::GetClientUI()->ZoomToSpecial(it->first);
        return true;
    }
    return false;
}
コード例 #5
0
ファイル: PopulationPanel.cpp プロジェクト: Ouaz/freeorion
bool PopulationPanel::EventFilter(GG::Wnd* w, const GG::WndEvent& event) {
    if (event.Type() != GG::WndEvent::RClick)
        return false;
    const GG::Pt& pt = event.Point();

    TemporaryPtr<const PopCenter> pc = GetPopCenter();
    if (!pc)
        return false;

    const std::string& species_name = pc->SpeciesName();
    if (species_name.empty())
        return false;

    if (m_meter_stats[0].second != w)
        return false;

    GG::MenuItem menu_contents;

    std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % UserString(species_name));
    menu_contents.next_level.push_back(GG::MenuItem(popup_label, 1, false, false));
    CUIPopupMenu popup(pt.x, pt.y, menu_contents);

    if (!popup.Run() || popup.MenuID() != 1)
        return false;

    ClientUI::GetClientUI()->ZoomToSpecies(species_name);
    return true;
}
コード例 #6
0
ファイル: DropDownList.cpp プロジェクト: matt474/freeorion
bool ModalListPicker::EventFilter(GG::Wnd* w, const GG::WndEvent& event) {
    if (w != m_lb_wnd.get())
        return false;

    switch (event.Type()) {
    case WndEvent::MouseWheel:
        MouseWheel(event.Point(), -event.WheelMove(), event.ModKeys());
        return true;
    default:
        break;
    };
    return false;
}
コード例 #7
0
ファイル: PopulationPanel.cpp プロジェクト: MatGB/freeorion
bool PopulationPanel::EventFilter(GG::Wnd* w, const GG::WndEvent& event) {
    if (event.Type() != GG::WndEvent::RClick)
        return false;
    const GG::Pt& pt = event.Point();

    MeterType meter_type = INVALID_METER_TYPE;
    for (const std::pair<MeterType, StatisticIcon*>& meter_stat : m_meter_stats) {
        if (meter_stat.second == w) {
            meter_type = meter_stat.first;
            break;
        }
    }
    if (meter_type == INVALID_METER_TYPE)
        return false;

    std::string meter_string = boost::lexical_cast<std::string>(meter_type);
    std::string meter_title;
    if (UserStringExists(meter_string))
        meter_title = UserString(meter_string);

    std::string species_name;
    bool retval = false;

    CUIPopupMenu popup(pt.x, pt.y);
    std::shared_ptr<const PopCenter> pc = GetPopCenter();
    if (meter_type == METER_POPULATION && pc) {
        species_name = pc->SpeciesName();
        if (!species_name.empty()) {
            auto zoom_species_action = [&retval, &species_name]() { retval = ClientUI::GetClientUI()->ZoomToSpecies(species_name); };
            std::string species_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % UserString(species_name));
            popup.AddMenuItem(GG::MenuItem(species_label, false, false, zoom_species_action));
        }
    }

    if (!meter_title.empty()) {
        auto pedia_meter_type_action = [&retval, &meter_string]() { retval = ClientUI::GetClientUI()->ZoomToMeterTypeArticle(meter_string); };
        std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % meter_title);
        popup.AddMenuItem(GG::MenuItem(popup_label, false, false, pedia_meter_type_action));
    }

    popup.Run();
    return retval;
}
コード例 #8
0
bool MultiIconValueIndicator::EventFilter(GG::Wnd* w, const GG::WndEvent& event) {
    if (event.Type() != GG::WndEvent::RClick)
        return false;
    const GG::Pt& pt = event.Point();

    MeterType meter_type = INVALID_METER_TYPE;
    for (unsigned int i = 0; i < m_icons.size(); ++i) {
        try {
            if (m_icons.at(i) == w) {
                meter_type = m_meter_types.at(i).first;
                break;
            }
        } catch(std::out_of_range &e) {
            ErrorLogger() << e.what();
            return false;
        }
    }
    if (meter_type == INVALID_METER_TYPE)
        return false;

    std::string meter_string = boost::lexical_cast<std::string>(meter_type);
    std::string meter_title;
    if (UserStringExists(meter_string))
        meter_title = UserString(meter_string);

    GG::MenuItem menu_contents;
    std::string species_name;

    std::shared_ptr<const PopCenter> pc = GetPopCenter(*m_object_ids.begin());
    if (meter_type == METER_POPULATION && pc && m_object_ids.size() == 1) {
	species_name = pc->SpeciesName();
	if (!species_name.empty()) {
	    std::string species_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % UserString(species_name));
	    menu_contents.next_level.push_back(GG::MenuItem(species_label, 1, false, false));
	}
    }

    if (!meter_title.empty()) {
        std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) %
                                                                meter_title);
        menu_contents.next_level.push_back(GG::MenuItem(popup_label, 2, false, false));
    }

    CUIPopupMenu popup(pt.x, pt.y, menu_contents);

    bool retval = false;

    if (popup.Run()) {
        switch (popup.MenuID()) {
            case 1: {
                retval = ClientUI::GetClientUI()->ZoomToSpecies(species_name);
                break;
            }
            case 2: {
                retval = ClientUI::GetClientUI()->ZoomToMeterTypeArticle(meter_string);
                break;
            }
            default:
                break;
        }
    }

    return retval;
}
コード例 #9
0
ファイル: CombatSetupWnd.cpp プロジェクト: anarsky/freeorion
bool CombatSetupWnd::EventFilter(GG::Wnd* w, const GG::WndEvent& event) {
    // Turn off all event handling to lock down CombatWnd.
    if (m_setup_finished_waiting_for_server)
        return true;

    bool retval = false;
    if (event.Type() == GG::WndEvent::LButtonDown) {
        Ogre::MovableObject* movable_object = 0;
        if (!PlaceableShipNode() && (movable_object = m_get_object_under_pt(event.Point()))) {
            Ogre::SceneNode* node = movable_object->getParentSceneNode();
            if (Ogre::any_cast<Ship*>(&node->getUserAny())) {
                m_button_press_placed_ship_node = node;
                assert(m_button_press_placed_ship_node);
                m_button_press_on_placed_ship = event.Point();
            }
        }
        m_dragging_placed_ship = false;
        m_mouse_dragged = false;
    } else if (event.Type() == GG::WndEvent::LDrag) {
        HandleMouseMoves(event.Point());
        if (m_button_press_placed_ship_node) {
            if (!m_dragging_placed_ship) {
                const int DRAG_THRESHOLD = 5;
                GG::Pt delta = event.Point() - m_button_press_on_placed_ship;
                if (DRAG_THRESHOLD < std::abs(Value(delta.x)) + std::abs(Value(delta.y)))
                    m_dragging_placed_ship = true;
            }
            if (m_dragging_placed_ship) {
                std::pair<bool, Ogre::Vector3> intersection = m_intersect_mouse_with_ecliptic(event.Point());
                Ship* ship = *Ogre::any_cast<Ship*>(&m_button_press_placed_ship_node->getUserAny());
                bool valid_location = intersection.first && ValidPlacement(ship, intersection.second);
                if (valid_location)
                    RepositionShip(ship, m_button_press_placed_ship_node, intersection.second);
            }
        }
        retval = true;
        m_mouse_dragged = true;
    } else if (event.Type() == GG::WndEvent::LButtonUp) {
        m_button_press_placed_ship_node = 0;
        m_mouse_dragged = false;
    } else if (event.Type() == GG::WndEvent::LClick) {
        Ogre::SceneNode* placement_node = PlaceableShipNode();
        bool valid_placement = false;
        if (placement_node) {
            std::pair<bool, Ogre::Vector3> intersection = m_intersect_mouse_with_ecliptic(event.Point());
            Ship* ship = *Ogre::any_cast<Ship*>(&placement_node->getUserAny());
            valid_placement = intersection.first && ValidPlacement(ship, intersection.second);
        }
        if (valid_placement) {
            PlaceCurrentShip();
            retval = true;
        } else if (m_mouse_dragged) {
            retval = true;
        }
        m_button_press_placed_ship_node = 0;
    } else if (event.Type() == GG::WndEvent::RClick) {
        CancelCurrentShipPlacement();
        retval = true;
    } else if (event.Type() == GG::WndEvent::RDoubleClick) {
        retval = true;
    } else if (event.Type() == GG::WndEvent::MouseEnter) {
        HandleMouseMoves(event.Point());
    } else if (event.Type() == GG::WndEvent::MouseHere) {
        HandleMouseMoves(event.Point());
    } else if (event.Type() == GG::WndEvent::MouseLeave) {
        if (Ogre::SceneNode* placement_node = PlaceableShipNode())
            placement_node->setVisible(false);
    }

    return retval;
}