#pragma once

#include "Sample.h"
#include "Character.h"

namespace Urho3D {

class Node;
class Scene;

}

/// Bunion example.
/// This sample demonstrates:
///     - Creating both static and moving physics objects to a scene
///     - Displaying physics debug geometry
///     - Using the Skybox component for setting up an unmoving sky
///     - Saving a scene to a file and loading it to restore a previous state
class Bunion : public Sample
{
    URHO3D_OBJECT(Bunion, Sample);

public:
    /// Construct.
    Bunion(Context* context);

    /// Setup before engine initialization. Modifies the engine parameters.
    void Setup() override;

    /// Setup after engine initialization and before running the main loop.
    void Start() override;

protected:
    /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
    String GetScreenJoystickPatchString() const override { return
        "<patch>"
        "    <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
        "    <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Spawn</replace>"
        "    <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
        "        <element type=\"Text\">"
        "            <attribute name=\"Name\" value=\"MouseButtonBinding\" />"
        "            <attribute name=\"Text\" value=\"LEFT\" />"
        "        </element>"
        "    </add>"
        "    <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
        "    <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Debug</replace>"
        "    <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
        "        <element type=\"Text\">"
        "            <attribute name=\"Name\" value=\"KeyBinding\" />"
        "            <attribute name=\"Text\" value=\"SPACE\" />"
        "        </element>"
        "    </add>"
        "</patch>";
    }

private:
    /// Construct the scene content.
    void CreateScene();

    void CreateInstructions();

    /// Create the player, which is also the camera.
    void CreatePlayer();

    /// Set up a viewport for displaying the scene.
    void SetupViewport();

    /// Subscribe to application-wide logic update and post-render update events.
    void SubscribeToEvents();

    /// Read input and moves the camera.
    void MoveCamera(Input &input, float timeStep);

    /// Spawn a physics object from the camera position.
    void SpawnObject();

    /// Handle the logic update event.
    void HandleUpdate(StringHash eventType, VariantMap& eventData);

    /// Handle input controlling options and menus.
    void HandleMiscInput(Input const &input);

    /// Handle the post-render update event.
    void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);

    void PlaySFX(Node &sourceNode, String const &name, float gain = 1.0f,
                 float frequencyRange = 0.0f);

    /// Flag for drawing debug geometry.
    bool drawDebug_;

    SharedPtr<Node> bunion_;
    SharedPtr<Node> tongue_;
    WeakPtr<Character> character_;
    int tofuEaten_;
};
