Debian Codegraph @

xbmc/games/controllers/guicontrols/GUISelectKeyButton.cpp

raw
1 /*
2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "GUISelectKeyButton.h"
10
11 #include "guilib/LocalizeStrings.h"
12
13 #include <string>
14
15 using namespace KODI;
16 using namespace GAME;
17
18 CGUISelectKeyButton::CGUISelectKeyButton(const CGUIButtonControl& buttonTemplate,
19 IConfigurationWizard* wizard,
20 unsigned int index)
21 : CGUIFeatureButton(buttonTemplate, wizard, GetFeature(), index)
22 {
23 }
24
25 const CPhysicalFeature& CGUISelectKeyButton::Feature(void) const
26 {
27 if (m_state == STATE::NEED_INPUT)
28 return m_selectedKey;
29
30 return CGUIFeatureButton::Feature();
31 }
32
33 bool CGUISelectKeyButton::PromptForInput(CEvent& waitEvent)
34 {
35 bool bInterrupted = false;
36
37 switch (m_state)
38 {
39 case STATE::NEED_KEY:
40 {
41 const std::string& strPrompt = g_localizeStrings.Get(35169); // "Press a key"
42 const std::string& strWarn = g_localizeStrings.Get(35170); // "Press a key ({1:d})"
43
44 bInterrupted = DoPrompt(strPrompt, strWarn, "", waitEvent);
45
46 m_state = GetNextState(m_state);
47
48 break;
49 }
50 case STATE::NEED_INPUT:
51 {
52 const std::string& strPrompt = g_localizeStrings.Get(35090); // "Press {0:s}"
53 const std::string& strWarn = g_localizeStrings.Get(35091); // "Press {0:s} ({1:d})"
54
55 bInterrupted = DoPrompt(strPrompt, strWarn, m_selectedKey.Label(), waitEvent);
56
57 m_state = GetNextState(m_state);
58
59 break;
60 }
61 default:
62 break;
63 }
64
65 return bInterrupted;
66 }
67
68 bool CGUISelectKeyButton::IsFinished(void) const
69 {
70 return m_state >= STATE::FINISHED;
71 }
72
73 void CGUISelectKeyButton::SetKey(const CPhysicalFeature& key)
74 {
75 m_selectedKey = key;
76 }
77
78 void CGUISelectKeyButton::Reset(void)
79 {
80 m_state = STATE::NEED_KEY;
81 m_selectedKey.Reset();
82 }
83
84 CPhysicalFeature CGUISelectKeyButton::GetFeature()
85 {
86 return CPhysicalFeature(35168); // "Select key"
87 }