📜 ⬆️ ⬇️

We work with SteamWorks. Part 3

The topic of this article is Interfaces Screenshots, UserStats, and the wxWidgets library. We will write a GUI application under Windows, with the help of which it will be possible to substitute screenshots and view unfulfilled achievements.


We need the wxWidgets library . Download the latest stable version 2.8.12 , unpack the archive and build the library using the finished project file:

"  "\build\msw\wx.dsw 

either run the VS20xx x86 Native Tools Command Prompt and execute:
')
 nmake /f makefile.vc 

if you have mingw:

 mingw32-make -f makefile.gcc 

After the build is finished, copy the lib and include files to your compiler directory or specify the path to them in your project.

To use the wxWidgets library we need to add a header file.

 #include "wx/wx.h" 


We define the class of our application. The OnInit () function is called when the application is started.

 class MyApp: public wxApp { virtual bool OnInit(); }; 


We define the class of our frame - the main window of the application.

 class MyFrame: public wxFrame { public: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); void OpenFile(wxCommandEvent& event); void InitializeSteam(); // SteamWorks void WriteImage(wxString CurrentDocPath); //    . void ShowAchievements(); //     EditBox. CSteamAPILoader loader; ISteamUserStats002* userStats; ISteamScreenshots001* screenShots; ISteamClient012* Client; wxTextCtrl *MainEditBox; wxString CurrentDocPath; DECLARE_EVENT_TABLE() }; 

Enumerations for assigning id to menu items.

 enum { ID_Quit = 1, ID_About, ID_Open, TEXT_Main }; //  BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(ID_Quit, MyFrame::OnQuit) // . EVT_MENU(ID_About, MyFrame::OnAbout) //   . EVT_MENU(ID_Open, MyFrame::OpenFile) //    . END_EVENT_TABLE() IMPLEMENT_APP(MyApp) //  main   wxWidgets. 

The OnInit method creates and displays the main window.

 bool MyApp::OnInit() { wxInitAllImageHandlers(); //      . putenv("SteamAppId=1250"); // 1250 Appid = KillingFloor -   . MyFrame *frame = new MyFrame( _("Fake Uploader"), wxPoint(50, 50), //  . wxSize(1024,768) ); frame->Show(true); //   . SetTopWindow(frame); //    . return true; } 

We form the main window and initialize SteamWorks.

 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame( NULL, -1, title, pos, size ) { //   wxMenu *menuFile = new wxMenu; menuFile->Append(ID_Open, _("&Open and write"), _("Open an existing file")); menuFile->Append( ID_About, _("&About...") ); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append( menuFile, _("&File") ); SetMenuBar( menuBar ); CreateStatusBar(); SetStatusText( _("Welcome to Steam fake image uploader") ); // C   . SetBackgroundColour(wxColour(240,240,240)); // . MainEditBox = new wxTextCtrl(this, ID_MainText, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_RICH , wxDefaultValidator, wxTextCtrlNameStr); // Edit Box    InitializeSteam(); } 

The event that is triggered when exiting the application.

 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(TRUE); } 

About the dialog in the menu.

 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxMessageBox( _("Fake uploader by Dinisoid"), _("Fake uploader"), wxOK | wxICON_INFORMATION, this); } 

The dialog that appears when we click Open.

 void MyFrame::OpenFile(wxCommandEvent& WXUNUSED(event)) { //       . wxFileDialog *OpenDialog = new wxFileDialog(this, wxFileSelectorPromptStr, wxEmptyString, wxEmptyString, _("Images|*.png;*.bmp;*.gif;*.tiff;*.jpg;*.jpeg"), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE); if (OpenDialog->ShowModal() == wxID_OK) //    . { CurrentDocPath = wxT("C:/"); CurrentDocPath = OpenDialog->GetPath(); SetTitle(wxString("Choosen - ") << OpenDialog->GetFilename()); //      . wxArrayString paths; OpenDialog->GetPaths(paths); for(unsigned int i = 0; i < paths.GetCount(); i++) //    . { WriteImage(paths[i]); //     . } } } 

We initialize Steam, which in turn starts the function of displaying unfulfilled achievements.

 void MyFrame::InitializeSteam() { Client = (ISteamClient012 *)loader.GetSteam3Factory()(STEAMCLIENT_INTERFACE_VERSION_012, NULL); if ( !Client ) { printf("Unable to get ISteamClient."); } HSteamPipe pipe = Client->CreateSteamPipe(); if ( !pipe ) { printf("Unable to get pipe"); } HSteamUser user = Client->ConnectToGlobalUser( pipe ); if ( !user ) { printf("Unable connect to global user"); } screenShots = (ISteamScreenshots001*)Client->GetISteamScreenshots(user, pipe, STEAMSCREENSHOTS_INTERFACE_VERSION_001); userStats = (ISteamUserStats002 *)Client->GetISteamUserStats(user, pipe, STEAMUSERSTATS_INTERFACE_VERSION_002); ShowAchievements(); } 


We write down a fake image.

 void MyFrame::WriteImage(wxString CurrentDocPath) { wxImage image(CurrentDocPath); //wxMessageOutput::Get()->Printf("%d %d", image.GetWidth(),image.GetHeight()); //      ScreenshotHandle hScreen = screenShots->WriteScreenshot(image.GetData(), image.GetWidth() * image.GetHeight() * 3, image.GetWidth(), image.GetHeight()); Sleep(100); } 

Show achievements in EditBox.

 void MyFrame::ShowAchievements() { CGameID Kfgame(1250); // id . userStats->RequestCurrentStats(Kfgame); //    uint32 maxAchievements = userStats->GetNumAchievements(Kfgame); //    bool data; if (maxAchievements > 0) { for (uint32 x = 0; x < maxAchievements; x++) { const char *name = userStats->GetAchievementName(Kfgame, x); userStats->GetAchievement(Kfgame,name,&data); //     . if(!data) //    { MainEditBox->AppendText(wxString(name) + "\n"); //     EditBox //userStats->SetAchievement(GameID,AchName); //  ,   . } } } userStats->StoreStats(Kfgame); //  } 

Sample loaded image.

We see the names of unfulfilled achievements in the Main Edit Box, upload files through File-> Open and write.

Source: https://habr.com/ru/post/158219/


All Articles