Skip to content

Commit a020d1b

Browse files
committedSep 21, 2014
Allow taking screenshots of formspecs and move message to chat
1 parent 2b7a1ca commit a020d1b

6 files changed

+53
-40
lines changed
 

‎src/client.cpp

+30-4
Original file line numberDiff line numberDiff line change
@@ -2538,16 +2538,14 @@ void Client::typeChatMessage(const std::wstring &message)
25382538
// Show locally
25392539
if (message[0] == L'/')
25402540
{
2541-
m_chat_queue.push_back(
2542-
(std::wstring)L"issued command: "+message);
2541+
m_chat_queue.push_back((std::wstring)L"issued command: " + message);
25432542
}
25442543
else
25452544
{
25462545
LocalPlayer *player = m_env.getLocalPlayer();
25472546
assert(player != NULL);
25482547
std::wstring name = narrow_to_wide(player->getName());
2549-
m_chat_queue.push_back(
2550-
(std::wstring)L"<"+name+L"> "+message);
2548+
m_chat_queue.push_back((std::wstring)L"<" + name + L"> " + message);
25512549
}
25522550
}
25532551

@@ -2732,6 +2730,34 @@ float Client::getAvgRate(void)
27322730
m_con.getLocalStat(con::AVG_DL_RATE));
27332731
}
27342732

2733+
void Client::makeScreenshot(IrrlichtDevice *device)
2734+
{
2735+
irr::video::IVideoDriver *driver = device->getVideoDriver();
2736+
irr::video::IImage* const raw_image = driver->createScreenShot();
2737+
if (raw_image) {
2738+
irr::video::IImage* const image = driver->createImage(video::ECF_R8G8B8,
2739+
raw_image->getDimension());
2740+
2741+
if (image) {
2742+
raw_image->copyTo(image);
2743+
irr::c8 filename[256];
2744+
snprintf(filename, sizeof(filename), "%s" DIR_DELIM "screenshot_%u.png",
2745+
g_settings->get("screenshot_path").c_str(),
2746+
device->getTimer()->getRealTime());
2747+
std::stringstream sstr;
2748+
if (driver->writeImageToFile(image, filename)) {
2749+
sstr << "Saved screenshot to '" << filename << "'";
2750+
} else {
2751+
sstr << "Failed to save screenshot '" << filename << "'";
2752+
}
2753+
m_chat_queue.push_back(narrow_to_wide(sstr.str()));
2754+
infostream << sstr << std::endl;
2755+
image->drop();
2756+
}
2757+
raw_image->drop();
2758+
}
2759+
}
2760+
27352761
// IGameDef interface
27362762
// Under envlock
27372763
IItemDefManager* Client::getItemDefManager()

‎src/client.h

+2
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
464464

465465
LocalClientState getState() { return m_state; }
466466

467+
void makeScreenshot(IrrlichtDevice *device);
468+
467469
private:
468470

469471
// Virtual methods from con::PeerHandler

‎src/game.cpp

+9-32
Original file line numberDiff line numberDiff line change
@@ -933,12 +933,12 @@ bool nodePlacementPrediction(Client &client,
933933
static inline void create_formspec_menu(GUIFormSpecMenu** cur_formspec,
934934
InventoryManager *invmgr, IGameDef *gamedef,
935935
IWritableTextureSource* tsrc, IrrlichtDevice * device,
936-
IFormSource* fs_src, TextDest* txt_dest
936+
IFormSource* fs_src, TextDest* txt_dest, Client* client
937937
) {
938938

939939
if (*cur_formspec == 0) {
940940
*cur_formspec = new GUIFormSpecMenu(device, guiroot, -1, &g_menumgr,
941-
invmgr, gamedef, tsrc, fs_src, txt_dest, cur_formspec );
941+
invmgr, gamedef, tsrc, fs_src, txt_dest, cur_formspec, client);
942942
(*cur_formspec)->doPause = false;
943943
(*cur_formspec)->drop();
944944
}
@@ -972,7 +972,7 @@ static void show_chat_menu(GUIFormSpecMenu** cur_formspec,
972972
FormspecFormSource* fs_src = new FormspecFormSource(formspec);
973973
LocalFormspecHandler* txt_dst = new LocalFormspecHandler("MT_CHAT_MENU", client);
974974

975-
create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst);
975+
create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst, NULL);
976976
}
977977

978978
static void show_deathscreen(GUIFormSpecMenu** cur_formspec,
@@ -993,7 +993,7 @@ static void show_deathscreen(GUIFormSpecMenu** cur_formspec,
993993
FormspecFormSource* fs_src = new FormspecFormSource(formspec);
994994
LocalFormspecHandler* txt_dst = new LocalFormspecHandler("MT_DEATH_SCREEN", client);
995995

996-
create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst);
996+
create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst, NULL);
997997
}
998998

999999
/******************************************************************************/
@@ -1060,7 +1060,7 @@ static void show_pause_menu(GUIFormSpecMenu** cur_formspec,
10601060
FormspecFormSource* fs_src = new FormspecFormSource(os.str());
10611061
LocalFormspecHandler* txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
10621062

1063-
create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst);
1063+
create_formspec_menu(cur_formspec, invmgr, gamedef, tsrc, device, fs_src, txt_dst, NULL);
10641064

10651065
(*cur_formspec)->doPause = true;
10661066
}
@@ -1966,7 +1966,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
19661966
PlayerInventoryFormSource* fs_src = new PlayerInventoryFormSource(&client);
19671967
TextDest* txt_dst = new TextDestPlayerInventory(&client);
19681968

