| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | //============================================================================ |
| 17 | |
| 18 | #include "bspf.hxx" |
| 19 | #include "Dialog.hxx" |
| 20 | #include "Widget.hxx" |
| 21 | #include "Font.hxx" |
| 22 | |
| 23 | #include "R77HelpDialog.hxx" |
| 24 | |
| 25 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 26 | R77HelpDialog::R77HelpDialog(OSystem& osystem, DialogContainer& parent, |
| 27 | const GUI::Font& font) |
| 28 | : Dialog(osystem, parent, font, "RetroN 77 help" ), |
| 29 | myPage(1), |
| 30 | myNumPages(4) |
| 31 | { |
| 32 | const int lineHeight = font.getLineHeight(), |
| 33 | fontWidth = font.getMaxCharWidth(), |
| 34 | fontHeight = font.getFontHeight(), |
| 35 | buttonWidth = font.getStringWidth("Previous" ) + 20, |
| 36 | buttonHeight = font.getLineHeight() + 4; |
| 37 | const int HBORDER = 10; |
| 38 | int xpos, ypos; |
| 39 | WidgetArray wid; |
| 40 | |
| 41 | // Set real dimensions |
| 42 | _w = 47 * fontWidth + HBORDER * 2; |
| 43 | _h = (LINES_PER_PAGE + 2) * lineHeight + 20 + _th; |
| 44 | |
| 45 | // Add Previous, Next and Close buttons |
| 46 | xpos = HBORDER; ypos = _h - buttonHeight - 10; |
| 47 | myPrevButton = |
| 48 | new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, |
| 49 | "Previous" , GuiObject::kPrevCmd); |
| 50 | myPrevButton->clearFlags(Widget::FLAG_ENABLED); |
| 51 | wid.push_back(myPrevButton); |
| 52 | |
| 53 | xpos += buttonWidth + 8; |
| 54 | myNextButton = |
| 55 | new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, |
| 56 | "Next" , GuiObject::kNextCmd); |
| 57 | wid.push_back(myNextButton); |
| 58 | |
| 59 | xpos = _w - buttonWidth - HBORDER; |
| 60 | ButtonWidget* b = |
| 61 | new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, |
| 62 | "Close" , GuiObject::kCloseCmd); |
| 63 | wid.push_back(b); |
| 64 | addCancelWidget(b); |
| 65 | |
| 66 | xpos = HBORDER; ypos = 5 + _th; |
| 67 | myTitle = new StaticTextWidget(this, font, xpos, ypos, _w - HBORDER * 2, fontHeight, |
| 68 | "" , TextAlign::Center); |
| 69 | |
| 70 | int jwidth = 11 * fontWidth; |
| 71 | int bwidth = 11 * fontWidth; |
| 72 | xpos = HBORDER; ypos += lineHeight + 4; |
| 73 | for (uInt8 i = 0; i < LINES_PER_PAGE; ++i) |
| 74 | { |
| 75 | myJoy[i] = |
| 76 | new StaticTextWidget(this, font, xpos, ypos, jwidth, |
| 77 | fontHeight, "" , TextAlign::Left); |
| 78 | myBtn[i] = |
| 79 | new StaticTextWidget(this, font, xpos + jwidth, ypos, bwidth, |
| 80 | fontHeight, "" , TextAlign::Left); |
| 81 | myDesc[i] = |
| 82 | new StaticTextWidget(this, font, xpos + jwidth + bwidth, ypos, _w - jwidth - bwidth - HBORDER * 2, |
| 83 | fontHeight, "" , TextAlign::Left); |
| 84 | ypos += fontHeight; |
| 85 | } |
| 86 | |
| 87 | addToFocusList(wid); |
| 88 | } |
| 89 | |
| 90 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 91 | void R77HelpDialog::loadConfig() |
| 92 | { |
| 93 | displayInfo(); |
| 94 | setFocus(getFocusList()[1]); // skip initially disabled 'Previous' button |
| 95 | } |
| 96 | |
| 97 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 98 | void R77HelpDialog::updateStrings(uInt8 page, uInt8 lines, string& title) |
| 99 | { |
| 100 | int i = 0; |
| 101 | auto ADD_BIND = [&](const string & j = "" , const string & b = "" , const string & d = "" ) |
| 102 | { |
| 103 | myJoyStr[i] = j; myBtnStr[i] = b; myDescStr[i] = d; i++; |
| 104 | }; |
| 105 | auto ADD_TEXT = [&](const string & d) { ADD_BIND("" , d.substr(0, 11), d.substr(11, 40)); }; |
| 106 | auto ADD_LINE = [&]() { ADD_BIND("-----------" , "-----------" , "------------------------" ); }; |
| 107 | |
| 108 | switch (page) |
| 109 | { |
| 110 | case 1: |
| 111 | title = "\\C\\c5Emulation commands" ; |
| 112 | ADD_BIND("The joystic" , "ks work nor" , "mal and all console" ); |
| 113 | ADD_BIND("buttons as " , "labeled exc" , "ept of the following:" ); |
| 114 | ADD_BIND(); |
| 115 | ADD_BIND("Joystick" , "Console" , "Command" ); |
| 116 | ADD_LINE(); |
| 117 | ADD_BIND("\\c2Button 3" , "4:3,16:9" , "Open command dialog" ); |
| 118 | ADD_BIND("\\c2Button 4" , "\\c2-" , "Open settings" ); |
| 119 | ADD_BIND("\\c2Button 5" , "FRY" , "Return to launcher" ); |
| 120 | ADD_BIND("\\c2Button 6" , "-" , "Rewind game" ); |
| 121 | ADD_BIND("\\c2Button 8" , "MODE" , "Select" ); |
| 122 | ADD_BIND("\\c2Button 9" , "RESET" , "Reset" ); |
| 123 | break; |
| 124 | |
| 125 | case 2: |
| 126 | title = "\\C\\c5Launcher commands" ; |
| 127 | ADD_BIND("Joystick" , "Console" , "Command" ); |
| 128 | ADD_LINE(); |
| 129 | ADD_BIND("Up" , "SAVE" , "Previous game" ); |
| 130 | ADD_BIND("Down" , "RESET" , "Next game" ); |
| 131 | ADD_BIND("Left" , "LOAD" , "Page up" ); |
| 132 | ADD_BIND("Right" , "MODE" , "Page down" ); |
| 133 | ADD_BIND("Button 1" , "SKILL P1" , "Start selected game" ); |
| 134 | ADD_BIND("\\c2Button 2" , "SKILL P2" , "Open power-on options" ); |
| 135 | ADD_BIND("\\c2Button 4" , "Color,B/W" , "Open settings" ); |
| 136 | break; |
| 137 | |
| 138 | case 3: |
| 139 | title = "\\C\\c5Dialog commands" ; |
| 140 | ADD_BIND("Joystick" , "Button" , "Command" ); |
| 141 | ADD_LINE(); |
| 142 | ADD_BIND("Up" , "SAVE" , "Increase current setting" ); |
| 143 | ADD_BIND("Down" , "RESET" , "Decrease current setting" ); |
| 144 | ADD_BIND("Left" , "LOAD" , "Previous dialog element" ); |
| 145 | ADD_BIND("Right" , "MODE" , "Next dialog element" ); |
| 146 | ADD_BIND("Button 1" , "SKILL P1" , "Select element" ); |
| 147 | ADD_BIND("\\c2Button 2" , "SKILL P2" , "OK" ); |
| 148 | ADD_BIND("\\c2Button 3" , "4:3,16:9" , "Previous tab" ); |
| 149 | ADD_BIND("\\c2Button 4" , "FRY" , "Next tab" ); |
| 150 | ADD_BIND("\\c2Button 6" , "\\c2-" , "Cancel" ); |
| 151 | break; |
| 152 | |
| 153 | case 4: |
| 154 | title = "\\C\\c5All commands" ; |
| 155 | ADD_BIND(); |
| 156 | ADD_BIND("Remapped Ev" , "ents" , "" ); |
| 157 | ADD_BIND(); |
| 158 | ADD_TEXT("Most commands can be remapped." ); |
| 159 | ADD_BIND(); |
| 160 | ADD_TEXT("Please use 'Advanced Settings'" ); |
| 161 | ADD_TEXT("and consult the 'Options/Input" + ELLIPSIS + "'" ); |
| 162 | ADD_TEXT("dialog for more information." ); |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | while (i < lines) |
| 167 | ADD_BIND(); |
| 168 | } |
| 169 | |
| 170 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 171 | void R77HelpDialog::displayInfo() |
| 172 | { |
| 173 | string titleStr; |
| 174 | updateStrings(myPage, LINES_PER_PAGE, titleStr); |
| 175 | |
| 176 | formatWidget(titleStr, myTitle); |
| 177 | for (uInt8 i = 0; i < LINES_PER_PAGE; ++i) |
| 178 | { |
| 179 | formatWidget(myJoyStr[i], myJoy[i]); |
| 180 | formatWidget(myBtnStr[i], myBtn[i]); |
| 181 | formatWidget(myDescStr[i], myDesc[i]); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 186 | void R77HelpDialog::formatWidget(const string& label, StaticTextWidget* widget) |
| 187 | { |
| 188 | const char* str = label.c_str(); |
| 189 | TextAlign align = TextAlign::Left; |
| 190 | ColorId color = kTextColor; |
| 191 | |
| 192 | while (str[0] == '\\') |
| 193 | { |
| 194 | switch (str[1]) |
| 195 | { |
| 196 | case 'C': |
| 197 | align = TextAlign::Center; |
| 198 | break; |
| 199 | |
| 200 | case 'L': |
| 201 | align = TextAlign::Left; |
| 202 | break; |
| 203 | |
| 204 | case 'R': |
| 205 | align = TextAlign::Right; |
| 206 | break; |
| 207 | |
| 208 | case 'c': |
| 209 | switch (str[2]) |
| 210 | { |
| 211 | case '0': |
| 212 | color = kTextColor; |
| 213 | break; |
| 214 | case '1': |
| 215 | color = kTextColorHi; |
| 216 | break; |
| 217 | case '2': |
| 218 | color = kColor; |
| 219 | break; |
| 220 | case '3': |
| 221 | color = kShadowColor; |
| 222 | break; |
| 223 | case '4': |
| 224 | color = kBGColor; |
| 225 | break; |
| 226 | case '5': |
| 227 | color = kTextColorEm; |
| 228 | break; |
| 229 | default: |
| 230 | break; |
| 231 | } |
| 232 | str++; |
| 233 | break; |
| 234 | |
| 235 | default: |
| 236 | break; |
| 237 | } |
| 238 | str += 2; |
| 239 | } |
| 240 | widget->setAlign(align); |
| 241 | widget->setTextColor(color); |
| 242 | widget->setLabel(str); |
| 243 | } |
| 244 | |
| 245 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 246 | void R77HelpDialog::handleCommand(CommandSender * sender, int cmd, |
| 247 | int data, int id) |
| 248 | { |
| 249 | switch (cmd) |
| 250 | { |
| 251 | case GuiObject::kNextCmd: |
| 252 | ++myPage; |
| 253 | if (myPage >= myNumPages) |
| 254 | myNextButton->clearFlags(Widget::FLAG_ENABLED); |
| 255 | if (myPage >= 2) |
| 256 | myPrevButton->setFlags(Widget::FLAG_ENABLED); |
| 257 | |
| 258 | displayInfo(); |
| 259 | break; |
| 260 | |
| 261 | case GuiObject::kPrevCmd: |
| 262 | --myPage; |
| 263 | if (myPage <= myNumPages) |
| 264 | myNextButton->setFlags(Widget::FLAG_ENABLED); |
| 265 | if (myPage <= 1) |
| 266 | myPrevButton->clearFlags(Widget::FLAG_ENABLED); |
| 267 | |
| 268 | displayInfo(); |
| 269 | break; |
| 270 | |
| 271 | default: |
| 272 | Dialog::handleCommand(sender, cmd, data, 0); |
| 273 | } |
| 274 | } |
| 275 | |