Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: eri0o on Mon 27/07/2020 00:25:40

Title: failed attempt to port microui to agsscript
Post by: eri0o on Mon 27/07/2020 00:25:40
AGS game project: microgui.zip (https://drive.google.com/file/d/1IBLyxbddwJAxs3zGS7taSBnF-E_-AHuB/view?usp=sharing)

Sometimes things doesn't work and we have to move on. I read the source code of microui here (https://github.com/rxi/microui) and it looked fairly simple so I decided, wait, maybe I can port this to AGS Script and have a reasonable Immediate Gui that can be scripted and doesn't relies on plugins, maybe it can even be customized later.

Problem is, I think some of the code relies on some gl concepts that I could not figure out how to reasonably translate to AGS Script and it's API, I think... It all is around 1k AGS Script code lines.

So a code like this:

room1.asc
Code (ags) Select
// room script file
CheckBoxState* chkbox;

void repeatedly_execute_always()
{
  if(chkbox==null) chkbox = new CheckBoxState;
 
  ImGi.Begin();
  if(ImGi.BeginWindow("My Window", 32, 32, 160, 86))
  {
    int rows[] = new int[2];
    rows[0] = 60;
    rows[1] = -1;
    ImGi.LayoutRow(2, rows);
   
    ImGi.Label("First:");
    if(ImGi.Button("Button1"))
    {
      player.Say("Button1 pressed!"); 
    }
   
    ImGi.Label("Second:");
    if(ImGi.Button("Button2"))
    {
      player.Say("Button2 pressed!"); 
    }
 
    ImGi.EndWindow();
  }
  ImGi.End();
 
  r_render();
}


Is giving me this wrong output like this

(https://i.imgur.com/h12wyTt.png)

Instead of something more like this: (https://i.imgur.com/8a8r51o.png)

Anyway, at least I learned a bit more about immediate mode GUIs. Decided to leave the attempt here even if failed in case someone has looked into something similar in the past. I find GUIs that are defined through code easier to respond dynamically, to be able to dynamically add controls, auto arranging the controls in the layout and similar.
Title: Re: failed attempt to port microui to agsscript
Post by: eri0o on Sat 13/02/2021 15:23:05
Spoiler
(https://i.imgur.com/2MZ2yWJ.gif)
[close]

Decided to gave a little try again. Zip above is updated. It's still buggy... But at  least it is possible to render something and get some output from the previous code. :)
Title: Re: failed attempt to port microui to agsscript
Post by: eri0o on Sat 13/02/2021 21:30:21
It's almost working!

(https://i.imgur.com/6tPvQVD.gif)

Spoiler
Code (ags) Select
// room script file
CheckBoxState* chkbox;
ImGi_Real* myFloat;

function room_RepExec()
{
  if(chkbox==null) chkbox = new CheckBoxState;
  if(myFloat==null) myFloat = new ImGi_Real;
 
  ImGi.Begin();
   
  if(ImGi.BeginWindow("My Window", 32, 32, 130, 60))
  {

    int rows[] = new int[2];
    rows[0] = 70;
    rows[1] = 60;
    ImGi.LayoutRow(2, rows);
   
    ImGi.Label("First:");
    if(ImGi.Button("Button1"))
    {
      player.Say("Button1 pressed!"); 
    }
   
    ImGi.Label("Second:");
    if(ImGi.Button("Button2"))
    {
      //player.Say("Button2 pressed!"); 
      ImGi.OpenPopup("popup1");
    }
   
    if(ImGi.BeginPopup("popup1"))
    {
      ImGi.Label("Hello World!");   
      ImGi.EndPopup();
    }
   
    ImGi.CheckBox("mycheck",chkbox);
    ImGi.Slider(myFloat, 0.0, 4.0, 0.5);
 
    ImGi.EndWindow();
  }
  ImGi.End();
 
  r_render();
}
[close]
Title: Re: failed attempt to port microui to agsscript
Post by: eri0o on Sun 14/02/2021 03:03:30
There's a lot more working if someone is interested I updated the zip on top. I need to refactor some more things but it should be somewhat usable for simple things.

Unfortunately somewhere I broke something - need to migrate to GitHub to figure out what. If you use a dynamically sized column, passing -1 as width when setting the row as in the first example on top now causes an engine crash :(

Edit: I started to push this script module here https://github.com/ericoporto/ImGi

I think I am kicking some bugs out of it and may make a reduced version that works for at least most common usecases.

Edit: Released as a script module: https://www.adventuregamestudio.co.uk/forums/index.php?topic=58842.0

There's a lot of work to do to move the abstractions from C to AGS Script and I still don't know the proper way of doing some things. AGS Script doesn't have something like the ability to return a tuple and you being able to assign things to different variables right there or quickly initializing a dynamic array with a set of values.