summaryrefslogtreecommitdiff
path: root/indra/newview/llmoveview.cpp
blob: a8ceaffde87161178b345694985d6c546ed7ee0d (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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/**
 * @file llmoveview.cpp
 * @brief Container for movement buttons like forward, left, fly
 *
 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * 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.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"

#include "llmoveview.h"

// Library includes
#include "indra_constants.h"
#include "llparcel.h"

// Viewer includes

#include "llagent.h"
#include "llagentcamera.h"
#include "llvoavatarself.h" // to check gAgentAvatarp->isSitting()
#include "llbutton.h"
#include "llfirstuse.h"
#include "llfloaterreg.h"
#include "llhints.h"
#include "lljoystickbutton.h"
#include "lluictrlfactory.h"
#include "llviewerwindow.h"
#include "llviewercontrol.h"
#include "llselectmgr.h"
#include "lltoolbarview.h"
#include "llviewerparcelmgr.h"
#include "llviewerregion.h"
#include "lltooltip.h"

//
// Constants
//

const F32 MOVE_BUTTON_DELAY = 0.0f;
const F32 YAW_NUDGE_RATE = 0.05f;   // fraction of normal speed
const F32 NUDGE_TIME = 0.25f;       // in seconds

//
// Member functions
//

// protected
LLFloaterMove::LLFloaterMove(const LLSD& key)
:   LLFloater(key),
    mForwardButton(NULL),
    mBackwardButton(NULL),
    mTurnLeftButton(NULL),
    mTurnRightButton(NULL),
    mMoveUpButton(NULL),
    mMoveDownButton(NULL),
    mModeActionsPanel(NULL),
    mCurrentMode(MM_WALK)
{
}

LLFloaterMove::~LLFloaterMove()
{
    // Ensure LLPanelStandStopFlying panel is not among floater's children. See EXT-8458.
    setVisible(false);

    // Otherwise it can be destroyed and static pointer in LLPanelStandStopFlying::getInstance() will become invalid.
    // Such situation was possible when LLFloaterReg returns "dead" instance of floater.
    // Should not happen after LLFloater::destroy was modified to remove "dead" instances from LLFloaterReg.
}

// virtual
bool LLFloaterMove::postBuild()
{
    updateTransparency(TT_ACTIVE); // force using active floater transparency (STORM-730)

    // Code that implements floater buttons toggling when user moves via keyboard is located in LLAgent::propagate()

    mForwardButton = getChild<LLJoystickAgentTurn>("forward btn");
    mForwardButton->setHeldDownDelay(MOVE_BUTTON_DELAY);

    mBackwardButton = getChild<LLJoystickAgentTurn>("backward btn");
    mBackwardButton->setHeldDownDelay(MOVE_BUTTON_DELAY);

    mSlideLeftButton = getChild<LLJoystickAgentSlide>("move left btn");
    mSlideLeftButton->setHeldDownDelay(MOVE_BUTTON_DELAY);

    mSlideRightButton = getChild<LLJoystickAgentSlide>("move right btn");
    mSlideRightButton->setHeldDownDelay(MOVE_BUTTON_DELAY);

    mTurnLeftButton = getChild<LLButton>("turn left btn");
    mTurnLeftButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
    mTurnLeftButton->setHeldDownCallback(boost::bind(&LLFloaterMove::turnLeft, this));
    mTurnRightButton = getChild<LLButton>("turn right btn");
    mTurnRightButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
    mTurnRightButton->setHeldDownCallback(boost::bind(&LLFloaterMove::turnRight, this));

    mMoveUpButton = getChild<LLButton>("move up btn");
    mMoveUpButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
    mMoveUpButton->setHeldDownCallback(boost::bind(&LLFloaterMove::moveUp, this));

    mMoveDownButton = getChild<LLButton>("move down btn");
    mMoveDownButton->setHeldDownDelay(MOVE_BUTTON_DELAY);
    mMoveDownButton->setHeldDownCallback(boost::bind(&LLFloaterMove::moveDown, this));


    mModeActionsPanel = getChild<LLPanel>("panel_modes");

    LLButton* btn;
    btn = getChild<LLButton>("mode_walk_btn");
    btn->setCommitCallback(boost::bind(&LLFloaterMove::onWalkButtonClick, this));

    btn = getChild<LLButton>("mode_run_btn");
    btn->setCommitCallback(boost::bind(&LLFloaterMove::onRunButtonClick, this));

    btn = getChild<LLButton>("mode_fly_btn");
    btn->setCommitCallback(boost::bind(&LLFloaterMove::onFlyButtonClick, this));

    initModeTooltips();

    initModeButtonMap();

    initMovementMode();

    gAgent.addParcelChangedCallback(LLFloaterMove::sUpdateFlyingStatus);

    return true;
}

// *NOTE: we assume that setVisible() is called on floater close.
// virtual
void LLFloaterMove::setVisible(bool visible)
{
    // Do nothing with Stand/Stop Flying panel in excessive calls of this method.
    if (getVisible() == visible)
    {
        LLFloater::setVisible(visible);
        return;
    }

    if (visible)
    {
        LLFirstUse::notMoving(false);
        // Attach the Stand/Stop Flying panel.
        LLPanelStandStopFlying* ssf_panel = LLPanelStandStopFlying::getInstance();
        ssf_panel->reparent(this);
        const LLRect& mode_actions_rect = mModeActionsPanel->getRect();
        ssf_panel->setOrigin(mode_actions_rect.mLeft, mode_actions_rect.mBottom);
    }
    else
    {
        // Detach the Stand/Stop Flying panel.
        LLPanelStandStopFlying::getInstance()->reparent(NULL);
    }

    LLFloater::setVisible(visible);
}

// static
F32 LLFloaterMove::getYawRate( F32 time )
{
    if( time < NUDGE_TIME )
    {
        F32 rate = YAW_NUDGE_RATE + time * (1 - YAW_NUDGE_RATE)/ NUDGE_TIME;
        return rate;
    }
    else
    {
        return 1.f;
    }
}


// static
void LLFloaterMove::setFlyingMode(bool fly)
{
    LLFloaterMove* instance = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
    if (instance)
    {
        instance->setFlyingModeImpl(fly);
        LLVOAvatarSelf* avatar_object = gAgentAvatarp;
        bool is_sitting = avatar_object
            && (avatar_object->getRegion() != NULL)
            && (!avatar_object->isDead())
            && avatar_object->isSitting();
        instance->showModeButtons(!fly && !is_sitting);
    }
    if (fly)
    {
        LLPanelStandStopFlying::setStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STOP_FLYING);
    }
    else
    {
        LLPanelStandStopFlying::clearStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STOP_FLYING);
    }
}
//static
void LLFloaterMove::setAlwaysRunMode(bool run)
{
    LLFloaterMove* instance = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
    if (instance)
    {
        instance->setAlwaysRunModeImpl(run);
    }
}

void LLFloaterMove::setFlyingModeImpl(bool fly)
{
    updateButtonsWithMovementMode(fly ? MM_FLY : (gAgent.getAlwaysRun() ? MM_RUN : MM_WALK));
}

void LLFloaterMove::setAlwaysRunModeImpl(bool run)
{
    if (!gAgent.getFlying())
    {
        updateButtonsWithMovementMode(run ? MM_RUN : MM_WALK);
    }
}

//static
void LLFloaterMove::setSittingMode(bool bSitting)
{
    if (bSitting)
    {
        LLPanelStandStopFlying::setStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STAND);
    }
    else
    {
        LLPanelStandStopFlying::clearStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STAND);

        // show "Stop Flying" button if needed. EXT-871
        if (gAgent.getFlying())
        {
            LLPanelStandStopFlying::setStandStopFlyingMode(LLPanelStandStopFlying::SSFM_STOP_FLYING);
        }
    }
    enableInstance();
}

// protected
void LLFloaterMove::turnLeft()
{
    F32 time = mTurnLeftButton->getHeldDownTime();
    gAgent.moveYaw( getYawRate( time ) );
}

// protected
void LLFloaterMove::turnRight()
{
    F32 time = mTurnRightButton->getHeldDownTime();
    gAgent.moveYaw( -getYawRate( time ) );
}

// protected
void LLFloaterMove::moveUp()
{
    // Jumps or flys up, depending on fly state
    gAgent.moveUp(1);
}

// protected
void LLFloaterMove::moveDown()
{
    // Crouches or flys down, depending on fly state
    gAgent.moveUp(-1);
}

//////////////////////////////////////////////////////////////////////////
// Private Section:
//////////////////////////////////////////////////////////////////////////

void LLFloaterMove::onWalkButtonClick()
{
    setMovementMode(MM_WALK);
}
void LLFloaterMove::onRunButtonClick()
{
    setMovementMode(MM_RUN);
}
void LLFloaterMove::onFlyButtonClick()
{
    setMovementMode(MM_FLY);
}

void LLFloaterMove::setMovementMode(const EMovementMode mode)
{
    mCurrentMode = mode;

    if(MM_FLY == mode)
    {
        LLAgent::toggleFlying();
    }
    else
    {
        gAgent.setFlying(false);
    }

    // attempts to set avatar flying can not set it real flying in some cases.
    // For ex. when avatar fell down & is standing up.
    // So, no need to continue processing FLY mode. See EXT-1079
    if (MM_FLY == mode && !gAgent.getFlying())
    {
        return;
    }

    switch (mode)
    {
    case MM_RUN:
        gAgent.setAlwaysRun();
        gAgent.setRunning();
        break;
    case MM_WALK:
        gAgent.clearAlwaysRun();
        gAgent.clearRunning();
        break;
    default:
        //do nothing for other modes (MM_FLY)
        break;
    }
    // tell the simulator.
    gAgent.sendWalkRun(gAgent.getAlwaysRun());

    updateButtonsWithMovementMode(mode);

    bool bHideModeButtons = MM_FLY == mode
        || (isAgentAvatarValid() && gAgentAvatarp->isSitting());

    showModeButtons(!bHideModeButtons);

}

void LLFloaterMove::updateButtonsWithMovementMode(const EMovementMode newMode)
{
    setModeTooltip(newMode);
    setModeButtonToggleState(newMode);
    setModeTitle(newMode);
}

void LLFloaterMove::initModeTooltips()
{
    control_tooltip_map_t walkTipMap;
    walkTipMap.insert(std::make_pair(mForwardButton, getString("walk_forward_tooltip")));
    walkTipMap.insert(std::make_pair(mBackwardButton, getString("walk_back_tooltip")));
    walkTipMap.insert(std::make_pair(mSlideLeftButton, getString("walk_left_tooltip")));
    walkTipMap.insert(std::make_pair(mSlideRightButton, getString("walk_right_tooltip")));
    walkTipMap.insert(std::make_pair(mMoveUpButton, getString("jump_tooltip")));
    walkTipMap.insert(std::make_pair(mMoveDownButton, getString("crouch_tooltip")));
    mModeControlTooltipsMap[MM_WALK] = walkTipMap;

    control_tooltip_map_t runTipMap;
    runTipMap.insert(std::make_pair(mForwardButton, getString("run_forward_tooltip")));
    runTipMap.insert(std::make_pair(mBackwardButton, getString("run_back_tooltip")));
    runTipMap.insert(std::make_pair(mSlideLeftButton, getString("run_left_tooltip")));
    runTipMap.insert(std::make_pair(mSlideRightButton, getString("run_right_tooltip")));
    runTipMap.insert(std::make_pair(mMoveUpButton, getString("jump_tooltip")));
    runTipMap.insert(std::make_pair(mMoveDownButton, getString("crouch_tooltip")));
    mModeControlTooltipsMap[MM_RUN] = runTipMap;

    control_tooltip_map_t flyTipMap;
    flyTipMap.insert(std::make_pair(mForwardButton, getString("fly_forward_tooltip")));
    flyTipMap.insert(std::make_pair(mBackwardButton, getString("fly_back_tooltip")));
    flyTipMap.insert(std::make_pair(mSlideLeftButton, getString("fly_left_tooltip")));
    flyTipMap.insert(std::make_pair(mSlideRightButton, getString("fly_right_tooltip")));
    flyTipMap.insert(std::make_pair(mMoveUpButton, getString("fly_up_tooltip")));
    flyTipMap.insert(std::make_pair(mMoveDownButton, getString("fly_down_tooltip")));
    mModeControlTooltipsMap[MM_FLY] = flyTipMap;

    setModeTooltip(MM_WALK);
}

void LLFloaterMove::initModeButtonMap()
{
    mModeControlButtonMap[MM_WALK] = getChild<LLButton>("mode_walk_btn");
    mModeControlButtonMap[MM_RUN] = getChild<LLButton>("mode_run_btn");
    mModeControlButtonMap[MM_FLY] = getChild<LLButton>("mode_fly_btn");
}

void LLFloaterMove::initMovementMode()
{
    EMovementMode initMovementMode = gAgent.getAlwaysRun() ? MM_RUN : MM_WALK;
    if (gAgent.getFlying())
    {
        initMovementMode = MM_FLY;
    }

    mCurrentMode = initMovementMode;
    bool hide_mode_buttons = (MM_FLY == mCurrentMode) || (isAgentAvatarValid() && gAgentAvatarp->isSitting());

    updateButtonsWithMovementMode(mCurrentMode);
    showModeButtons(!hide_mode_buttons);
}

void LLFloaterMove::setModeTooltip(const EMovementMode mode)
{
    llassert_always(mModeControlTooltipsMap.end() != mModeControlTooltipsMap.find(mode));
    control_tooltip_map_t controlsTipMap = mModeControlTooltipsMap[mode];
    control_tooltip_map_t::const_iterator it = controlsTipMap.begin();
    for (; it != controlsTipMap.end(); ++it)
    {
        LLView* ctrl = it->first;
        std::string tooltip = it->second;
        ctrl->setToolTip(tooltip);
    }
}

void LLFloaterMove::setModeTitle(const EMovementMode mode)
{
    std::string title;
    switch(mode)
    {
    case MM_WALK:
        title = getString("walk_title");
        break;
    case MM_RUN:
        title = getString("run_title");
        break;
    case MM_FLY:
        title = getString("fly_title");
        break;
    default:
        // title should be provided for all modes
        llassert(false);
        break;
    }
    setTitle(title);
}

//static
void LLFloaterMove::sUpdateFlyingStatus()
{
    LLFloaterMove *floater = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
    if (floater) floater->mModeControlButtonMap[MM_FLY]->setEnabled(gAgent.canFly());

}

void LLFloaterMove::showModeButtons(bool bShow)
{
    if (mModeActionsPanel->getVisible() == bShow)
        return;
    mModeActionsPanel->setVisible(bShow);
}

//static
void LLFloaterMove::enableInstance()
{
    LLFloaterMove* instance = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
    if (instance)
    {
        if (gAgent.getFlying())
        {
            instance->showModeButtons(false);
        }
        else
        {
            instance->showModeButtons(isAgentAvatarValid() && !gAgentAvatarp->isSitting());
        }
    }
}

void LLFloaterMove::onOpen(const LLSD& key)
{
    if (gAgent.getFlying())
    {
        setFlyingMode(true);
        showModeButtons(false);
    }

    if (isAgentAvatarValid() && gAgentAvatarp->isSitting())
    {
        setSittingMode(true);
        showModeButtons(false);
    }

    sUpdateFlyingStatus();
}

void LLFloaterMove::setModeButtonToggleState(const EMovementMode mode)
{
    llassert_always(mModeControlButtonMap.end() != mModeControlButtonMap.find(mode));

    mode_control_button_map_t::const_iterator it = mModeControlButtonMap.begin();
    for (; it != mModeControlButtonMap.end(); ++it)
    {
        it->second->setToggleState(false);
    }

    mModeControlButtonMap[mode]->setToggleState(true);
}



/************************************************************************/
/*                        LLPanelStandStopFlying                        */
/************************************************************************/
LLPanelStandStopFlying::LLPanelStandStopFlying() :
    mStandButton(NULL),
    mStopFlyingButton(NULL),
    mAttached(false)
{
    // make sure we have the only instance of this class
    static bool b = true;
    llassert_always(b);
    b=false;
}

// static
LLPanelStandStopFlying* LLPanelStandStopFlying::getInstance()
{
    static LLPanelStandStopFlying* panel = getStandStopFlyingPanel();
    return panel;
}

//static
void LLPanelStandStopFlying::setStandStopFlyingMode(EStandStopFlyingMode mode)
{
    LLPanelStandStopFlying* panel = getInstance();

    if (mode == SSFM_STAND)
    {
        LLFirstUse::sit();
        LLFirstUse::notMoving(false);
    }
    panel->mStandButton->setVisible(SSFM_STAND == mode);
    panel->mStopFlyingButton->setVisible(SSFM_STOP_FLYING == mode);

    //visibility of it should be updated after updating visibility of the buttons
    panel->setVisible(true);
}

//static
void LLPanelStandStopFlying::clearStandStopFlyingMode(EStandStopFlyingMode mode)
{
    LLPanelStandStopFlying* panel = getInstance();
    switch(mode) {
    case SSFM_STAND:
        panel->mStandButton->setVisible(false);
        break;
    case SSFM_STOP_FLYING:
        panel->mStopFlyingButton->setVisible(false);
        break;
    default:
        LL_ERRS() << "Unexpected EStandStopFlyingMode is passed: " << mode << LL_ENDL;
    }

}

bool LLPanelStandStopFlying::postBuild()
{
    mStandButton = getChild<LLButton>("stand_btn");
    mStandButton->setCommitCallback(boost::bind(&LLPanelStandStopFlying::onStandButtonClick, this));
    mStandButton->setCommitCallback(boost::bind(&LLFloaterMove::enableInstance));
    mStandButton->setVisible(false);
    LLHints::getInstance()->registerHintTarget("stand_btn", mStandButton->getHandle());

    mStopFlyingButton = getChild<LLButton>("stop_fly_btn");
    //mStopFlyingButton->setCommitCallback(boost::bind(&LLFloaterMove::setFlyingMode, false));
    mStopFlyingButton->setCommitCallback(boost::bind(&LLPanelStandStopFlying::onStopFlyingButtonClick, this));
    mStopFlyingButton->setVisible(false);

    gViewerWindow->setOnWorldViewRectUpdated(boost::bind(&LLPanelStandStopFlying::updatePosition, this));

    return true;
}

//virtual
void LLPanelStandStopFlying::setVisible(bool visible)
{
    //we dont need to show the panel if these buttons are not activated
    if (gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK) visible = false;

    if (visible)
    {
        updatePosition();
    }

    // do not change parent visibility in case panel is attached into Move Floater: EXT-3632, EXT-4646
    if (!mAttached)
    {
        //change visibility of parent layout_panel to animate in/out. EXT-2504
        if (getParent()) getParent()->setVisible(visible);
    }

    // also change own visibility to avoid displaying the panel in mouselook (broken when EXT-2504 was implemented).
    // See EXT-4718.
    LLPanel::setVisible(visible);
}

bool LLPanelStandStopFlying::handleToolTip(S32 x, S32 y, MASK mask)
{
    LLToolTipMgr::instance().unblockToolTips();

    if (mStandButton->getVisible())
    {
        LLToolTipMgr::instance().show(mStandButton->getToolTip());
    }
    else if (mStopFlyingButton->getVisible())
    {
        LLToolTipMgr::instance().show(mStopFlyingButton->getToolTip());
    }

    return LLPanel::handleToolTip(x, y, mask);
}

void LLPanelStandStopFlying::reparent(LLFloaterMove* move_view)
{
    LLPanel* parent = dynamic_cast<LLPanel*>(getParent());
    if (!parent)
    {
        LL_WARNS() << "Stand/stop flying panel parent is unset, already attached?: " << mAttached << ", new parent: " << (move_view == NULL ? "NULL" : "Move Floater") << LL_ENDL;
        return;
    }

    if (move_view != NULL)
    {
        llassert(move_view != parent); // sanity check

        // Save our original container.
        if (!mOriginalParent.get())
            mOriginalParent = parent->getHandle();

        // Attach to movement controls.
        parent->removeChild(this);
        move_view->addChild(this);
        // Origin must be set by movement controls.
        mAttached = true;
    }
    else
    {
        if (!mOriginalParent.get())
        {
            LL_WARNS() << "Original parent of the stand / stop flying panel not found" << LL_ENDL;
            return;
        }

        // Detach from movement controls.
        parent->removeChild(this);
        mOriginalParent.get()->addChild(this);
        // update parent with self visibility (it is changed in setVisible()). EXT-4743
        mOriginalParent.get()->setVisible(getVisible());

        mAttached = false;
        updatePosition(); // don't defer until next draw() to avoid flicker
    }
}

//////////////////////////////////////////////////////////////////////////
// Private Section
//////////////////////////////////////////////////////////////////////////

//static
LLPanelStandStopFlying* LLPanelStandStopFlying::getStandStopFlyingPanel()
{
    LLPanelStandStopFlying* panel = new LLPanelStandStopFlying();
    panel->buildFromFile("panel_stand_stop_flying.xml");

    panel->setVisible(false);
    //LLUI::getInstance()->getRootView()->addChild(panel);

    LL_INFOS() << "Build LLPanelStandStopFlying panel" << LL_ENDL;

    panel->updatePosition();
    return panel;
}

void LLPanelStandStopFlying::onStandButtonClick()
{
    LLFirstUse::sit(false);

    LLSelectMgr::getInstance()->deselectAllForStandingUp();
    gAgent.setControlFlags(AGENT_CONTROL_STAND_UP);

    setFocus(false);
}

void LLPanelStandStopFlying::onStopFlyingButtonClick()
{
    gAgent.setFlying(false);

    setFocus(false); // EXT-482
}

/**
 * Updates position of the Stand & Stop Flying panel to be center aligned with Move button.
 */
void LLPanelStandStopFlying::updatePosition()
{
    if (mAttached) return;

    S32 bottom_tb_center = 0;
    if (LLToolBar* toolbar_bottom = gToolBarView->getToolbar(LLToolBarEnums::TOOLBAR_BOTTOM))
    {
        bottom_tb_center = toolbar_bottom->getRect().getCenterX();
    }

    S32 left_tb_width = 0;
    if (LLToolBar* toolbar_left = gToolBarView->getToolbar(LLToolBarEnums::TOOLBAR_LEFT))
    {
        left_tb_width = toolbar_left->getRect().getWidth();
    }

    if (gToolBarView != NULL && gToolBarView->getToolbar(LLToolBarEnums::TOOLBAR_LEFT)->hasButtons())
    {
        S32 x_pos = bottom_tb_center - getRect().getWidth() / 2 - left_tb_width;
        setOrigin( x_pos, 0);
    }
    else
    {
        S32 x_pos = bottom_tb_center - getRect().getWidth() / 2;
        setOrigin( x_pos, 0);
    }
}

// EOF