]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
xml: dialog options
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 9 Jan 2016 15:06:35 +0000 (10:06 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 9 Jan 2016 15:06:35 +0000 (10:06 -0500)
src/gameplay.cpp
src/ui.cpp
xml/playerSpawnHill1.xml

index 6637d239ce265ccda66504bbcff4ea8f324a8671..9cae698fd5df855220cd158cd81256c3dbe90961 100644 (file)
@@ -37,13 +37,14 @@ typedef struct {
        unsigned int index;
 } NPCDialog;
 
-std::vector<NPCDialog> npcd;
-std::vector<WorldXML>  earthxml;
-std::vector<World *>   earth;
+std::vector<NPCDialog>         npcd;
+std::vector<WorldXML>          earthxml;
+std::vector<World *>           earth;
+std::vector<XMLElement *>      dopt;
 
 int commonAIFunc(NPC *speaker){
        XMLDocument xml;
-       XMLElement *exml;
+       XMLElement *exml,*oxml;
        unsigned int idx;
        
        for(auto &n : npcd){
@@ -56,13 +57,51 @@ int commonAIFunc(NPC *speaker){
        for(auto &e : earthxml){
                if(e.ptr == currentWorld){
                        xml.LoadFile(e.file);
-                       exml = xml.FirstChildElement("Dialog")->FirstChildElement();
+                       
+                       exml = xml.FirstChildElement("Dialog");
+                       while(strcmp(exml->Attribute("name"),speaker->name))
+                               exml = exml->NextSiblingElement();
+                       
+                       exml = exml->FirstChildElement();
                        
                        do{
                                if(!strcmp(exml->Name(),"text")){
-                                       if(!strcmp(exml->Attribute("name"),speaker->name) && exml->UnsignedAttribute("id") == idx){
-                                               ui::dialogBox(speaker->name,"",false,exml->GetText());
-                                               ui::waitForDialog();
+                                       if(/*!strcmp(exml->Attribute("name"),speaker->name) &&*/ exml->UnsignedAttribute("id") == idx){
+                                               
+                                               if((oxml = exml->FirstChildElement("option"))){
+                                                       const char *op;
+                                                       char *bp1 = new char[1],*bp2,*tmp;
+                                                       unsigned int idx = 0;
+                                                       bp1[0] = '\0';
+                                                       while(oxml){
+                                                               op = oxml->Attribute("text");
+                                                               
+                                                               bp2 = new char[strlen(bp1) + strlen(op) + 2];
+                                                               strcpy(bp2,bp1);
+                                                               
+                                                               bp2[idx++] = ':';
+                                                               strcpy(bp2+idx,op);
+                                                               idx += strlen(op);
+                                                               
+                                                               tmp = bp1;
+                                                               bp1 = bp2;
+                                                               delete[] tmp;
+                                                               
+                                                               dopt.push_back(oxml);
+                                                               
+                                                               oxml = oxml->NextSiblingElement();
+                                                       }
+                                                       ui::dialogBox(speaker->name,bp1,false,exml->GetText());
+                                                       ui::waitForDialog();
+                                                       if(ui::dialogOptChosen){
+                                                               exml = dopt[ui::dialogOptChosen-1];
+                                                       }
+                                                       while(!dopt.empty())
+                                                               dopt.pop_back();
+                                               }else{
+                                                       ui::dialogBox(speaker->name,"",false,exml->GetText());
+                                                       ui::waitForDialog();
+                                               }
                                                if(exml->QueryUnsignedAttribute("nextid",&idx) == XML_NO_ERROR){
                                                        for(auto &n : npcd){
                                                                if(n.npc == speaker){
@@ -98,7 +137,8 @@ void initEverything(void){
        
        for(auto x : xmlFiles){
                if(strncmp(x.c_str(),".",1) && strncmp(x.c_str(),"..",2)){
-                       file = new char[4 + x.size()];
+                       file = new char[5 + x.size()];
+                       memset(file,0,5 + x.size());
                        strncpy(file,"xml/",4);
                        strcpy(file+4,x.c_str());
                        xml.LoadFile(file);
index ead9d8cc48cae1e1d246d1e437307b26bbe91cc8..6e33692dce172b295d8dc0a4f58d99f547041f64 100644 (file)
@@ -437,10 +437,11 @@ namespace ui {
                        dialogOptCount--;
                };
 
-               dialogOptChosen=0;
+               dialogOptCount = 0;
+               dialogOptChosen = 0;
                memset(&dialogOptLoc,0,sizeof(float)*12);
                
-               if(opt){
+               if(opt != NULL){
                        
                        soptbuf = new char[strlen(opt)+1];
                        strcpy(soptbuf,opt);
index c924d7e6af74a874324e84c84e71cc2bbaf7c6b5..94292ab54432f7376cc34e54dc0dee3977ba2b94 100644 (file)
@@ -9,14 +9,20 @@
 
 </World>
 
-<Dialog>
+<Dialog name="Ralph">
        
-       <text name="Ralph" id="0" nextid="1">
+       <text id="0">
                Hello there!
+               <option text="Hello" nextid="1" />
+               <option text="Frig" nextid="2" />
        </text>
        
-       <text name="Ralph" id="1">
-               Lol
+       <text id="1">
+               gg.
+       </text>
+       
+       <text id="2">
+               Frrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
        </text>
        
 </Dialog>