From 10b06419ab454e8931a9b6502029bc298e8bce35 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 23 Dec 2010 22:35:53 +0200 Subject: changes to handing of digging (non backwards-compatible i guess) --- src/main.cpp | 165 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 118 insertions(+), 47 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index da727811e..cfc47bbb2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -167,6 +167,9 @@ TODO: Better handling of objects and mobs TODO: Draw big amounts of torches better (that is, throw them in the same meshbuffer (can the meshcollector class be used?)) +TODO: Check if the usage of Client::isFetchingBlocks() in + updateViewingRange() actually does something + Doing now: ====================================================================== @@ -270,6 +273,7 @@ extern void set_default_settings(); u16 g_selected_item = 0; IrrlichtDevice *g_device = NULL; +Client *g_client = NULL; /* GUI Stuff @@ -323,6 +327,46 @@ u32 getTimeMs() return g_irrlicht->getTime(); } +/* + Text input system +*/ + +struct TextDestSign : public TextDest +{ + TextDestSign(v3s16 blockpos, s16 id, Client *client) + { + m_blockpos = blockpos; + m_id = id; + m_client = client; + } + void gotText(std::wstring text) + { + std::string ntext = wide_to_narrow(text); + dstream<<"Changing text of a sign object: " + <sendSignText(m_blockpos, m_id, ntext); + } + + v3s16 m_blockpos; + s16 m_id; + Client *m_client; +}; + +struct TextDestChat : public TextDest +{ + TextDestChat(Client *client) + { + m_client = client; + } + void gotText(std::wstring text) + { + m_client->sendChatMessage(text); + m_client->addChatMessage(text); + } + + Client *m_client; +}; + class MyEventReceiver : public IEventReceiver { public: @@ -371,6 +415,14 @@ public: &g_active_menu_count))->drop(); return true; } + if(event.KeyInput.Key == irr::KEY_KEY_T) + { + TextDest *dest = new TextDestChat(g_client); + + (new GUITextInputMenu(guienv, guiroot, -1, + &g_active_menu_count, dest, + L""))->drop(); + } } // Material selection @@ -965,31 +1017,6 @@ private: s32 m_selection; }; -/* - Text input system -*/ - -struct TextDestSign : public TextDest -{ - TextDestSign(v3s16 blockpos, s16 id, Client *client) - { - m_blockpos = blockpos; - m_id = id; - m_client = client; - } - void gotText(std::wstring text) - { - std::string ntext = wide_to_narrow(text); - dstream<<"Changing text of a sign object: " - <sendSignText(m_blockpos, m_id, ntext); - } - - v3s16 m_blockpos; - s16 m_id; - Client *m_client; -}; - int main(int argc, char *argv[]) { /* @@ -1334,6 +1361,10 @@ int main(int argc, char *argv[]) gui::IGUIFont* font = guienv->getFont("../data/fontlucida.png"); if(font) skin->setFont(font); + + u32 text_height = font->getDimension(L"Hello, world!").Height; + dstream<<"text_height="<setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0)); skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255)); //skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(0,0,0,0)); @@ -1343,11 +1374,7 @@ int main(int argc, char *argv[]) const wchar_t *text = L"Loading and connecting..."; core::vector2d center(screenW/2, screenH/2); - core::dimension2d textd = font->getDimension(text); - std::cout<(70, 60, 795, 150), + false, true); + core::list chat_lines; + //chat_lines.push_back(L"Minetest-c55 up and running!"); + /* Some statistics are collected in these */ @@ -2033,7 +2070,7 @@ int main(int argc, char *argv[]) if(g_input->getLeftClicked() || (g_input->getLeftState() && nodepos != nodepos_old)) { - std::cout<getLeftClicked()) @@ -2042,23 +2079,28 @@ int main(int argc, char *argv[]) } if(g_input->getLeftState()) { - float dig_time_complete = 0.5; MapNode n = client.getNode(nodepos); + + // TODO: Get this from some table that is sent by server + float dig_time_complete = 0.5; if(n.d == CONTENT_STONE) dig_time_complete = 1.5; - float dig_time_complete0 = dig_time_complete+client.getAvgRtt()*2; - if(dig_time_complete0 < 0.0) - dig_time_complete0 = 0.0; - dig_index = (u16)((float)CRACK_ANIMATION_LENGTH - * dig_time/dig_time_complete0); + * dig_time/dig_time_complete); - if(dig_time > 0.125 && dig_index < CRACK_ANIMATION_LENGTH) + if(dig_index < CRACK_ANIMATION_LENGTH) { //dstream<<"dig_index="<getLeftReleased()) { - std::cout<getRightReleased()) @@ -2180,16 +2223,44 @@ int main(int argc, char *argv[]) } { - /*wchar_t temptext[100]; - swprintf(temptext, 100, - SWPRINTF_CHARSTRING, - infotext.substr(0,99).c_str() - ); - - guitext_info->setText(temptext);*/ - guitext_info->setText(infotext.c_str()); } + + /* + Get chat messages from client + */ + { + // Get messages + std::wstring message; + while(client.getChatMessage(message)) + { + chat_lines.push_back(message); + if(chat_lines.size() > 5) + { + core::list::Iterator + i = chat_lines.begin(); + chat_lines.erase(i); + } + } + // Append them to form the whole static text and throw + // it to the gui element + std::wstring whole; + for(core::list::Iterator + i = chat_lines.begin(); + i != chat_lines.end(); i++) + { + whole += (*i) + L'\n'; + } + chat_guitext->setText(whole.c_str()); + // Update gui element size and position + core::rect rect( + 10, + screensize.Y - 10 - text_height*chat_lines.size(), + screensize.X - 10, + screensize.Y - 10 + ); + chat_guitext->setRelativePosition(rect); + } /* Inventory -- cgit v1.2.3