예제 #1
0
	SpriteViewer::SpriteViewer()
	{
		PushScopeEnterOnStack scope;

		auto layout = mnew VerticalLayout();
		layout->borderTop = 5;
		layout->expandWidth = true;
		layout->expandHeight = false;
		layout->fitByChildren = true;

		mViewWidget = layout;

		auto commonFieldsLayout = mnew VerticalLayout();
		commonFieldsLayout->spacing = 5;
		commonFieldsLayout->expandWidth = true;
		commonFieldsLayout->expandHeight = false;
		commonFieldsLayout->fitByChildren = true;
		layout->AddChild(commonFieldsLayout);

		const Type& spriteType = TypeOf(Sprite);

		mImageProperty = dynamic_cast<ImageAssetProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "image", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mSizePivotProperty = dynamic_cast<Vec2FProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "szPivot", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mPivotProperty = dynamic_cast<Vec2FProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "pivot", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mColorProperty = dynamic_cast<ColorProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "color", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mAlphaProperty = dynamic_cast<FloatProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "transparency", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mModeProperty = dynamic_cast<EnumProperty*>(
			o2EditorProperties.BuildField(commonFieldsLayout, spriteType, "mode", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		mModeProperty->onChanged += [&](IPropertyField* x) { OnModeSelected(); };

		mHiddenProperties = o2UI.CreateWidget<VerticalLayout>();
		mHiddenProperties->expandWidth = true;
		mHiddenProperties->expandHeight = false;
		mHiddenProperties->fitByChildren = true;
		layout->AddChild(mHiddenProperties);

		// Fill properties
		mFillPropertiesSpoiler = o2UI.CreateWidget<Spoiler>();
		mHiddenProperties->AddChild(mFillPropertiesSpoiler);

		auto fillSpace = mnew Widget();
		fillSpace->layout->minHeight = 5;
		mFillPropertiesSpoiler->AddChildWidget(fillSpace);

		mFillProperty = dynamic_cast<FloatProperty*>(
			o2EditorProperties.BuildField(mFillPropertiesSpoiler, spriteType, "fill", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		// Slice properties
		mSlicedPropertiesSpoiler = o2UI.CreateWidget<Spoiler>();
		mHiddenProperties->AddChild(mSlicedPropertiesSpoiler);

		auto sliceSpace = mnew Widget();
		sliceSpace->layout->minHeight = 5;
		mSlicedPropertiesSpoiler->AddChildWidget(sliceSpace);

		mSliceBorderProperty = dynamic_cast<BorderIProperty*>(
			o2EditorProperties.BuildField(mSlicedPropertiesSpoiler, spriteType, "sliceBorder", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));

		// Slice properties
		mTiledPropertiesSpoiler = o2UI.CreateWidget<Spoiler>();
		mHiddenProperties->AddChild(mTiledPropertiesSpoiler);

		auto tiledSpace = mnew Widget();
		tiledSpace->layout->minHeight = 5;
		mTiledPropertiesSpoiler->AddChildWidget(tiledSpace);

		mTileScaleProperty = dynamic_cast<FloatProperty*>(
			o2EditorProperties.BuildField(mTiledPropertiesSpoiler, spriteType, "tileScale", "", mFieldProperties, mOnChildFieldChangeCompleted, onChanged));
	}
예제 #2
0
CombatSetupWnd::CombatSetupWnd(
    const std::vector<CombatSetupGroup>& setup_groups,
    CombatWnd* combat_wnd,
    const CombatData* combat_data,
    Ogre::SceneManager* scene_manager,
    boost::function<std::pair<bool, Ogre::Vector3> (const GG::Pt& pt)>
    intersect_mouse_with_ecliptic,
    boost::function<const Ogre::MaterialPtr& (const Ship&)>
    get_ship_material,
    boost::function<void (int, Ogre::SceneNode*, Ogre::Entity*, const Ogre::MaterialPtr&)>
    add_ship_node_to_combat_wnd,
    boost::function<Ogre::MovableObject* (const GG::Pt&)>
    get_object_under_pt,
    boost::function<void (int, const Ogre::Vector3&, const Ogre::Quaternion&)>
    reposition_ship_node,
    boost::function<void (int)>
    remove_ship,
    boost::function<void (const Ogre::Vector3&)>
    look_at,
    GG::Flags<GG::WndFlag> flags/* = GG::INTERACTIVE | GG::DRAGABLE*/) :
    CUIWnd("Ships", GG::X(PAD), GG::GUI::GetGUI()->AppHeight() - SETUP_WND_HEIGHT - GG::Y(PAD),
           GG::X(500), SETUP_WND_HEIGHT, flags),
    m_setup_groups(setup_groups),
    m_current_setup_group(m_setup_groups.size()),
    m_setup_finished_waiting_for_server(false),
    m_dragging_placed_ship(false),
    m_button_press_on_placed_ship(INVALID_PRESS_POS),
    m_button_press_placed_ship_node(0),
    m_mouse_dragged(false),
    m_listbox(new CUIListBox(GG::X0, GG::Y0, GG::X1, GG::Y1)),
    m_redo_placements_button(new CUIButton(GG::X0, GG::Y1, GG::X1, UserString("REDO_PLACEMENTS"))),
    m_auto_place_button(new CUIButton(GG::X0, GG::Y(2), GG::X1, UserString("AUTO_PLACE_SHIPS"))),
    m_done_button(new CUIButton(GG::X0, GG::Y(3), GG::X1, UserString("DONE"))),
    m_selected_placeable_ship(0),
    m_placeable_ship_node(0),
    m_scene_manager(scene_manager),
    m_combat_universe(combat_data->m_combat_universe),
    m_intersect_mouse_with_ecliptic(intersect_mouse_with_ecliptic),
    m_get_ship_material(get_ship_material),
    m_add_ship_node_to_combat_wnd(add_ship_node_to_combat_wnd),
    m_get_object_under_pt(get_object_under_pt),
    m_reposition_ship_node(reposition_ship_node),
    m_remove_ship(remove_ship),
    m_look_at(look_at)
{
    m_listbox->SetStyle(m_listbox->Style() | GG::LIST_SINGLESEL);
    Connect(m_redo_placements_button->ClickedSignal, &CombatSetupWnd::RedoPlacementsButtonClicked, this);
    Connect(m_auto_place_button->ClickedSignal, &CombatSetupWnd::AutoPlaceButtonClicked, this);
    Connect(m_done_button->ClickedSignal, &CombatSetupWnd::DoneButtonClicked, this);

    GG::Y original_button_height = m_done_button->Height();
    GG::Y original_all_buttons_height = original_button_height * 3;

    AttachChild(m_listbox);
    AttachChild(m_redo_placements_button);
    AttachChild(m_auto_place_button);
    AttachChild(m_done_button);
    VerticalLayout();
    GetLayout()->SetRowStretch(0, Value(Height() - original_all_buttons_height));
    GetLayout()->SetRowStretch(1, Value(original_button_height));
    GetLayout()->SetRowStretch(2, Value(original_button_height));
    GetLayout()->SetRowStretch(3, Value(original_button_height));
    GetLayout()->SetCellMargin(2);

    const GG::Pt row_size = ListRowSize();

    for (PathingEngine::const_iterator it = combat_data->m_pathing_engine.begin();
            it != combat_data->m_pathing_engine.end();
            ++it) {
        if (CombatShipPtr combat_ship = boost::dynamic_pointer_cast<CombatShip>(*it)) {
            // create scene node
            Ship& ship = combat_ship->GetShip();

            // TODO: Temporary!  Serialization of CombatData currently sends
            // everything to everyone.  Fix this.
            if (!ship.OwnedBy(HumanClientApp::GetApp()->EmpireID()))
                continue;

            Ogre::SceneNode* node = GetShipNode(ship);

            if (combat_ship->position() == OpenSteer::Vec3(0.0, 0.0, 0.0)) {
                UniverseObject* o = m_combat_universe[ship.FleetID()];
                Fleet* fleet = boost::polymorphic_downcast<Fleet*>(o);
                ShipRow* row = new ShipRow(&ship, fleet, row_size.x, row_size.y);
                m_listbox->Insert(row);
            } else {
                node->setPosition(ToOgre(combat_ship->position()));
                node->setOrientation(Ogre::Quaternion(ToOgre(combat_ship->side()),
                                                      ToOgre(combat_ship->forward()),
                                                      ToOgre(combat_ship->up())));
                PlaceShip(&ship, node);
                node->setVisible(true);
            }
        }
    }

    m_redo_placements_button->Disable(m_placed_nodes.empty());
    m_auto_place_button->Disable(m_listbox->Empty());
    m_done_button->Disable(!m_listbox->Empty());

    GG::Connect(m_listbox->SelChangedSignal, &CombatSetupWnd::PlaceableShipSelected_, this);

    combat_wnd->InstallEventFilter(this);
}