1969-
create_formspec_menu(&current_formspec, &client, gamedef, tsrc, device, fs_src, txt_dst);
1969+
create_formspec_menu(&current_formspec, &client, gamedef, tsrc, device, fs_src, txt_dst, &client);
19701970

19711971
InventoryLocation inventoryloc;
19721972
inventoryloc.setCurrentPlayer();
@@ -2070,30 +2070,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
20702070
}
20712071
else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
20722072
{
2073-
irr::video::IImage* const raw_image = driver->createScreenShot();
2074-
if (raw_image) {
2075-
irr::video::IImage* const image = driver->createImage(video::ECF_R8G8B8,
2076-
raw_image->getDimension());
2077-
2078-
if (image) {
2079-
raw_image->copyTo(image);
2080-
irr::c8 filename[256];
2081-
snprintf(filename, sizeof(filename), "%s" DIR_DELIM "screenshot_%u.png",
2082-
g_settings->get("screenshot_path").c_str(),
2083-
device->getTimer()->getRealTime());
2084-
if (driver->writeImageToFile(image, filename)) {
2085-
std::wstringstream sstr;
2086-
sstr << "Saved screenshot to '" << filename << "'";
2087-
infostream << "Saved screenshot to '" << filename << "'" << std::endl;
2088-
statustext = sstr.str();
2089-
statustext_time = 0;
2090-
} else {
2091-
infostream << "Failed to save screenshot '" << filename << "'" << std::endl;
2092-
}
2093-
image->drop();
2094-
}
2095-
raw_image->drop();
2096-
}
2073+
client.makeScreenshot(device);
20972074
}
20982075
else if(input->wasKeyDown(getKeySetting("keymap_toggle_hud")))
20992076
{
@@ -2483,7 +2460,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
24832460
new TextDestPlayerInventory(&client,*(event.show_formspec.formname));
24842461

24852462
create_formspec_menu(&current_formspec, &client, gamedef,
2486-
tsrc, device, fs_src, txt_dst);
2463+
tsrc, device, fs_src, txt_dst, &client);
24872464

24882465
delete(event.show_formspec.formspec);
24892466
delete(event.show_formspec.formname);
@@ -3033,7 +3010,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
30333010
TextDest* txt_dst = new TextDestNodeMetadata(nodepos, &client);
30343011

30353012
create_formspec_menu(&current_formspec, &client, gamedef,
3036-
tsrc, device, fs_src, txt_dst);
3013+
tsrc, device, fs_src, txt_dst, &client);
30373014

30383015
current_formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
30393016
}

‎src/guiEngine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
189189
m_texture_source,
190190
m_formspecgui,
191191
m_buttonhandler,
192-
NULL);
192+
NULL, NULL);
193193

194194
m_menu->allowClose(false);
195195
m_menu->lockSize(true,v2u32(800,600));

‎src/guiFormSpecMenu.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4949
#include "porting.h"
5050
#include "main.h"
5151
#include "settings.h"
52+
#include "client.h"
5253

5354
#define MY_CHECKPOS(a,b) \
5455
if (v_pos.size() != 2) { \
@@ -71,7 +72,7 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
7172
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
7273
InventoryManager *invmgr, IGameDef *gamedef,
7374
ISimpleTextureSource *tsrc, IFormSource* fsrc, TextDest* tdst,
74-
GUIFormSpecMenu** ext_ptr) :
75+
GUIFormSpecMenu** ext_ptr, Client* client) :
7576
GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr),
7677
m_device(dev),
7778
m_invmgr(invmgr),
@@ -88,7 +89,8 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
8889
m_text_dst(tdst),
8990
m_ext_ptr(ext_ptr),
9091
m_font(dev->getGUIEnvironment()->getSkin()->getFont()),
91-
m_formspec_version(0)
92+
m_formspec_version(0),
93+
m_client(client)
9294
#ifdef __ANDROID__
9395
,m_JavaDialogFieldName(L"")
9496
#endif
@@ -2912,6 +2914,9 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
29122914
m_text_dst->gotText(narrow_to_wide("MenuQuit"));
29132915
}
29142916
return true;
2917+
} else if (m_client != NULL && event.KeyInput.PressedDown &&
2918+
(kp == getKeySetting("keymap_screenshot"))) {
2919+
m_client->makeScreenshot(m_device);
29152920
}
29162921
if (event.KeyInput.PressedDown &&
29172922
(event.KeyInput.Key==KEY_RETURN ||

‎src/guiFormSpecMenu.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3333
class IGameDef;
3434
class InventoryManager;
3535
class ISimpleTextureSource;
36+
class Client;
3637

3738
typedef enum {
3839
f_Button,
@@ -209,7 +210,8 @@ class GUIFormSpecMenu : public GUIModalMenu
209210
ISimpleTextureSource *tsrc,
210211
IFormSource* fs_src,
211212
TextDest* txt_dst,
212-
GUIFormSpecMenu** ext_ptr
213+
GUIFormSpecMenu** ext_ptr,
214+
Client* client
213215
);
214216

215217
~GUIFormSpecMenu();
@@ -294,6 +296,7 @@ class GUIFormSpecMenu : public GUIModalMenu
294296
InventoryManager *m_invmgr;
295297
IGameDef *m_gamedef;
296298
ISimpleTextureSource *m_tsrc;
299+
Client *m_client;
297300

298301
std::string m_formspec_string;
299302
InventoryLocation m_current_inventory_location;

0 commit comments

Comments
 (0)
Please sign in to comment.