Browse Source

add ItemStack UIML view

Kolja Strohm 1 year ago
parent
commit
e41913cb4a

+ 22 - 22
FactoryCraft/CustomUIDX11PixelShader.h

@@ -355,10 +355,10 @@ ret
 
 const BYTE CustomUIDX11PixelShader[] =
 {
-     68,  88,  66,  67, 124,  85, 
-    223, 106, 137, 232,  14, 113, 
-     51, 130, 216, 121,  66, 193, 
-    227, 109,   1,   0,   0,   0, 
+     68,  88,  66,  67, 171, 201, 
+    199,  85, 115, 128, 158, 198, 
+    123, 194,  73,  66,  69, 176, 
+     71, 132,   1,   0,   0,   0, 
     192, 137,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
     252,   4,   0,   0, 188,   5, 
@@ -1625,10 +1625,10 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0, 148,  46,  49,   1, 
-    159,  65, 201, 100,   1,   0, 
-      0,   0,   6,  42, 177,  22, 
-    105, 168, 230,  71, 164, 200, 
-      8, 198,  63, 139, 208,  23, 
+    192, 168, 216, 100,   1,   0, 
+      0,   0,  45, 148,  49,  15, 
+     55,  88,  40,  79, 151,  58, 
+     76, 100, 250, 142, 212, 168, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   1,   0,   0,   0, 
       1,   0,   0,   0,   0,   0, 
@@ -1801,10 +1801,10 @@ const BYTE CustomUIDX11PixelShader[] =
       3,   0,  28,  19,   2,   0, 
      65,  36,   1,   0, 236, 179, 
       1,   0, 125, 226,   0,   0, 
-     21, 230,   0,   0, 147,  37, 
-      3,   0,  73,  20,   1,   0, 
-    153, 189,   3,   0, 197,  77, 
-      3,   0, 209,  10,   2,   0, 
+     21, 230,   0,   0, 133, 128, 
+      0,   0,  73,  20,   1,   0, 
+    153, 189,   3,   0,  19, 140, 
+      1,   0, 209,  10,   2,   0, 
      53, 174,   3,   0, 146, 230, 
       3,   0,  98, 163,   2,   0, 
     118,  19,   1,   0, 140, 144, 
@@ -3076,8 +3076,8 @@ const BYTE CustomUIDX11PixelShader[] =
      32,  32,  32,  32,  32,  32, 
      32,  32,  32,  32,  32,  32, 
      27, 226,  48,   1, 128,   0, 
-      0,   0, 152,  95,   3,  29, 
-    158, 196, 217,   1,   1,   0, 
+      0,   0,  73, 125, 221, 102, 
+    204, 205, 217,   1,   1,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -4330,13 +4330,13 @@ const BYTE CustomUIDX11PixelShader[] =
       8,  16,   0,   0,   1,   0, 
       0,   2,  14,   0,  23,  21, 
       0,  16,   0,   0,   3,   2, 
-     80,  66,   0,   0, 242, 241, 
+     16,  47,   0,   0, 242, 241, 
      10,   0,  24,  21,  10,  16, 
       0,   0,   1,   0,   1,   0, 
      10,   0,  24,  21,  11,  16, 
       0,   0,   1,   0,   0,   2, 
      14,   0,  23,  21,   0,   0, 
-      0,   0,  10,   2,  80,  66, 
+      0,   0,  10,   2,  16,  47, 
       0,   0, 242, 241,  10,   0, 
      24,  21,  13,  16,   0,   0, 
       1,   0,   1,   0,  10,   0, 
@@ -5806,11 +5806,11 @@ const BYTE CustomUIDX11PixelShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 159,  65, 201, 100, 
-      1,   0,   0,   0,   6,  42, 
-    177,  22, 105, 168, 230,  71, 
-    164, 200,   8, 198,  63, 139, 
-    208,  23, 174,   0,   0,   0, 
+     49,   1, 192, 168, 216, 100, 
+      1,   0,   0,   0,  45, 148, 
+     49,  15,  55,  88,  40,  79, 
+    151,  58,  76, 100, 250, 142, 
+    212, 168, 174,   0,   0,   0, 
      47,  76, 105, 110, 107,  73, 
     110, 102, 111,   0,  47, 110, 
      97, 109, 101, 115,   0,  47, 
@@ -5910,7 +5910,7 @@ const BYTE CustomUIDX11PixelShader[] =
       2,   0,   9,   0,  88,   9, 
       0,   0,   0,   0,   0,   0, 
     156,  13,   0,   0,   1,   0, 
-    105, 154,   0,   0,   0,   0, 
+    163, 143,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,  84, 101, 120, 116, 
     117, 114, 101,  80, 105, 120, 

+ 17 - 17
FactoryCraft/CustomUIDX11VertexShader.h

@@ -281,10 +281,10 @@ ret
 
 const BYTE CustomUIDX11VertexShader[] =
 {
-     68,  88,  66,  67,  95,  62, 
-      2,  87,  35, 249, 151,  64, 
-     93, 138, 129,  85, 129,  76, 
-    143,  67,   1,   0,   0,   0, 
+     68,  88,  66,  67,  93,  90, 
+     93,  57, 122, 213,  63, 168, 
+     91,  28, 153, 244,  90,  82, 
+    139, 247,   1,   0,   0,   0, 
     124, 103,   0,   0,   6,   0, 
       0,   0,  56,   0,   0,   0, 
      76,   4,   0,   0,   4,   5, 
@@ -1454,11 +1454,11 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0, 148,  46, 
-     49,   1, 159,  65, 201, 100, 
-      1,   0,   0,   0,  78,  50, 
-    172, 180, 254,  67, 209,  72, 
-    145,  74, 103, 239,  33,  51, 
-    237,  72,   0,   0,   0,   0, 
+     49,   1, 192, 168, 216, 100, 
+      1,   0,   0,   0, 234, 162, 
+     64, 102, 133,  53, 194,  70, 
+    177, 194,  88, 215, 116, 147, 
+     79, 245,   0,   0,   0,   0, 
       0,   0,   0,   0,   1,   0, 
       0,   0,   1,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -2393,8 +2393,8 @@ const BYTE CustomUIDX11VertexShader[] =
     106, 101,  99, 116, 105, 111, 
     110,  59,  13,  10, 125,  13, 
      10,  13,  27, 226,  48,   1, 
-    128,   0,   0,   0,   5, 132, 
-     31,  29, 158, 196, 217,   1, 
+    128,   0,   0,   0, 218,  25, 
+    250, 102, 204, 205, 217,   1, 
       1,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
@@ -4355,11 +4355,11 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,   0,   0, 
-    148,  46,  49,   1, 159,  65, 
-    201, 100,   1,   0,   0,   0, 
-     78,  50, 172, 180, 254,  67, 
-    209,  72, 145,  74, 103, 239, 
-     33,  51, 237,  72, 175,   0, 
+    148,  46,  49,   1, 192, 168, 
+    216, 100,   1,   0,   0,   0, 
+    234, 162,  64, 102, 133,  53, 
+    194,  70, 177, 194,  88, 215, 
+    116, 147,  79, 245, 175,   0, 
       0,   0,  47,  76, 105, 110, 
     107,  73, 110, 102, 111,   0, 
      47, 110,  97, 109, 101, 115, 
@@ -4459,7 +4459,7 @@ const BYTE CustomUIDX11VertexShader[] =
       0,   0,   2,   0,   9,   0, 
     148,   7,   0,   0,   0,   0, 
       0,   0, 220,   9,   0,   0, 
-      1,   0,  53, 210,   0,   0, 
+      1,   0,  21,  44,   0,   0, 
       0,   0,   0,   0,   0,   0, 
       0,   0,   0,   0,  84, 101, 
     120, 116, 117, 114, 101,  86, 

+ 19 - 15
FactoryCraft/Dialog.cpp

@@ -11,6 +11,7 @@
 #include "Equipment.h"
 #include "Globals.h"
 #include "InventoryView.h"
+#include "ItemStack.h"
 #include "ListView.h"
 #include "QuestGraph.h"
 #include "RecipieIngredient.h"
@@ -40,6 +41,7 @@ UIMLDialog::UIMLDialog(
     view->addKnownElement(new ListViewElement());
     view->addKnownElement(new QuestGraphElement());
     view->addKnownElement(new QuestGraphItemElement());
+    view->addKnownElement(new ItemStackElement());
     view->setOnMemberMouseEvent([](Framework::XML::Element& element,
                                     Framework::Zeichnung& z,
                                     MausEreignis me) {
@@ -253,21 +255,23 @@ const Framework::Text& UIMLDialog::getName() const
 void UIMLDialog::updateUIML(const char* uiml)
 {
     XML::Element* xml = new XML::Element(uiml);
-    view->setSize((int)xml->getAttributeValue("width"),
-        (int)xml->getAttributeValue("height"));
-    view->setUIML(uiml);
-    view->layout();
-    if (!xml->hasAttribute("width"))
-    {
-        view->setSize(view->calculateContentSize().x, view->getHeight());
-    }
-    if (!xml->hasAttribute("height"))
-    {
-        view->setSize(view->getBreite(), view->calculateContentSize().y);
-    }
-    Punkt oldSize = getSize();
-    setSize(view->getBreite() + 4, view->getHeight() + 24);
-    setPosition(getPosition() + (oldSize - getSize()) / 2);
+    uiFactory.initParam.bildschirm->postAction([this, xml]() {
+        view->setSize((int)xml->getAttributeValue("width"),
+            (int)xml->getAttributeValue("height"));
+        view->setUIML(xml);
+        view->layout();
+        if (!xml->hasAttribute("width"))
+        {
+            view->setSize(view->calculateContentSize().x, view->getHeight());
+        }
+        if (!xml->hasAttribute("height"))
+        {
+            view->setSize(view->getBreite(), view->calculateContentSize().y);
+        }
+        Punkt oldSize = getSize();
+        setSize(view->getBreite() + 4, view->getHeight() + 24);
+        setPosition(getPosition() + (oldSize - getSize()) / 2);
+    });
 }
 
 void UIMLDialog::close()

+ 2 - 0
FactoryCraft/FactoryCraft.vcxproj

@@ -207,6 +207,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClCompile Include="InventoryView.cpp" />
     <ClCompile Include="ItemBar.cpp" />
     <ClCompile Include="ItemList.cpp" />
+    <ClCompile Include="ItemStack.cpp" />
     <ClCompile Include="ItemType.cpp" />
     <ClCompile Include="ListView.cpp" />
     <ClCompile Include="Load.cpp" />
@@ -267,6 +268,7 @@ copy "..\..\..\..\..\Allgemein\Network\x64\Release\Network.dll" "network.dll"</C
     <ClInclude Include="InventoryView.h" />
     <ClInclude Include="ItemBar.h" />
     <ClInclude Include="ItemList.h" />
+    <ClInclude Include="ItemStack.h" />
     <ClInclude Include="ItemType.h" />
     <ClInclude Include="ListView.h" />
     <ClInclude Include="Load.h" />

+ 6 - 0
FactoryCraft/FactoryCraft.vcxproj.filters

@@ -250,6 +250,9 @@
     <ClCompile Include="QuestGraph.cpp">
       <Filter>Menu\uiml\quests</Filter>
     </ClCompile>
+    <ClCompile Include="ItemStack.cpp">
+      <Filter>Menu\uiml\quests</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Area.h">
@@ -429,6 +432,9 @@
     <ClInclude Include="QuestGraph.h">
       <Filter>Menu\uiml\quests</Filter>
     </ClInclude>
+    <ClInclude Include="ItemStack.h">
+      <Filter>Menu\uiml\quests</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <FxCompile Include="DX11CustomVertexShader.hlsl">

+ 10 - 0
FactoryCraft/Initialisierung.cpp

@@ -58,6 +58,16 @@ ObjTabelle* createObjTabelle(const Framework::UIInitParam& params)
     return ret;
 }
 
+Fenster* createFenster(const Framework::UIInitParam& params)
+{
+    Fenster* ret = Framework::defaultUI(params.schrift, params.bildschirm)
+                          .createFenster(params);
+    ret->setTitel("");
+    ret->zTTextFeld()->setRahmenFarbe(0xFF52525E);
+    ret->setRFarbe(0xFF52525E);
+    return ret;
+}
+
 Knopf* initKnopf(int x, int y, int br, int hö, __int64 style, char* titel)
 {
     Knopf* ret = uiFactory.createKnopf(uiFactory.initParam);

+ 1 - 0
FactoryCraft/Initialisierung.h

@@ -24,6 +24,7 @@ Knopf* createKnopf(const Framework::UIInitParam& params);
 TextFeld* createTextFeld(const Framework::UIInitParam& params);
 KontrollKnopf* createKontrollKnopf(const Framework::UIInitParam& params);
 ObjTabelle* createObjTabelle(const Framework::UIInitParam& params);
+Fenster* createFenster(const Framework::UIInitParam& params);
 
 Knopf* initKnopf(int x, int y, int br, int hö, __int64 style, char* titel);
 KontrollKnopf* initKontrollKnopf(

+ 96 - 0
FactoryCraft/ItemStack.cpp

@@ -0,0 +1,96 @@
+#include "ItemStack.h"
+
+#include <XML.h>
+
+#include "Globals.h"
+#include "UIMLToolTip.h"
+
+ItemStackElement::ItemStackElement()
+    : Framework::UIMLElement()
+{}
+
+bool ItemStackElement::isApplicableFor(Framework::XML::Element& element)
+{
+    return element.getName().istGleich("itemStack");
+}
+
+Framework::Zeichnung* ItemStackElement::parseElement(
+    Framework::XML::Element& element, Framework::UIMLContainer& generalFactory)
+{
+    ItemStackView* result = new ItemStackView(dynamic_cast<Framework::Schrift*>(
+        generalFactory.getFactory().initParam.schrift->getThis()));
+    updateElement(element, *result, generalFactory);
+    return result;
+}
+
+bool ItemStackElement::updateElement(Framework::XML::Element& element,
+    Framework::Zeichnung& z,
+    Framework::UIMLContainer& generalFactory)
+{
+    ItemStackView* view = dynamic_cast<ItemStackView*>(&z);
+    if (!view) return false;
+    view->setCount(element.getAttributeValue("count"));
+    auto tip = element.selectChildsByName("tip");
+    if (tip.exists())
+    {
+        view->setToolTip((Framework::RCPointer<Framework::XML::Element>)
+                             tip.getFirstElement());
+    }
+    int type = (int)element.getAttributeValue("type");
+    const ItemType* itemType = zItemType(type);
+    if (itemType)
+    {
+        view->setHintergrundBildZ(
+            dynamic_cast<Framework::Bild*>(itemType->zIcon()->getThis()));
+    }
+    return true;
+}
+
+ItemStackView::ItemStackView(Framework::Schrift* schrift)
+    : Framework::ZeichnungHintergrund(),
+      count("")
+{
+    setStyle(ZeichnungHintergrund::Style::Erlaubt
+             | ZeichnungHintergrund::Style::Sichtbar
+             | ZeichnungHintergrund::Style::Hintergrund
+             | ZeichnungHintergrund::Style::HBild
+             | ZeichnungHintergrund::Style::HAlpha
+             | ZeichnungHintergrund::Style::Rahmen);
+    setRahmenBreite(1);
+    setRahmenFarbe(0xFF52525E);
+    tr.setSchriftZ(schrift);
+    tr.setSchriftSize(12);
+}
+
+void ItemStackView::setCount(Framework::Text count)
+{
+    this->count = count;
+}
+
+void ItemStackView::setToolTip(Framework::XML::Element* zToolTipUIML)
+{
+    UIMLToolTip* tip = new UIMLToolTip();
+    tip->setUIML(zToolTipUIML->toString());
+    setToolTipZ(tip);
+}
+
+void ItemStackView::render(Framework::Bild& rObj)
+{
+    Framework::ZeichnungHintergrund::render(rObj);
+    if (rObj.setDrawOptions(pos, gr))
+    {
+        if (rObj.setDrawOptions(getRahmenBreite(),
+                getRahmenBreite(),
+                getInnenBreite(),
+                getInnenHeight()))
+        {
+            tr.renderText(getInnenBreite() - 5 - tr.getTextBreite(count),
+                getInnenHeight() - 5 - tr.getTextHeight(count),
+                count,
+                rObj,
+                0xFFFFFFFF);
+            rObj.releaseDrawOptions();
+        }
+        rObj.releaseDrawOptions();
+    }
+}

+ 32 - 0
FactoryCraft/ItemStack.h

@@ -0,0 +1,32 @@
+#pragma once
+
+#include <Schrift.h>
+#include <UIMLView.h>
+
+class ItemStackElement : public Framework::UIMLElement
+{
+public:
+    ItemStackElement();
+    //! prüft, ob dieses UIML Element für ein bestimmtes xml Element zuständig
+    //! ist
+    bool isApplicableFor(Framework::XML::Element& element) override;
+    //! erstellt eine neue Zeichnung zu einem gegebenen xml Element
+    Framework::Zeichnung* parseElement(Framework::XML::Element& element,
+        Framework::UIMLContainer& generalFactory) override;
+    bool updateElement(Framework::XML::Element& element,
+        Framework::Zeichnung& z,
+        Framework::UIMLContainer& generalFactory) override;
+};
+
+class ItemStackView : public Framework::ZeichnungHintergrund
+{
+private:
+    Framework::Text count;
+    Framework::TextRenderer tr;
+
+public:
+    ItemStackView(Framework::Schrift* schrift);
+    void setCount(Framework::Text count);
+    void setToolTip(Framework::XML::Element* zToolTipUIML);
+    void render(Framework::Bild& rObj) override;
+};

+ 1 - 0
FactoryCraft/Main.cpp

@@ -174,6 +174,7 @@ int KSGStart Framework::Start(Framework::Startparam p)
     uiFactory.createTextFeld = createTextFeld;
     uiFactory.createKontrollKnopf = createKontrollKnopf;
     uiFactory.createObjTabelle = createObjTabelle;
+    uiFactory.createFenster = createFenster;
     initMenus();
 
     RenderTh rTh;