summaryrefslogtreecommitdiff
path: root/indra/newview/llquickprefs.cpp
blob: 800aa7abaca21312cb357438d6ca0cbdb7154776 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
 * @file   llquickprefs.cpp
 * @brief  Quick Preferences floater: hover height and bandwidth sliders.
 *
 * Ported from Firestorm Viewer (quickprefs.cpp).
 * Original authors: WoLf Loonie, Zi Ree, Ansariel Hiller @ Second Life.
 *
 * $LicenseInfo:firstyear=2011&license=viewerlgpl$
 * Phoenix Firestorm Viewer Source Code
 * Copyright (C) 2011, WoLf Loonie @ Second Life
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"

#include "llquickprefs.h"

#include "llagent.h"
#include "llsliderctrl.h"
#include "lltextbox.h"
#include "llviewercontrol.h"
#include "llviewerregion.h"
#include "llvoavatar.h"       // for MIN_HOVER_Z / MAX_HOVER_Z
#include "llvoavatarself.h"   // for gAgentAvatarp, isAgentAvatarValid()

// ---------------------------------------------------------------------------
// Constructor / destructor
// ---------------------------------------------------------------------------

LLFloaterQuickPrefs::LLFloaterQuickPrefs(const LLSD& key)
    : LLFloater(key)
    , mAvatarZOffsetSlider(nullptr)
{
}

LLFloaterQuickPrefs::~LLFloaterQuickPrefs()
{
    if (mRegionChangedSlot.connected())
    {
        mRegionChangedSlot.disconnect();
    }
}

// ---------------------------------------------------------------------------
// postBuild – wire up all widgets
// ---------------------------------------------------------------------------

bool LLFloaterQuickPrefs::postBuild()
{
    // ---- Hover height slider ------------------------------------------------
    mAvatarZOffsetSlider = getChild<LLSliderCtrl>("HoverHeightSlider");
    mAvatarZOffsetSlider->setMinValue(MIN_HOVER_Z);
    mAvatarZOffsetSlider->setMaxValue(MAX_HOVER_Z);

    // Live preview while dragging
    mAvatarZOffsetSlider->setCommitCallback(
        boost::bind(&LLFloaterQuickPrefs::onAvatarZOffsetSliderMoved, this));

    // Persist on release or typed entry
    mAvatarZOffsetSlider->setSliderMouseUpCallback(
        boost::bind(&LLFloaterQuickPrefs::onAvatarZOffsetFinalCommit, this));
    mAvatarZOffsetSlider->setSliderEditorCommitCallback(
        boost::bind(&LLFloaterQuickPrefs::onAvatarZOffsetFinalCommit, this));

    // Pull current value from settings
    syncAvatarZOffsetFromPreferenceSetting();

    // Keep slider in sync when something else changes the setting (e.g. RLVa,
    // the Edit Shape floater, or the standalone Hover Height floater).
    if (gSavedPerAccountSettings.getControl("AvatarHoverOffsetZ"))
    {
        gSavedPerAccountSettings.getControl("AvatarHoverOffsetZ")
            ->getCommitSignal()
            ->connect(boost::bind(
                &LLFloaterQuickPrefs::syncAvatarZOffsetFromPreferenceSetting, this));
    }
    else
    {
        LL_WARNS("QuickPrefs") << "Control 'AvatarHoverOffsetZ' not found" << LL_ENDL;
    }

    // Watch for region changes so we can enable/disable the slider
    if (!mRegionChangedSlot.connected())
    {
        mRegionChangedSlot = gAgent.addRegionChangedCallback(
            boost::bind(&LLFloaterQuickPrefs::onRegionChanged, this));
    }
    onRegionChanged();  // evaluate current region immediately

    return true;
}

// ---------------------------------------------------------------------------
// onClose
// ---------------------------------------------------------------------------

void LLFloaterQuickPrefs::onClose(bool app_quitting)
{
    if (mRegionChangedSlot.connected())
    {
        mRegionChangedSlot.disconnect();
    }
    LLFloater::onClose(app_quitting);
}

// ---------------------------------------------------------------------------
// Hover height callbacks
// ---------------------------------------------------------------------------

void LLFloaterQuickPrefs::onAvatarZOffsetSliderMoved()
{
    F32 value = mAvatarZOffsetSlider->getValueF32();
    LLVector3 offset(0.0f, 0.0f, llclamp(value, MIN_HOVER_Z, MAX_HOVER_Z));

    LL_INFOS("Avatar") << "QuickPrefs: setting hover from slider moved " << offset[VZ] << LL_ENDL;

    if (gAgent.getRegion() && gAgent.getRegion()->avatarHoverHeightEnabled())
    {
        if (mAvatarZOffsetSlider->isMouseHeldDown())
        {
            // Live preview: send to avatar but don't persist yet
            if (isAgentAvatarValid())
            {
                gAgentAvatarp->setHoverOffset(offset, false);
            }
        }
        else
        {
            // Committed (e.g. arrow-key step): persist immediately
            gSavedPerAccountSettings.setF32("AvatarHoverOffsetZ", value);
        }
    }
    else if (isAgentAvatarValid())
    {
        gSavedPerAccountSettings.setF32("AvatarHoverOffsetZ", value);
    }
}

void LLFloaterQuickPrefs::onAvatarZOffsetFinalCommit()
{
    F32 value = mAvatarZOffsetSlider->getValueF32();
    LL_INFOS("Avatar") << "QuickPrefs: setting hover from slider final commit " << value << LL_ENDL;
    gSavedPerAccountSettings.setF32("AvatarHoverOffsetZ",
        llclamp(value, MIN_HOVER_Z, MAX_HOVER_Z));
}

// ---------------------------------------------------------------------------
// Enable / disable based on region support
// ---------------------------------------------------------------------------

void LLFloaterQuickPrefs::updateAvatarZOffsetEditEnabled()
{
    bool enabled = gAgent.getRegion() && gAgent.getRegion()->avatarHoverHeightEnabled();

    if (!enabled && isAgentAvatarValid())
    {
        enabled = true;
    }

    mAvatarZOffsetSlider->setEnabled(enabled);

    if (enabled)
    {
        syncAvatarZOffsetFromPreferenceSetting();
    }
}

void LLFloaterQuickPrefs::onRegionChanged()
{
    LLViewerRegion* region = gAgent.getRegion();
    if (region && region->simulatorFeaturesReceived())
    {
        updateAvatarZOffsetEditEnabled();
    }
    else if (region)
    {
        region->setSimulatorFeaturesReceivedCallback(
            boost::bind(&LLFloaterQuickPrefs::onSimulatorFeaturesReceived, this, _1));
    }
}

void LLFloaterQuickPrefs::onSimulatorFeaturesReceived(const LLUUID& region_id)
{
    LLViewerRegion* region = gAgent.getRegion();
    if (region && region->getRegionID() == region_id)
    {
        updateAvatarZOffsetEditEnabled();
    }
}

void LLFloaterQuickPrefs::syncAvatarZOffsetFromPreferenceSetting()
{
    F32 value = gSavedPerAccountSettings.getF32("AvatarHoverOffsetZ");
    mAvatarZOffsetSlider->setValue(value, false);   // false = no commit signal
}