Added initial implementation of inventory window, contains basic layout with hardcoded values.

actorid
Jan Borsodi 15 years ago
parent 6a12ce313e
commit 0e1a761167

@ -5,6 +5,8 @@
#include <openengine/gui/layout.hpp>
#include <boost/array.hpp>
/*
This file contains classes corresponding to all the window layouts
defined in resources/mygui/ *.xml.
@ -268,5 +270,124 @@ namespace MWGui
}
}
};
class InventoryWindow : public OEngine::GUI::Layout
{
public:
enum CategoryMode
{
CM_All = 0, // All items
CM_Weapon = 1, // Only weapons
CM_Apparel = 2, // Apparel
CM_Magic = 3, // Magic
CM_Misc = 4 // Misc
};
InventoryWindow ()
: Layout("openmw_inventory_window_layout.xml")
, categoryMode(CM_All)
// color should be fetched from skin
, activeColor(0, 0, 1)
, inactiveColor(0.7, 0.7, 0.7)
{
setCoord(0, 200, 600, 400);
// These are just demo values, you should replace these with
// real calls from outside the class later.
mMainWidget->setCaption("Glass Frostsword");
setText("EncumbranceBarT", "176/210");
MyGUI::ProgressPtr pt;
getWidget(pt, "EncumbranceBar");
pt->setProgressRange(210);
pt->setProgressPosition(176);
MyGUI::WidgetPtr avatar;
getWidget(avatar, "Avatar");
// Adjust armor rating text to bottom of avatar widget
MyGUI::StaticTextPtr armor_rating;
getWidget(armor_rating, "ArmorRating");
armor_rating->setCaption("Armor: 11");
MyGUI::IntCoord coord = armor_rating->getCoord();
coord.top = avatar->getCoord().height - 4 - coord.height;
armor_rating->setCoord(coord);
names[0] = "All";
names[1] = "Weapon";
names[2] = "Apparel";
names[3] = "Magic";
names[4] = "Misc";
boost::array<CategoryMode, 5> categories = { {
CM_All, CM_Weapon, CM_Apparel, CM_Magic, CM_Misc
} };
// Initialize buttons with text and adjust sizes, also mark All as active button
int margin = 2;
int last_x = 0;
for (int i = 0; i < categories.size(); ++i)
{
CategoryMode mode = categories[i];
std::string name = names[mode];
name += "Button";
setText(name, names[mode]);
getWidget(buttons[mode], name);
MyGUI::ButtonPtr &button_pt = buttons[mode];
if (mode == CM_All)
button_pt->setTextColour(activeColor);
else
button_pt->setTextColour(inactiveColor);
MyGUI::IntCoord coord = button_pt->getCoord();
coord.left = last_x;
last_x += coord.width + margin;
button_pt->setCoord(coord);
button_pt->eventMouseButtonClick = MyGUI::newDelegate(this, &InventoryWindow::onCategorySelected);
}
}
void setCategory(CategoryMode mode)
{
MyGUI::ButtonPtr pt = getCategoryButton(categoryMode);
pt->setTextColour(inactiveColor);
pt = getCategoryButton(mode);
pt->setTextColour(activeColor);
categoryMode = mode;
}
MyGUI::ButtonPtr getCategoryButton(CategoryMode mode)
{
return buttons[mode];
}
void onCategorySelected(MyGUI::Widget *widget)
{
boost::array<CategoryMode, 5> categories = { {
CM_All, CM_Weapon, CM_Apparel, CM_Magic, CM_Misc
} };
for (int i = 0; i < categories.size(); ++i)
{
CategoryMode mode = categories[i];
if (widget == buttons[mode])
{
setCategory(mode);
return;
}
}
}
CategoryMode categoryMode; // Current category filter
MyGUI::ButtonPtr buttons[5]; // Button pointers
std::string names[5]; // Names of category buttons
MyGUI::Colour activeColor;
MyGUI::Colour inactiveColor;
};
}
#endif

@ -22,6 +22,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
menu = new MainMenu(w,h);
map = new MapWindow();
stats = new StatsWindow (environment.mWorld->getStore());
inventory = new InventoryWindow ();
console = new Console(w,h, environment, extensions);
// The HUD is always on
@ -38,6 +39,7 @@ WindowManager::~WindowManager()
delete map;
delete menu;
delete stats;
delete inventory;
}
void WindowManager::updateVisible()
@ -46,6 +48,7 @@ void WindowManager::updateVisible()
map->setVisible(false);
menu->setVisible(false);
stats->setVisible(false);
inventory->setVisible(false);
console->disable();
// Mouse is visible whenever we're not in game mode
@ -81,6 +84,7 @@ void WindowManager::updateVisible()
// Show the windows we want
map -> setVisible( eff & GW_Map );
stats -> setVisible( eff & GW_Stats );
inventory -> setVisible( eff & GW_Inventory );
return;
}

@ -36,6 +36,7 @@ namespace MWGui
class MapWindow;
class MainMenu;
class StatsWindow;
class InventoryWindow;
class Console;
enum GuiMode
@ -80,6 +81,7 @@ namespace MWGui
MapWindow *map;
MainMenu *menu;
StatsWindow *stats;
InventoryWindow *inventory;
Console *console;
MyGUI::Gui *gui;

@ -38,6 +38,7 @@ configure_file("${SDIR}/openmw.font.xml" "${DDIR}/openmw.font.xml" COPYONLY)
configure_file("${SDIR}/openmw_hud_box.skin.xml" "${DDIR}/openmw_hud_box.skin.xml" COPYONLY)
configure_file("${SDIR}/openmw_hud_energybar.skin.xml" "${DDIR}/openmw_hud_energybar.skin.xml" COPYONLY)
configure_file("${SDIR}/openmw_hud_layout.xml" "${DDIR}/openmw_hud_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_inventory_window_layout.xml" "${DDIR}/openmw_inventory_window_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_layers.xml" "${DDIR}/openmw_layers.xml" COPYONLY)
configure_file("${SDIR}/openmw_mainmenu_layout.xml" "${DDIR}/openmw_mainmenu_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_mainmenu_skin.xml" "${DDIR}/openmw_mainmenu_skin.xml" COPYONLY)

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout">
<Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 600 300" name="_Main">
<!-- Player enumbrance -->
<Widget type="Progress" skin="MW_Progress_Blue" position="8 8 212 18" name="EncumbranceBar">
<Widget type="StaticText" skin="ProgressText" position="0 0 212 18" align="Center" name="EncumbranceBarT"/>
</Widget>
<!-- Avatar -->
<Widget type="Widget" skin="MW_Box" position="8 32 212 166" name="Avatar">
<Widget type="StaticText" skin="ProgressText" position="0 -8 212 18" align="HCenter Bottom" name="ArmorRating"/>
</Widget>
<!-- Items in inventory -->
<Widget type="Widget" skin="MW_Box" position="228 32 300 166" name="Items"/>
<!-- Categories -->
<Widget type="Widget" position="228 8 300 18" align="ALIGN_TOP ALIGN_LEFT" name="Categories">
<Widget type="Button" skin="MW_Button" position="0 0 30 18" name="AllButton"/>
<Widget type="Button" skin="MW_Button" position="134 0 60 18" name="WeaponButton"/>
<Widget type="Button" skin="MW_Button" position="98 0 60 18" name="ApparelButton"/>
<Widget type="Button" skin="MW_Button" position="160 0 50 18" name="MagicButton"/>
<Widget type="Button" skin="MW_Button" position="214 0 45 18" name="MiscButton"/>
</Widget>
</Widget>
</MyGUI>
Loading…
Cancel
Save