News:

SimuTranslator
Make Simutrans speak your language.

[Code] Show windows.

Started by Yona-TYT, April 24, 2017, 06:13:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT

A small window of information for the scenario, I think it is very useful.

/gui/simwin.h

    magic_scenario_pop_ups,


/dataobj/scenario.cc

bool scenario_t::open_pop_ups_win(const char* err) const
{
    if (err) {
        koord pos = message_t::get_coord_from_text(err);
        if (pos != koord::invalid) {
            news_loc *si = new news_loc(err, pos);
            scr_coord xy( display_get_width() - si->get_windowsize().w, display_get_height() - si->get_windowsize().h-15 );
            create_win(xy.x, xy.y, si, w_do_not_delete, magic_scenario_pop_ups);
        }
        else {
            news_img *si = new news_img(err);
            scr_coord xy( display_get_width() - si->get_windowsize().w, display_get_height() - si->get_windowsize().h-15 );
            create_win(xy.x, xy.y, si, w_do_not_delete, magic_scenario_pop_ups);
        }       
        return false;
    }
    else {
        destroy_win(magic_scenario_pop_ups); //The window with a "null" value is destroyed
    }
    return true;
}


/dataobj/scenario.h

bool open_pop_ups_win( const char* text) const;

/script/api/api_gui.cc

        STATIC register_method(vm, &scenario_t::open_pop_ups_win, "open_pop_ups_win");


I would use it in this way:

    function is_chapter_completed(pl) {
        local percentage=0
        local test=coord3d(0,0,1)
        local txt=test.tostring()
        switch (this.step) {
            case 1:
                if (pot0==0){
                    gui.open_pop_ups_win("To proceed to the next step, rotate the map")
                    pot0=1
                }
                if (txt!="0,0,1") {
                    gui.open_pop_ups_win(null)   //destroy windows
                    this.next_step()
                }
                return percentage
                break
       
            case 2:
                if (pot1==0){
                    gui.open_pop_ups_win("To proceed to the next step, click on the statue located at ("+posnext.tostring()+") with the Query tool.")
                    pot1=1
                }

                return percentage
                break
            case 3:
                if (pot2==0){
                    gui.open_pop_ups_win("To continue to the next chapter click on ("+coord(postc.x1, postc.y1).tostring()+").")
                    pot2=1
                }
        }
        percentage=33*(this.step-1)+1
        return percentage
    }
     
    function is_work_allowed_here(pl, tool_id, pos) {

       local  result = translate("Action not allowed")
         
        switch (this.step)
        {
            case 1:
                break
            case 2: 
                if ( (tool_id == 4096) && (pos.x == posnext.x) && (pos.y == posnext.y) ){
                    result = this.next_step()
                    gui.open_pop_ups_win(null)   //destroy windows
                }
                break
            case 3:
                if ( (tool_id == 4096 ) && (pos.x >= postc.x1)&&(pos.x<=postc.x2)&&(pos.y>=postc.y1)&&(pos.y<=postc.y2)){
                    result = this.next_step()
                    gui.open_pop_ups_win(null)   //destroy windows
                    persistent.step=1
                }
                     
                break
        }
        if (tool_id == 4096){   
            result = null    // Always allow query tool
        }


        return result     
    }


Capture:


Dwachs

What is wrong with gui.add_message and add_message_at? At least, these will respect player's setting about messaging. Pop-ups can be quite annoying.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Quote from: Dwachs on April 25, 2017, 06:12:19 AM
What is wrong with gui.add_message and add_message_at?
Because I'm sure a novice player will not know how to configure the window for to be displayed on the screen. This also ensures that the player will not lose the message since the window does not close.


Quote from: Dwachs on April 25, 2017, 06:12:19 AM
Pop-ups can be quite annoying.
This window is not so annoying by the following rules:

1- It has a fixed position in the lower right corner.
2- Only one window is displayed at a time.

Yona-TYT

I do not think the window is a problem, tests this: tutorial-testt4.zip  ;)

Again I apologize for the double post.  :P