From: Perttu Ahola Date: Wed, 22 Dec 2010 01:34:21 +0000 (+0200) Subject: missing files X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=4ec61b0ccdedecf54cd697d0b1cfa16aaf92bf82;p=zefram%2Fminetest%2Fminetest_engine.git missing files --- diff --git a/src/guiInventoryMenu.cpp b/src/guiInventoryMenu.cpp new file mode 100644 index 00000000..370ebd5d --- /dev/null +++ b/src/guiInventoryMenu.cpp @@ -0,0 +1,261 @@ +/* +Minetest-c55 +Copyright (C) 2010 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + + +#include "guiInventoryMenu.h" +#include "constants.h" + +void drawInventoryItem(gui::IGUIEnvironment* env, + InventoryItem *item, core::rect rect, + const core::rect *clip) +{ + gui::IGUISkin* skin = env->getSkin(); + if (!skin) + return; + video::IVideoDriver* driver = env->getVideoDriver(); + + video::ITexture *texture = NULL; + + if(item != NULL) + { + texture = item->getImage(); + } + + if(texture != NULL) + { + const video::SColor color(255,255,255,255); + const video::SColor colors[] = {color,color,color,color}; + driver->draw2DImage(texture, rect, + core::rect(core::position2d(0,0), + core::dimension2di(texture->getOriginalSize())), + clip, colors, false); + } + else + { + video::SColor bgcolor(128,128,128,128); + driver->draw2DRectangle(bgcolor, rect, clip); + } + + if(item != NULL) + { + gui::IGUIFont *font = skin->getFont(); + if(font) + { + core::rect rect2(rect.UpperLeftCorner, + (core::dimension2d(rect.getWidth(), 15))); + + video::SColor bgcolor(128,0,0,0); + driver->draw2DRectangle(bgcolor, rect2, clip); + + font->draw(item->getText().c_str(), rect2, + video::SColor(255,255,255,255), false, false, + clip); + } + } +} + +/* + GUIInventorySlot +*/ + +GUIInventorySlot::GUIInventorySlot(gui::IGUIEnvironment* env, + gui::IGUIElement* parent, s32 id, core::rect rect): + IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rect) +{ + m_item = NULL; +} + +void GUIInventorySlot::draw() +{ + if(!IsVisible) + return; + + drawInventoryItem(Environment, m_item, AbsoluteRect, + &AbsoluteClippingRect); + + gui::IGUIElement::draw(); +} + +bool GUIInventorySlot::OnEvent(const SEvent& event) +{ + /*if (!IsEnabled) + return IGUIElement::OnEvent(event);*/ + + switch(event.EventType) + { + case EET_MOUSE_INPUT_EVENT: + if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) + { + dstream<<"Slot pressed"<OnEvent(event) : false; +} + +/* + GUIInventoryMenu +*/ + +GUIInventoryMenu::GUIInventoryMenu(gui::IGUIEnvironment* env, + gui::IGUIElement* parent, s32 id, + Inventory *inventory): + IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, + core::rect(0,0,100,100)) +{ + m_inventory = inventory; + m_screensize_old = v2u32(0,0); + + resizeGui(); + + setVisible(false); +} + +GUIInventoryMenu::~GUIInventoryMenu() +{ +} + +void GUIInventoryMenu::resizeGui() +{ + video::IVideoDriver* driver = Environment->getVideoDriver(); + v2u32 screensize = driver->getScreenSize(); + if(screensize == m_screensize_old) + return; + m_screensize_old = screensize; + + for(u32 i=0; iremove(); + } + m_slots.clear(); + + core::rect rect( + screensize.X/2 - 560/2, + screensize.Y/2 - 300/2, + screensize.X/2 + 560/2, + screensize.Y/2 + 300/2 + ); + + DesiredRect = rect; + recalculateAbsolutePosition(false); + + //v2s32 size = rect.getSize(); + + core::rect imgsize(0,0,48,48); + v2s32 basepos(30, 30); + for(s32 i=0; i rect = imgsize + basepos + p; + GUIInventorySlot *item = + new GUIInventorySlot(Environment, this, -1, rect); + m_slots.push_back(item); + } + + update(); +} + +void GUIInventoryMenu::update() +{ + for(s32 i=0; isetItem(m_inventory->getItem(i)); + } +} + +void GUIInventoryMenu::draw() +{ + if(!IsVisible) + return; + + gui::IGUISkin* skin = Environment->getSkin(); + if (!skin) + return; + video::IVideoDriver* driver = Environment->getVideoDriver(); + + video::SColor bgcolor(140,0,0,0); + driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); + + gui::IGUIElement::draw(); +} + +bool GUIInventoryMenu::OnEvent(const SEvent& event) +{ + if(event.EventType==EET_KEY_INPUT_EVENT) + { + if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown) + { + setVisible(false); + return true; + } + if(event.KeyInput.Key==KEY_KEY_I && event.KeyInput.PressedDown) + { + setVisible(false); + return true; + } + } + if(event.EventType==EET_MOUSE_INPUT_EVENT) + { + if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) + { + } + } + if(event.EventType==EET_GUI_EVENT) + { + if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST + && isVisible()) + { + if(!canTakeFocus(event.GUIEvent.Element)) + { + dstream<<"GUIInventoryMenu: Not allowing focus change." + <getID()) + { + case 256: // continue + setVisible(false); + break; + case 257: // exit + dev->closeDevice(); + break; + }*/ + } + } + + return Parent ? Parent->OnEvent(event) : false; +} + + diff --git a/src/guiInventoryMenu.h b/src/guiInventoryMenu.h new file mode 100644 index 00000000..8bfade4c --- /dev/null +++ b/src/guiInventoryMenu.h @@ -0,0 +1,88 @@ +/* +Minetest-c55 +Copyright (C) 2010 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + + +#ifndef GUIINVENTORYMENU_HEADER +#define GUIINVENTORYMENU_HEADER + +#include "common_irrlicht.h" +#include "inventory.h" + +void drawInventoryItem(gui::IGUIEnvironment* env, + InventoryItem *item, core::rect rect, + const core::rect *clip=0); + +class GUIInventorySlot: public gui::IGUIElement +{ +public: + GUIInventorySlot(gui::IGUIEnvironment* env, + gui::IGUIElement* parent, s32 id, core::rect rect); + + void setItem(InventoryItem *item) + { + m_item = item; + } + + void draw(); + + bool OnEvent(const SEvent& event); + +private: + InventoryItem *m_item; +}; + +class GUIInventoryMenu : public gui::IGUIElement +{ +public: + GUIInventoryMenu(gui::IGUIEnvironment* env, + gui::IGUIElement* parent, s32 id, + Inventory *inventory); + ~GUIInventoryMenu(); + + /* + Remove and re-add (or reposition) stuff + */ + void resizeGui(); + + // Updates stuff from inventory to screen + void update(); + + void draw(); + + void launch() + { + setVisible(true); + Environment->setFocus(this); + } + + bool canTakeFocus(gui::IGUIElement *e) + { + return (e && (e == this || isMyChild(e))); + } + + bool OnEvent(const SEvent& event); + +private: + Inventory *m_inventory; + core::array m_slots; + v2u32 m_screensize_old; +}; + +#endif +