failed attempt to port microui to agsscript

Started by eri0o, Mon 27/07/2020 00:25:40

Previous topic - Next topic

eri0o

AGS game project: microgui.zip

Sometimes things doesn't work and we have to move on. I read the source code of microui here 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
// 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



Instead of something more like this:

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.

eri0o

#1
Spoiler
[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. :)

eri0o

It's almost working!



Spoiler
Code: ags
// 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]

eri0o

#3
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.

SMF spam blocked by CleanTalk