| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/CtlCfgElem.h $ |
| 21 | * $Revision: 15 $ |
| 22 | * $Date: 7/16/99 11:15a $ |
| 23 | * $Author: Samir $ |
| 24 | * |
| 25 | * Header file |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/CtlCfgElem.h $ |
| 28 | * |
| 29 | * 15 7/16/99 11:15a Samir |
| 30 | * multiple hat support |
| 31 | * |
| 32 | * 14 4/14/99 3:56a Jeff |
| 33 | * fixed case mismatch in #includes |
| 34 | * |
| 35 | * 13 2/26/99 2:09a Samir |
| 36 | * added '?' button. |
| 37 | * |
| 38 | * 12 2/21/99 6:36p Samir |
| 39 | * focusing changes and key input changes to ui., |
| 40 | * |
| 41 | * 11 2/16/99 12:07p Samir |
| 42 | * redid controller config with new ui. |
| 43 | * |
| 44 | * 10 11/30/98 4:54p Samir |
| 45 | * added rear view config item. |
| 46 | * |
| 47 | * 9 10/22/98 4:11p Samir |
| 48 | * put inventory keys back in. |
| 49 | * |
| 50 | * 8 10/22/98 2:40p Samir |
| 51 | * took out inventory keys for demo. |
| 52 | * |
| 53 | * 7 10/21/98 12:32p Samir |
| 54 | * fixed problem with size of gadget. |
| 55 | * |
| 56 | * 6 10/18/98 1:07p Samir |
| 57 | * tweaked user interface for controller config. |
| 58 | * |
| 59 | * 5 10/17/98 7:31p Samir |
| 60 | * added invertible axes |
| 61 | * |
| 62 | * 4 10/08/98 10:52a Samir |
| 63 | * added countermeasure and weapon cycling. |
| 64 | * |
| 65 | * 3 10/02/98 4:15p Samir |
| 66 | * added fancy artwork for config screens. |
| 67 | * |
| 68 | * 2 9/30/98 4:37p Samir |
| 69 | * 'incremental checkin' |
| 70 | * |
| 71 | * 1 9/28/98 3:48p Samir |
| 72 | * initial revision |
| 73 | * |
| 74 | * $NoKeywords: $ |
| 75 | */ |
| 76 | |
| 77 | #ifndef CTLCFGELEM_H |
| 78 | #define CTLCFGELEM_H |
| 79 | |
| 80 | #include "newui.h" |
| 81 | #include "Controller.h" |
| 82 | #include "controls.h" |
| 83 | #include "stringtable.h" |
| 84 | |
| 85 | ////////////////////////////////////////////////////////////////////////////// |
| 86 | // Data types |
| 87 | #define N_CFGELEM_SLOTS CTLBINDS_PER_FUNC // number of controller slots per function |
| 88 | #define CFGELEM_SLOT_CLEAR 2 |
| 89 | |
| 90 | ////////////////////////////////////////////////////////////////////////////// |
| 91 | // |
| 92 | class cfg_element : public UIGadget { |
| 93 | static UIBitmapItem *m_btn_bmp_lit, *m_btn_bmp, *m_xbtn_bmp_lit, *m_xbtn_bmp; |
| 94 | static int16_t m_count; |
| 95 | const char *m_title; |
| 96 | int8_t m_fnid, m_flags; // fnflags : 1 if invert btn visible |
| 97 | int8_t m_slot, m_curslot; // what slow is in focus and number of slots. |
| 98 | uint8_t m_slot_alpha; |
| 99 | int8_t m_blink_state; |
| 100 | |
| 101 | public: |
| 102 | void Create(UIWindow *wnd, int str_i, int x, int y, int fnid, int id); |
| 103 | int8_t GetActiveSlot() const { return m_slot; }; |
| 104 | bool Configure(ct_type *elem_type, uint8_t *controller, uint8_t *new_elem, |
| 105 | int8_t *slot); // calls configuration routines (returns true if approved) |
| 106 | |
| 107 | protected: |
| 108 | virtual void OnDraw(); |
| 109 | virtual void OnKeyDown(int key); |
| 110 | virtual void OnMouseBtnDown(int btn); |
| 111 | virtual void OnMouseBtnUp(int btn); |
| 112 | virtual void OnLostFocus(); |
| 113 | virtual void OnGainFocus(); |
| 114 | virtual void OnDestroy(); |
| 115 | virtual void OnFormat(); |
| 116 | }; |
| 117 | |
| 118 | struct tCfgDataParts { |
| 119 | uint8_t bind_0, bind_1, ctrl_0, ctrl_1; |
| 120 | }; |
| 121 | |
| 122 | static inline void parse_config_data(tCfgDataParts *parts, ct_type type0, ct_type type1, ct_config_data cfgdata) { |
| 123 | switch (type0) { |
| 124 | case ctKey: |
| 125 | parts->bind_0 = CONTROLLER_KEY1_VALUE(CONTROLLER_VALUE(cfgdata)); |
| 126 | break; |
| 127 | case ctAxis: |
| 128 | case ctMouseAxis: |
| 129 | case ctButton: |
| 130 | case ctMouseButton: |
| 131 | case ctPOV: |
| 132 | case ctPOV2: |
| 133 | case ctPOV3: |
| 134 | case ctPOV4: |
| 135 | parts->bind_0 = CONTROLLER_CTL1_VALUE(CONTROLLER_VALUE(cfgdata)); |
| 136 | break; |
| 137 | default: |
| 138 | parts->bind_0 = 0; |
| 139 | } |
| 140 | |
| 141 | switch (type1) { |
| 142 | case ctKey: |
| 143 | parts->bind_1 = CONTROLLER_KEY2_VALUE(CONTROLLER_VALUE(cfgdata)); |
| 144 | break; |
| 145 | case ctAxis: |
| 146 | case ctMouseAxis: |
| 147 | case ctButton: |
| 148 | case ctMouseButton: |
| 149 | case ctPOV: |
| 150 | case ctPOV2: |
| 151 | case ctPOV3: |
| 152 | case ctPOV4: |
| 153 | parts->bind_1 = CONTROLLER_CTL2_VALUE(CONTROLLER_VALUE(cfgdata)); |
| 154 | break; |
| 155 | default: |
| 156 | parts->bind_1 = 0; |
| 157 | } |
| 158 | |
| 159 | parts->ctrl_0 = CONTROLLER_CTL1_INFO(CONTROLLER_INFO(cfgdata)); |
| 160 | parts->ctrl_1 = CONTROLLER_CTL2_INFO(CONTROLLER_INFO(cfgdata)); |
| 161 | } |
| 162 | |
| 163 | static inline ct_config_data unify_config_data(tCfgDataParts *parts) { |
| 164 | return MAKE_CONFIG_DATA(CONTROLLER_CTL_INFO(parts->ctrl_0, parts->ctrl_1), |
| 165 | CONTROLLER_CTL_VALUE(parts->bind_0, parts->bind_1)); |
| 166 | } |
| 167 | |
| 168 | extern const char *cfg_binding_text(ct_type ctype, uint8_t ctrl, uint8_t binding); |
| 169 | |
| 170 | #endif |