diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/cheatMenu.cpp | 79 | ||||
-rw-r--r-- | src/gui/cheatMenu.h | 13 | ||||
-rw-r--r-- | src/script/lua_api/l_clientobject.cpp | 7 | ||||
-rw-r--r-- | src/script/lua_api/l_clientobject.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_inventoryaction.cpp | 45 | ||||
-rw-r--r-- | src/script/lua_api/l_inventoryaction.h | 34 |
6 files changed, 95 insertions, 85 deletions
diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp index e66fbc250..d441e8dfc 100644 --- a/src/gui/cheatMenu.cpp +++ b/src/gui/cheatMenu.cpp @@ -23,8 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "cheatMenu.h" #include <cstddef> -FontMode CheatMenu::fontStringToEnum(std::string str) { - if (str == "FM_Standard") +FontMode CheatMenu::fontStringToEnum(std::string str) +{ + if (str == "FM_Standard") return FM_Standard; else if (str == "FM_Mono") return FM_Mono; @@ -52,18 +53,21 @@ CheatMenu::CheatMenu(Client *client) : m_client(client) font_color = g_settings->getV3F("cheat_menu_font_color"); selected_font_color = g_settings->getV3F("cheat_menu_selected_font_color"); - m_bg_color = video::SColor(g_settings->getU32("cheat_menu_bg_color_alpha"), - bg_color.X, bg_color.Y, bg_color.Z); - - m_active_bg_color = video::SColor(g_settings->getU32("cheat_menu_active_bg_color_alpha"), - active_bg_color.X, active_bg_color.Y, active_bg_color.Z); + m_bg_color = video::SColor(g_settings->getU32("cheat_menu_bg_color_alpha"), + bg_color.X, bg_color.Y, bg_color.Z); + + m_active_bg_color = video::SColor( + g_settings->getU32("cheat_menu_active_bg_color_alpha"), + active_bg_color.X, active_bg_color.Y, active_bg_color.Z); m_font_color = video::SColor(g_settings->getU32("cheat_menu_font_color_alpha"), - font_color.X, font_color.Y, font_color.Z); + font_color.X, font_color.Y, font_color.Z); + + m_selected_font_color = video::SColor( + g_settings->getU32("cheat_menu_selected_font_color_alpha"), + selected_font_color.X, selected_font_color.Y, + selected_font_color.Z); - m_selected_font_color = video::SColor(g_settings->getU32("cheat_menu_selected_font_color_alpha"), - selected_font_color.X, selected_font_color.Y, selected_font_color.Z); - m_font = g_fontengine->getFont(FONT_SIZE_UNSPECIFIED, fontMode); if (!m_font) { @@ -137,64 +141,73 @@ void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug) void CheatMenu::drawHUD(video::IVideoDriver *driver, double dtime) { CHEAT_MENU_GET_SCRIPTPTR - + m_rainbow_offset += dtime; m_rainbow_offset = fmod(m_rainbow_offset, 6.0f); - + std::vector<std::string> enabled_cheats; - + int cheat_count = 0; - - for (auto category = script->m_cheat_categories.begin(); category != script->m_cheat_categories.end(); category++) { - for (auto cheat = (*category)->m_cheats.begin(); cheat != (*category)->m_cheats.end(); cheat++) { + + for (auto category = script->m_cheat_categories.begin(); + category != script->m_cheat_categories.end(); category++) { + for (auto cheat = (*category)->m_cheats.begin(); + cheat != (*category)->m_cheats.end(); cheat++) { if ((*cheat)->is_enabled()) { enabled_cheats.push_back((*cheat)->m_name); cheat_count++; } } } - + if (enabled_cheats.empty()) return; - + std::vector<video::SColor> colors; - + for (int i = 0; i < cheat_count; i++) { video::SColor color; f32 h = (f32)i * 2.0f / (f32)cheat_count - m_rainbow_offset; if (h < 0) h = 6.0f + h; f32 x = (1 - fabs(fmod(h, 2.0f) - 1.0f)) * 255.0f; - switch((int)h) { + switch ((int)h) { case 0: - color = video::SColor(255, 255, x, 0); break; + color = video::SColor(255, 255, x, 0); + break; case 1: - color = video::SColor(255, x, 255, 0); break; + color = video::SColor(255, x, 255, 0); + break; case 2: - color = video::SColor(255, 0, 255, x); break; + color = video::SColor(255, 0, 255, x); + break; case 3: - color = video::SColor(255, 0, x, 255); break; + color = video::SColor(255, 0, x, 255); + break; case 4: - color = video::SColor(255, x, 0, 255); break; + color = video::SColor(255, x, 0, 255); + break; case 5: - color = video::SColor(255, 255, 0, x); break; + color = video::SColor(255, 255, 0, x); + break; } colors.push_back(color); } - + core::dimension2d<u32> screensize = driver->getScreenSize(); - + u32 y = 5; - + int i = 0; for (std::string cheat : enabled_cheats) { - core::dimension2d<u32> dim = m_font->getDimension(utf8_to_wide(cheat).c_str()); + core::dimension2d<u32> dim = + m_font->getDimension(utf8_to_wide(cheat).c_str()); u32 x = screensize.Width - 5 - dim.Width; - + core::rect<s32> fontbounds(x, y, x + dim.Width, y + dim.Height); m_font->draw(cheat.c_str(), fontbounds, colors[i], false, false); - + y += dim.Height; i++; } diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h index 8be73c483..b15858a48 100644 --- a/src/gui/cheatMenu.h +++ b/src/gui/cheatMenu.h @@ -42,18 +42,15 @@ class CheatMenu public: CheatMenu(Client *client); - ClientScripting *getScript() - { - return m_client->getScript(); - } + ClientScripting *getScript() { return m_client->getScript(); } void draw(video::IVideoDriver *driver, bool show_debug); - + void drawHUD(video::IVideoDriver *driver, double dtime); void drawEntry(video::IVideoDriver *driver, std::string name, int number, - bool selected, bool active, - CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY); + bool selected, bool active, + CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY); void selectUp(); void selectDown(); @@ -82,6 +79,6 @@ private: gui::IGUIFont *m_font = nullptr; v2u32 m_fontsize; - + float m_rainbow_offset = 0.0; }; diff --git a/src/script/lua_api/l_clientobject.cpp b/src/script/lua_api/l_clientobject.cpp index d88b538a1..05b3e2850 100644 --- a/src/script/lua_api/l_clientobject.cpp +++ b/src/script/lua_api/l_clientobject.cpp @@ -146,7 +146,7 @@ int ClientObjectRef::l_punch(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - PointedThing pointed(gcao->getId(), v3f(0,0,0), v3s16(0,0,0), 0); + PointedThing pointed(gcao->getId(), v3f(0, 0, 0), v3s16(0, 0, 0), 0); getClient(L)->interact(INTERACT_START_DIGGING, pointed); return 0; } @@ -155,7 +155,7 @@ int ClientObjectRef::l_rightclick(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - PointedThing pointed(gcao->getId(), v3f(0,0,0), v3s16(0,0,0), 0); + PointedThing pointed(gcao->getId(), v3f(0, 0, 0), v3s16(0, 0, 0), 0); getClient(L)->interact(INTERACT_PLACE, pointed); return 0; } @@ -223,6 +223,5 @@ luaL_Reg ClientObjectRef::methods[] = {luamethod(ClientObjectRef, get_pos), luamethod(ClientObjectRef, get_attach), luamethod(ClientObjectRef, get_nametag), luamethod(ClientObjectRef, get_item_textures), - luamethod(ClientObjectRef, get_max_hp), - luamethod(ClientObjectRef, punch), + luamethod(ClientObjectRef, get_max_hp), luamethod(ClientObjectRef, punch), luamethod(ClientObjectRef, rightclick), {0, 0}}; diff --git a/src/script/lua_api/l_clientobject.h b/src/script/lua_api/l_clientobject.h index 521591444..a4516e047 100644 --- a/src/script/lua_api/l_clientobject.h +++ b/src/script/lua_api/l_clientobject.h @@ -60,7 +60,7 @@ private: // is_player(self) static int l_is_player(lua_State *L); - + // is_local_player(self) static int l_is_local_player(lua_State *L); diff --git a/src/script/lua_api/l_inventoryaction.cpp b/src/script/lua_api/l_inventoryaction.cpp index f3037ba83..f65137465 100644 --- a/src/script/lua_api/l_inventoryaction.cpp +++ b/src/script/lua_api/l_inventoryaction.cpp @@ -43,9 +43,9 @@ int LuaInventoryAction::l_apply(lua_State *L) std::ostringstream os(std::ios::binary); o->m_action->serialize(os); - + std::istringstream is(os.str(), std::ios_base::binary); - + InventoryAction *a = InventoryAction::deSerialize(is); getClient(L)->inventoryAction(a); @@ -69,29 +69,30 @@ int LuaInventoryAction::l_to(lua_State *L) int LuaInventoryAction::l_craft(lua_State *L) { LuaInventoryAction *o = checkobject(L, 1); - + if (o->m_action->getType() != IAction::Craft) return 0; - + std::string locStr; InventoryLocation loc; - + locStr = readParam<std::string>(L, 2); - + try { loc.deSerialize(locStr); dynamic_cast<ICraftAction *>(o->m_action)->craft_inv = loc; - } catch (SerializationError &) {} - + } catch (SerializationError &) { + } + return 0; } int LuaInventoryAction::l_set_count(lua_State *L) { LuaInventoryAction *o = checkobject(L, 1); - + s16 count = luaL_checkinteger(L, 2); - + switch (o->m_action->getType()) { case IAction::Move: ((IMoveAction *)o->m_action)->count = count; @@ -103,7 +104,7 @@ int LuaInventoryAction::l_set_count(lua_State *L) ((ICraftAction *)o->m_action)->count = count; break; } - + return 0; } @@ -127,23 +128,25 @@ LuaInventoryAction::~LuaInventoryAction() delete m_action; } -void LuaInventoryAction::readFullInventoryLocationInto(lua_State *L, InventoryLocation *loc, std::string *list, s16 *index) +void LuaInventoryAction::readFullInventoryLocationInto( + lua_State *L, InventoryLocation *loc, std::string *list, s16 *index) { try { loc->deSerialize(readParam<std::string>(L, 2)); std::string l = readParam<std::string>(L, 3); *list = l; *index = luaL_checkinteger(L, 4) - 1; - } catch (SerializationError &) {} + } catch (SerializationError &) { + } } int LuaInventoryAction::create_object(lua_State *L) { IAction type; std::string typeStr; - + typeStr = readParam<std::string>(L, 1); - + if (typeStr == "move") type = IAction::Move; else if (typeStr == "drop") @@ -206,11 +209,7 @@ void LuaInventoryAction::Register(lua_State *L) } const char LuaInventoryAction::className[] = "InventoryAction"; -const luaL_Reg LuaInventoryAction::methods[] = { - luamethod(LuaInventoryAction, apply), - luamethod(LuaInventoryAction, from), - luamethod(LuaInventoryAction, to), - luamethod(LuaInventoryAction, craft), - luamethod(LuaInventoryAction, set_count), - {0,0} -}; +const luaL_Reg LuaInventoryAction::methods[] = {luamethod(LuaInventoryAction, apply), + luamethod(LuaInventoryAction, from), luamethod(LuaInventoryAction, to), + luamethod(LuaInventoryAction, craft), + luamethod(LuaInventoryAction, set_count), {0, 0}}; diff --git a/src/script/lua_api/l_inventoryaction.h b/src/script/lua_api/l_inventoryaction.h index c1a96d010..a4cc6cbe5 100644 --- a/src/script/lua_api/l_inventoryaction.h +++ b/src/script/lua_api/l_inventoryaction.h @@ -20,44 +20,46 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "inventorymanager.h" #include "lua_api/l_base.h" -#define GET_MOVE_ACTION \ - LuaInventoryAction *o = checkobject(L, 1); \ - if (o->m_action->getType() == IAction::Craft) \ - return 0; \ +#define GET_MOVE_ACTION \ + LuaInventoryAction *o = checkobject(L, 1); \ + if (o->m_action->getType() == IAction::Craft) \ + return 0; \ MoveAction *act = dynamic_cast<MoveAction *>(o->m_action); -class LuaInventoryAction : public ModApiBase { +class LuaInventoryAction : public ModApiBase +{ private: InventoryAction *m_action; - - static void readFullInventoryLocationInto(lua_State *L, InventoryLocation *loc, std::string *list, s16 *index); - + + static void readFullInventoryLocationInto(lua_State *L, InventoryLocation *loc, + std::string *list, s16 *index); + static const char className[]; static const luaL_Reg methods[]; - + // Exported functions - + // garbage collector static int gc_object(lua_State *L); // __tostring metamethod static int mt_tostring(lua_State *L); - + // apply(self) static int l_apply(lua_State *L); - + // from(self, location, list, index) static int l_from(lua_State *L); - + // to(self, location, list, index) static int l_to(lua_State *L); - + // craft(self, location) static int l_craft(lua_State *L); // set_count(self, count) static int l_set_count(lua_State *L); - + public: LuaInventoryAction(const IAction &type); ~LuaInventoryAction(); @@ -67,6 +69,6 @@ public: static int create_object(lua_State *L); // Not callable from Lua static int create(lua_State *L, const IAction &type); - static LuaInventoryAction* checkobject(lua_State *L, int narg); + static LuaInventoryAction *checkobject(lua_State *L, int narg); static void Register(lua_State *L); }; |