diff --git a/planet/Graphics.ocg/Authors.txt b/planet/Graphics.ocg/Authors.txt index eceedaf4b..7bad63d21 100644 --- a/planet/Graphics.ocg/Authors.txt +++ b/planet/Graphics.ocg/Authors.txt @@ -13,3 +13,6 @@ StartupPlrSelBG.jpg StartupScenSelBG.jpg) Loader1.jpg - Nachtfalter + +ControllerIcons.png - Nicolae Berbece (http://opengameart.org/content/free-keyboard-and-controllers-prompts-pack) + License: CC0 diff --git a/planet/Graphics.ocg/ControllerIcons.png b/planet/Graphics.ocg/ControllerIcons.png new file mode 100644 index 000000000..a7429c2dc Binary files /dev/null and b/planet/Graphics.ocg/ControllerIcons.png differ diff --git a/src/game/C4Game.cpp b/src/game/C4Game.cpp index 8fa12a6d0..74440d868 100644 --- a/src/game/C4Game.cpp +++ b/src/game/C4Game.cpp @@ -75,6 +75,8 @@ #include #include +#include + class C4GameSec1Timer : public C4ApplicationSec1Timer { public: @@ -3609,6 +3611,33 @@ void C4Game::Abort(bool fApproved) Application.QuitGame(); } +static const std::unordered_map str_to_icon = +{ + { "Locked", C4GUI::Ico_Ex_LockedFrontal }, + { "League", C4GUI::Ico_Ex_League }, + { "GameRunning", C4GUI::Ico_GameRunning }, + { "Lobby", C4GUI::Ico_Lobby }, + { "RuntimeJoin", C4GUI::Ico_RuntimeJoin }, + + { "A", C4GUI::Ico_Controller_A }, + { "B", C4GUI::Ico_Controller_B }, + { "X", C4GUI::Ico_Controller_X }, + { "Y", C4GUI::Ico_Controller_Y }, + { "Back", C4GUI::Ico_Controller_Back }, + { "Start", C4GUI::Ico_Controller_Start }, + { "Dpad", C4GUI::Ico_Controller_Dpad }, + { "DpadLeft", C4GUI::Ico_Controller_DpadLeft }, + { "DpadRight", C4GUI::Ico_Controller_DpadRight }, + { "DpadDown", C4GUI::Ico_Controller_DpadDown }, + { "DpadUp", C4GUI::Ico_Controller_DpadUp }, + { "LeftShoulder", C4GUI::Ico_Controller_LeftShoulder }, + { "RightShoulder", C4GUI::Ico_Controller_RightShoulder }, + { "LeftTrigger", C4GUI::Ico_Controller_LeftTrigger }, + { "RightTrigger", C4GUI::Ico_Controller_RightTrigger }, + { "LeftStick", C4GUI::Ico_Controller_LeftStick }, + { "RightStick", C4GUI::Ico_Controller_RightStick }, +}; + bool GetTextSpecFacet(const char* szSpec, C4Facet& fct) { // safety @@ -3618,19 +3647,12 @@ bool GetTextSpecFacet(const char* szSpec, C4Facet& fct) if (SEqual2(szSpec, "@Ico:")) { szSpec += 5; - if (SEqual2(szSpec, "Locked")) - fct = C4GUI::Icon::GetIconFacet(C4GUI::Ico_Ex_LockedFrontal); - else if (SEqual2(szSpec, "League")) - fct = C4GUI::Icon::GetIconFacet(C4GUI::Ico_Ex_League); - else if (SEqual2(szSpec, "GameRunning")) - fct = C4GUI::Icon::GetIconFacet(C4GUI::Ico_GameRunning); - else if (SEqual2(szSpec, "Lobby")) - fct = C4GUI::Icon::GetIconFacet(C4GUI::Ico_Lobby); - else if (SEqual2(szSpec, "RuntimeJoin")) - fct = C4GUI::Icon::GetIconFacet(C4GUI::Ico_RuntimeJoin); - else - return false; - return true; + auto it = str_to_icon.find(szSpec); + if (it != str_to_icon.end()) + { + fct = C4GUI::Icon::GetIconFacet(it->second); + return true; + } } return false; diff --git a/src/graphics/C4GraphicsResource.cpp b/src/graphics/C4GraphicsResource.cpp index 56cf7af83..383a91ac1 100644 --- a/src/graphics/C4GraphicsResource.cpp +++ b/src/graphics/C4GraphicsResource.cpp @@ -128,6 +128,7 @@ void C4GraphicsResource::Clear() idSfcCaption = idSfcButton = idSfcButtonD = idSfcScroll = idSfcContext = 0; barCaption.Clear(); barButton.Clear(); barButtonD.Clear(); fctButtonHighlight.Clear(); fctIcons.Clear(); fctIconsEx.Clear(); + fctControllerIcons.Clear(); fctButtonHighlightRound.Clear(); fctSubmenu.Clear(); fctCheckbox.Clear(); @@ -218,6 +219,8 @@ bool C4GraphicsResource::Init() fctIcons.Set(fctIcons.Surface,0,0,C4GUI_IconWdt,C4GUI_IconHgt); if (!LoadFile(fctIconsEx, "GUIIcons2", Files, C4FCT_Full, C4FCT_Full, false, 0)) return false; fctIconsEx.Set(fctIconsEx.Surface,0,0,C4GUI_IconExWdt,C4GUI_IconExHgt); + if (!LoadFile(fctControllerIcons, "ControllerIcons", Files, C4FCT_Full, C4FCT_Full, false, 0)) return false; + fctControllerIcons.Set(fctControllerIcons.Surface,0,0,C4GUI_ControllerIconWdt,C4GUI_ControllerIconHgt); if (!LoadFile(sfcScroll, "GUIScroll", Files, idSfcScroll, 0)) return false; sfctScroll.Set(C4Facet(&sfcScroll,0,0,32,32)); if (!LoadFile(sfcContext, "GUIContext", Files, idSfcContext, 0)) return false; diff --git a/src/graphics/C4GraphicsResource.h b/src/graphics/C4GraphicsResource.h index bc83798e3..95456813e 100644 --- a/src/graphics/C4GraphicsResource.h +++ b/src/graphics/C4GraphicsResource.h @@ -83,6 +83,7 @@ public: C4FacetID fctButtonHighlight; C4FacetID fctButtonHighlightRound; C4FacetID fctIcons, fctIconsEx; + C4FacetID fctControllerIcons; C4FacetID fctSubmenu; C4FacetID fctCheckbox; C4FacetID fctBigArrows; diff --git a/src/gui/C4Gui.h b/src/gui/C4Gui.h index 51bac6147..ff7facb98 100644 --- a/src/gui/C4Gui.h +++ b/src/gui/C4Gui.h @@ -94,6 +94,8 @@ #define C4GUI_IconHgt 40 #define C4GUI_IconExWdt 64 #define C4GUI_IconExHgt 64 +#define C4GUI_ControllerIconWdt 100 +#define C4GUI_ControllerIconHgt 100 #define C4GUI_IconLabelSpacing 2 // space between an icon and its text @@ -627,7 +629,11 @@ namespace C4GUI }; // icon indices - enum { Ico_Extended = 0x100 }; // icon index offset for extended icons + enum + { + Ico_Extended = 0x100, // icon index offset for extended icons + Ico_Controller = 0x200, + }; enum Icons { Ico_Empty = -2, // for context menus only @@ -705,7 +711,25 @@ namespace C4GUI Ico_Ex_Update = Ico_Extended + 14, Ico_Ex_Chat = Ico_Extended + 15, Ico_Ex_GameList = Ico_Extended + 16, - Ico_Ex_Comment = Ico_Extended + 17 + Ico_Ex_Comment = Ico_Extended + 17, + + Ico_Controller_A = Ico_Controller + 0, + Ico_Controller_B = Ico_Controller + 3, + Ico_Controller_X = Ico_Controller + 17, + Ico_Controller_Y = Ico_Controller + 18, + Ico_Controller_Back = Ico_Controller + 1, + Ico_Controller_Start = Ico_Controller + 16, + Ico_Controller_Dpad = Ico_Controller + 6, + Ico_Controller_DpadLeft = Ico_Controller + 5, + Ico_Controller_DpadRight = Ico_Controller + 7, + Ico_Controller_DpadDown = Ico_Controller + 4, + Ico_Controller_DpadUp = Ico_Controller + 8, + Ico_Controller_LeftShoulder = Ico_Controller + 9, + Ico_Controller_RightShoulder = Ico_Controller + 12, + Ico_Controller_LeftTrigger = Ico_Controller + 11, + Ico_Controller_RightTrigger = Ico_Controller + 14, + Ico_Controller_LeftStick = Ico_Controller + 10, + Ico_Controller_RightStick = Ico_Controller + 13, }; // cute, litte, useless thingy diff --git a/src/gui/C4GuiLabels.cpp b/src/gui/C4GuiLabels.cpp index 1305920d8..9db88cb0d 100644 --- a/src/gui/C4GuiLabels.cpp +++ b/src/gui/C4GuiLabels.cpp @@ -428,12 +428,18 @@ namespace C4GUI C4Facet Icon::GetIconFacet(Icons icoIconIndex) { if (icoIconIndex == Ico_None) return C4Facet(); - C4Facet &rFacet = (icoIconIndex & Ico_Extended) ? ::GraphicsResource.fctIconsEx : ::GraphicsResource.fctIcons; - icoIconIndex = Icons(icoIconIndex & (Ico_Extended-1)); + C4Facet *rFacet; + switch (icoIconIndex & ~0xff) + { + case Ico_Extended: rFacet = &::GraphicsResource.fctIconsEx; break; + case Ico_Controller: rFacet = &::GraphicsResource.fctControllerIcons; break; + default: rFacet = &::GraphicsResource.fctIcons; + } + icoIconIndex = Icons(icoIconIndex & 0xff); int32_t iXMax, iYMax; - rFacet.GetPhaseNum(iXMax, iYMax); + rFacet->GetPhaseNum(iXMax, iYMax); if (!iXMax) iXMax = 6; - return rFacet.GetPhase(icoIconIndex % iXMax, icoIconIndex / iXMax); + return rFacet->GetPhase(icoIconIndex % iXMax, icoIconIndex / iXMax); } diff --git a/src/gui/C4KeyboardInput.cpp b/src/gui/C4KeyboardInput.cpp index 7cfb8c384..b4f209808 100644 --- a/src/gui/C4KeyboardInput.cpp +++ b/src/gui/C4KeyboardInput.cpp @@ -333,32 +333,32 @@ StdStrBuf C4KeyCodeEx::KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool { switch (Key_GetGamepadEvent(wCode)) { - case KEY_CONTROLLER_ButtonA : return StdStrBuf("A"); - case KEY_CONTROLLER_ButtonB : return StdStrBuf("B"); - case KEY_CONTROLLER_ButtonX : return StdStrBuf("X"); - case KEY_CONTROLLER_ButtonY : return StdStrBuf("Y"); - case KEY_CONTROLLER_ButtonBack : return StdStrBuf("Back"); + case KEY_CONTROLLER_ButtonA : return StdStrBuf("{{@Ico:A}}"); + case KEY_CONTROLLER_ButtonB : return StdStrBuf("{{@Ico:B}}"); + case KEY_CONTROLLER_ButtonX : return StdStrBuf("{{@Ico:X}}"); + case KEY_CONTROLLER_ButtonY : return StdStrBuf("{{@Ico:Y}}"); + case KEY_CONTROLLER_ButtonBack : return StdStrBuf("{{@Ico:Back}}"); case KEY_CONTROLLER_ButtonGuide : return StdStrBuf("Guide"); - case KEY_CONTROLLER_ButtonStart : return StdStrBuf("Start"); - case KEY_CONTROLLER_ButtonLeftStick : return StdStrBuf("Left Stick Click"); - case KEY_CONTROLLER_ButtonRightStick : return StdStrBuf("Right Stick Click"); - case KEY_CONTROLLER_ButtonLeftShoulder : return StdStrBuf("Left Shoulder"); - case KEY_CONTROLLER_ButtonRightShoulder : return StdStrBuf("Right Shoulder"); - case KEY_CONTROLLER_ButtonDpadUp : return StdStrBuf("Dpad Up"); - case KEY_CONTROLLER_ButtonDpadDown : return StdStrBuf("Dpad Down"); - case KEY_CONTROLLER_ButtonDpadLeft : return StdStrBuf("Dpad Left"); - case KEY_CONTROLLER_ButtonDpadRight : return StdStrBuf("Dpad Right"); + case KEY_CONTROLLER_ButtonStart : return StdStrBuf("{{@Ico:Start}}"); + case KEY_CONTROLLER_ButtonLeftStick : return StdStrBuf("{{@Ico:LeftStick}}"); + case KEY_CONTROLLER_ButtonRightStick : return StdStrBuf("{{@Ico:RightStick}}"); + case KEY_CONTROLLER_ButtonLeftShoulder : return StdStrBuf("{{@Ico:LeftShoulder}}"); + case KEY_CONTROLLER_ButtonRightShoulder : return StdStrBuf("{{@Ico:RightShoulder}}"); + case KEY_CONTROLLER_ButtonDpadUp : return StdStrBuf("{{@Ico:DpadUp}}"); + case KEY_CONTROLLER_ButtonDpadDown : return StdStrBuf("{{@Ico:DpadDown}}"); + case KEY_CONTROLLER_ButtonDpadLeft : return StdStrBuf("{{@Ico:DpadLeft}}"); + case KEY_CONTROLLER_ButtonDpadRight : return StdStrBuf("{{@Ico:DpadRight}}"); case KEY_CONTROLLER_AnyButton : return StdStrBuf("Any Button"); - case KEY_CONTROLLER_AxisLeftXLeft : return StdStrBuf("Left Stick Left"); - case KEY_CONTROLLER_AxisLeftXRight : return StdStrBuf("Left Stick Right"); - case KEY_CONTROLLER_AxisLeftYUp : return StdStrBuf("Left Stick Up"); - case KEY_CONTROLLER_AxisLeftYDown : return StdStrBuf("Left Stick Down"); - case KEY_CONTROLLER_AxisRightXLeft : return StdStrBuf("Right Stick Left"); - case KEY_CONTROLLER_AxisRightXRight : return StdStrBuf("Right Stick Right"); - case KEY_CONTROLLER_AxisRightYUp : return StdStrBuf("Right Stick Up"); - case KEY_CONTROLLER_AxisRightYDown : return StdStrBuf("Right Stick Down"); - case KEY_CONTROLLER_AxisTriggerLeft : return StdStrBuf("Left Trigger"); - case KEY_CONTROLLER_AxisTriggerRight : return StdStrBuf("Right Trigger"); + case KEY_CONTROLLER_AxisLeftXLeft : return StdStrBuf("{{@Ico:LeftStick}} Left"); + case KEY_CONTROLLER_AxisLeftXRight : return StdStrBuf("{{@Ico:LeftStick}} Right"); + case KEY_CONTROLLER_AxisLeftYUp : return StdStrBuf("{{@Ico:LeftStick}} Up"); + case KEY_CONTROLLER_AxisLeftYDown : return StdStrBuf("{{@Ico:LeftStick}} Down"); + case KEY_CONTROLLER_AxisRightXLeft : return StdStrBuf("{{@Ico:RightStick}} Left"); + case KEY_CONTROLLER_AxisRightXRight : return StdStrBuf("{{@Ico:RightStick}} Right"); + case KEY_CONTROLLER_AxisRightYUp : return StdStrBuf("{{@Ico:RightStick}} Up"); + case KEY_CONTROLLER_AxisRightYDown : return StdStrBuf("{{@Ico:RightStick}} Down"); + case KEY_CONTROLLER_AxisTriggerLeft : return StdStrBuf("{{@Ico:LeftTrigger}}"); + case KEY_CONTROLLER_AxisTriggerRight : return StdStrBuf("{{@Ico:RightTrigger}}"); } } else diff --git a/src/gui/C4StartupOptionsDlg.cpp b/src/gui/C4StartupOptionsDlg.cpp index d1f89c0e9..5ae86a329 100644 --- a/src/gui/C4StartupOptionsDlg.cpp +++ b/src/gui/C4StartupOptionsDlg.cpp @@ -212,7 +212,7 @@ bool C4StartupOptionsDlg::KeySelDialog::KeyDown(const C4KeyCodeEx &key) // --- C4StartupOptionsDlg::ControlConfigListBox::ControlAssignmentLabel C4StartupOptionsDlg::ControlConfigListBox::ControlAssignmentLabel::ControlAssignmentLabel(class C4PlayerControlAssignment *assignment, class C4PlayerControlAssignmentSet *assignment_set, const C4Rect &bounds) - : C4GUI::Label("", bounds, ALeft, 0xffffffff, NULL, false, false, false), assignment(assignment), assignment_set(assignment_set) + : C4GUI::Label("", bounds, ALeft, 0xffffffff, NULL, false, false, true), assignment(assignment), assignment_set(assignment_set) { UpdateAssignmentString(); }